diff --git a/.vscode/settings.json b/.vscode/settings.json index a4f87ee..f52dc45 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -29,4 +29,11 @@ "/.vscode/**", "/variables.s[ac]ss" ], + "compile-hero": { + "disable-compile-files-on-did-save-code": false, + "notification-toggle": false, + "javascript-output-directory": "dist/js/", + "javascript-output-toggle": false, + "watch": ["src/framework.js"], + } } \ No newline at end of file diff --git a/dist/framework.dev.js b/dist/framework.dev.js index 074f39c..aaf3a85 100644 --- a/dist/framework.dev.js +++ b/dist/framework.dev.js @@ -1,30 +1,40 @@ "use strict"; +function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + Object.defineProperty(exports, "__esModule", { value: true }); +Object.defineProperty(exports, "Core", { + enumerable: true, + get: function get() { + return _core.Framework; + } +}); +Object.defineProperty(exports, "selector", { + enumerable: true, + get: function get() { + return _selector.selector; + } +}); Object.defineProperty(exports, "Framework", { enumerable: true, get: function get() { - return _core.Framework; + return _framework.Framework; } }); -Object.defineProperty(exports, "f", { +Object.defineProperty(exports, "default", { enumerable: true, get: function get() { - return _core.Framework; - } -}); -Object.defineProperty(exports, "$", { - enumerable: true, - get: function get() { - return _core.Framework; + return _framework["default"]; } }); -var _core = require("./framework/core.js"); +var _core = require("./framework/core"); -require("./framework/selector.js"); +var CoreUtils = _interopRequireWildcard(require("./helpers")); + +var _selector = require("./framework/selector.js"); require("./framework/traversing.js"); @@ -148,8 +158,8 @@ require("./framework/elements/responsiveAccordionTabs.js"); -require("./framework/elements/deprecated.js"); +var _framework = _interopRequireWildcard(require("./entries/framework")); -require("./framework/exports/amd.js"); +function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } -require("./framework/exports/global.js"); \ No newline at end of file +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } \ No newline at end of file diff --git a/src/framework.js b/src/framework.js index 4c663db..375b009 100644 --- a/src/framework.js +++ b/src/framework.js @@ -1,6 +1,7 @@ -import { Framework } from "./framework/core.js"; +export { Framework as Core } from "./framework/core"; -import "./framework/selector.js"; +import * as CoreUtils from "./helpers"; +export { selector } from "./framework/selector.js"; import "./framework/traversing.js"; import "./framework/callbacks.js"; import "./framework/deferred.js"; @@ -62,8 +63,6 @@ import './framework/elements/toggler.js'; import './framework/elements/tooltip.js'; import './framework/elements/responsiveAccordionTabs.js'; -import "./framework/elements/deprecated.js"; -import "./framework/exports/amd.js"; -import "./framework/exports/global.js"; -export { Framework, Framework as f, Framework as $ }; \ No newline at end of file +export { Framework } from './entries/framework'; +export { default } from './entries/framework'; \ No newline at end of file diff --git a/src/framework/core.js b/src/framework/core.js index 50d2475..5079ca2 100644 --- a/src/framework/core.js +++ b/src/framework/core.js @@ -1,140 +1,139 @@ -(function(w){ - var Framework=function(el){ - return Framework.fn.init(el); - } - Framework.__proto__ = Framework.prototype = {}; - Framework.v={}; - Framework.f={}; - Framework.f.init=function(el){ +var Framework=function(el){ + return Framework.fn.init(el); +} +Framework.__proto__ = Framework.prototype = {}; +Framework.v={}; +Framework.f={}; +Framework.f.init=function(el){ - }; - Framework.fn.extend=function(name,func){ - if((typeof name) == "string"){ - Framework.extend(Framework.fn,{name:func}); - }else if((typeof name) == "object"){ - for (var n in name){ - Framework.fn.extend(n,name[n]); - } +}; +Framework.fn.extend=function(name,func){ + if((typeof name) == "string"){ + Framework.extend(Framework.fn,{name:func}); + }else if((typeof name) == "object"){ + for (var n in name){ + Framework.fn.extend(n,name[n]); } - return Framework.fn; - }; - Framework.extend=function(name,func){ - if((typeof name) == "string"){ - Framework[name] = func; - }else if(typeof name === typeof func === "object"){ - $keys=Object.keys(func); - for(var i=0; i<$keys.length; i++){ - var n=$keys[i]; - var v=func[n]; - name[n] = v; - } + } + return Framework.fn; +}; +Framework.extend=function(name,func){ + if((typeof name) == "string"){ + Framework[name] = func; + }else if(typeof name === typeof func === "object"){ + $keys=Object.keys(func); + for(var i=0; i<$keys.length; i++){ + var n=$keys[i]; + var v=func[n]; + name[n] = v; } - return Framework; - }; - Framework.extend(Framework.fn,{ - ready: function(callback){ - this[0].addEventListener('readystatechange', e => { - if(this[0].readyState === "complete"){ - callback(); - return true; - } - }); - }, - each: function(callback) { - if (callback && typeof(callback) == 'function') { - for (let i = 0; i < this.length; i++) { - callback(this[i], i); - } - return this; - } - }, - siblings: function(){ - return [...this[0].parentNode.children].filter(c=>c!=this[0]) - }, - addClass: function(className) { - this.each(function(el) { - el.classList.add(className); + } + return Framework; +}; +Framework.extend(Framework.fn,{ + ready: function(callback){ + this[0].addEventListener('readystatechange', e => { + if(this[0].readyState === "complete"){ + callback(); + return true; + } + }); + }, + each: function(callback) { + if (callback && typeof(callback) == 'function') { + for (let i = 0; i < this.length; i++) { + callback(this[i], i); + } + return this; + } + }, + siblings: function(){ + return [...this[0].parentNode.children].filter(c=>c!=this[0]) + }, + addClass: function(className) { + this.each(function(el) { + el.classList.add(className); + }) + return this; + }, + removeClass: function(className) { + this.each(function(el) { + el.classList.remove(className); + }) + return this; + }, + hasClass: function(className) { + return this[0].classList.contains(className); + }, + css: function(propertyObject) { + this.each(function(el) { + Object.assign(el.style,propertyObject); }) return this; - }, - removeClass: function(className) { + }, + attr: function(attr, value = null) { + let getattr = this; + if (value){ this.each(function(el) { - el.classList.remove(className); - }) - return this; - }, - hasClass: function(className) { - return this[0].classList.contains(className); - }, - css: function(propertyObject) { - this.each(function(el) { - Object.assign(el.style,propertyObject); - }) - return this; - }, - attr: function(attr, value = null) { - let getattr = this; - if (value){ - this.each(function(el) { - el.setAttribute(attr, value); - - }); - } else { - getattr = this[0].getAttribute(attr); - } - return getattr; - }, - html: function(data) { - if (data) { - this.each(function(el) { - el.innerHTML = data; - }) - } else { - return this[0].innerHTML; - } - return this; - }, - prepend: function(el){ - this[0].prepend(el); - return this; - }, - append: function(el){ - this[0].append(el); - return this; - }, - hide: function() { - this.each(function(el) { - el.style.display = "none"; + el.setAttribute(attr, value); + }); - return this; - }, - show: function() { - this.each(function(el) { - el.style.display = "block"; - }); - return this; - }, - on: function(event, child, callback = null) { - if (callback != null) { - let selector = child; - this.each(function(element) { - element.addEventListener(event, function(event) { - if (event.target.matches(selector + ', ' + selector + ' *')) { - callback.apply(event.target.closest(selector), arguments); - } - }) - }) - } else { - //if the callback argument is not present then assume the child argument is being use as callback - callback = child; - this.each(function(element) { - element.addEventListener(event, callback); - }) - } - - return this; + } else { + getattr = this[0].getAttribute(attr); } - }); - window.Framework &= Framework; -})(window); + return getattr; + }, + html: function(data) { + if (data) { + this.each(function(el) { + el.innerHTML = data; + }) + } else { + return this[0].innerHTML; + } + return this; + }, + prepend: function(el){ + this[0].prepend(el); + return this; + }, + append: function(el){ + this[0].append(el); + return this; + }, + hide: function() { + this.each(function(el) { + el.style.display = "none"; + }); + return this; + }, + show: function() { + this.each(function(el) { + el.style.display = "block"; + }); + return this; + }, + on: function(event, child, callback = null) { + if (callback != null) { + let selector = child; + this.each(function(element) { + element.addEventListener(event, function(event) { + if (event.target.matches(selector + ', ' + selector + ' *')) { + callback.apply(event.target.closest(selector), arguments); + } + }) + }) + } else { + //if the callback argument is not present then assume the child argument is being use as callback + callback = child; + this.each(function(element) { + element.addEventListener(event, callback); + }) + } + + return this; + } +}); + + export {Framework}; \ No newline at end of file diff --git a/src/framework/entries/framework.js b/src/framework/entries/framework.js new file mode 100644 index 0000000..ef6b4e1 --- /dev/null +++ b/src/framework/entries/framework.js @@ -0,0 +1,17 @@ +import $ from 'jquery'; + +import * as CoreUtils from "../helpers"; +import { Framework } from '../core'; +import { Ajax } from '../ajax'; +import { Selector } from '../selector'; + +Framework.extend("ajax",Ajax); +Framework.extend("selector",Selector); +export { + Framework, + CoreUtils, + Ajax, + Selector +} + +export default Framework; \ No newline at end of file diff --git a/src/framework/exports/amd.js b/src/framework/exports/amd.js deleted file mode 100644 index 81bb3d1..0000000 --- a/src/framework/exports/amd.js +++ /dev/null @@ -1,20 +0,0 @@ -import { Framework } from "../../framework.core.js"; - -// Register as a named AMD module, since Framework can be concatenated with other -// files that may use define, but not via a proper concatenation script that -// understands anonymous AMD modules. A named AMD is safest and most robust -// way to register. Lowercase framework is used because AMD module names are -// derived from file names, and Framework is normally delivered in a lowercase -// file name. Do this after creating the global so that if an AMD module wants -// to call noConflict to hide this version of Framework, it will work. - -// Note that for maximum portability, libraries that are not Framework should -// declare themselves as anonymous modules, and avoid setting a global if an -// AMD loader is present. Framework is a special case. For more information, see -// https://github.com/jrburke/requirejs/wiki/Updating-existing-libraries#wiki-anon - -if ( typeof define === "function" && define.amd ) { - define( "framework", [], function() { - return Framework; - } ); -} \ No newline at end of file diff --git a/src/framework/exports/global.js b/src/framework/exports/global.js deleted file mode 100644 index 630d73c..0000000 --- a/src/framework/exports/global.js +++ /dev/null @@ -1,28 +0,0 @@ -import { Framework } from "../../framework.core.js"; - -var - - // Map over jQuery in case of overwrite - _Framework = window.Framework, - - // Map over the $ in case of overwrite - _f = window.f; - -Framework.noConflict = function( deep ) { - if ( window.f === Framework ) { - window.f = _f; - } - - if ( deep && window.Framework === Framework ) { - window.Framework = _Framework; - } - - return Framework; -}; - -// Expose jQuery and $ identifiers, even in AMD -// (trac-7102#comment:10, gh-557) -// and CommonJS for browser emulators (trac-13566) -if ( typeof noGlobal === "undefined" ) { - window.Framework = window.f = Framework; -} \ No newline at end of file diff --git a/src/framework/helpers.js b/src/framework/helpers.js new file mode 100644 index 0000000..7756eb7 --- /dev/null +++ b/src/framework/helpers.js @@ -0,0 +1,90 @@ +var intval=() => { + return parseInt.apply(console,arguments); +}; +var floatval=() => { + return parseFloat.apply(console,arguments); +}; +var json_decode=() => { + return JSON.parse.apply(console,arguments); +} +var json_encode=() => { + return JSON.stringify.apply(console,arguments); +} +var explode = (selector, string) => { + return string.toString().split(selector); +} +var implode = (selector, array) => { + return array.join(selector); +} +var str_replace = (find,replace,string) => { + if(typeof find == "array"){ + var temp=""; + find.forEach(function(toFind){ + if(temp==""){ + temp=string.toString(); + } + temp=temp.replace(toFind,replace); + }); + return temp; + } + return string.replace(find,replace); +} +var is_int = (val) => { + if(parseInt(val) < parseFloat(val)){ + return false; + } + return true; +} +var is_float = (val) => { + if(parseInt(val) < parseFloat(val)){ + return true; + } + return false; +} +var isset = (val) => { + if((typeof val) !== "undefined"){ + return true; + } + return false; +} +var name_to_object= ($name) => { + $switch = $name.toLocaleLowerCase(); + switch($switch){ + case "function": + return Function; + break; + case "string": + return String; + break; + case "object": + return Object; + break; + case "array": + return Array; + break; + default: + if(isset(window[$name])){ + return window[$name]; + }else if(isset(document[$name])){ + return document[$name]; + }else { + return null; + } + break; + } +} +var instance_of = ($var, $class) => { + var $origin=$class; + if(typeof $class == "string"){ + $class=name_to_object($class); + } + if($class === null){ + console.warn("not implemented", $origin); + return false; + } + if($var instanceof $class){ + return true; + } + return false; +} +export {intval, floatval, json_decode, json_encode, explode, implode, str_replace, instance_of, is_int, is_float, isset}; \ No newline at end of file diff --git a/src/framework/isElement.js b/src/framework/isElement.js new file mode 100644 index 0000000..edbf422 --- /dev/null +++ b/src/framework/isElement.js @@ -0,0 +1,15 @@ +function isElement(obj) { + try { + //Using W3 DOM2 (works for FF, Opera and Chrome) + return obj instanceof HTMLElement; + } + catch(e){ + //Browsers not supporting W3 DOM2 don't have HTMLElement and + //an exception is thrown and we end up here. Testing some + //properties that all elements have (works on IE7) + return (typeof obj==="object") && + (obj.nodeType===1) && (typeof obj.style === "object") && + (typeof obj.ownerDocument ==="object"); + } +} +export {isElement}; \ No newline at end of file diff --git a/src/framework/selector.js b/src/framework/selector.js new file mode 100644 index 0000000..935db0b --- /dev/null +++ b/src/framework/selector.js @@ -0,0 +1,17 @@ +import { isElement } from "./isElement"; +import * as CoreUtils from "./helpers"; + +var Selector = function(obj, parentNode = document){ + if(typeof obj == "string"){ + return Selector.resolve_string_to_object(obj,parentNode); + }else if(isElement(obj)){ + return obj; + }else{ + return {}; + } +}; +Selector.prototype = Selector.__proto__ = {}; +Selector.resolve_string_to_object = (string,parentNode) =>{ + +}; +export {Selector}; \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..3695c73 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,6 @@ +{ + "buildOptions": { + "alwaysStrict": true, + "importHelpers": false + } +} \ No newline at end of file