├── js └── bundle.js ├── make ├── custom.js ├── check.js ├── list.js ├── a.js ├── init.js ├── tabs │ ├── reduce.js │ ├── index.js │ └── make.js ├── tabs.js ├── inputs.js ├── viewers.js ├── tabsBackup.js └── creator.js ├── ui.js ├── common.js ├── package.json ├── view.js ├── router.js ├── add.js ├── sketch.js ├── make.js ├── router ├── back.js ├── get.js ├── init.js ├── set.js └── nav.js ├── meta.js ├── index.js ├── set.js ├── request.js ├── time.js ├── wet.js ├── params.js ├── session.js ├── binder.js ├── get.js ├── data.js ├── idb.js ├── validate.js ├── loader.js └── README.md /js/bundle.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /make/custom.js: -------------------------------------------------------------------------------- 1 | const creator = require('./creator'); 2 | 3 | module.exports = { 4 | 5 | element : function(options){ 6 | if(!options.tag){ 7 | return engine.common.error('not_found-tag-custom-make-engine'); 8 | } 9 | return creator(options.tag,options); 10 | } 11 | 12 | }; 13 | -------------------------------------------------------------------------------- /ui.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | window.uiModules = {}; 4 | 5 | module.exports = { 6 | 7 | add:(name,modules)=>{ 8 | window.uiModules[name] = modules; 9 | }, 10 | 11 | 12 | getComp:(lib,comp)=>{ 13 | if(!window.uiModules[lib]){return false;} 14 | if(!window.uiModules[lib][comp]){return false;} else { 15 | return window.uiModules[lib][comp]; 16 | } 17 | } 18 | 19 | }; 20 | -------------------------------------------------------------------------------- /common.js: -------------------------------------------------------------------------------- 1 | module.exports= { 2 | 3 | kill : false, 4 | 5 | tell : function(message,control){ 6 | if(control == true || this.kill == true){ 7 | console.log('>>> ' + message); 8 | } 9 | return true; 10 | }, 11 | 12 | error : function(error,data){ 13 | if(data){ 14 | console.log(data); 15 | } 16 | console.log('!!! ' + error); 17 | return false; 18 | } 19 | 20 | }; 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vegana-engine", 3 | "version": "0.2.8", 4 | "description": "vengana workers provide routing view binder and make tools for making a vegana project", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [ 10 | "vegana-js", 11 | "js", 12 | "vegana-engine" 13 | ], 14 | "author": "akku", 15 | "license": "ISC", 16 | "dependencies": { 17 | "md5": "^2.2.1", 18 | "uniqid": "^5.0.3" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /make/check.js: -------------------------------------------------------------------------------- 1 | const common = require('../common'); 2 | 3 | module.exports = { 4 | 5 | check: function(object){ 6 | 7 | if(typeof(object) !== 'object'){ 8 | return common.error('invalid_object'); 9 | } 10 | 11 | //check parent property 12 | if(!object.hasOwnProperty('parent') == true){ 13 | return common.error('not_found-parent'); 14 | } 15 | if(typeof(object.parent) !== 'string'){ 16 | return common.error('not_found-parent'); 17 | } 18 | 19 | return true; 20 | 21 | } 22 | 23 | }; 24 | -------------------------------------------------------------------------------- /view.js: -------------------------------------------------------------------------------- 1 | function doo(id,what){ 2 | let get = document.getElementById(id); 3 | if(get == null){ 4 | return false; 5 | } 6 | if(what == 'show'){ 7 | get.style.display = 'block'; 8 | } else if (what == 'hide'){ 9 | get.style.display = 'none'; 10 | } else if (what == 'remove'){ 11 | get.remove(); 12 | } 13 | return id; 14 | } 15 | 16 | module.exports= { 17 | 18 | hide : (id)=>{ 19 | return doo(id,'hide'); 20 | }, 21 | show : (id)=>{ 22 | return doo(id,'show'); 23 | }, 24 | remove : (id)=>{ 25 | return doo(id,'remove'); 26 | }, 27 | 28 | }; 29 | -------------------------------------------------------------------------------- /router.js: -------------------------------------------------------------------------------- 1 | const log = false; 2 | const initWorker = require('./router/init'); 3 | const navWorker = require('./router/nav'); 4 | const getWorker = require('./router/get'); 5 | const setWorker = require('./router/set'); 6 | const back = require('./router/back'); 7 | 8 | window.onpopstate = function(){ 9 | back.nav_back(); 10 | } 11 | 12 | let active = { 13 | page:null, 14 | cont:null, 15 | panel:null 16 | }; 17 | 18 | let built = { 19 | page:[], 20 | cont:[], 21 | panel:[], 22 | tab:[], 23 | comp:[] 24 | }; 25 | 26 | let route = [],closeures = []; 27 | 28 | let track = { 29 | cont:{}, 30 | panel:{}, 31 | tabs:{}, 32 | comp:{} 33 | }; 34 | 35 | let mods = { 36 | page:{}, 37 | cont:{}, 38 | panel:{} 39 | }; 40 | 41 | module.exports = { 42 | 43 | //nav data 44 | closeures:closeures, 45 | active:active, 46 | built:built, 47 | route:route, 48 | track:track, 49 | mods:mods, 50 | back:back, 51 | 52 | //functions 53 | get : getWorker, 54 | set : setWorker, 55 | navigate : navWorker, 56 | init : initWorker 57 | 58 | }; 59 | -------------------------------------------------------------------------------- /add.js: -------------------------------------------------------------------------------- 1 | const common = require('./common'); 2 | const log = false; 3 | 4 | module.exports = { 5 | 6 | object : function(key,object){ 7 | common.tell('adding global function',log); 8 | if(!key){ 9 | return common.error('not_found-key'); 10 | } 11 | if(!object){ 12 | return common.error('not_found-object'); 13 | } 14 | engine['global']['object'][key] = object; 15 | return true; 16 | }, 17 | 18 | function : function(key,func){ 19 | common.tell('adding global function',log); 20 | if(!key){ 21 | return common.error('not_found-key'); 22 | } 23 | if(!func){ 24 | return common.error('not_found-func'); 25 | } 26 | engine['global']['function'][key] = func; 27 | return true; 28 | }, 29 | 30 | comp : function(key,mod){ 31 | common.tell('adding global comp',log); 32 | if(!key){ 33 | return common.error('not_found-key'); 34 | } 35 | if(!mod){ 36 | return common.error('not_found-module'); 37 | } 38 | engine['global']['comp'][key] = mod; 39 | return true; 40 | } 41 | 42 | }; 43 | -------------------------------------------------------------------------------- /sketch.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | let book = { 4 | fonts:{}, 5 | colors:{} 6 | }; 7 | 8 | module.exports = { 9 | 10 | colors:{ 11 | add:(name,val)=>{ 12 | book.colors[name] = val; 13 | }, 14 | get:(name)=>{ 15 | return book.colors[name]; 16 | } 17 | }, 18 | 19 | fonts:{ 20 | add:async (tag,name,location,style,global_url)=>{ 21 | return new Promise((resolve,reject)=>{ 22 | if((window.hasOwnProperty('is_electron') || window.hasOwnProperty('is_cordova') && !global_url)){ 23 | location = location; 24 | } else { 25 | if(!global_url){ 26 | if(location[0] !== "/"){ 27 | location = "/" + location; 28 | } 29 | location = baseHref + location; 30 | } 31 | } 32 | location = "URL(" + location + ")"; 33 | const run = new FontFace(name,location); 34 | run.load() 35 | .then((d)=>{ 36 | document.fonts.add(d); 37 | book.fonts[tag] = name; 38 | resolve(); 39 | }) 40 | .catch((e)=>{ 41 | reject(e); 42 | }); 43 | }); 44 | }, 45 | get:(tag)=>{ 46 | return book.fonts[tag]; 47 | } 48 | } 49 | 50 | }; 51 | -------------------------------------------------------------------------------- /make.js: -------------------------------------------------------------------------------- 1 | const initImport = require('./make/init'); 2 | const viewersImport = require('./make/viewers'); 3 | const inputsImport = require('./make/inputs'); 4 | const listImport = require('./make/list'); 5 | const customImport = require('./make/custom'); 6 | const tabsImport = require('./make/tabs/index'); 7 | const a = require('./make/a.js'); 8 | 9 | module.exports = { 10 | 11 | a:a, 12 | 13 | //init 14 | init : initImport, 15 | //viewers 16 | div:viewersImport.div, 17 | card:viewersImport.card, 18 | text:viewersImport.text, 19 | span:viewersImport.span, 20 | p:viewersImport.p, 21 | heading:viewersImport.heading, 22 | image:viewersImport.image, 23 | addClass:viewersImport.addClass, 24 | removeClass:viewersImport.removeClass, 25 | style:viewersImport.style, 26 | message:viewersImport.message, 27 | tabs:tabsImport, 28 | 29 | //inputs 30 | select:inputsImport.select, 31 | input:inputsImport.input, 32 | upload:inputsImport.upload, 33 | textarea:inputsImport.textarea, 34 | checkBox:inputsImport.checkBox, 35 | checkbox:inputsImport.checkBox, 36 | button:inputsImport.button, 37 | enableButton:inputsImport.enableButton, 38 | 39 | //lists 40 | list:listImport.list, 41 | listItem:listImport.listItem, 42 | listItems:listImport.listItems, 43 | 44 | //custom 45 | element:customImport.element 46 | 47 | }; 48 | -------------------------------------------------------------------------------- /router/back.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | module.exports = { 4 | 5 | nav_back : function(){ 6 | 7 | if(engine.router.closeures.length > 1){ 8 | let closeures = engine.router.closeures; 9 | if(closeures.length === 0){return false;} 10 | let last = closeures[closeures.length - 1]; 11 | last(true); 12 | engine.router.closeures.pop(); 13 | return true; 14 | } 15 | 16 | if(engine.router.route.length > 1){ 17 | let route = engine.router.route; 18 | route.pop(); 19 | let last = route[route.length - 1]; 20 | engine.router.navigate.to[last.type](last.mod,null); 21 | engine.router.route.pop(); 22 | window.history.replaceState("object or string", null, last.url); 23 | } 24 | 25 | }, 26 | 27 | close:{ 28 | 29 | new:(func)=>{ 30 | engine.router.closeures.push(func); 31 | }, 32 | 33 | pop:()=>{ 34 | let closeures = engine.router.closeures; 35 | if(closeures.length === 0){return false;} 36 | engine.router.closeures.pop(); 37 | return true; 38 | }, 39 | 40 | back:()=>{ 41 | let closeures = engine.router.closeures; 42 | if(closeures.length === 0){return false;} 43 | let last = closeures[closeures.length - 1]; 44 | last(true); 45 | engine.router.closeures.pop(); 46 | return true; 47 | } 48 | 49 | } 50 | 51 | }; 52 | -------------------------------------------------------------------------------- /meta.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | module.exports = { 4 | 5 | add:(options)=>{ 6 | if(!options.name){return engine.common.error('not_found-name-add-meta-engine');} 7 | if(document.querySelector('meta[name="' + options.name + '"]')){ 8 | return engine.common.error('already_exists-meta_tag-add-meta-engine=>"you might wanna update the meta tag, not set it again."'); 9 | } 10 | var meta = document.createElement('meta'); 11 | if(options.href){meta.httpEquiv = options.href;} 12 | meta.content = options.content; 13 | meta.name = options.name; 14 | document.getElementsByTagName('head')[0].appendChild(meta); 15 | return true; 16 | }, 17 | 18 | update:(options)=>{ 19 | let get = document.querySelector('meta[name="' + options.name + '"]'); 20 | if(!get){ 21 | let check = engine.meta.add(options); 22 | if(!check){ 23 | return engine.common.error('failed-add_meta_tag-update-meta-engine'); 24 | } else { 25 | get = document.querySelector('meta[name="' + options.name + '"]'); 26 | } 27 | } 28 | get.setAttribute("content", options.content); 29 | return true; 30 | }, 31 | 32 | delete:(name)=>{ 33 | let get = document.querySelector('meta[name="' + name + '"]'); 34 | if(get){ 35 | get.remove(); 36 | return true; 37 | } else { 38 | return engine.common.error('not_found-meta_tag-delete-meta-engine'); 39 | } 40 | } 41 | 42 | }; 43 | -------------------------------------------------------------------------------- /router/get.js: -------------------------------------------------------------------------------- 1 | const common = require('../common'); 2 | const log = false; 3 | 4 | module.exports = { 5 | 6 | pageModule : function(pageName){ 7 | 8 | common.tell('fetching pageModule',log); 9 | 10 | if(!pageName){ 11 | return common.error('not_found-inputs'); 12 | } 13 | if(!window.pageModules[pageName]){ 14 | return common.error('not_found-pageModule'); 15 | } else { 16 | return window.pageModules[pageName]; 17 | } 18 | 19 | }, 20 | 21 | contModule : function(pageName,contName){ 22 | 23 | common.tell('fetching contModule',log); 24 | 25 | if(!pageName || !contName){ 26 | return common.error('not_found-inputs'); 27 | } 28 | if(!window.pageModules[pageName].contModules[contName]){ 29 | return common.error('not_found-pageModule'); 30 | } else { 31 | return window.pageModules[pageName].contModules[contName]; 32 | } 33 | 34 | }, 35 | 36 | panelModule : function(pageName,contName,panelName){ 37 | 38 | common.tell('fetching panelModule',log); 39 | 40 | if(!pageName || !contName || !panelName){ 41 | return common.error('not_found-inputs'); 42 | } 43 | if(!window.pageModules[pageName].contModules[contName].panelModules[panelName]){ 44 | return common.error('not_found-pageModule'); 45 | } else { 46 | return window.pageModules[pageName].contModules[contName].panelModules[panelName]; 47 | } 48 | 49 | }, 50 | 51 | baseHref : function(){ 52 | return window.baseHref; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /router/init.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | function build(parent,type,mod,data,cls){ 4 | 5 | //check parent 6 | let get = document.getElementById(parent); 7 | if(get == null){ 8 | return common.error('invalid_parent : ' + parent); 9 | } 10 | 11 | //make router 12 | let router = document.createElement("div"); 13 | 14 | if(type == 'comp'){ 15 | router.id = parent + '-router-' + engine.uniqid() + '-' + type; 16 | } else { 17 | router.id = parent + '-router-' + type; 18 | } 19 | 20 | if(cls){ 21 | router.className = cls; 22 | } else { 23 | router.className = 'router-' + type; 24 | } 25 | 26 | let routerApp = require('../router'); 27 | 28 | //append router 29 | get.appendChild(router); 30 | if(mod && type == 'comp'){ 31 | routerApp.track.comp[router.id] = router.id + mod.ref; 32 | routerApp.built.comp.push(router.id + mod.ref); 33 | mod.init(router.id,data); 34 | } 35 | return router.id; 36 | 37 | } 38 | 39 | module.exports = { 40 | 41 | conts : function(parent,cls){ 42 | if(parent == null){ 43 | return common.error('no_parent_found : ' + parent); 44 | } 45 | return build(parent,'cont',null,null,cls); 46 | }, 47 | 48 | panels : function(parent,cls){ 49 | if(parent == null){ 50 | return common.error('no_parent_found : ' + parent); 51 | } 52 | return build(parent,'panel',null,null,cls); 53 | }, 54 | 55 | comps : function(parent,mod,data,cls){ 56 | if(parent == null){ 57 | return common.error('no_parent_found : ' + parent); 58 | } 59 | return build(parent,'comp',mod,data,cls); 60 | } 61 | 62 | }; 63 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const make = require('./make'); 2 | const view = require('./view'); 3 | const router = require('./router'); 4 | const common = require('./common'); 5 | const binder = require('./binder'); 6 | const loader = require('./loader'); 7 | const session = require('./session'); 8 | const request = require('./request'); 9 | const get = require('./get'); 10 | const wet = require('./wet'); 11 | const validate = require('./validate'); 12 | const set = require('./set'); 13 | const add = require('./add'); 14 | const data = require('./data'); 15 | const time = require('./time'); 16 | const params = require('./params'); 17 | const meta = require('./meta'); 18 | const sketch = require('./sketch'); 19 | const ui = require("./ui"); 20 | 21 | const md5 = require('md5'); 22 | const uniqid = require('uniqid'); 23 | 24 | //common.tell('one'); 25 | 26 | let hooks = { 27 | pages:{}, 28 | conts:{}, 29 | panels:{}, 30 | comps:{} 31 | }; 32 | 33 | module.exports = { 34 | ui:ui, 35 | sketch:sketch, 36 | meta:meta, 37 | add:add, 38 | binder:binder, 39 | make:make, 40 | view:view, 41 | router:router, 42 | common:common, 43 | loader:loader, 44 | session:session, 45 | request:request.send, 46 | validate:validate, 47 | get:get, 48 | wet:wet, 49 | set:set, 50 | data:data, 51 | time:time, 52 | params:params, 53 | global:{ 54 | function:{}, 55 | comp:new Proxy({},{ 56 | set(obj, prop, value){ 57 | obj[prop] = value; 58 | if(hooks.comps.hasOwnProperty(prop) == true){ 59 | hooks.comps[prop](); 60 | } 61 | } 62 | }), 63 | object:{} 64 | }, 65 | hooks:hooks, 66 | md5:md5, 67 | uniqid:uniqid, 68 | app_version:null 69 | }; 70 | -------------------------------------------------------------------------------- /set.js: -------------------------------------------------------------------------------- 1 | const log = false; 2 | 3 | module.exports = { 4 | 5 | pageTitle : function(title){ 6 | 7 | engine.common.tell('setting pageTitle',log); 8 | 9 | if(typeof(title) !== 'string'){ 10 | return engine.common.error('invalid-title-data_type'); 11 | } 12 | 13 | document.title = title; 14 | return true; 15 | 16 | }, 17 | 18 | input : { 19 | 20 | value : function(id,value){ 21 | let get = document.getElementById(id); 22 | if(get == null){ 23 | return engine.common.error('invalid-parent'); 24 | } 25 | get.value = value; 26 | return true; 27 | } 28 | 29 | }, 30 | 31 | style: function(id,styles){ 32 | 33 | if(!id || typeof(styles) !== 'object' || !styles.length || styles.length == 0){ 34 | return engine.common.error("not_found-id/styles"); 35 | } 36 | 37 | let get = document.getElementById(id); 38 | if(get == null){ 39 | return engine.common.error('invalid-parent'); 40 | } 41 | 42 | for(var i=0;i{ 61 | //console.log(response); 62 | 63 | if(typeof(response) == 'string'){ 64 | return reponseProcessor(response); 65 | } else { 66 | let data = response.json(); 67 | return data; 68 | } 69 | }) 70 | .catch((error)=>{ 71 | engine.common.error('request_error : ' + error); 72 | return engine.common.error('failed-request'); 73 | }); 74 | 75 | engine.common.tell('worker called',log); 76 | 77 | return worker; 78 | 79 | } 80 | 81 | }; 82 | -------------------------------------------------------------------------------- /make/list.js: -------------------------------------------------------------------------------- 1 | const creator = require('./creator'); 2 | 3 | module.exports = { 4 | 5 | list : function(options){ 6 | 7 | if(options.type !== 'ol' && options.type !== 'ul'){ 8 | options.type == 'ol'; 9 | } 10 | if(!options.data){ 11 | options.data = 0; 12 | } 13 | 14 | let list_id = creator(options.type,options); 15 | 16 | for(var i=0;i{ 26 | return make_list_item(options.list_id,options,options.itemClass,options.function,options.events,options.event); 27 | }, 28 | 29 | listItems : function(options){ 30 | 31 | if(!options.list_id){ 32 | return engine.common.error('not_found-list_id-listItems_make_engine'); 33 | } 34 | let items = options.data; 35 | for(var i in items){ 36 | make_list_item(options.list_id,items[i],options.itemClass,options.function,options.events,options.event); 37 | } 38 | return options.id; 39 | 40 | } 41 | 42 | }; 43 | 44 | function make_list_item(id,item,superClass,superFunction,superEvents,superEvent){ 45 | 46 | if(!item.id){ 47 | item.id = engine.uniqid(); 48 | } 49 | 50 | let cls = 'list-item'; 51 | if(item.class){ 52 | cls = item.class; 53 | } else if(superClass){ 54 | cls = superClass; 55 | } 56 | 57 | let func = item.function; 58 | if(!func && superFunction){ 59 | func = superFunction; 60 | } 61 | 62 | let local_function = (object)=>{ 63 | if(typeof(func) == 'function'){ 64 | func(object.id); 65 | } 66 | }; 67 | 68 | let events = item.events; 69 | if(!events && superEvents){ 70 | events = superEvents; 71 | } 72 | 73 | let eve = item.event; 74 | if(!eve && superEvent){ 75 | eve = superEvent; 76 | } 77 | 78 | let build = { 79 | id:item.id, 80 | parent:id, 81 | class:cls, 82 | text:item.text, 83 | function:local_function, 84 | event:eve, 85 | events:events 86 | }; 87 | 88 | return creator('li',build); 89 | 90 | } 91 | -------------------------------------------------------------------------------- /time.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | module.exports = { 4 | 5 | now : function(g){ 6 | let d;if(g){d = new Date(g);} else {d = new Date();} 7 | return d.getTime(); 8 | }, 9 | 10 | date : function(g){ 11 | let d;if(g){d = new Date(g);} else {d = new Date();} 12 | return d.getDate(); 13 | }, 14 | 15 | month : function(g){ 16 | let d;if(g){d = new Date(g);} else {d = new Date();} 17 | return (d.getMonth() + 1); 18 | }, 19 | 20 | year : function(g){ 21 | let d;if(g){d = new Date(g);} else {d = new Date();} 22 | return (d.getFullYear()); 23 | }, 24 | 25 | day : function(g){ 26 | let d;if(g){d = new Date(g);} else {d = new Date();} 27 | return (d.getDay() + 1); 28 | }, 29 | 30 | diff : { 31 | 32 | days : function(time1,time2){ 33 | 34 | let 35 | aHold = new Date(time1), 36 | bHold = new Date(time2), 37 | a,b; 38 | 39 | a = { 40 | day:aHold.getDate(), 41 | month:aHold.getMonth(), 42 | year:aHold.getFullYear(), 43 | hour:aHold.getHours(), 44 | minutes:aHold.getMinutes(), 45 | seconds:aHold.getSeconds() 46 | }; 47 | 48 | b = { 49 | day:bHold.getDate(), 50 | month:bHold.getMonth(), 51 | year:bHold.getFullYear(), 52 | hour:bHold.getHours(), 53 | minutes:bHold.getMinutes(), 54 | seconds:bHold.getSeconds() 55 | }; 56 | 57 | let base = 0; 58 | 59 | //check if same year 60 | if(a.year !== b.year){ 61 | let yearDiff = b.year - a.year; 62 | base += yearDiff * 365; 63 | } 64 | 65 | //check month 66 | if(a.month !== b.month){ 67 | let monthDiff = b.month - a.month; 68 | base += monthDiff * 30; 69 | } 70 | 71 | //check days 72 | if(a.day !== b.day){ 73 | let dayDiff = b.day - a.day; 74 | if(dayDiff > 0){ 75 | base += dayDiff; 76 | } 77 | } 78 | 79 | if(base > 0){ 80 | return base; 81 | } 82 | 83 | //check hours 84 | if(a.hour !== b.hour){ 85 | let hourDiff = b.hour - a.hour; 86 | base += hourDiff / 100; 87 | } 88 | 89 | return base; 90 | 91 | } 92 | 93 | } 94 | 95 | }; 96 | -------------------------------------------------------------------------------- /router/set.js: -------------------------------------------------------------------------------- 1 | const common = require('../common'); 2 | const log = false; 3 | 4 | module.exports = { 5 | 6 | pageModule : function(pageName,controller){ 7 | 8 | common.tell('activating pageModule : ' + controller.pageName,log); 9 | 10 | if(!pageName || !controller){ 11 | return common.error('not_found-inputs'); 12 | } 13 | if(typeof(controller) !== 'object'){ 14 | return common.error('invalid-controller'); 15 | } 16 | 17 | window.pageModules[pageName] = controller; 18 | window.pageList[pageName] = 'onboard'; 19 | 20 | return true; 21 | 22 | }, 23 | 24 | contModule : function(pageName,contName,controller){ 25 | 26 | common.tell('activating contModule : ' + controller.contName,log); 27 | 28 | if(!pageName || !contName || !controller){ 29 | return common.error('not_found-inputs'); 30 | } 31 | if(typeof(controller) !== 'object'){ 32 | return common.error('invalid-controller'); 33 | } 34 | 35 | window.pageModules[pageName].contModules[contName] = controller; 36 | window.pageModules[pageName].contList[contName] = 'onboard'; 37 | 38 | return true; 39 | 40 | }, 41 | 42 | panelModule : function(pageName,contName,panelName,controller){ 43 | 44 | common.tell('activating panelModule : ' + panelName,log); 45 | 46 | if(!pageName || !contName || !panelName || !controller){ 47 | return common.error('not_found-inputs'); 48 | } 49 | if(typeof(controller) !== 'object'){ 50 | return common.error('invalid-controller'); 51 | } 52 | 53 | window.pageModules[pageName].contModules[contName].panelModules[panelName] = controller; 54 | window.pageModules[pageName].contModules[contName].panelList[panelName] = 'onboard'; 55 | 56 | return true; 57 | 58 | }, 59 | 60 | baseHref : function(url){ 61 | 62 | common.tell('activating baseHref',log); 63 | 64 | let location; 65 | let protocol = window.location.protocol; 66 | let host = window.location.hostname; 67 | let port = window.location.port; 68 | 69 | let hold = ''; 70 | if(protocol && protocol !== 'file:'){ 71 | hold += protocol + '//'; 72 | } 73 | if(host){ 74 | hold += host; 75 | } 76 | if(port){ 77 | hold += ':' + port; 78 | } 79 | if(url && url !== '/'){ 80 | hold += '/' + url; 81 | } 82 | 83 | window.baseHref = hold; 84 | 85 | return true; 86 | 87 | } 88 | 89 | }; 90 | -------------------------------------------------------------------------------- /wet.js: -------------------------------------------------------------------------------- 1 | var address = null; 2 | 3 | //this function takes a authetication token from sessions api 4 | async function query(options){ 5 | 6 | // if(engine.session.check() == false){ 7 | // return engine.common.error('not_found-session'); 8 | // } 9 | if(typeof(options) !== 'object'){ 10 | return engine.common.error('invalid_options'); 11 | } 12 | 13 | 14 | if(!options.method){ 15 | options.method = 'POST'; 16 | } 17 | 18 | if(options){ 19 | if(typeof(options) == 'object'){ 20 | if(!options.url){ 21 | return engine.common.error('not_found-url=>options'); 22 | } 23 | if(!options.body){ 24 | return engine.common.error('not_found-body=>options'); 25 | } 26 | if(engine.session.check()){ 27 | let token = engine.session.get.token(); 28 | if(options.headers){ 29 | if(typeof(options.headers) !== 'object'){ 30 | options.headers['td-wet-token'] = token; 31 | } else { 32 | options.headers = { 33 | 'td-wet-token':token 34 | }; 35 | } 36 | } else { 37 | options.headers = { 38 | 'td-wet-token':token 39 | }; 40 | } 41 | } 42 | 43 | } 44 | } 45 | 46 | let worker = await engine.request(options); 47 | if(worker == false){ 48 | return engine.common.error('failed-wet_query'); 49 | } 50 | return worker; 51 | 52 | } 53 | 54 | module.exports = { 55 | 56 | address:address, 57 | 58 | api:{ 59 | 60 | get : function(){ 61 | return address; 62 | }, 63 | 64 | set : function(url){ 65 | address = url; 66 | return true; 67 | }, 68 | 69 | query : async function(options){ 70 | //this query is performed without authetication token 71 | if(address == null){ 72 | return engine.common.error('please set the api address first'); 73 | } 74 | if(!options){ 75 | return engine.common.error('not_found-options'); 76 | } 77 | if(options){ 78 | if(options.at){ 79 | options.url = address + options.at; 80 | let result = await query(options); 81 | if(result == false){ 82 | return engine.common.error('failed-wet_api_query'); 83 | } else { 84 | return result; 85 | } 86 | } else { 87 | return engine.common.error('not_found-options=>at'); 88 | } 89 | } 90 | return engine.common.error('invalid-options'); 91 | } 92 | 93 | }, 94 | 95 | query : query 96 | 97 | }; 98 | -------------------------------------------------------------------------------- /make/a.js: -------------------------------------------------------------------------------- 1 | 2 | const creator = require('./creator'); 3 | 4 | 5 | module.exports = (options)=>{ 6 | 7 | if(!options.href && options.type == 'url'){ 8 | return engine.common.error('not_found/invalid-href-a-make-engine'); 9 | } 10 | if(options.type !== 'url' && options.type !== 'local'){ 11 | return engine.common.error('not_found/invalid-type-a-make-engine'); 12 | } 13 | 14 | if(options.type == 'local'){ 15 | 16 | let href = window.baseHref; 17 | 18 | if(options.page){ 19 | let local = options.page; 20 | let replace = local.replace('Page',''); 21 | href += '/' + replace; 22 | } 23 | if(options.cont){ 24 | let local = options.cont; 25 | let replace = local.replace('Cont',''); 26 | href += '/' + replace; 27 | } 28 | if(options.panel){ 29 | let local = options.panel; 30 | let replace = local.replace('Panel',''); 31 | href += '/' + replace; 32 | } 33 | 34 | if(options.params){ 35 | for(var key in options.params){ 36 | if(href.indexOf('?') < 0){ 37 | href += '?' + key + '=' + options.params[key]; 38 | } else { 39 | href += '&' + key + '=' + options.params[key]; 40 | } 41 | } 42 | } 43 | 44 | options.href = href; 45 | 46 | //options.href = '#'; 47 | 48 | let router = 'to'; 49 | if(options.new == true){ 50 | router = 'new'; 51 | } 52 | 53 | options.function = (object,data,e)=>{ 54 | 55 | e.preventDefault(); 56 | e.stopPropagation(); 57 | 58 | if(options.baseFunction){ 59 | options.baseFunction(); 60 | } 61 | 62 | if(options.superFunction){ 63 | options.superFunction(); 64 | return; 65 | } 66 | 67 | if(options.page && !options.cont && !options.panel){ 68 | const page = engine.get.pageModule(options.page); 69 | if(page){ 70 | engine.router.navigate[router].page(page,options.data); 71 | } 72 | } 73 | 74 | if(options.page && options.cont && !options.panel){ 75 | const cont = engine.get.contModule(options.page,options.cont); 76 | if(cont){ 77 | engine.router.navigate[router].cont(cont,options.data); 78 | } 79 | } 80 | 81 | if(options.page && options.cont && options.panel){ 82 | const panel = engine.get.panelModule(options.page,options.cont,options.panel); 83 | if(panel){ 84 | engine.router.navigate[router].panel(panel,options.data); 85 | } 86 | } 87 | 88 | return true; 89 | 90 | }// local function 91 | 92 | }// make the href local 93 | 94 | 95 | 96 | return creator('a',options); 97 | 98 | }; 99 | -------------------------------------------------------------------------------- /make/init.js: -------------------------------------------------------------------------------- 1 | const common = require('../common'); 2 | const log = false; 3 | 4 | async function build(type,id,parent,cls){ 5 | 6 | common.tell('initiating ' + type,log); 7 | 8 | //security checks 9 | if(id == null){ 10 | return common.error('not_found-id'); 11 | } 12 | if(parent == null){ 13 | return common.error('not-found-parent'); 14 | } 15 | 16 | //check parent 17 | let get = document.getElementById(parent); 18 | if(get == null){ 19 | return common.error('invalid_parent'); 20 | } 21 | 22 | //make element 23 | let div = document.createElement("div"); 24 | div.id = id; 25 | if(cls){ 26 | div.className = cls; 27 | } 28 | get.appendChild(div); 29 | 30 | let router = require('../router'); 31 | 32 | if(type == 'page' && !engine.router.active.page){ 33 | let pageName = id.split('-')[1] + 'Page'; 34 | let mod = engine.get.pageModule(pageName); 35 | engine.router.route.push({ 36 | url:window.baseHref, 37 | mod:mod, 38 | type:'page' 39 | }); 40 | } 41 | 42 | if(type == 'page' && !engine.router.active.page){ 43 | let hold = id.split('-')[1] + 'Page'; 44 | let app = engine.get.pageModule(hold); 45 | if(app){ 46 | if(app.trackers){ 47 | let trackers = app.trackers; 48 | if(trackers.title){ 49 | engine.set.pageTitle(trackers.title); 50 | } 51 | if(trackers.meta){ 52 | for(var i in trackers.meta){ 53 | engine.meta.update(trackers.meta[i]); 54 | } 55 | } 56 | if(trackers.function){ 57 | if(trackers.function_data){ 58 | trackers.function(trackers.function_data); 59 | } else { 60 | trackers.function(); 61 | } 62 | } 63 | } 64 | } 65 | } 66 | 67 | //update router catalogs here 68 | if(type == 'page'){ 69 | //router.route.push(id); 70 | router.built.page.push(id); 71 | router.active.page = id; 72 | router.navigate.url.add.page(id); 73 | } else if(type == 'cont'){ 74 | //router.route.push(id); 75 | router.built.cont.push(id); 76 | router.active.cont = id; 77 | router.track.cont[parent] = id; 78 | } else if(type == 'panel'){ 79 | //router.route.push(id); 80 | router.built.panel.push(id); 81 | router.active.panel = id; 82 | router.track.panel[parent] = id; 83 | } 84 | 85 | //page-router 86 | 87 | 88 | 89 | return id; 90 | 91 | } 92 | 93 | module.exports = { 94 | 95 | page : function(id,cls){ 96 | return build('page',id,'page-router',cls); 97 | }, 98 | 99 | comp : function(id,parent,cls){ 100 | return build('comp',id,parent,cls); 101 | }, 102 | 103 | cont : function(id,parent,cls){ 104 | return build('cont',id,parent,cls); 105 | }, 106 | 107 | panel : function(id,parent,cls){ 108 | return build('panel',id,parent,cls); 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /make/tabs/reduce.js: -------------------------------------------------------------------------------- 1 | const common = require('../../common'); 2 | const checkBaseOptions = require('../check').check; 3 | const view = require('../../view'); 4 | const router = require('../../router'); 5 | const gets = require('../../get'); 6 | const log = false; 7 | const viewers = require('../viewers'); 8 | 9 | module.exports = reduce; 10 | 11 | function reduce(parent,navButtonClass){ 12 | 13 | common.tell('reducing tabs',log); 14 | 15 | //check parent 16 | let linksCont = document.getElementById(parent); 17 | if(linksCont == null){ 18 | return common.error('invalid_parent'); 19 | } 20 | let linksContId = linksCont.id; 21 | 22 | if(!linksCont.length){ 23 | if(linksCont.length == 0){ 24 | return common.error('invalid_length-linksCont'); 25 | } 26 | } 27 | 28 | let nodes = linksCont.childNodes; 29 | let lastNode = nodes[nodes.length - 1]; 30 | 31 | //left button 32 | let leftButton = document.createElement('div'); 33 | leftButton.id = linksContId + '-button-left'; 34 | leftButton.style.float = 'left'; 35 | leftButton.style.width = '10%'; 36 | if(navButtonClass){ 37 | leftButton.className = navButtonClass; 38 | } 39 | if(gets.body.width() > 640){ 40 | leftButton.style.display = 'none'; 41 | } 42 | leftButton.innerHTML = '↫'; 43 | linksCont.insertBefore(leftButton,nodes[0]); 44 | 45 | //right button 46 | let rightButton = document.createElement('div'); 47 | rightButton.id = linksContId + '-button-right'; 48 | rightButton.style.float = 'left'; 49 | rightButton.style.width = '10%'; 50 | if(navButtonClass){ 51 | rightButton.className = navButtonClass; 52 | } 53 | if(gets.body.width() > 640){ 54 | rightButton.style.display = 'none'; 55 | } 56 | rightButton.innerHTML = '↬'; 57 | linksCont.appendChild(rightButton); 58 | 59 | if(linksCont.scrollHeight > 50){ 60 | 61 | rightButton.style.display = 'block'; 62 | leftButton.style.display = 'block'; 63 | 64 | //while loop counter 65 | let count = 2; 66 | 67 | //remove the excess tabs 68 | while(linksCont.scrollHeight > 50 && count < nodes.length){ 69 | let hideThisTab = nodes[nodes.length - count]; 70 | view.hide(hideThisTab.id); 71 | count++; 72 | } 73 | 74 | function tabSlide(hide,show){ 75 | view.hide(hide); 76 | view.show(show); 77 | } 78 | 79 | let firstTabIndex = 1; 80 | let nextTabIndex = nodes.length - count + 1; 81 | 82 | rightButton.addEventListener('click',()=>{ 83 | if(nextTabIndex < nodes.length - 1){ 84 | tabSlide(nodes[firstTabIndex].id,nodes[nextTabIndex].id); 85 | firstTabIndex++,nextTabIndex++; 86 | } 87 | }); 88 | 89 | leftButton.addEventListener('click',()=>{ 90 | if(firstTabIndex >= 2){ 91 | firstTabIndex--,nextTabIndex--; 92 | tabSlide(nodes[nextTabIndex].id,nodes[firstTabIndex].id); 93 | } 94 | }); 95 | 96 | } 97 | //if statement ends here 98 | 99 | return true; 100 | 101 | } 102 | -------------------------------------------------------------------------------- /params.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | function fetch(){ 4 | 5 | let params = {}; 6 | 7 | if (/\?(.+?\=.+){1}/.test(document.URL)) { 8 | document.URL.split('?')[1].split('&').forEach(function(both){ 9 | var e = both.split('='); 10 | params[e[0]] = e[1]; 11 | }); 12 | } 13 | 14 | return params; 15 | 16 | } 17 | 18 | function post(params){ 19 | 20 | let url = document.URL.split('?')[0]; 21 | for(var i in params){ 22 | if(i && params[i]){ 23 | if(url.indexOf("?") < 0){ 24 | url += '?' + i + '=' + params[i]; 25 | } else { 26 | url += '&' + i + '=' + params[i]; 27 | } 28 | } 29 | } 30 | 31 | window.history.pushState("object or string", null, url); 32 | 33 | return true; 34 | 35 | } 36 | 37 | module.exports = { 38 | 39 | get : fetch, 40 | 41 | add:(key,val)=>{ 42 | 43 | let params = fetch(); 44 | 45 | if(typeof(key) == 'string'){ 46 | params[key] = val; 47 | } 48 | 49 | if(typeof(key) == 'object'){ 50 | for(var i in key){ 51 | if(i && key[i]){ 52 | params[i] = key[i]; 53 | } 54 | } 55 | } 56 | 57 | post(params); 58 | 59 | }, 60 | 61 | delete:(key)=>{ 62 | 63 | let params = fetch(); 64 | 65 | if(params.hasOwnProperty(key)){ 66 | delete params[key]; 67 | post(params); 68 | } 69 | 70 | return true; 71 | 72 | }, 73 | 74 | native:{ 75 | 76 | get:()=>{ 77 | 78 | let result = { 79 | page:null, 80 | cont:null, 81 | panel:null, 82 | custom:[], 83 | params:fetch() 84 | }; 85 | 86 | let url = document.URL; 87 | if(url.indexOf('?') >= 0){ 88 | url = url.split('?')[0]; 89 | } 90 | url = url.replace(window.location.protocol,''); 91 | url = url.replace(window.location.hostname,''); 92 | url = url.replace(window.location.port,''); 93 | url = url.replace('//',''); 94 | url = url.replace(':',''); 95 | 96 | let natives = url.split('/'); 97 | 98 | if(natives.length == 0){ 99 | return result; 100 | } 101 | if(natives[0].length == 0){ 102 | delete natives.splice(0,1); 103 | } 104 | if(natives[0]){ 105 | result.page = natives[0] + 'Page'; 106 | natives.splice(0,1); 107 | } 108 | if(natives[0]){ 109 | result.cont = natives[0] + 'Cont'; 110 | natives.splice(0,1); 111 | } 112 | if(natives[0]){ 113 | result.panel = natives[0] + 'Panel'; 114 | natives.splice(0,1); 115 | } 116 | if(natives.length > 0){ 117 | result.custom = natives; 118 | } 119 | 120 | return result; 121 | 122 | }, 123 | 124 | push:(data)=>{ 125 | 126 | let hold = document.URL.split('?'); 127 | 128 | if(hold.length > 1){ 129 | url = hold[0] + '/' + data + '?' + hold[1]; 130 | } else { 131 | url = hold[0] + '/' + data; 132 | } 133 | 134 | window.history.pushState("object or string", null, url); 135 | return url; 136 | 137 | } 138 | 139 | } 140 | 141 | } 142 | -------------------------------------------------------------------------------- /session.js: -------------------------------------------------------------------------------- 1 | const log = false; 2 | 3 | let token,user,user_type,uid,session_type; 4 | 5 | function check(){ 6 | 7 | let type = engine.data.get('session_type','local'); 8 | if(!type){ 9 | return false; 10 | } 11 | 12 | if(type == 'temp'){ 13 | token = engine.data.get('token','session'); 14 | user = engine.data.get('user','session'); 15 | user_type = engine.data.get('user_type','session'); 16 | uid = engine.data.get('uid','session'); 17 | session_type = engine.data.get('session_type','local'); 18 | } else { 19 | token = engine.data.get('token','local'); 20 | user = engine.data.get('user','local'); 21 | user_type = engine.data.get('user_type','local'); 22 | uid = engine.data.get('uid','local'); 23 | session_type = engine.data.get('session_type','local'); 24 | } 25 | 26 | if(!token){ 27 | return false; 28 | } 29 | 30 | return true; 31 | 32 | } 33 | 34 | function end(){ 35 | 36 | let type = engine.data.get('session_type','local'); 37 | if(!type){ 38 | return false; 39 | } 40 | 41 | if(type == 'temp'){ 42 | token = engine.data.delete('token','session'); 43 | user = engine.data.delete('user','session'); 44 | user_type = engine.data.delete('user_type','session'); 45 | uid = engine.data.delete('uid','session'); 46 | session_type = engine.data.delete('session_type','local'); 47 | } else { 48 | token = engine.data.delete('token','local'); 49 | user = engine.data.delete('user','local'); 50 | user_type = engine.data.delete('user_type','local'); 51 | uid = engine.data.delete('uid','local'); 52 | session_type = engine.data.delete('session_type','local'); 53 | } 54 | 55 | return true; 56 | 57 | } 58 | 59 | module.exports = { 60 | 61 | check : check, 62 | 63 | start : function(token_arg,user_arg,uid,remember){ 64 | 65 | engine.common.tell('starting-session',log); 66 | 67 | if(!token_arg){ 68 | return engine.common.error("not_found-token"); 69 | } 70 | 71 | if(remember === true){ 72 | engine.data.reset('token',token_arg,'local'); 73 | engine.data.reset('user',user_arg,'local'); 74 | engine.data.reset('uid',uid,'local'); 75 | engine.data.reset('session_type','persistant','local'); 76 | } else { 77 | engine.data.reset('token',token_arg,'session'); 78 | engine.data.reset('user',user_arg,'session'); 79 | engine.data.reset('uid',uid,'session'); 80 | engine.data.reset('session_type','temp','local'); 81 | } 82 | 83 | return check(); 84 | 85 | }, 86 | 87 | end : end, 88 | 89 | token : token, 90 | uid : uid, 91 | user : user, 92 | user_type : user_type, 93 | session_type:session_type, 94 | 95 | get : { 96 | 97 | user: function(){ 98 | if(check() == false){ 99 | return null; 100 | } 101 | if(user_type == "object"){ 102 | return JSON.parse(user); 103 | } else { 104 | return user; 105 | } 106 | }, 107 | 108 | token:function(){ 109 | check(); 110 | return token; 111 | }, 112 | 113 | uid:function(){ 114 | check(); 115 | return uid; 116 | }, 117 | 118 | session_type:function(){ 119 | check(); 120 | return session_type; 121 | }, 122 | 123 | } 124 | 125 | }; 126 | -------------------------------------------------------------------------------- /binder.js: -------------------------------------------------------------------------------- 1 | module.exports= { 2 | 3 | hover : function(id,func){ 4 | 5 | if(!id || !func){ 6 | return engine.common.error('not_found-id/function=>binder-hover'); 7 | } 8 | 9 | let get = document.getElementById(id); 10 | if(get == null){ 11 | return engine.common.error('invalid_id'); 12 | } 13 | 14 | get.addEventListener('mouseenter',()=>{ 15 | func(id); 16 | }); 17 | return id; 18 | 19 | }, 20 | 21 | click : function(id,func){ 22 | 23 | if(!id || !func){ 24 | return engine.common.error('not_found-id/function=>binder-click'); 25 | } 26 | 27 | let get = document.getElementById(id); 28 | if(get == null){ 29 | return engine.common.error('invalid_id'); 30 | } 31 | 32 | get.addEventListener('click',()=>{ 33 | func(id); 34 | }); 35 | return id; 36 | 37 | }, 38 | 39 | files : function(id){ 40 | 41 | if(id == null){ 42 | return engine.common.error('no_id_found'); 43 | } 44 | 45 | let get = document.getElementById(id); 46 | if(get == null){ 47 | return engine.common.error('invalid_id'); 48 | } 49 | 50 | return get.files; 51 | 52 | }, 53 | 54 | text : function(id){ 55 | 56 | if(id == null){ 57 | return engine.common.error('no_id_found'); 58 | } 59 | 60 | let get = document.getElementById(id); 61 | if(get == null){ 62 | return engine.common.error('invalid_id'); 63 | } 64 | 65 | return get.value; 66 | 67 | }, 68 | 69 | number : function(id){ 70 | 71 | if(id == null){ 72 | return engine.common.error('no_id_found'); 73 | } 74 | 75 | let get = document.getElementById(id); 76 | if(get == null){ 77 | return engine.common.error('invalid_id'); 78 | } 79 | 80 | if(Number(get.value)){ 81 | return Number(get.value); 82 | } else if(get.value === '0'){ 83 | return 0; 84 | } else { 85 | return false; 86 | } 87 | 88 | }, 89 | 90 | value : function(id){ 91 | 92 | if(id == null){ 93 | return engine.common.error('no_id_found'); 94 | } 95 | 96 | let get = document.getElementById(id); 97 | if(get == null){ 98 | return engine.common.error('invalid_id'); 99 | } 100 | 101 | if(get.value){ 102 | return get.value; 103 | } else if(get.innerHTML){ 104 | return get.innerHTML; 105 | } else { 106 | return false; 107 | } 108 | 109 | }, 110 | 111 | active : function(id){ 112 | 113 | if(id == null){ 114 | return engine.common.error('no_id_found'); 115 | } 116 | let get = document.getElementById(id); 117 | if(get == null){ 118 | return engine.common.error('invalid_id'); 119 | } 120 | 121 | if(get.checked){ 122 | return true; 123 | } else { 124 | return false; 125 | } 126 | 127 | }, 128 | 129 | boolean : function(id){ 130 | 131 | if(id == null){ 132 | return engine.common.error('no_id_found'); 133 | } 134 | 135 | let get = document.getElementById(id); 136 | if(get == null){ 137 | return engine.common.error('invalid_id'); 138 | } 139 | 140 | let value = get.value; 141 | 142 | try{ 143 | return JSON.parse(value); 144 | } catch(err){ 145 | return null; 146 | } 147 | 148 | } 149 | 150 | }; 151 | -------------------------------------------------------------------------------- /make/tabs.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | const make = require('./tabs/make'); 3 | 4 | //input object sample 5 | // { 6 | // tabs:[ 7 | // {value:value0,module,module0,active:true}, 8 | // {value:value1,module,module1} 9 | // ] 10 | // } 11 | 12 | 13 | function build(type,options,clickFunction,activeFunction){ 14 | 15 | if(!options || !options.tabs.length || !options.parent || !document.getElementById(options.parent)){ 16 | return common.error('invalid_parent : ' + options); 17 | } 18 | 19 | options.tabClass = options.tabClass || 'tab-idle'; 20 | options.tabsContClass = options.tabsContClass || 'tab-cont-main'; 21 | options.activeTabClass = options.activeTabClass || 'tab-active'; 22 | options.navButtonClass = options.navButtonClass || 'tab-nav'; 23 | options.linksContClass = options.linksContClass || 'tab-cont-links'; 24 | options.moduleContClass = options.moduleContClass || 'tab-cont-module'; 25 | options.navButtonClass = options.navButtonClass || 'tab-nav'; 26 | 27 | const parentButtonCont = engine.make.div({ 28 | id:'links', 29 | parent:options.parent, 30 | class:options.linksContClass 31 | }); 32 | 33 | let parentModuleCont; 34 | if(type == 'comp'){ 35 | const moduleCont = engine.make.div({ 36 | id:'modules', 37 | parent:options.parent, 38 | class:options.tabsContClass 39 | }); 40 | parentModuleCont = engine.router.init.comps(moduleCont,null,null,options.moduleContClass); 41 | } else { 42 | parentModuleCont = engine.make.div({ 43 | id:'tabs', 44 | parent:options.parent, 45 | class:options.tabsContClass 46 | }); 47 | } 48 | 49 | make.tabs( 50 | parentButtonCont, 51 | parentModuleCont, 52 | options.tabs, 53 | clickFunction, 54 | activeFunction, 55 | options.tabClass, 56 | options.activeTabClass, 57 | options.navButtonClass 58 | ); 59 | 60 | return true; 61 | 62 | } 63 | 64 | module.exports = { 65 | 66 | comp : function(options){ 67 | 68 | function clickFunction(id,mod,data,router){ 69 | engine.router.navigate.to.comp(mod,data,router); 70 | } 71 | 72 | function activeFunction(id,mod,data,router){ 73 | mod.init(router,data); 74 | engine.router.track.comp[router] = router + mod.ref; 75 | engine.router.built.comp.push(router + mod.ref); 76 | } 77 | 78 | return build('comp',options,clickFunction,activeFunction); 79 | 80 | }, 81 | 82 | panel : function(options){ 83 | 84 | let routerId; 85 | 86 | function clickFunction(id,mod,data){ 87 | engine.router.navigate.to.panel(mod,data); 88 | } 89 | 90 | function activeFunction(id,mod,data){ 91 | const page = engine.router.active.page + '-router-cont'; 92 | const cont = engine.router.track.cont[page]; 93 | routerId = engine.router.init.panels(cont); 94 | mod.init(routerId); 95 | } 96 | 97 | return build('panel',options,clickFunction,activeFunction); 98 | 99 | }, 100 | 101 | cont : function(options){ 102 | 103 | function clickFunction(id,mod,data){ 104 | engine.router.navigate.to.cont(mod,data); 105 | } 106 | 107 | function activeFunction(id,mod,data){ 108 | const routerId = engine.router.init.conts(engine.router.active.page); 109 | mod.init(routerId,data); 110 | } 111 | 112 | return build('cont',options,clickFunction,activeFunction); 113 | 114 | } 115 | 116 | }; 117 | -------------------------------------------------------------------------------- /make/tabs/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | const make = require('./make'); 3 | 4 | //input object sample 5 | // { 6 | // tabs:[ 7 | // {value:value0,module,module0,active:true}, 8 | // {value:value1,module,module1} 9 | // ] 10 | // } 11 | 12 | function build(type,options,clickFunction,activeFunction){ 13 | 14 | if(!options || !options.tabs.length || !options.parent || !document.getElementById(options.parent)){ 15 | return engine.common.error('invalid_parent : ' + options); 16 | } 17 | 18 | options.tabClass = options.tabClass || 'tab-idle'; 19 | options.tabsContClass = options.tabsContClass || 'tab-cont-main'; 20 | options.activeTabClass = options.activeTabClass || 'tab-active'; 21 | options.navButtonClass = options.navButtonClass || 'tab-nav'; 22 | options.linksContClass = options.linksContClass || 'tab-cont-links'; 23 | options.moduleContClass = options.moduleContClass || 'tab-cont-module'; 24 | options.navButtonClass = options.navButtonClass || 'tab-nav'; 25 | 26 | const parentButtonCont = engine.make.div({ 27 | id:'links', 28 | parent:options.parent, 29 | class:options.linksContClass 30 | }); 31 | 32 | let parentModuleCont; 33 | if(type == 'comp'){ 34 | const moduleCont = engine.make.div({ 35 | id:'modules', 36 | parent:options.parent, 37 | class:options.tabsContClass 38 | }); 39 | parentModuleCont = engine.router.init.comps(moduleCont,null,null,options.moduleContClass); 40 | } else { 41 | parentModuleCont = engine.make.div({ 42 | id:'tabs', 43 | parent:options.parent, 44 | class:options.tabsContClass 45 | }); 46 | } 47 | 48 | make.tabs( 49 | parentButtonCont, 50 | parentModuleCont, 51 | options.tabs, 52 | clickFunction, 53 | activeFunction, 54 | options.tabClass, 55 | options.activeTabClass, 56 | options.navButtonClass 57 | ); 58 | 59 | return parentModuleCont; 60 | 61 | } 62 | 63 | module.exports = { 64 | 65 | comp : function(options){ 66 | 67 | function clickFunction(id,mod,data,router){ 68 | engine.router.navigate.to.comp(mod,data,router); 69 | } 70 | 71 | function activeFunction(id,mod,data,router){ 72 | mod.init(router,data); 73 | engine.router.track.comp[router] = router + mod.ref; 74 | engine.router.built.comp.push(router + mod.ref); 75 | } 76 | 77 | return build('comp',options,clickFunction,activeFunction); 78 | 79 | }, 80 | 81 | panel : function(options){ 82 | 83 | let routerId; 84 | 85 | function clickFunction(id,mod,data){ 86 | engine.router.navigate.to.panel(mod,data); 87 | } 88 | 89 | function activeFunction(id,mod,data){ 90 | const page = engine.router.active.page + '-router-cont'; 91 | const cont = engine.router.track.cont[page]; 92 | routerId = engine.router.init.panels(cont); 93 | mod.init(routerId,data); 94 | } 95 | 96 | return build('panel',options,clickFunction,activeFunction); 97 | 98 | }, 99 | 100 | cont : function(options){ 101 | 102 | function clickFunction(id,mod,data){ 103 | engine.router.navigate.to.cont(mod,data); 104 | } 105 | 106 | function activeFunction(id,mod,data){ 107 | const routerId = engine.router.init.conts(engine.router.active.page); 108 | mod.init(routerId,data); 109 | } 110 | 111 | return build('cont',options,clickFunction,activeFunction); 112 | 113 | } 114 | 115 | }; 116 | -------------------------------------------------------------------------------- /make/inputs.js: -------------------------------------------------------------------------------- 1 | const common = require('../common'); 2 | const checkBaseOptions = require('./check').check; 3 | const log = false; 4 | const seprator = false; 5 | const creator = require('./creator'); 6 | 7 | module.exports = { 8 | 9 | upload: function(options){ 10 | if(options.function){ 11 | let user_function = options.function; 12 | let local_function = (object)=>{ 13 | user_function(object.id,object.files); 14 | }; 15 | options.function = local_function; 16 | } 17 | options.type = 'file'; 18 | return creator('input',options); 19 | }, 20 | 21 | select : function(options){ 22 | if(options.function){ 23 | let user_function = options.function; 24 | let local_function = (object)=>{ 25 | user_function(object.id,object.value); 26 | }; 27 | options.function = local_function; 28 | } 29 | return creator('select',options); 30 | }, 31 | 32 | input : function(options){ 33 | 34 | if(options.function){ 35 | let user_function = options.function; 36 | let fetch_this = 'value'; 37 | if(options.type == 'file'){fetch_this = 'files';} 38 | let local_function = (object)=>{ 39 | if(options.type == 'number'){ 40 | user_function(object.id,Number(object[fetch_this])); 41 | } else { 42 | user_function(object.id,object[fetch_this]); 43 | } 44 | }; 45 | options.function = local_function; 46 | } 47 | 48 | if(!options.type){options.type = 'string';} 49 | return creator('input',options); 50 | 51 | }, 52 | 53 | checkBox : function(options){ 54 | 55 | //check options object 56 | let check = checkBaseOptions(options); 57 | if(check == false){ 58 | return common.error('invalid_options',options); 59 | } 60 | 61 | //check parent 62 | let get = document.getElementById(options.parent); 63 | if(get == null){ 64 | return common.error('invalid_parent',options); 65 | } 66 | 67 | //make label first 68 | let label = document.createElement("label"); 69 | if(options.labelClass){ 70 | label.className = options.labelClass; 71 | } else { 72 | label.className = 'form-checkbox-label'; 73 | } 74 | 75 | //create object 76 | let object = document.createElement("input"); 77 | object.id = options.parent + '-checkbox-' + options.id; 78 | object.type = 'checkbox'; 79 | if(options.class){ 80 | object.className = options.class; 81 | } else { 82 | object.className = 'form-checkbox'; 83 | } 84 | if(options.checked){ 85 | if(options.checked == true){ 86 | object.checked = true; 87 | } 88 | } 89 | label.appendChild(object); 90 | label.appendChild(document.createElement('span')); 91 | 92 | if(options.function){ 93 | object.addEventListener('click',()=>{ 94 | options.function(object.id); 95 | }); 96 | } 97 | 98 | get.appendChild(label); 99 | return object.id; 100 | 101 | }, 102 | 103 | textarea : function(options){ 104 | 105 | if(options.function){ 106 | let user_function = options.function; 107 | let local_function = (object)=>{ 108 | user_function(object.id,object.value); 109 | }; 110 | options.function = local_function; 111 | } 112 | 113 | return creator('textarea',options); 114 | 115 | }, 116 | 117 | button : function(options){ 118 | 119 | if(options.function){ 120 | let user_function = options.function; 121 | let local_function = (object,data)=>{ 122 | user_function(object.id,data); 123 | }; 124 | options.function = local_function; 125 | } 126 | 127 | options.type = 'button'; 128 | return creator('input',options); 129 | 130 | }, 131 | 132 | enableButton : function(buttonId){ 133 | 134 | let get = document.getElementById(buttonId); 135 | if(get == null){ 136 | return common.error('not-found/invalid-buttonId'); 137 | } else { 138 | get.disabled = false; 139 | return true; 140 | } 141 | 142 | } 143 | 144 | }; 145 | -------------------------------------------------------------------------------- /make/tabs/make.js: -------------------------------------------------------------------------------- 1 | "use strict" 2 | 3 | module.exports = { 4 | 5 | tabs : function(parent,moduleCont,tabs,clickFunction,activeFunction,idleClass,activeClass,navButtonClass){ 6 | 7 | let tab_style = 'float:left;'; 8 | if(engine.get.body.width() <= 640){ 9 | tab_style += 'width:26.66%;'; 10 | } 11 | if(engine.get.body.width() <= 480){ 12 | tab_style += 'width:40%;'; 13 | } 14 | if(engine.get.body.width() > 640 && tabs.length <= 6){ 15 | tab_style += 'width:auto;'; 16 | } 17 | 18 | let tab_ids = [],linksCont,nodes,firstTabIndex,nextTabIndex,count = 2,hidden_count = 0,total_nodes,visible; 19 | 20 | const leftButton = engine.make.div({ 21 | parent:parent, 22 | text:'↫', 23 | style:'width:10%;float:left;display:none;', 24 | class:navButtonClass, 25 | function:()=>{ 26 | if(firstTabIndex > 1){ 27 | engine.view.hide(nodes[nextTabIndex].id); 28 | firstTabIndex--; 29 | nextTabIndex--; 30 | engine.view.show(nodes[firstTabIndex].id); 31 | } 32 | } 33 | }); 34 | 35 | for(const tab of tabs){ 36 | 37 | if(tab.value && tab.module){ 38 | 39 | let tabRef = parent + tab.module.ref; 40 | let data = null; 41 | if(tab.data){ 42 | data = tab.data; 43 | } 44 | 45 | const tabId = engine.make.button({ 46 | parent:parent, 47 | value:tab.value, 48 | style:tab_style, 49 | class:idleClass, 50 | function:()=>{ 51 | 52 | //check for active tab 53 | if(engine.router.track.tabs[parent]['tab'] == tabId){ 54 | return true; 55 | } 56 | 57 | //remove active class from active tab 58 | let activeTab = engine.router.track.tabs[parent]['tab']; 59 | if(activeClass){ 60 | engine.make.removeClass({id:activeTab,parent:'any',class:activeClass}); 61 | engine.make.addClass({id:tabId,parent:'any',class:activeClass}); 62 | } else { 63 | engine.make.removeClass({id:activeTab,parent:'any',class:'tab-active'}); 64 | engine.make.addClass({id:tabId,parent:'any',class:'tab-active'}); 65 | } 66 | 67 | clickFunction(tabId,tab.module,data,moduleCont); 68 | 69 | //set comp router tags 70 | engine.router.track.tabs[parent] = {module:tabRef,tab:tabId}; 71 | engine.router.built.tab.push(tabRef); 72 | 73 | } 74 | }); 75 | 76 | tab_ids.push(tabId); 77 | 78 | //set active tab class here 79 | if(tab.active){ 80 | if(tab.active == true){ 81 | //set router tabs track catalog here 82 | engine.router.track.tabs[parent] = {module:tabRef,tab:tabId}; 83 | engine.router.built.tab.push(tabRef); 84 | if(activeClass){ 85 | engine.make.addClass({id:tabId,parent:'any',class:activeClass}); 86 | } else { 87 | engine.make.addClass({id:tabId,parent:'any',class:'tab-active'}); 88 | } 89 | if(activeFunction){ 90 | activeFunction(tabId,tab.module,data,moduleCont); 91 | } 92 | } 93 | } 94 | 95 | }//tab object check 96 | 97 | }//loop ends here 98 | 99 | linksCont = document.getElementById(parent); 100 | nodes = linksCont.childNodes; 101 | total_nodes = nodes.length; 102 | firstTabIndex = 1; 103 | nextTabIndex = nodes.length - count + 1; 104 | 105 | const rightButton = engine.make.div({ 106 | parent:parent, 107 | text:'↬', 108 | style:'width:10%;float:left;display:none;', 109 | class:navButtonClass, 110 | function:()=>{ 111 | if(firstTabIndex + visible <= total_nodes - 1){ 112 | nextTabIndex = firstTabIndex + visible; 113 | if(nodes[nextTabIndex]){ 114 | engine.view.hide(nodes[firstTabIndex].id); 115 | engine.view.show(nodes[nextTabIndex].id); 116 | firstTabIndex++; 117 | } 118 | } 119 | } 120 | }); 121 | 122 | if(linksCont.scrollHeight > 50){ 123 | while(linksCont.scrollHeight > 50 && count < nodes.length){ 124 | let hideThisTab = nodes[nodes.length - count]; 125 | engine.view.hide(hideThisTab.id); 126 | count++; 127 | hidden_count++; 128 | } 129 | engine.view.show(leftButton); 130 | engine.view.show(rightButton); 131 | } 132 | 133 | visible = total_nodes - hidden_count - 1; 134 | 135 | return true; 136 | 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /make/viewers.js: -------------------------------------------------------------------------------- 1 | const creator = require('./creator'); 2 | 3 | module.exports = { 4 | 5 | style : (options)=>{ 6 | 7 | if(!options.id || !options.style){ 8 | return engine.common.error('not_found-id/style-addStyle-make-engine'); 9 | } 10 | 11 | let object = document.getElementById(options.id); 12 | if(object){ 13 | object.style = options.style; 14 | return true; 15 | } else { 16 | return engine.common.error('not_found-doc_element_by_id-addStyle-make-engine'); 17 | } 18 | 19 | }, 20 | 21 | addClass : function(options){ 22 | 23 | if(!options.id || !options.class){ 24 | return engine.common.error('not_found-id/class-addClass-make-engine'); 25 | } 26 | 27 | let object = document.getElementById(options.id); 28 | if(object){ 29 | let style = object.className; 30 | if(style.indexOf(options.class) >= 0){ 31 | return true; 32 | } 33 | style = style + ' ' + options.class; 34 | object.className = style; 35 | return true; 36 | } else { 37 | return engine.common.error('not_found-doc_element_by_id-addClass-make-engine'); 38 | } 39 | 40 | 41 | }, 42 | 43 | removeClass : function(options){ 44 | 45 | if(!options.id || !options.class){ 46 | return engine.common.error('not_found-id/class-removeClass-make-engine'); 47 | } 48 | 49 | let object = document.getElementById(options.id); 50 | if(object){ 51 | let style = object.className; 52 | if(style.indexOf(options.class) < 0){ 53 | return true; 54 | } 55 | let updated = style.replace(options.class,""); 56 | object.className = updated; 57 | return true; 58 | } else { 59 | return engine.common.error('not_found-doc_element_by_id-removeClass-make-engine'); 60 | } 61 | 62 | }, 63 | 64 | span : function(options){ 65 | if(options.function){ 66 | let user_function = options.function; 67 | let local_function = (object)=>{ 68 | user_function(object.id); 69 | }; 70 | options.function = local_function; 71 | } 72 | return creator('span',options); 73 | }, 74 | 75 | div : function(options){ 76 | if(options.function){ 77 | let user_function = options.function; 78 | let local_function = (object)=>{ 79 | user_function(object.id); 80 | }; 81 | options.function = local_function; 82 | } 83 | return creator('div',options); 84 | }, 85 | 86 | heading : function(options){ 87 | if(options.function){ 88 | let user_function = options.function; 89 | let local_function = (object)=>{ 90 | user_function(object.id); 91 | }; 92 | options.function = local_function; 93 | } 94 | if(!options.level){options.level = 1;} 95 | return creator('h' + options.level,options); 96 | }, 97 | 98 | p : function(options){ 99 | if(options.function){ 100 | let user_function = options.function; 101 | let local_function = (object)=>{ 102 | user_function(object.id); 103 | }; 104 | options.function = local_function; 105 | } 106 | return creator('p',options); 107 | }, 108 | 109 | text : function(options){ 110 | 111 | if(!options.id || !options.text){ 112 | return engine.common.error('not_found-id/text-text-make-engine'); 113 | } 114 | 115 | let object = document.getElementById(options.id); 116 | if(object){ 117 | object.innerHTML = options.text; 118 | return true; 119 | } else { 120 | return engine.common.error('not_found-doc_element_by_id-text-make-engine'); 121 | } 122 | 123 | }, 124 | 125 | image : function(options){ 126 | 127 | if(!options.location){ 128 | return engine.common.error('not_found-image_location-image-make-engine'); 129 | } 130 | if(!options.type || (options.type !== 'local' && options.type !== 'url')){ 131 | options.type = 'local'; 132 | } 133 | if(options.type == 'local'){ 134 | if(options.location[0] !== '/'){ 135 | if(!window.hasOwnProperty('is_electron') && !window.hasOwnProperty('is_cordova')){ 136 | options.location = '/' + options.location; 137 | } 138 | } 139 | options.src = window.baseHref + options.location; 140 | } 141 | if(options.type == 'url'){ 142 | options.src = options.location; 143 | } 144 | if(options.function){ 145 | let user_function = options.function; 146 | let local_function = (object)=>{ 147 | user_function(object.id); 148 | }; 149 | options.function = local_function; 150 | } 151 | 152 | return creator('img',options); 153 | 154 | } 155 | 156 | }; 157 | -------------------------------------------------------------------------------- /get.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 3 | os:()=>{ 4 | let ua = navigator.userAgent.toLowerCase(); 5 | if(!ua){return 'unknown';} 6 | if(ua && /ipad|iphone|ipod/.test(ua)){return 'ios';} 7 | if(ua && /android/.test(ua)){return 'android';} 8 | if(ua && /windows/.test(ua)){return 'windows';} 9 | if(ua && /mac/.test(ua)){return 'mac';} 10 | if(ua && /linux/.test(ua)){return 'linux';} 11 | return 'unknown'; 12 | }, 13 | 14 | host:()=>{ 15 | return window.location.hostname; 16 | }, 17 | 18 | element:(id)=>{ 19 | return document.getElementById(id); 20 | }, 21 | 22 | platform:(data)=>{ 23 | 24 | if(!data){ 25 | if(window.hasOwnProperty('is_cordova')){ 26 | return 'cordova'; 27 | } 28 | if(window.hasOwnProperty('is_electron')){ 29 | return 'electron'; 30 | } 31 | data = 'platform'; 32 | } 33 | 34 | if(data == 'electron'){ 35 | if(window.hasOwnProperty('is_electron')){ 36 | return true; 37 | } else { 38 | return false; 39 | } 40 | } 41 | 42 | if(data == 'cordova'){ 43 | if(window.hasOwnProperty('is_cordova')){ 44 | return true; 45 | } else { 46 | return false; 47 | } 48 | } 49 | 50 | // let w = document.body.offsetWidth; 51 | // let h = Math.max(window.innerHeight, document.body.clientHeight); 52 | 53 | let w = window.innerWidth; 54 | let h = window.innerHeight; 55 | let ans; 56 | 57 | if(w >= h){ 58 | if(data == 'platform'){ 59 | ans = 'pc'; 60 | } else if(data == 'mobile'){ 61 | ans = false; 62 | } else if(data == 'pc'){ 63 | ans = true; 64 | } 65 | } 66 | 67 | if(w < h){ 68 | if(data == 'platform'){ 69 | ans = 'mobile'; 70 | } else if(data == 'mobile'){ 71 | ans = true; 72 | } else if(data == 'pc'){ 73 | ans = false; 74 | } 75 | } 76 | 77 | return ans; 78 | 79 | }, 80 | 81 | pageModule : function(pageName){ 82 | 83 | if(window.pageModules[pageName]){ 84 | return window.pageModules[pageName]; 85 | } else { 86 | return null; 87 | } 88 | 89 | }, 90 | 91 | contName : function(contId){ 92 | 93 | if(!contId || typeof(contId) !== 'string'){ 94 | return engine.common.error('invalid/not_found-contId'); 95 | } 96 | 97 | if(!contId.match('-')){ 98 | return engine.common.error('invalid-contId'); 99 | } 100 | 101 | let name = contId.split('-')[3]; 102 | return name + 'Cont'; 103 | 104 | }, 105 | 106 | contModule : function(pageName,contName){ 107 | 108 | if(!pageName || typeof(pageName) !== 'string'){ 109 | return engine.common.error('invalid/not_found-pageName'); 110 | } 111 | if(!contName || typeof(contName) !== 'string'){ 112 | return engine.common.error('invalid/not_found-contName'); 113 | } 114 | 115 | let pool = window.pageModules[pageName].contModules; 116 | 117 | if(pool[contName]){ 118 | return pool[contName]; 119 | } else { 120 | return false; 121 | } 122 | 123 | }, 124 | 125 | panelModule : function(pageName,contName,panelName){ 126 | 127 | if(!pageName || typeof(pageName) !== 'string'){ 128 | return engine.common.error('invalid/not_found-pageName'); 129 | } 130 | if(!contName || typeof(contName) !== 'string'){ 131 | return engine.common.error('invalid/not_found-contName'); 132 | } 133 | if(!panelName || typeof(panelName) !== 'string'){ 134 | return engine.common.error('invalid/not_found-panelName'); 135 | } 136 | 137 | let pool = window.pageModules[pageName].contModules[contName].panelModules[panelName]; 138 | 139 | if(pool){ 140 | return pool; 141 | } else { 142 | return false; 143 | } 144 | 145 | }, 146 | 147 | rowByTdId : function(id){ 148 | 149 | if(id==null){ 150 | return engine.common.error('not_found-td_id'); 151 | } 152 | if(!id.match('-') || !id.match('row')){ 153 | return engine.common.error('invalid-td_id'); 154 | } 155 | let array = id.split('-'); 156 | let rowIndex = array.indexOf('row') + 2; 157 | let rowId = null; 158 | for(var i=0;i{ 125 | 126 | if(!type_collection){ 127 | process_type_collection(); 128 | } 129 | 130 | if(where == 'mem'){ 131 | delete db[tag]; 132 | } 133 | if(where == 'session'){ 134 | remove_data_type(tag,'session'); 135 | sessionStorage.removeItem(tag); 136 | } 137 | if(where == 'local'){ 138 | remove_data_type(tag,'local'); 139 | localStorage.removeItem(tag); 140 | } 141 | 142 | return true; 143 | 144 | } 145 | 146 | }; 147 | 148 | function convert(type,data){ 149 | if(type == "number"){ 150 | return Number(data); 151 | } 152 | if(type == "object"){ 153 | return JSON.parse(data); 154 | } 155 | if(type == "boolean"){ 156 | return JSON.parse(data); 157 | } 158 | return data; 159 | } 160 | 161 | function remove_data_type(tag,where){ 162 | 163 | if(!type_collection){ 164 | process_type_collection(); 165 | } 166 | 167 | if(where === "local"){ 168 | delete type_collection.local[tag]; 169 | localStorage.setItem("type_collection_local",JSON.stringify(type_collection.local)); 170 | } 171 | if(where === "session"){ 172 | delete type_collection.session[tag]; 173 | localStorage.setItem("type_collection_session",JSON.stringify(type_collection.session)); 174 | } 175 | 176 | return true; 177 | 178 | } 179 | 180 | function save_data_type(tag,where,type){ 181 | 182 | if(!type_collection){ 183 | process_type_collection(); 184 | } 185 | 186 | if(where === "local"){ 187 | type_collection.local[tag] = type; 188 | localStorage.setItem("type_collection_local",JSON.stringify(type_collection.local)); 189 | } 190 | if(where === "session"){ 191 | type_collection.session[tag] = type; 192 | localStorage.setItem("type_collection_session",JSON.stringify(type_collection.session)); 193 | } 194 | 195 | return true; 196 | 197 | } 198 | 199 | async function process_type_collection(){ 200 | let get_local,get_session; 201 | try{ 202 | const fetch = localStorage.getItem("type_collection_session"); 203 | if(fetch){ 204 | get_session = JSON.parse(fetch) 205 | } else { 206 | get_session = {}; 207 | } 208 | } catch(e) { 209 | get_session = {} 210 | } 211 | try{ 212 | const fetch = localStorage.getItem("type_collection_local"); 213 | if(fetch){ 214 | get_local = JSON.parse(fetch) 215 | } else { 216 | get_local = {}; 217 | } 218 | } catch(e) { 219 | get_local = {} 220 | } 221 | type_collection = { 222 | session:get_session, 223 | local:get_local 224 | }; 225 | return true; 226 | } 227 | -------------------------------------------------------------------------------- /idb.js: -------------------------------------------------------------------------------- 1 | window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB; 2 | window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.msIDBTransaction; 3 | window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.msIDBKeyRange; 4 | 5 | let dbs = {}; 6 | let stores = {}; 7 | 8 | module.exports = { 9 | 10 | open:async (name)=>{ 11 | 12 | return new Promise(function(resolve, reject) { 13 | 14 | let error; 15 | 16 | if(!name){ 17 | error = 'not_found-name-open-idb-engine'; 18 | reject(error); 19 | } 20 | if(dbs.hasOwnProperty(name)){ 21 | error = 'db_already_initiated-open-idb-engine'; 22 | reject(error); 23 | } 24 | 25 | const run = indexedDB.open(name); 26 | run.onsuccess = (e)=>{ 27 | dbs[name] = run.result; 28 | stores[name] = {}; 29 | resolve(); 30 | } 31 | run.onerror = (e)=>{ 32 | error = 'failed-open-ids-engine'; 33 | reject(error); 34 | } 35 | 36 | }); 37 | 38 | 39 | 40 | }, 41 | 42 | stores:(db)=>{ 43 | 44 | return new Promise(function(resolve, reject) { 45 | 46 | if(!db){ 47 | return reject('not_found-db/store-stores-idb-engine'); 48 | } 49 | 50 | if(!dbs[db]){ 51 | return reject('db_not_initiated_yet-stores-idb-engine'); 52 | } 53 | 54 | return resolve(dbs[db].objectStoreNames); 55 | 56 | }); 57 | 58 | }, 59 | 60 | store:{ 61 | 62 | create:async (data)=>{ 63 | 64 | const logger = false; 65 | 66 | return new Promise(async function(resolve, reject) { 67 | 68 | if(!data.db || !data.store){ 69 | return reject('not_found-db/store-create-store-idb-engine'); 70 | } 71 | 72 | engine.common.tell('object_verified-create-store-idb-engine',logger); 73 | 74 | if(!dbs[data.db]){ 75 | return reject('db_not_initiated_yet-create-store-idb-engine'); 76 | } 77 | 78 | engine.common.tell('db_intiation_checked-create-store-idb-engine',logger); 79 | 80 | if(true){ 81 | console.log({ 82 | list:dbs[data.db].objectStoreNames, 83 | contains:dbs[data.db].objectStoreNames.contains(data.store) 84 | }); 85 | } 86 | 87 | if(dbs[data.db].objectStoreNames.contains(data.store)){ 88 | return reject('already_exists-object_store-db_version_check-create-store-idb-engine'); 89 | } 90 | 91 | engine.common.tell('store_duplicate_checked-create-store-idb-engine',logger); 92 | 93 | const version = dbs[data.db].version; 94 | dbs[data.db].close(); 95 | delete dbs[data.db]; 96 | 97 | engine.common.tell('old_db_connection_closed-create-store-idb-engine',logger); 98 | 99 | const open = indexedDB.open(data.db,version + 1); 100 | open.onupgradeneeded = ()=>{ 101 | 102 | engine.common.tell('upgrade_function_called-create-store-idb-engine',logger); 103 | 104 | const run = open.result.createObjectStore(data.store,data.key,data.options); 105 | run.onsuccess = (e)=>{ 106 | engine.common.tell('object_store_created-create-store-idb-engine',logger); 107 | dbs[data.db] = open.result; 108 | return resolve(); 109 | } 110 | run.onerror = (e)=>{ 111 | return reject('failed-create-store-db_version_upgrade-db_version_check-create-store-idb-engine'); 112 | } 113 | 114 | } 115 | open.onerror = (e)=>{ 116 | return reject('failed-db_version_upgrade-create-store-idb-engine'); 117 | } 118 | 119 | }); 120 | 121 | }, 122 | 123 | check:(data)=>{ 124 | 125 | return new Promise(function(resolve, reject){ 126 | 127 | if(!data.db || !data.store){ 128 | return reject('not_found-db/store-create-store-idb-engine'); 129 | } 130 | 131 | if(!dbs[data.db]){ 132 | return reject('db_not_initiated_yet-create-store-idb-engine'); 133 | } 134 | 135 | if(dbs[data.db].objectStoreNames.contains(data.store)){ 136 | return resolve(true); 137 | } else { 138 | return resolve(false); 139 | } 140 | 141 | }); 142 | 143 | }, 144 | 145 | delete : (data)=>{ 146 | 147 | const logger = false; 148 | 149 | return new Promise(async function(resolve, reject) { 150 | 151 | if(!data.db || !data.store){ 152 | return reject('not_found-db/store-delete-store-idb-engine'); 153 | } 154 | 155 | engine.common.tell('object_verified-delete-store-idb-engine',logger); 156 | 157 | if(!dbs[data.db]){ 158 | return reject('db_not_initiated_yet-delete-store-idb-engine'); 159 | } 160 | 161 | engine.common.tell('db_intiation_checked-delete-store-idb-engine',logger); 162 | 163 | if(false){ 164 | console.log({ 165 | list:dbs[data.db].objectStoreNames, 166 | contains:dbs[data.db].objectStoreNames.contains(data.store) 167 | }); 168 | } 169 | 170 | if(!dbs[data.db].objectStoreNames.contains(data.store)){ 171 | return reject('not_found-object_store-db_version_check-delete-store-idb-engine'); 172 | } 173 | 174 | engine.common.tell('store_duplicate_checked-delete-store-idb-engine',logger); 175 | 176 | const version = dbs[data.db].version; 177 | dbs[data.db].close(); 178 | delete dbs[data.db]; 179 | 180 | engine.common.tell('old_db_connection_closed-delete-store-idb-engine',logger); 181 | 182 | const open = indexedDB.open(data.db,version + 1); 183 | open.onupgradeneeded = ()=>{ 184 | 185 | engine.common.tell('upgrade_function_called-delete-store-idb-engine',logger); 186 | 187 | const run = open.result.deleteObjectStore(data.store); 188 | 189 | console.log(run); 190 | 191 | run.onsuccess = (e)=>{ 192 | engine.common.tell('object_store_created-delete-store-idb-engine',logger); 193 | dbs[data.db] = open.result; 194 | return resolve(); 195 | } 196 | run.onerror = (e)=>{ 197 | return reject('failed-create-store-db_version_upgrade-db_version_check-delete-store-idb-engine'); 198 | } 199 | 200 | } 201 | open.onerror = (e)=>{ 202 | return reject('failed-db_version_upgrade-delete-store-idb-engine'); 203 | } 204 | 205 | }); 206 | 207 | } 208 | 209 | } 210 | 211 | }; 212 | -------------------------------------------------------------------------------- /make/tabsBackup.js: -------------------------------------------------------------------------------- 1 | const common = require('../common'); 2 | const checkBaseOptions = require('./check').check; 3 | const view = require('../view'); 4 | const router = require('../router'); 5 | const log = true; 6 | const viewers = require('./viewers'); 7 | let gets = require('../get'); 8 | 9 | module.exports = { 10 | 11 | init : function(options){ 12 | 13 | common.tell('+++ tabs',log); 14 | 15 | /* 16 | { 17 | .. 18 | tabsContClass:tabsCont, 19 | linksContClass:linksCont, 20 | tabClass:idleTab, 21 | activeTabClass:activeTab, 22 | navButtonClass:navButton, 23 | moduleContClass:viewerCont, 24 | tabs:[ 25 | {value:value0,module,module0,active:true}, 26 | {value:value1,module,module1} 27 | ] 28 | } 29 | */ 30 | 31 | let check = checkBaseOptions(options); 32 | if(check == false){ 33 | return common.error('invalid_options'); 34 | } 35 | if(!options.tabs || !options.tabs.length || options.tabs.length == 0){ 36 | return common.error('not_found-tabs'); 37 | } 38 | 39 | //check parent 40 | let get = document.getElementById(options.parent); 41 | if(get == null){ 42 | return common.error('invalid_parent : ' + options); 43 | } 44 | 45 | //make tabsCont 46 | let tabsContId = options.parent + '-tabs-cont-' + options.id; 47 | let tabsCont = document.createElement('div'); 48 | tabsCont.id = tabsContId; 49 | if(options.tabsContClass){ 50 | tabsCont.className = options.tabsContClass; 51 | } 52 | get.appendChild(tabsCont); 53 | 54 | //make linksCont 55 | let linksContId = tabsContId + '-links-cont'; 56 | let linksCont = document.createElement('div'); 57 | linksCont.id = linksContId; 58 | if(options.linksContClass){ 59 | linksCont.className = options.linksContClass; 60 | } 61 | tabsCont.appendChild(linksCont); 62 | 63 | //make viewerCont 64 | let moduleContId = tabsContId + '-viewer-cont'; 65 | let moduleCont = document.createElement('div'); 66 | moduleCont.id = moduleContId; 67 | if(options.moduleContClass){ 68 | moduleCont.className = options.moduleContClass; 69 | } 70 | tabsCont.appendChild(moduleCont); 71 | 72 | let tabs = options.tabs; 73 | let activated = false; 74 | 75 | for(var i=0;i 640 && options.tabs.length <= 6){ 94 | tabObject.style.width = 'auto'; 95 | } 96 | linksCont.appendChild(tabObject); 97 | 98 | //set tab class here 99 | if(tab.active){ 100 | if(tab.active == true){ 101 | //set tab router track tab here 102 | activated = true; 103 | //set active tab class here 104 | if(options.activeTabClass){ 105 | viewers.addClass({id:tabId,parent:'any',class:options.activeTabClass}); 106 | } 107 | //init the tab module 108 | router.track.tabs[tabsContId] = {module:tabRef,tab:tabId}; 109 | router.built.tab.push(tabRef); 110 | tab.module.init(moduleContId); 111 | } 112 | } 113 | 114 | if(gets.body.width() <= 640){ 115 | tabObject.style.width = '26.66%'; 116 | } 117 | if(gets.body.width() <= 480){ 118 | tabObject.style.width = '40%'; 119 | } 120 | 121 | //set tab function here 122 | tabObject.addEventListener('click',()=>{ 123 | 124 | //check for active tab 125 | if(router.track.tabs[tabsContId]['tab'] == tabId){ 126 | return true; 127 | } 128 | 129 | //remove active class from active tab 130 | let activeTab = router.track.tabs[tabsContId]['tab']; 131 | if(options.activeTabClass){ 132 | viewers.removeClass({id:activeTab,parent:'any',class:options.activeTabClass}); 133 | viewers.addClass({id:tabId,parent:'any',class:options.activeTabClass}); 134 | } 135 | 136 | //hide the active tab 137 | view.hide(router.track.tabs[tabsContId].module); 138 | 139 | //check if tab was buolt previously 140 | if(router.built.tab.indexOf(tabRef) >= 0){ 141 | router.track.tabs[tabsContId]['module'] = tabRef; 142 | router.track.tabs[tabsContId]['tab'] = tabId; 143 | view.show(tabRef); 144 | return true; 145 | } else { 146 | tab.module.init(moduleContId); 147 | } 148 | 149 | //set comp router tags 150 | router.track.tabs[tabsContId] = {module:tabRef,tab:tabId}; 151 | router.built.tab.push(tabRef); 152 | 153 | }); 154 | 155 | //add tab to linsk cont here 156 | 157 | 158 | } 159 | } 160 | //for loop ends here 161 | 162 | let nodes = linksCont.childNodes; 163 | let lastNode = nodes[nodes.length - 1]; 164 | 165 | //left button 166 | let leftButton = document.createElement('div'); 167 | leftButton.id = linksContId + '-button-left'; 168 | leftButton.style.float = 'left'; 169 | leftButton.style.width = '10%'; 170 | if(options.navButtonClass){ 171 | leftButton.className = options.navButtonClass; 172 | } 173 | if(gets.body.width() > 640){ 174 | leftButton.style.display = 'none'; 175 | } 176 | leftButton.innerHTML = 'keyboard_arrow_left'; 177 | linksCont.insertBefore(leftButton,nodes[0]); 178 | 179 | //right button 180 | let rightButton = document.createElement('div'); 181 | rightButton.id = linksContId + '-button-right'; 182 | rightButton.style.float = 'left'; 183 | rightButton.style.width = '10%'; 184 | if(options.navButtonClass){ 185 | rightButton.className = options.navButtonClass; 186 | } 187 | if(gets.body.width() > 640){ 188 | rightButton.style.display = 'none'; 189 | } 190 | rightButton.innerHTML = 'keyboard_arrow_right'; 191 | linksCont.appendChild(rightButton); 192 | 193 | //display 194 | if(linksCont.scrollHeight > 50){ 195 | 196 | rightButton.style.display = 'block'; 197 | leftButton.style.display = 'block'; 198 | 199 | //while loop counter 200 | let count = 2; 201 | 202 | //remove the excess tabs 203 | while(linksCont.scrollHeight > 50 && count <= 10){ 204 | let hideThisTab = nodes[nodes.length - count]; 205 | view.hide(hideThisTab.id); 206 | count++; 207 | } 208 | 209 | let firstTabIndex = 1; 210 | let nextTabIndex = nodes.length - count + 1; 211 | 212 | rightButton.addEventListener('click',()=>{ 213 | if(nextTabIndex < nodes.length - 1){ 214 | tabSlide(nodes[firstTabIndex].id,nodes[nextTabIndex].id); 215 | firstTabIndex++,nextTabIndex++; 216 | } 217 | }); 218 | 219 | leftButton.addEventListener('click',()=>{ 220 | if(firstTabIndex >= 2){ 221 | firstTabIndex--,nextTabIndex--; 222 | tabSlide(nodes[nextTabIndex].id,nodes[firstTabIndex].id); 223 | } 224 | }); 225 | 226 | } 227 | 228 | function tabSlide(hide,show){ 229 | view.hide(hide); 230 | view.show(show); 231 | } 232 | 233 | if(activated == false){ 234 | return common.error('no_found-active_tab'); 235 | } else { 236 | return tabsContId; 237 | } 238 | 239 | } 240 | 241 | }; 242 | -------------------------------------------------------------------------------- /router/nav.js: -------------------------------------------------------------------------------- 1 | const common = require('../common'); 2 | const log = false; 3 | 4 | function toWorker(app,type,reset,routerId,data){ 5 | 6 | common.tell("navigation initiated",log); 7 | common.tell("reinitiate module : " + reset,log); 8 | 9 | //other modules 10 | let router = require('../router'); 11 | let view = require('../view'); 12 | 13 | common.tell("router / view localised",log); 14 | 15 | //catalogs 16 | let active = router.active; 17 | let built = router.built; 18 | let route = router.route; 19 | let track = router.track; 20 | let mods = router.mods; 21 | 22 | common.tell("router objects localised",log); 23 | 24 | //check if there is a initiated page heres 25 | if(type == 'page'){ 26 | if(active[type] == null){ 27 | return common.error('no_page_initiated_from_app_starter'); 28 | } 29 | } 30 | 31 | common.tell("base page intiation validated",log); 32 | 33 | //security checks 34 | if(app == null || app == undefined){ 35 | return common.error('not_found-app'); 36 | } 37 | if(app.ref == null || app.ref == undefined){ 38 | return common.error('invalid_app'); 39 | } 40 | if(type == 'comp'){ 41 | if(!routerId){ 42 | return common.error('not_found-routerId'); 43 | } 44 | } 45 | 46 | common.tell("module checks completed",log); 47 | 48 | //set ref here 49 | let toId; 50 | if(type == 'page'){ 51 | toId = app.ref; 52 | } else if(type == 'cont'){ 53 | toId = active.page + '-router-cont' + app.ref; 54 | } else if(type == 'panel'){ 55 | let page = active.page + '-router-cont'; 56 | let cont = track.cont[page]; 57 | toId = cont + '-router-panel' + app.ref; 58 | } else if(type == 'comp'){ 59 | toId = routerId + app.ref; 60 | } 61 | 62 | common.tell("module ref built",log); 63 | 64 | if(reset == true){ 65 | if(document.getElementById(toId)){ 66 | document.getElementById(toId).remove(); 67 | while(built[type].indexOf(toId) >= 0){ 68 | let toIdPos = built[type].indexOf(toId); 69 | if(toIdPos >= 0){ 70 | built[type].splice(toIdPos, 1); 71 | } 72 | } 73 | } 74 | } 75 | 76 | common.tell("pre-built module removed",log); 77 | 78 | if(type == 'page'){ 79 | view.hide(active.page); 80 | } else if(type == 'cont'){ 81 | let page = active.page + '-router-cont'; 82 | let cont = track.cont[page]; 83 | view.hide(cont); 84 | } else if(type == 'panel'){ 85 | let page = active.page + '-router-cont'; 86 | let cont = track.cont[page] + '-router-panel'; 87 | let panel = track.panel[cont]; 88 | view.hide(panel); 89 | } else if(type == 'comp'){ 90 | view.hide(track['comp'][routerId]); 91 | } 92 | 93 | common.tell("active module hidden",log); 94 | 95 | //update track catalog with toId 96 | if(type == 'page'){ 97 | active[type] = toId; 98 | } else if(type == 'cont'){ 99 | let page = active.page + '-router-cont'; 100 | track.cont[page] = toId; 101 | active[type] = toId; 102 | } else if(type == 'panel'){ 103 | let page = active.page + '-router-cont'; 104 | let cont = track.cont[page] + '-router-panel'; 105 | track.panel[cont] = toId; 106 | active[type] = toId; 107 | } else if(type == 'comp'){ 108 | track.comp[routerId] = toId; 109 | } 110 | 111 | common.tell("to-module cataloged",log); 112 | 113 | //navigate here 114 | let url; 115 | if(type == 'page'){ 116 | url = exp.url.add.page(toId); 117 | route.push({type:type,id:toId,url:url,mod:app}); 118 | } else if(type == 'cont'){ 119 | url = exp.url.add.cont(toId); 120 | route.push({type:type,id:toId,url:url,mod:app}); 121 | } else if(type == 'panel'){ 122 | url = exp.url.add.panel(toId); 123 | route.push({type:type,id:toId,url:url,mod:app}); 124 | } 125 | 126 | if(app.trackers){ 127 | let trackers = app.trackers; 128 | if(trackers.title){ 129 | engine.set.pageTitle(trackers.title); 130 | } 131 | if(trackers.meta){ 132 | for(var i in trackers.meta){ 133 | engine.meta.update(trackers.meta[i]); 134 | } 135 | } 136 | if(trackers.function){ 137 | if(trackers.function_data){ 138 | trackers.function(trackers.function_data); 139 | } else { 140 | trackers.function(); 141 | } 142 | } 143 | } 144 | 145 | //already built the app 146 | if(built[type].indexOf(toId) >= 0 && document.getElementById(toId)){ 147 | view.show(toId); 148 | common.tell("to-module view activated",log); 149 | } 150 | 151 | //app not built yet 152 | if(built[type].indexOf(toId) < 0 || !document.getElementById(toId)){ 153 | 154 | //initiate app 155 | if(type == 'page'){ 156 | app.init(data); 157 | } else if(type == 'cont'){ 158 | let page = active.page + '-router-cont'; 159 | app.init(page,data); 160 | } else if(type == 'panel'){ 161 | let page = active.page + '-router-cont'; 162 | let cont = track.cont[page] + '-router-panel'; 163 | app.init(cont,data); 164 | } else if(type == 'comp'){ 165 | app.init(routerId,data); 166 | } 167 | 168 | if(type == 'comp'){ 169 | built[type].push(toId); 170 | } 171 | 172 | 173 | 174 | common.tell("to-module built",log); 175 | 176 | } 177 | 178 | common.tell("to-module router tags pushed",log); 179 | 180 | return true; 181 | 182 | } 183 | 184 | 185 | 186 | let exp = { 187 | 188 | url:{ 189 | add : { 190 | page:function(id){ 191 | let page; 192 | if(id){ 193 | page = id; 194 | } else { 195 | page = engine.router.active.page; 196 | } 197 | let url = "/" + clean_page(page); 198 | // if(document.URL.split('?').length > 1){ 199 | // url += '?' + document.URL.split('?')[1]; 200 | // } 201 | let platform = engine.get.platform(); 202 | if(platform == "cordova" || platform == "electron"){ 203 | return url; 204 | } 205 | if(window.hasOwnProperty('vegana_do_not_route_with_url')){ 206 | if(window.vegana_do_not_route_with_url === true){ 207 | return url; 208 | } 209 | } 210 | window.history.pushState("object or string", null, url); 211 | return url; 212 | }, 213 | cont:function(id){ 214 | let page = engine.router.active.page; 215 | let cont; 216 | if(id){ 217 | cont = id; 218 | } else { 219 | cont = engine.router.track.cont[page]; 220 | } 221 | let url = "/" + clean_page(page) + "/" + clean_cont(cont); 222 | // if(document.URL.split('?').length > 1){ 223 | // url += '?' + document.URL.split('?')[1]; 224 | // } 225 | let platform = engine.get.platform(); 226 | if(platform == "cordova" || platform == "electron"){ 227 | return url; 228 | } 229 | if(window.hasOwnProperty('vegana_do_not_route_with_url')){ 230 | if(window.vegana_do_not_route_with_url === true){ 231 | return url; 232 | } 233 | } 234 | window.history.pushState("object or string", null, url); 235 | return url; 236 | }, 237 | panel:function(id){ 238 | let page = engine.router.active.page; 239 | let cont = engine.router.track.cont[page + '-router-cont']; 240 | let panel; 241 | if(id){ 242 | panel = id; 243 | } else { 244 | panel = engine.router.track.panel[cont]; 245 | } 246 | let url = "/" + clean_page(page) + "/" + clean_cont(cont) + "/" + clean_panel(panel); 247 | // if(document.URL.split('?').length > 1){ 248 | // url += '?' + document.URL.split('?')[1]; 249 | // } 250 | let platform = engine.get.platform(); 251 | if(platform == "cordova" || platform == "electron"){ 252 | return url; 253 | } 254 | if(window.hasOwnProperty('vegana_do_not_route_with_url')){ 255 | if(window.vegana_do_not_route_with_url === true){ 256 | return url; 257 | } 258 | } 259 | window.history.pushState("object or string", null, url); 260 | return url; 261 | } 262 | } 263 | }, 264 | 265 | to : { 266 | page : function(app,data){ 267 | if(engine.router.active.page == app.ref){ 268 | return true; 269 | } 270 | return toWorker(app,'page',false,null,data); 271 | }, 272 | cont : function(app,data){ 273 | let parse = engine.router.active.page + '-router-cont' + app.ref; 274 | if(engine.router.active.cont == parse){ 275 | return true; 276 | } 277 | return toWorker(app,'cont',false,null,data); 278 | }, 279 | panel : function(app,data){ 280 | let parse = engine.router.active.cont + '-router-panel' + app.ref; 281 | if(engine.router.active.panel == parse){ 282 | return true; 283 | } 284 | return toWorker(app,'panel',false,null,data); 285 | }, 286 | comp : function(app,data,routerId){ 287 | return toWorker(app,'comp',false,routerId,data); 288 | } 289 | }, 290 | 291 | new : { 292 | page : function(app,data){ 293 | return toWorker(app,'page',true,null,data); 294 | }, 295 | cont : function(app,data){ 296 | return toWorker(app,'cont',true,null,data); 297 | }, 298 | panel : function(app,data){ 299 | return toWorker(app,'panel',true,null,data); 300 | }, 301 | comp : function(app,data,routerId){ 302 | return toWorker(app,'comp',true,routerId,data); 303 | } 304 | } 305 | 306 | } 307 | 308 | module.exports = exp; 309 | 310 | 311 | 312 | function clean_page(p){ 313 | let h = p.split('-')[1]; 314 | //console.log({clean_page_result:h}); 315 | return h; 316 | } 317 | 318 | function clean_cont(c){ 319 | 320 | if(!c){ 321 | return engine.common.error('not_found-cont-clean_cont-navigate-router'); 322 | } 323 | 324 | let page = engine.router.active.page; 325 | 326 | let final = c; 327 | final = final.replace(page,''); 328 | final = final.replace('-router-cont-cont-',''); 329 | 330 | //console.log({clean_cont_result:final}); 331 | 332 | return final; 333 | 334 | } 335 | 336 | function clean_panel(p){ 337 | 338 | let page = engine.router.active.page; 339 | let cont = engine.router.track.cont[page + '-router-cont']; 340 | 341 | //console.log({cont:cont}); 342 | 343 | let final = p; 344 | final = final.replace(cont,''); 345 | final = final.replace('-router-panel-panel-',''); 346 | 347 | //console.log({clean_panel_result:final}); 348 | 349 | return final; 350 | 351 | } 352 | -------------------------------------------------------------------------------- /validate.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | json:json, 3 | email:checkEmail 4 | }; 5 | 6 | function error(a,t,e){ 7 | return { 8 | all:a, 9 | tag:t, 10 | error:e 11 | } 12 | } 13 | 14 | function json(schema,data,schema_type,maxSize,returnError){ 15 | 16 | //if no type or maxSize is given static type and max size of 21 is automatically assumed 17 | if(!schema_type){schema_type = 'static'} 18 | if(schema_type == 'dynamic' && !maxSize){maxSize = 21;} 19 | 20 | //check schema 21 | if(!schema || typeof(schema) !== 'object' || Object.keys(schema).length == 0){ 22 | if(returnError){return error(true,null,'not_found-valid_schema');} 23 | return engine.common.error('not_found-valid_schema'); 24 | } 25 | 26 | //check data 27 | if(!data || typeof(data) !== 'object' || Object.keys(data).length == 0){ 28 | if(returnError){return error(true,null,'not_found-valid_data');} 29 | return engine.common.error('not_found-valid_data'); 30 | } 31 | 32 | let keys_schema = Object.keys(schema); 33 | let keys_data = Object.keys(data); 34 | 35 | //check size of both objects 36 | if(schema_type == 'static'){ 37 | if(keys_schema.length !== keys_data.length){ 38 | if(returnError){return error(true,null,'miss_matched-object_size');} 39 | return engine.common.error('miss_matched-object_size'); 40 | } 41 | } 42 | 43 | //check data object keys size if maxSize property is set 44 | if(schema_type == 'dynamic' && maxSize){ 45 | if(keys_data.length > maxSize){ 46 | if(returnError){return error(true,null,'max_limit_reached-data_size');} 47 | return engine.common.error('max_limit_reached-data_size'); 48 | } 49 | } 50 | 51 | //add any further data types first 52 | let dataTypes = ['object','array','string','number','email','boolean']; 53 | 54 | const defaultStrLen = 255; 55 | 56 | //loop the schema and check the data 57 | for(let key in schema){ 58 | 59 | const item = schema[key]; 60 | 61 | //check shcema item type 62 | if(typeof(item) !== 'object'){ 63 | if(returnError){return error(false,key,'invalid-schema_item_type');} 64 | return engine.common.error('invalid-schema_item_type-' + key); 65 | break; 66 | } 67 | 68 | //check if schema item have been declared 69 | if(!item.type || dataTypes.indexOf(item.type) < 0){ 70 | if(returnError){return error(false,key,'not_found/invalid-schema_item_type');} 71 | return engine.common.error('not_found/invalid-schema_item_type-' + key); 72 | break; 73 | } 74 | 75 | let 76 | type = item.type, 77 | needed = true, 78 | present = false; 79 | 80 | //check if the item is elective 81 | if(item.elective && item.elective == true){ 82 | if(schema_type == 'static'){ 83 | if(returnError){return error(false,key,'invalid-elective_item_in_static_schema-schema_key_in_data');} 84 | return engine.common.error('invalid-elective_item_in_static_schema-schema_key_in_data-' + key); 85 | break; 86 | } else { 87 | needed = false; 88 | } 89 | } 90 | 91 | //check if schema key exists in data 92 | if(needed == true && data.hasOwnProperty(key) == false){ 93 | if(returnError){return error(false,key,'not_found-schema_key_in_data');} 94 | return engine.common.error('not_found-schema_key_in_data-' + key); 95 | break; 96 | } 97 | 98 | //check if static data exists 99 | if(data.hasOwnProperty(key) == true && data[key] !== undefined && data[key] !== null){ 100 | present = true; 101 | } 102 | 103 | //check if the data value is not false for non boolean keys 104 | if(present && type !== 'boolean' && data[key] === false){ 105 | present = false; 106 | } 107 | 108 | //check if the data is needed and present 109 | if(present == false && needed == true){ 110 | if(returnError){return error(false,key,'not_found-data-data_type_for_key');} 111 | return engine.common.error('not_found-data-data_type_for_key-' + key); 112 | break; 113 | } 114 | 115 | //check if data type is valid 116 | if(present == true && type !== 'email' && checkType(data[key]) !== type){ 117 | if(returnError){return error(false,key,'invalid-data_type_for_key');} 118 | return engine.common.error('invalid-data_type_for_key-' + key); 119 | break; 120 | } 121 | 122 | //check the array and string length for schema key in data 123 | if((type == 'array' || type == 'string') && present == true){ 124 | 125 | if(!data[key]){ 126 | if(returnError){return error(false,key,'not_found-data-schema_key_in_data');} 127 | return engine.common.error('not_found-data-schema_key_in_data-' + key); 128 | break; 129 | } 130 | 131 | if(item.min && data[key].length < item.min){ 132 | if(returnError){return error(false,key,'min_length_reached-schema_key_in_data');} 133 | return engine.common.error('min_length_reached-schema_key_in_data-' + key); 134 | break; 135 | } 136 | 137 | if(item.max && data[key].length > item.max){ 138 | if(returnError){return error(false,key,'max_length_reached-schema_key_in_data');} 139 | return engine.common.error('max_length_reached-schema_key_in_data-' + key); 140 | break; 141 | } else if(!item.max && type == 'string' && data[key].length > defaultStrLen){ 142 | if(returnError){return error(false,key,'default_max_length_reached-schema_key_in_data');} 143 | return engine.common.error('default_max_length_reached-schema_key_in_data-' + key); 144 | break; 145 | } 146 | 147 | //check if the key is a valid option 148 | if(type == 'string'){ 149 | if(item.options && checkType(item.options)){ 150 | if(item.options.indexOf(data[key]) < 0){ 151 | if(returnError){return error(false,key,'invalid_option-schema_key_in_data');} 152 | return engine.common.error('invalid_option-schema_key_in_data-' + key); 153 | break; 154 | } 155 | } 156 | } 157 | 158 | } 159 | 160 | //check the number for schema key in data 161 | if(type == 'number' && present == true){ 162 | 163 | if(data[key] !== 0 && !data[key]){ 164 | if(returnError){return error(false,key,'not_found-data-schema_key_in_data');} 165 | return engine.common.error('not_found-data-schema_key_in_data-' + key); 166 | break; 167 | } 168 | 169 | if(item.min && data[key] < item.min){ 170 | if(returnError){return error(false,key,'min_length_reached-schema_key_in_data');} 171 | return engine.common.error('min_length_reached-schema_key_in_data-' + key); 172 | break; 173 | } 174 | 175 | if(item.max && data[key] > item.max){ 176 | if(returnError){return error(false,key,'max_length_reached-schema_key_in_data');} 177 | return engine.common.error('max_length_reached-schema_key_in_data-' + key); 178 | break; 179 | } 180 | 181 | } 182 | 183 | //check the object key size for schema key in data 184 | if(type == 'object' && present == true){ 185 | 186 | if(data[key] == false){ 187 | if(returnError){return error(false,key,'not_found-data-schema_key_in_data');} 188 | return engine.common.error('not_found-data-schema_key_in_data-' + key); 189 | break; 190 | } 191 | 192 | if(item.min && Object.keys(data[key]).length < item.min){ 193 | if(returnError){return error(false,key,'min_length_reached-schema_key_in_data');} 194 | return engine.common.error('min_length_reached-schema_key_in_data-' + key); 195 | break; 196 | } 197 | 198 | if(item.max && Object.keys(data[key]).length > item.max){ 199 | if(returnError){return error(false,key,'max_length_reached-schema_key_in_data');} 200 | return engine.common.error('max_length_reached-schema_key_in_data-' + key); 201 | break; 202 | } 203 | 204 | if(item.validate && typeof(item.validate) === "object" && item.validate.hasOwnProperty('schema')){ 205 | let checkSchema = json(item.validate.schema,data[key],item.validate.dynamic,item.validate.maxSize,item.validate.returnError); 206 | if(!checkSchema){ 207 | if(returnError && item.validate.returnError){return error(false,key,'failed-object_schema_check-schema_key_in_data-'+key);} 208 | return engine.common.error('failed-object_schema_check-schema_key_in_data-' + key); 209 | break; 210 | } 211 | } 212 | 213 | } 214 | 215 | //check the boolean data type 216 | if(type == 'boolean' && present == true){ 217 | if(data[key] !== true && data[key] !== false){ 218 | if(returnError){return error(false,key,'invalid-invalid_data-expected_boolean');} 219 | return engine.common.error('invalid-invalid_data-expected_boolean' + key); 220 | break; 221 | } 222 | } 223 | 224 | //check email and email string length for schema key in data 225 | if(type == 'email' && present == true){ 226 | 227 | if(checkType(data[key]) !== 'string'){ 228 | if(returnError){return error(false,key,'invalid-schema_key_in_data');} 229 | return engine.common.error('invalid-schema_key_in_data-' + key); 230 | break; 231 | } 232 | 233 | if(item.min && Object.keys(data[key]).length < item.min){ 234 | if(returnError){return error(false,key,'min_length_reached-schema_key_in_data');} 235 | return engine.common.error('min_length_reached-schema_key_in_data-' + key); 236 | break; 237 | } 238 | 239 | if(item.max && Object.keys(data[key]).length > item.max){ 240 | if(returnError){return error(false,key,'max_length_reached-schema_key_in_data');} 241 | return engine.common.error('max_length_reached-schema_key_in_data-' + key); 242 | break; 243 | } 244 | 245 | if(checkEmail(data[key]) == false){ 246 | if(returnError){return error(false,key,'invalid-email_key');} 247 | return engine.common.error('invalid-email_key-' + key); 248 | break; 249 | } 250 | 251 | } 252 | 253 | } 254 | //loop ends here 255 | 256 | //final functional return 257 | return true; 258 | 259 | } 260 | 261 | function checkType(data){ 262 | 263 | if(data == undefined || data == null){ 264 | return data; 265 | } 266 | 267 | let base = typeof(data); 268 | 269 | if(base == 'object'){ 270 | if(data instanceof Array){ 271 | return 'array'; 272 | } 273 | if(data instanceof Object){ 274 | return 'object'; 275 | } 276 | } 277 | 278 | if(base == 'string' || base == 'number'){ 279 | return base; 280 | } 281 | 282 | if(data == false || data == true){ 283 | return 'boolean'; 284 | } 285 | 286 | return null; 287 | 288 | } 289 | 290 | function checkEmail(mail){ 291 | 292 | let re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 293 | let test = re.test(String(mail).toLowerCase()); 294 | 295 | if(test == true){ 296 | return true; 297 | } else { 298 | return false; 299 | } 300 | 301 | } 302 | -------------------------------------------------------------------------------- /loader.js: -------------------------------------------------------------------------------- 1 | const log = false; 2 | const httpMarker = 'http://'; 3 | 4 | module.exports = { 5 | 6 | load : { 7 | 8 | image:function(url){ 9 | let img=new Image(); 10 | img.src=url; 11 | }, 12 | 13 | wasm : async function(options){ 14 | 15 | return new Promise(async (resolve,reject)=>{ 16 | 17 | engine.common.tell('loading page module',log); 18 | 19 | let error; 20 | 21 | if(!engine.validate.json({ 22 | type:{type:'string',options:['local','url']}, 23 | url:{type:'string',elective:true}, 24 | module:{type:'string',elective:true} 25 | },options,'dynamic',3)){ 26 | error = 'invalid/not_found-compName'; 27 | reject(error); 28 | } 29 | 30 | let location; 31 | if(options.type === 'local'){ 32 | if(!options.module){ 33 | error = 'invalid/not_found-module'; 34 | reject(error); 35 | } 36 | if(window.hasOwnProperty('is_electron') || window.hasOwnProperty('is_cordova')){ 37 | location = 'js/wasm/' + options.module + '/index.wasm'; 38 | } else { 39 | location = baseHref + '/js/wasm/' + options.module + '/' + '/index.wasm'; 40 | } 41 | } 42 | if(options.type === 'url'){ 43 | location = options.url; 44 | } 45 | 46 | let js_path = 'wasm/' + options.module + '/wrapper.js'; 47 | const load_js = await engine.loader.load.js({ 48 | type:'local', 49 | url:js_path, 50 | }); 51 | if(!load_js){ 52 | reject("failed-load_wasm_js_wrapper_file"); 53 | return false; 54 | } 55 | 56 | let controller = options.module + '_wasm_controller'; 57 | if(!eval(controller)){ 58 | reject("failed-load_wasm_js_wrapper_controller"); 59 | return false; 60 | } 61 | 62 | let hold_controller = eval(controller); 63 | if(!window.wasmControllers){ 64 | window.wasmControllers = {}; 65 | } 66 | window.wasmControllers[controller] = hold_controller; 67 | 68 | if(engine.get.platform("cordova")){ 69 | let cordova_location = 'file:///android_asset/www/' + location; 70 | document.addEventListener("deviceready", ()=>{ 71 | window.resolveLocalFileSystemURL(cordova_location,(fileEntry)=>{ 72 | fileEntry.file((file)=>{ 73 | var reader = new FileReader(); 74 | reader.onloadend = async ()=>{ 75 | let init = await hold_controller(reader.result); 76 | if(!init){ 77 | error = "failed-init-wasm_module"; 78 | console.log(e); 79 | console.log(error); 80 | reject(error); 81 | return false; 82 | } 83 | if(!window.wasmModules){ 84 | window.wasmModules = {}; 85 | } 86 | window.wasmModules[options.module] = init; 87 | resolve(init); 88 | }; 89 | reader.onerror = (e)=>{ 90 | error = "failed-file_reader"; 91 | console.log(e); 92 | console.log(error); 93 | reject(error); 94 | } 95 | reader.readAsArrayBuffer(file); 96 | },(e)=>{ 97 | error = "failed-file_opener"; 98 | console.log(e); 99 | console.log(error); 100 | reject(error); 101 | }); 102 | },(e)=>{ 103 | error = "failed-resolveLocalFileSystemURL"; 104 | console.log(e); 105 | console.log(error); 106 | reject(error); 107 | }); 108 | }, false); 109 | return; 110 | } 111 | 112 | let init = await hold_controller(location); 113 | if(!init){ 114 | reject("failed-init-wasm_module"); 115 | return false; 116 | } 117 | if(!window.wasmModules){ 118 | window.wasmModules = {}; 119 | } 120 | window.wasmModules[options.module] = hold_controller; 121 | resolve(hold_controller); 122 | 123 | }); 124 | 125 | }, 126 | 127 | js:(options)=>{ 128 | if(!engine.validate.json({ 129 | id:{type:'string',elective:true}, 130 | type:{type:'string',options:['local','url']}, 131 | url:{type:'string',max:4048}, 132 | module:{type:'boolean',elective:true} 133 | },options,'dynamic',4)){return engine.common.error("failed-invalid_data-load_js");} 134 | let link = options.type != "url"?process_location("js/" + ensure(options.url,".js")):options.url; 135 | return load_js(options.id,link,options.module); 136 | }, 137 | 138 | comp:(compName,load_css)=>{ 139 | if(engine.global.comp[compName]){return return_resolve();} 140 | return load_js_with_css( 141 | process_location('js/globals/' + ensure(compName,"Comp") + '/globalComp.js'), 142 | process_location('css/globals/' + ensure(compName,"Comp") + '/comp.css'),load_css 143 | ); 144 | }, 145 | 146 | page:(pageName,load_css)=>{ 147 | if(engine.get.pageModule(pageName)){return return_resolve();} 148 | return load_js_with_css( 149 | process_location('js/pages/' + ensure(pageName,"Page") + '/page.js'), 150 | process_location('css/pages/' + ensure(pageName,"Page") + '/page.css'),load_css 151 | ); 152 | }, 153 | 154 | cont:(pageName,contName,load_css)=>{ 155 | if(engine.get.contModule(pageName,contName)){return return_resolve();} 156 | return load_js_with_css( 157 | process_location('js/pages/' + ensure(pageName,"Page") + '/conts/' + ensure(contName,"Cont") + "/cont.js"), 158 | process_location('css/pages/' + ensure(pageName,"Page") + '/conts/' + ensure(contName,"Cont") + "/cont.css"),load_css 159 | ); 160 | }, 161 | 162 | panel:(pageName,contName,panelName,load_css)=>{ 163 | if(engine.get.panelModule(pageName,contName,panelName)){return return_resolve();} 164 | return load_js_with_css( 165 | process_location('js/pages/' + ensure(pageName,"Page") + '/conts/' + ensure(contName,"Cont") + '/panels/' + ensure(panelName,"Panel") + '/panel.js'), 166 | process_location('css/pages/' + ensure(pageName,"Page") + '/conts/' + ensure(contName,"Cont") + '/panels/' + ensure(panelName,"Panel") + '/panel.css'),load_css 167 | ); 168 | }, 169 | 170 | sassPack : function(packName,is_link){ 171 | return load_css(process_location('css/sassPack/' + ensure(packName,"Pack") + "/pack.css")); 172 | } 173 | 174 | }, 175 | 176 | css : function(fileName,is_link){ 177 | let link = fileName; 178 | if(!is_link){ 179 | link = process_location('css/' + ensure(fileName,".css")); 180 | } 181 | return load_css(link); 182 | }, 183 | 184 | hook : { 185 | 186 | comp:(data)=>{ 187 | 188 | if(!data.comp || !data.function){ 189 | return engine.common.error("not_found-comp/function"); 190 | } 191 | 192 | engine.hooks.comps[data.comp] = data.function; 193 | 194 | }, 195 | 196 | page:(data)=>{ 197 | 198 | if(!data.page || !data.function){ 199 | return engine.common.error("not_found-page/function"); 200 | } 201 | 202 | engine.hooks.pages[data.page] = data.function; 203 | let hold = window.pageModules; 204 | window.pageModules = new Proxy(hold,{ 205 | set(obj,key,val){ 206 | obj[key] = val; 207 | engine.hooks.pages[data.page](); 208 | } 209 | }); 210 | 211 | }, 212 | 213 | cont:(data)=>{ 214 | 215 | if(!data.page || !data.cont || !data.function){ 216 | return engine.common.error("not_found-page/cont/function"); 217 | } 218 | 219 | engine.hooks.conts[data.page] = {}; 220 | engine.hooks.conts[data.page][data.cont] = data.function; 221 | let hold = window.pageModules; 222 | 223 | window.pageModules[data.page].contModules = new Proxy(hold,{ 224 | set(obj,key,val){ 225 | obj[key] = val; 226 | engine.hooks.conts[data.page][key](); 227 | } 228 | }); 229 | 230 | }, 231 | 232 | panel:(data)=>{ 233 | 234 | if(!data.page || !data.cont || !data.panel || !data.function){ 235 | return engine.common.error("not_found-page/cont/panel/function"); 236 | } 237 | 238 | engine.hooks.panels[data.page] = {}; 239 | engine.hooks.panels[data.page][data.cont] = {}; 240 | engine.hooks.panels[data.page][data.cont][data.panel] = data.function; 241 | let hold = window.pageModules; 242 | 243 | window.pageModules[data.page].contModules[data.cont].panelModules = new Proxy(hold,{ 244 | set(obj,key,val){ 245 | obj[key] = val; 246 | engine.hooks.panels[data.page][data.cont][key](); 247 | } 248 | }); 249 | 250 | } 251 | 252 | } 253 | 254 | }; 255 | 256 | function return_resolve(){ 257 | return new Promise((resolve)=>{resolve();}); 258 | } 259 | 260 | function ensure(text,anchor){ 261 | if(text.indexOf(anchor) >= 0){return text;} else {return text + anchor;} 262 | } 263 | 264 | function process_location(location){ 265 | if(window.hasOwnProperty('is_electron') || window.hasOwnProperty('is_cordova')){ 266 | return location; 267 | } else { 268 | return location = baseHref + '/' + location; 269 | } 270 | } 271 | 272 | function load_js_with_css(jsPath,cssPath,do_load_css){ 273 | if(do_load_css){ 274 | return new Promise((resolve,reject)=>{ 275 | Promise.all([ 276 | load_js(null,jsPath,false), 277 | load_css(cssPath) 278 | ]) 279 | .then(()=>{ 280 | resolve(); 281 | }) 282 | .catch((e)=>{ 283 | reject(e); 284 | }); 285 | }); 286 | } else { 287 | return load_js(null,jsPath,false); 288 | } 289 | } 290 | 291 | function load_js(id,location,is_module){ 292 | 293 | return new Promise((resolve,reject)=>{ 294 | 295 | let parent = document.getElementsByTagName("head")[0]; 296 | let scp = document.createElement('script'); 297 | scp.type = "text/javascript"; 298 | scp.src = location; 299 | if(is_module){ 300 | scp.type = "module"; 301 | if(id){ 302 | scp.id = id; 303 | } 304 | } 305 | 306 | scp.onload = function(dd){ 307 | engine.common.tell('js_loaded',log); 308 | resolve(true); 309 | }; 310 | 311 | scp.onerror = function(e){ 312 | console.error(e); 313 | engine.common.error('failed-load_js'); 314 | reject('failed-load_js'); 315 | } 316 | 317 | parent.appendChild(scp); 318 | 319 | }); 320 | 321 | } 322 | 323 | function load_css(location){ 324 | 325 | return new Promise((resolve,reject)=>{ 326 | let parent = document.getElementsByTagName("head")[0]; 327 | let css = document.createElement('link'); 328 | css.rel = 'stylesheet'; 329 | css.type = 'text/css'; 330 | css.href = location; 331 | css.media = 'all'; 332 | parent.appendChild(css); 333 | css.onload = function(dd){ 334 | resolve(); 335 | }; 336 | css.onerror = function(e){ 337 | console.error(e); 338 | engine.common.error('failed-load_js'); 339 | reject('failed-load_css =>' + e); 340 | } 341 | }); 342 | 343 | } 344 | -------------------------------------------------------------------------------- /make/creator.js: -------------------------------------------------------------------------------- 1 | const common = require('../common'); 2 | const checkBaseOptions = require('./check').check; 3 | const httpMarker = 'http://'; 4 | const body = document.getElementsByTagName("BODY")[0]; 5 | let scollers = {}; 6 | let keepScroller = []; 7 | let scoll_direction = 'down'; 8 | let last_scroll_position = window.pageYOffset; 9 | let showing = {}; 10 | let exit = {}; 11 | let os,platform; 12 | 13 | window.addEventListener('scroll', scrollFunction); 14 | 15 | function scrollFunction(){ 16 | 17 | let keys = Object.keys(scollers); 18 | let windowHeight = window.innerHeight; 19 | 20 | let current_scroll_position = window.pageYOffset; 21 | if(current_scroll_position < last_scroll_position){ 22 | scoll_direction = 'up'; 23 | } else { 24 | scoll_direction = 'down'; 25 | } 26 | let view_count = windowHeight + current_scroll_position; 27 | 28 | for(var id in scollers){ 29 | 30 | let e = document.getElementById(id); 31 | if(!e){ 32 | delete scollers[id]; 33 | } else { 34 | 35 | if(!showing.hasOwnProperty(id)){ 36 | showing[id] = false; 37 | } 38 | 39 | let positionFromBottom = e.getBoundingClientRect().bottom; 40 | let positionFromTop = e.getBoundingClientRect().top; 41 | 42 | let bottom_diff = windowHeight - positionFromBottom; 43 | let top_diff = windowHeight - positionFromTop; 44 | 45 | if(scoll_direction == 'up'){ 46 | if(positionFromBottom >= 0 && bottom_diff >= 0 && showing[id] == false){ 47 | process_enter(id); 48 | } 49 | if(top_diff < 0){ 50 | process_exit(id); 51 | } 52 | } 53 | 54 | if(scoll_direction == 'down'){ 55 | if(top_diff >= 0 && positionFromBottom >= 0 && showing[id] == false){ 56 | process_enter(id); 57 | } 58 | if(positionFromBottom <= 0){ 59 | process_exit(id); 60 | } 61 | } 62 | 63 | } 64 | 65 | 66 | 67 | }//loop ends here 68 | 69 | function process_enter(id){ 70 | if(showing[id] == true){return false;} 71 | showing[id] = true; 72 | let func = scollers[id] 73 | if(typeof(func) == 'function'){func(id);} 74 | if(keepScroller.indexOf(id) < 0 && exit.hasOwnProperty(id) == false){ 75 | delete scollers[id]; 76 | delete showing[id]; 77 | } 78 | return true; 79 | } 80 | 81 | function process_exit(id){ 82 | if(showing[id] == false){return false;} 83 | showing[id] = false; 84 | let func = exit[id] 85 | if(typeof(func) == 'function'){func(id);} 86 | if(keepScroller.indexOf(id) < 0){ 87 | delete scollers[id]; 88 | delete showing[id]; 89 | delete exit[id]; 90 | } 91 | return true; 92 | } 93 | 94 | last_scroll_position = current_scroll_position; 95 | 96 | }; 97 | 98 | module.exports = (tag,options)=>{ 99 | 100 | if(!os || !platform){ 101 | os = engine.get.os(),platform = engine.get.platform(); 102 | } 103 | 104 | //check options object 105 | let check = checkBaseOptions(options); 106 | if(check == false){ 107 | return common.error('invalid_options',options); 108 | } 109 | 110 | if(!options.id){ 111 | options.id = engine.uniqid(); 112 | } 113 | 114 | //check parent 115 | let get = document.getElementById(options.parent); 116 | if(get == null){ 117 | return common.error('invalid_parent',options); 118 | } 119 | 120 | //make element 121 | let id = options.parent + '-' + tag + '-' + options.id; 122 | let object = document.createElement(tag); 123 | object.id = id; 124 | 125 | if(options.enter){ 126 | if(!scollers.hasOwnProperty(id)){ 127 | scollers[id] = options.enter; 128 | } 129 | if(options.keepScroller && options.keepScroller == true){ 130 | if(keepScroller.indexOf(id) < 0){ 131 | keepScroller.push(id); 132 | } 133 | } 134 | } 135 | 136 | if(options.exit){ 137 | if(!scollers.hasOwnProperty(id)){ 138 | if(!options.enter){ 139 | scollers[id] = null; 140 | } 141 | } 142 | if(exit.hasOwnProperty(id) == false){ 143 | exit[id] = options.exit; 144 | } 145 | if(options.keepScroller && options.keepScroller == true){ 146 | if(keepScroller.indexOf(id) < 0){ 147 | keepScroller.push(id); 148 | } 149 | } 150 | } 151 | 152 | if(options.class){ 153 | object.className = options.class; 154 | } else { 155 | if(tag == 'input' && options.type !== 'button'){ 156 | object.className = 'form-input'; 157 | } 158 | if(tag == 'select'){ 159 | object.className = 'form-select'; 160 | } 161 | if(tag == 'checkbox'){ 162 | object.className = 'form-checkbox'; 163 | } 164 | if(tag == 'input' && options.type == 'button'){ 165 | object.className = 'form-button'; 166 | } 167 | } 168 | 169 | if(options.hasOwnProperty('text') && options.text !== undefined && options.text !== null){ 170 | object.innerHTML = options.text; 171 | } 172 | if(options.style){ 173 | object.style = options.style; 174 | } 175 | 176 | for(var i in options){ 177 | if( 178 | i !== 'function' && 179 | i !== 'events' && 180 | i !== 'event' && 181 | i !== 'text' && 182 | i !== 'style' && 183 | i !== 'class' && 184 | i !== 'parent' && 185 | i !== 'tag' && 186 | i !== 'list_id' && 187 | i !== 'id' && 188 | i !== 'draw' 189 | ){ 190 | if(options[i]){ 191 | object[i] = options[i]; 192 | } 193 | } 194 | } 195 | 196 | //select items 197 | if(options.options && typeof(options.options) == 'object' && options.options.length > 0){ 198 | for(var i=0;i{ 229 | options.function(object,options.functionData,eve); 230 | }); 231 | } 232 | 233 | if(options.event && options.events){ 234 | common.error('invalid_config=>event&&events__cannot_co_exists',options); 235 | } 236 | 237 | if(options.events && !options.event){ 238 | for(var i in options.events){ 239 | let e = options.events[i]; 240 | if(e.event && e.function){ 241 | if( 242 | typeof(e.event) == 'string' && 243 | typeof(e.function) == 'function' 244 | ){ 245 | object.addEventListener(e.event,(eve)=>{ 246 | e.function(object.id,eve) 247 | }); 248 | } 249 | } 250 | } 251 | 252 | } 253 | 254 | if(options.event){ 255 | if( 256 | typeof(options.event.type) == 'string' && 257 | typeof(options.event.function) == 'function' 258 | ){ 259 | object.addEventListener(options.event.type,(eve)=>{ 260 | options.event.function(object.id,eve) 261 | }); 262 | } 263 | } 264 | 265 | if(options.expire && typeof(options.expire) == 'number' && options.expire > 1000){ 266 | setTimeout(function(){ 267 | engine.view.remove(object.id); 268 | scrollFunction(); 269 | }, options.expire); 270 | } 271 | 272 | if(options.position){ 273 | get.insertAdjacentElement(options.position,object); 274 | } else { 275 | get.appendChild(object); 276 | } 277 | 278 | //*************************** 279 | //draw here 280 | 281 | if(options.draw){ 282 | 283 | let draw; 284 | if(options.draw.all){ 285 | draw = options.draw.all; 286 | } 287 | if(platform === "pc" && options.draw.browser){ 288 | if(options.draw.browser.pc){ 289 | reduce_draw(draw,options.draw.browser.pc); 290 | } 291 | } 292 | if(platform === "mobile" && options.draw.browser){ 293 | if(options.draw.browser.mobile){ 294 | reduce_draw(draw,options.draw.browser.mobile); 295 | } 296 | } 297 | if(platform === "cordova" && options.draw.cordova){ 298 | if(options.draw.cordova.all){ 299 | reduce_draw(draw,options.draw.cordova.all); 300 | } 301 | if(os==="ios" && options.draw.cordova.ios){ 302 | reduce_draw(draw,options.draw.cordova.ios); 303 | } 304 | if(os==="android" && options.draw.cordova.android){ 305 | reduce_draw(draw,options.draw.cordova.android); 306 | } 307 | } 308 | if(platform === "electron" && options.draw.electron){ 309 | if(options.draw.electron.all){ 310 | reduce_draw(draw,options.draw.electron.all); 311 | } 312 | if(os==="windows" && options.draw.electron.windows){ 313 | reduce_draw(draw,options.draw.electron.windows); 314 | } 315 | if(os==="linux" && options.draw.electron.linux){ 316 | reduce_draw(draw,options.draw.electron.linux); 317 | } 318 | if(os==="mac" && options.draw.electron.mac){ 319 | reduce_draw(draw,options.draw.electron.mac); 320 | } 321 | } 322 | 323 | object.style = draw_as_string(draw); 324 | 325 | } 326 | 327 | function reduce_draw(base,next){ 328 | for(let k in next){ 329 | if(next[k] === false){delete base[k];} else if(typeof(next[k]) === "string"){base[k] = next[k];} 330 | } 331 | } 332 | function draw_as_string(final){ 333 | let collect = ''; 334 | for(let k in final){ 335 | collect += k + ":" + final[k] + ";" 336 | } 337 | return collect; 338 | } 339 | 340 | //*************************** 341 | //touch func 342 | 343 | let startTime; 344 | 345 | if(options.hasOwnProperty("touch")){ 346 | if(typeof(options.touch) == "function"){ 347 | let startX,startY,lastX,lastY; 348 | object.addEventListener("touchstart",(eve)=>{ 349 | x = eve.touches[0].clientX,y = eve.touches[0].clientY; 350 | startX = x;startY = y; 351 | startTime = new Date().getTime(); 352 | }); 353 | object.addEventListener("touchmove",(eve)=>{ 354 | eve.preventDefault(); 355 | x = eve.touches[0].clientX,y = eve.touches[0].clientY; 356 | if(!lastX || !lastY){lastX = x,lastY = y;return;} 357 | const process = process_move(startX,startY,x,y,"continue",startTime); 358 | lastX = process.posX,lastY = process.posY; 359 | options.touch(object.id,process,eve); 360 | }); 361 | object.addEventListener("touchend",(eve)=>{ 362 | if(!startX || !startY){startX = lastX,startY = lastY;return;} 363 | const process = process_move(startX,startY,lastX,lastY,"end",startTime); 364 | options.touch(object.id,process,eve); 365 | }); 366 | object.addEventListener("mousedown",(eve)=>{ 367 | startX = eve.clientX;startY = eve.clientY; 368 | startTime = new Date().getTime(); 369 | document.addEventListener("mousemove",move); 370 | document.addEventListener("mouseup",end); 371 | }); 372 | const move = (eve)=>{ 373 | x = eve.clientX,y = eve.clientY; 374 | if(!lastX || !lastY){lastX = x,lastY = y;return;} 375 | const process = process_move(startX,startY,x,y,"continue",startTime); 376 | lastX = process.posX,lastY = process.posY; 377 | options.touch(object.id,process,eve); 378 | }; 379 | const end = (eve)=>{ 380 | if(!startX || !startY){startX = lastX,startY = lastY;return;} 381 | const process = process_move(startX,startY,lastX,lastY,"end",startTime); 382 | document.removeEventListener("mousemove", move); 383 | document.removeEventListener("mouseup", end); 384 | options.touch(object.id,process,eve); 385 | }; 386 | } 387 | } 388 | 389 | //**************************************** 390 | //timer 391 | 392 | if(options.timer){ 393 | if(options.timer.time && options.timer.function){ 394 | let timer_started = false,timer_timeout; 395 | object.addEventListener("mousedown",(eve)=>{ 396 | timer_started = true; 397 | timer_timeout = setTimeout(function () { 398 | timer_started = false; 399 | options.timer.function(); 400 | }, options.timer.time); 401 | }); 402 | object.addEventListener("mouseout",(eve)=>{ 403 | if(!timer_started){return;} else { 404 | clearTimeout(timer_timeout); 405 | } 406 | }); 407 | object.addEventListener("mouseup",(eve)=>{ 408 | if(!timer_started){return;} else { 409 | clearTimeout(timer_timeout); 410 | } 411 | }); 412 | } 413 | } 414 | 415 | scrollFunction(); 416 | 417 | return object.id; 418 | 419 | } 420 | 421 | function process_move(lastX,lastY,x,y,type,startTime){ 422 | let dirX = 'left',dirY = 'up', 423 | diffX = x - lastX,diffY = y - lastY, 424 | perc_x = Math.ceil((Math.abs(diffX) / screen.width) * 100), 425 | perc_y = Math.ceil((Math.abs(diffY) / screen.height) * 100); 426 | if(diffY === 0){dirY = 'none';} 427 | if(diffY > 0){dirY = 'down';} 428 | if(diffY < 0){dirY = 'up';} 429 | if(diffX === 0){dirX = 'none';} 430 | if(diffX > 0){dirX = 'right';} 431 | if(diffX < 0){dirX = 'left';} 432 | let now = new Date().getTime(); 433 | let time_diff = now - startTime; 434 | let collect = { 435 | type:type, 436 | dirX:dirX,dirY:dirY, 437 | moveX:Math.abs(diffX),moveY:Math.abs(diffY), 438 | posX:x,posY:y, 439 | basePosX:lastX, 440 | basePosY:lastY, 441 | percX:perc_x,percY:perc_y, 442 | time:time_diff 443 | }; 444 | return collect; 445 | } 446 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vegana 2 | 3 | Vegana is a js framework to build single page apps with native support of a defined document structure for ease of developemnt in big teams, code sharing, native and fast lazyness for a smooth browsing experience and native js web api plugins for ease of use and faster development speeds.basic concept is to reduce final bundle size and break the bundle based on a document structure making the browsing experience smooth and fast. 4 | 5 | - tiny and broken up document structure 6 | - native lazyness with super fast loading and web api plugins. 7 | - native api framework support with rocket iron and wet. 8 | - only js and sass develoment enviorment to speed up development multitudes of time. 9 | - prebuilt native components and upcoming support for web compoenets. 10 | - defined code structure to make onboarding new devs easy for big teams. 11 | - native nodejs cli with cross platform support. 12 | - non defined sass data structure. 13 | - sass loader for electron and cordova is now supported sorry guys for breaking that. 14 | 15 | # what's new 16 | 17 | - loader is more efficient in space and faster then before. 18 | - module loader now checks if modules are already loaded and resolves if they are. 19 | - loader now allows to load module css just by passing load_css param as true. 20 | - you can load sassPack from sassPack loader api 21 | - native sass lazy files are deprecated. 22 | 23 | # When to use! 24 | 25 | - if your project is big and you need the website to load in under a sec. 26 | - if you have a big team and want to develop something fast with easy of dev onboarding 27 | - if your project is with multiple use heavy pages. 28 | - if your project use an api. 29 | - if you dont want breaking changes in upcoming updates in app or in cli. 30 | - if you have prebuilt sass or css style sheet. 31 | 32 | # Before you start 33 | 34 | - please get yourself familiar with atleast js css and sass. 35 | - get a little bit familiar with concepts of js api's, npm libraries, size of final bundle and component laziness. 36 | - get familier with nodejs and npm. 37 | - installing npm module as a global app. 38 | - efficiency of js data structures. 39 | - read the document structure docs. 40 | 41 | this framework is a js and sass only enviorment please dont get confused in finding where to place the html. 42 | 43 | official docs at [Docs] 44 | 45 | [Docs]: 46 | 47 | ------ 48 | ------ 49 | 50 | ## Installation 51 | 52 | - install node js here [NodeJs] 53 | - make sure npm is installed. 54 | - install vegana as a global module ``` $ npm i --global vegana ``` 55 | - check if vegana is installed globally ``` $ vegana check ``` 56 | 57 | [NodeJs]: 58 | 59 | ------ 60 | ------ 61 | 62 | # Index 63 | - [CLI](#cli) 64 | - [Initiate a new Project](#initiate-a-new-project) 65 | - [Serve the Project Generated](#serve-the-project-generated) 66 | - [Build the Project](#build-the-project) 67 | - [Generate Components](#generate-components) 68 | - [Generate a Page](#generate-a-page) 69 | - [Generate a Cont](#generate-a-cont) 70 | - [Generate a Panel](#generate-a-panel) 71 | - [Generate a Component](#generate-a-component) 72 | - [Vegana Document Structure](#vegana-document-structure) 73 | - [Vegana App Structure](#vegana-app-structure) 74 | - [Vegana engine Apis](#vegana-engine-apis) 75 | - [Vegana Routing System](#vegana-routing-system) 76 | - [Router Init Apis](#router-init-apis) 77 | - [Router Navigate](#router-navigate) 78 | - [Router Get](#router-get) 79 | - [Router Set](#router-set) 80 | - [Lazy Loader Apis](#lazy-loader-apis) 81 | - [Vegana Make Apis](#vegana-make-apis) 82 | - [Vegana Standard Dom Element Apis](#vegana-standard-dom-element-apis) 83 | - [Vegana Exclusive Element Apis](#vegana-exclusive-element-apis) 84 | - [Vegana view Api](#vegana-view-api) 85 | - [Vegana Session Api](#vegana-session-api) 86 | - [Vegana Validate Api](#vegana-validate-api) 87 | - [Vegana Http Request Api](#vegana-http-request-api) 88 | - [Wet Vegana Api](#wet-vegana-api) 89 | 90 | ------ 91 | ------ 92 | 93 | ## Cli 94 | Vegana cli is a nodejs based cli app and gives a cross platform uniform experience. the goal with cli was to make a fast developement enviorment by doing all the heavy lifting like live reloading, final app building and optimization image optimization ,component generation and inbuilt server for development. 95 | 96 | ### features 97 | 98 | - Inbuilt Server with Live Reloading 99 | - Live sass compilation 100 | - Native app building and code and image optimization. 101 | - Fast Component generation and auto lazy componet integration. 102 | 103 | ------ 104 | 105 | ### Commands 106 | 107 | #### Initiate a new Project 108 | this shell command generates the files required by the vegana framework in current working directory or the directory where you have called the command. in other words make the directory with project name and initiate the project inside the new directory. 109 | 110 | ```sh 111 | $ vegana init test 112 | ``` 113 | here test is the project name. 114 | 115 | ------ 116 | 117 | #### Serve the Project Generated 118 | this command starts a server and compiles the app files and serves a built app to the browser. Vegana use the port 5566 to start the server at and currently cannot use any other port please make sure the port is not in use while you serve the app. 119 | this app listens for file chnages in the app directory and re buods the app as nessesery. the app is optimized to reload only the compoent rebuild you should not have any issue with the optimization either.the bundle served is non optimized for faster builds and does not represent the final bundle size. 120 | 121 | ```sh 122 | $ vegana serve 123 | ``` 124 | 125 | you can now start you app development. the app comes with a test document which can be removed or worked around your choice. 126 | 127 | ------ 128 | 129 | #### Build the Project 130 | this app builds a optimized version of you app with app the lazy components integrated in the build folder the build folder is now ready to be deployed to any server.the code generated cannot be used for further generated so please keep you app sources code backed up for future development. 131 | 132 | ```sh 133 | $ vegana build 134 | ``` 135 | 136 | ------ 137 | 138 | ## Generate Components 139 | this command generates a predined set of components please read the component docs before hand to understand the proper and optimized use of em. 140 | 141 | #### Generate a Page 142 | this command generates a page ocmponets and takes page name and lazziness flag as argument please make sure you are running this command in the app/pages folder for it to work. if page name is repeated i guess the query fails if not a folder with page name will be generated with a page.js file inside of it all the further page componets have to be built inside of the page folder.this mod can be routed inside the page router. 143 | 144 | ```sh 145 | $ vegana generate page home --lazy 146 | ``` 147 | 148 | here the page name is home and the lazy flag integartes the component as a lazy one. 149 | you dont have to use the lazy flag if the page is not lazy. 150 | 151 | #### Generate a Cont 152 | this command have to be called inside the page folder 'app/page/homePage/' and generates and cont mod inside a folder names cont in page direcoty. again the format is same and this component is also lazy and can be loaded when is required by the user.this component can be routed inside the page in cont router. 153 | 154 | ```sh 155 | $ vegana generate cont home --lazy 156 | ``` 157 | 158 | this componet cannot be shared with other pages. 159 | 160 | #### Generate a Panel 161 | this module can be generated inside a cont and can be routed in the panel router with the cont module.this command generated the panel file insde a panel folder with the cont folder 'app/pages/homePage/cont/mainCont/panels/mainPanel/panel.js' with a panel js file insdie of it. 162 | 163 | ```sh 164 | $ vegana generate panel main --lazy 165 | ``` 166 | 167 | #### Generate a Component 168 | this module can be genearted in any of the other modules and can be shared inbetween other modules by making itself global within the app. this module cannot be lazy and is to be available whenever is called. is have to be called within the app folder to work. 169 | 170 | ```sh 171 | $ vegana generate comp menu 172 | ``` 173 | 174 | where menu is the name of the component generated. this can be used by multiple pages. 175 | 176 | ------ 177 | ------ 178 | 179 | # Vegana Document Structure 180 | Vegana follows a predifined nesting document structure which allows the final bundle to be broken up into multiple lazy modules which can be loaded whenever is requires by the user this makes the final bundle very light, making experience of browsing through the app smooth and fast.the initial page load is also super fast which makes the user experience even better. 181 | 182 | ## Page Module 183 | this is the top level module and is routable in the page router.this can be a contact page, home page,login page or singup page and can be loaded to the app as required.the app needs to contain atleast one page module. all the further mods are nested inside of it. 184 | this module is required to be generated inside the app/pages folder to work. 185 | page module can call vegana apis to make html and vegana dom elements. 186 | 187 | ### file structure 188 | this module consist of constants with the page name and page id varibales with a init function this function is called whenever a page is to be loaded the page module automatically integrates itself into the app bundle once is required in the nodejs code or the lazy loader more will be provided on this in the routing system docs. 189 | you need to code your app within the init function and call any further functions from it user defined function are not globally available. 190 | constants modules are required to be called from outside the init function so then can be included in the final bundle. 191 | 192 | ------- 193 | 194 | ## Cont Module 195 | this module is nested inside of the page module directory and is routable in the cont router each page has its own cont router and any route request for conts is treated to be on the activated page.this cont can be used for diffrent features of a page like tabs which does diffrent things for example a home page on instagram have search cont, feed cont or user account cont.which can be loaded as required. 196 | 197 | ### file structure 198 | file structure is mainly similar design wise execpt this module defines the page id and page name too and exists inside the parent page directory.any arguments require by the module can be passed in through the init function by the parent page or can be transferred through the native vegana data managemnt system. 199 | 200 | ----- 201 | 202 | ## Panel Module 203 | this module is nested inside the cont module and is routable through panel router. each cont have a unique panel router and each panel route query is processed for the activated cont module.these can be used for diffrent tabs inside the user info section like followers albums and such. 204 | 205 | ### file structure 206 | file structure is mainly similar design wise execpt this module defines the cont id and name too and exists inside the parent cont directory.any arguments require by the module can be passed in through the init function by the parent cont or can be transferred through the native vegana data managemnt system. 207 | 208 | ----- 209 | 210 | ## Comp Module 211 | this module is a static part of any of the other modules and can be shared inbetween them, this module have a native routing system too if required by the app.this is not a lazy module and is required to be a part of any other module. 212 | 213 | ### file structure 214 | file structure is mainly similar design wise, this mod exists inside the parent mod directory.any arguments require by the module can be passed in through the init function by the parent mod or can be transferred through the native vegana data managemnt system. 215 | 216 | ----- 217 | ----- 218 | 219 | # Vegana App Structure 220 | 221 | ----- 222 | ----- 223 | 224 | # Vegana engine Apis 225 | Vegana engine is the core vegana apis which enables devs to build pure js html elements like divs, inputs, images, links and buttons,make http api requestes, manage data stored locally on user's browser control js apis with easy to use plugins,apply lazy modules, authentication and routing systems. 226 | 227 | # Vegana Routing System 228 | Vegana use a module based routing system with uniqe router for each module type. 229 | page,cont and panel mods can be lazy and loaded whenever is required, comp module have a native routing system too but cannot be lazy loaded. page,cont and panel modules are nested inside by the order defined in the document structure first page mod then cont module is nested within the page router in the cont router each page consist of its unique cont router and can only be called once.panel router is same and is nested within the cont with its own unique panel router which can be called only once.comp router can be called as many times as the app requires it to within it self. 230 | 231 | routing system have the following apis 232 | - router apis 233 | - router init 234 | - navigate 235 | - get 236 | - set 237 | - lazy loader apis 238 | - load 239 | - page 240 | - cont 241 | - panel 242 | - css 243 | 244 | ## Router Apis 245 | 246 | ### Router Init Apis 247 | these apis init diffrent routers in diff mods 248 | 249 | #### Conts Router Init 250 | this api initiates a cont router on a page module this api can only be called once and returns the div id of the router div on current page. 251 | 252 | ```sh 253 | engine.conts.init(pageId); 254 | ``` 255 | 256 | this function should only be called on the page module with the pageId as input. 257 | pageId is predefined on the page module. 258 | 259 | #### Panels Router Init 260 | this api initiates a cont router on a Cont module this api can only be called once and returns the div id of the router div on current Cont. 261 | 262 | ```sh 263 | engine.panels.init(contId); 264 | ``` 265 | 266 | this function should only be called on the Cont module with the contId as input. 267 | contId is predefined on the Cont module. 268 | 269 | #### Comps Router Init 270 | this api initiates a comp router on any other module this api can be called multiple times and returns the div id of the router div.this api takes parent mod's id, comp module which is to be activated and the data which is needed to be transafered. 271 | 272 | ```sh 273 | //engine.router.comps.init(pageId,pageModule,any_data); 274 | let pageModule = engine.router.get.pageModule("homePage"); 275 | engine.router.comps.init(pageId,pageModule,{user_exists:true}); 276 | ``` 277 | 278 | data is a optional argument in this module. 279 | 280 | this function should only be called on the Cont module with the contId as input. 281 | contId is predefined on the Cont module. 282 | 283 | ----- 284 | 285 | ### Router Navigate 286 | these apis navigate mods through there routers. this api have two options if you wanna recreate a module you can call the new function or if you just wanna navigate to a prebuilt module just call the to option of the api. 287 | 288 | #### To Navigate Api 289 | this api navigates to prebuilt module or builts a module if it doent exists and navigates to it.this api navigates in between page,cont,panel and comp modules. 290 | nested modules only need module and data to navigate but comp navigation router takes the router if which is returned when comp router is initated.the data argument is optional. 291 | 292 | ```sh 293 | engine.router.navigate.to.page(pageModule,any_data); 294 | engine.router.navigate.to.cont(contModule,any_data); 295 | engine.router.navigate.to.panel(panelModule,any_data); 296 | engine.router.navigate.to.comp(compModule,any_data,Router_id); 297 | ``` 298 | 299 | #### New Navigate Api 300 | this api rebuilds a module and navigates to it, arguments are same as the to module. 301 | 302 | ```sh 303 | engine.router.navigate.new.page(pageModule,any_data); 304 | engine.router.navigate.new.cont(contModule,any_data); 305 | engine.router.navigate.new.panel(panelModule,any_data); 306 | engine.router.navigate.new.comp(compModule,any_data,Router_id); 307 | ``` 308 | 309 | ----- 310 | 311 | ### Router Get 312 | these apis can be called to fetch diffrent modules. 313 | 314 | #### Get Page Module 315 | this api fetch the page module if available or returns a string as an error if its not found. this takes the page name as a argument. 316 | 317 | ```sh 318 | engine.router.get.pageModule(pageName); 319 | ``` 320 | 321 | here pageName is the name of a directory of the page. 322 | 323 | #### Get Cont Module 324 | this api fetch the cont module if available or returns a string as an error if its not found. this takes the page name and cont name as its arguments. 325 | 326 | ```sh 327 | engine.router.get.contModule(pageName,contName); 328 | ``` 329 | 330 | here pageName is the name of a directory of the page and contName is the name of the directory of the cont. 331 | 332 | #### Get Panel Module 333 | this api fetch the cont module if available or returns a string as an error if its not found. this takes the page, cont and panel name as its arguments. 334 | 335 | ```sh 336 | engine.router.get.contModule(pageName,contName,panelName); 337 | ``` 338 | 339 | #### Get Base Href 340 | this argument fetches the base href url of the app. this is generally setuped on the index.js page in the app dirctory.this function does not take any argument and returns a string. 341 | 342 | ```sh 343 | engine.router.get.baseHref(); 344 | ``` 345 | 346 | ----- 347 | 348 | ### Router Set 349 | these apis integrate modules to the base app.there are many sub apis in this set but you will only use one rest are for module integration and you dont wannna use em they are already automated. 350 | 351 | #### Set Base Href 352 | this argument sets the base href if you are going to host the app in a sub directory i mean you can do it. if you wanna fetch something manually.this function takes the hosting directory path without the '/' at the begnning of the address. 353 | 354 | ```sh 355 | //engine.router.set.baseHref(path_as_string); 356 | engine.router.set.baseHref('home/test/'); 357 | ``` 358 | 359 | ----- 360 | ----- 361 | 362 | ## Lazy Loader Apis 363 | these apis fetch lazy modules and files when you need em.all of these are async and returns a error if the files are not found. 364 | 365 | ### Lazy Load Page Module 366 | this api fetches the lazy page and takes the pageName as a argument and resolves it the page is successfully loaded or returns a error if not. 367 | 368 | ```sh 369 | engine.loader.load.page('testPage') 370 | .then(()=>{ 371 | console.log('fetched'); 372 | }) 373 | .catch((error)=>{ 374 | console.log(error); 375 | }) 376 | ``` 377 | 378 | ### Lazy Load Cont Module 379 | this api fetches the lazy Cont and takes the pageName and contName as arguments and resolves it the cont is successfully loaded or returns a error if not. 380 | 381 | ```sh 382 | engine.loader.load.cont('testPage','testCont') 383 | .then(()=>{ 384 | console.log('fetched'); 385 | }) 386 | .catch((error)=>{ 387 | console.log(error); 388 | }) 389 | ``` 390 | 391 | ### Lazy Load Panel Module 392 | this api fetches the lazy page and takes the pageName,contName and panelName as arguments and resolves it the panel is successfully loaded or returns a error if not. 393 | 394 | ```sh 395 | engine.loader.load.panel('testPage','contName','panelName') 396 | .then(()=>{ 397 | console.log('fetched'); 398 | }) 399 | .catch((error)=>{ 400 | console.log(error); 401 | }) 402 | ``` 403 | 404 | ### Lazy Load Css StyleSheet 405 | this api fetches a lazy sass file by the filename. 406 | 407 | ```sh 408 | engine.loader.load.css('testCss') 409 | .then(()=>{ 410 | console.log('fetched'); 411 | }) 412 | .catch((error)=>{ 413 | console.log(error); 414 | }) 415 | ``` 416 | 417 | ----- 418 | ----- 419 | 420 | # Vegana Make Apis 421 | these apis make html dom and vegana elements. each make api returns a id of the dom element. 422 | 423 | ## Vegana Standard Dom Element Apis 424 | 425 | ### Make A Div 426 | this api makes a div container inside a module and takes the following arguments. 427 | 428 | ```sh 429 | engine.make.div({ 430 | id:'whatever-box', 431 | parent:'parent-cont-id', 432 | class:'whatever-class', 433 | text:'this is a test div', 434 | function:(id)=>{ 435 | console.log(id); 436 | } 437 | }); 438 | ``` 439 | 440 | the text function here is called whenever the div is clicked and the text makes the test node inside the div. 441 | 442 | -------- 443 | 444 | ### Make A Text Node 445 | this api makes a text node in a div 446 | 447 | ```sh 448 | engine.make.text({ 449 | parent:'parent-cont-id', 450 | text:'this is a text node' 451 | }); 452 | ``` 453 | 454 | -------- 455 | 456 | ### Make A Image 457 | this api makes a div container inside a module and takes the following arguments. 458 | 459 | ```sh 460 | engine.make.div({ 461 | id:'whatever-box', 462 | parent:'parent-cont-id', 463 | class:'whatever-class', 464 | type:"local", //options are : local and url. 465 | location:'images/text.png', 466 | function:(id)=>{ 467 | console.log(id); 468 | } 469 | }); 470 | ``` 471 | 472 | this api make a image node in parent div it takes a type of local or url if local you can store your images in any directory inside the assets directory these images can be fetched where ever you deploy your app you just have to set the base href address in the index.js file in the app directory.if you use the url type the image can be fetched by a url. 473 | 474 | -------- 475 | 476 | ### Make Input Feild 477 | this api makes a input feild and takes the following arguments. 478 | 479 | ```sh 480 | engine.make.input({ 481 | id:'text-input', 482 | parent:'text-form', 483 | class:'test-input', 484 | type:'string', //type can be string or number 485 | value:'hello world', 486 | placeholder:'type something', 487 | function:(id)=>{ 488 | console.log(id); 489 | let val = engine.binder.value(id); 490 | console.log(val); 491 | //val would be the input feild value 492 | } 493 | }); 494 | ``` 495 | 496 | here the value key defines the value of the feild placeholder is self explanetory and the function is called whenever the user types something. 497 | 498 | ----- 499 | 500 | ### Make Select Input 501 | this api makes a select input and takes the following arguments. 502 | 503 | ```sh 504 | engine.make.select({ 505 | id:'text-input', 506 | parent:'text-form', 507 | class:'test-input', 508 | options:{ 509 | {text:'yes',value:true}, 510 | {text:'no',value:false} 511 | } 512 | }); 513 | ``` 514 | 515 | options is a array of objects with text and value as keys value can be any data and can be binded as nesseseary.text needs to be a string. 516 | 517 | ----- 518 | 519 | ### Make Check Box 520 | this api makes a check box input and takes the following arguments. 521 | 522 | ```sh 523 | engine.make.checkBox({ 524 | id:'test-checkBox', 525 | parent:'test-form', 526 | class:'test-check_box', 527 | labelClass:'test-label-class', 528 | checked:true 529 | }); 530 | ``` 531 | 532 | ----- 533 | 534 | ### Make textarea 535 | this api makes a textarea and takes the following arguments. 536 | 537 | ```sh 538 | engine.make.textarea({ 539 | id:'test-textarea', 540 | parent:'test-form', 541 | class:'test-textarea', 542 | rows:5, 543 | placeholder:'please write something.', 544 | value:'this is a textarea.' 545 | }); 546 | ``` 547 | 548 | ----- 549 | 550 | ### Make Button 551 | this api makes a button and takes the following arguments. 552 | 553 | ```sh 554 | engine.make.button({ 555 | id:'test-textarea', 556 | parent:'test-form', 557 | class:'test-textarea', 558 | value:"click me.", 559 | disabled:true, 560 | function:(id)=>{ 561 | console.log(id); 562 | } 563 | }); 564 | ``` 565 | 566 | the function will be triggered when someone clicks the button and the value is the text node inside the button.disabled makes the button non clickable. 567 | 568 | to enable a button run the following function 569 | 570 | 571 | ```sh 572 | engine.make.enableButton(buttonId); 573 | ``` 574 | 575 | ----- 576 | 577 | ### Make Html Web Component / Custom Element 578 | this api makes a custom html web component or a custom element whatever you call it and takes the following arguments. 579 | 580 | ```sh 581 | engine.make.element({ 582 | id:'messages', 583 | parent:pageId, 584 | class:'if-you-waana-pass-something', 585 | tag:'message', 586 | options:[{ 587 | tag:'height', 588 | data:5 589 | },{ 590 | tag:'width', 591 | data:10 592 | }] 593 | }); 594 | ``` 595 | 596 | the options array are the arguments passed with the html dom element.tag have to be passed. 597 | 598 | ### Add Class to a Element 599 | 600 | ```sh 601 | engine.make.addClass({ 602 | id:'test-textarea', 603 | class:'super-text' 604 | }); 605 | ``` 606 | 607 | ### Remove a Class from a Element 608 | 609 | ```sh 610 | engine.make.removeClass({ 611 | id:'test-textarea', 612 | class:'super-text' 613 | }); 614 | ``` 615 | 616 | ## Vegana Exclusive Element Apis 617 | 618 | ### Vegana Make Card 619 | this api makes a custom vegana dom element.the card have a header section which is optional and a close button which will call a close function passed onto the element. 620 | 621 | ```sh 622 | engine.make.card({ 623 | id:'test-card', 624 | parent:pageId, 625 | class:'card', //default class. 626 | close:true, // can be false and still use card header 627 | headerText:'test card header', // pass if you wanna use close button. 628 | headerClass:'card-header', //default class. 629 | headerTextContClass:'card-header-text-cont', //default class. 630 | headerActionContClass:'card-header-action-cont', //default class. 631 | closeButtonClass:'card-header-close-button', //default class. 632 | closeButtonValue:'close', //default value. 633 | closeButtonFunction:()=>{ 634 | //do something 635 | } 636 | }); 637 | ``` 638 | 639 | default classes and value dosent need to be passed but can be used if you wanna style you card diffrently, you can use default values to style your cards globally. 640 | 641 | ### Vegana Make Message 642 | this api makes message with a close button with the following arguments. 643 | 644 | ```sh 645 | engine.make.card({ 646 | id:'test-card', 647 | parent:pageId, 648 | type:'info' //default value 649 | message:'this is a test message', 650 | style:'display:flex', //optional 651 | closeButtonClass:'message-close-button', //default class 652 | closeButtonValue:'close' //default value 653 | }); 654 | ``` 655 | 656 | message have fixed class names of 'message' for the div and 'message-info', 'message-success', 'message-warning', 'message-danger'. 657 | 658 | message type options are info,success,warning and danger. 659 | 660 | ### Vegana Make Tabs 661 | Vegana tabs is a custom vegana component which makes a cutom router of components and tabs which is built upon dynamic css and works with mobile and desktop just fine.tabs are optimized for efficiency and does not rebuild the comps if already built and takes the following arguments. 662 | 663 | ```sh 664 | engine.make.tabs({ 665 | id:'test-tabs', 666 | parent:pageId, 667 | tabsContClass:'tab-cont-main', //deafult class 668 | linksContClass:'tab-cont-links', //deafult class 669 | tabClass:'tab-idle', //deafult class 670 | activeTabClass:'tab-active', //deafult class 671 | navButtonClass:'tab-nav', //deafult class 672 | moduleContClass:'tab-cont-module', //deafult class 673 | tabs:[ 674 | {value:'profile',module,profileComp,active:true}, 675 | {value:'albums',module,albumsComp} 676 | ] 677 | }) 678 | ``` 679 | 680 | custom classes can be passed to style the tabs however you like.for ease of use please use default class to style the tabs in your stylesheet 681 | 682 | ----- 683 | ----- 684 | 685 | # Vegana view Api 686 | these apis hides and shows the div or any html dom element or the custom elements. 687 | 688 | ## Show Element Api 689 | this api sets the display style property of any html dom element to block to make the element visible. 690 | 691 | ```sh 692 | engine.view.show(id); 693 | ``` 694 | 695 | ## Hide Element Api 696 | this api sets the display style property of any html dom element to none to make the element hidden. 697 | now here is a bug in here if you hide a element you cannot get the elements height and width so keep that in mind while playing around. 698 | 699 | ```sh 700 | engine.view.hide(id); 701 | ``` 702 | ----- 703 | ----- 704 | 705 | # Vegana Session Api 706 | this api handles a user session. 707 | 708 | ## Start a Session 709 | this api start a session with the folowing arguments 710 | 711 | ```sh 712 | engine.session.start(token,user,uid); 713 | ``` 714 | 715 | here token have to be a string user can be a json or a string and uid can be passed if you want it.only token is required to start a session through. 716 | 717 | ## Check a Session 718 | this api checks if a session is started. 719 | 720 | ```sh 721 | engine.session.check(); 722 | ``` 723 | 724 | this function returns a boolean. 725 | 726 | ## End a Session 727 | this api checks if a session is started. 728 | 729 | ```sh 730 | engine.session.end(); 731 | ``` 732 | 733 | this function returns a boolean. 734 | 735 | ## Get Session Params 736 | this api checks if a session is started. 737 | 738 | ```sh 739 | engine.session.get.token(); 740 | engine.session.get.user(); 741 | engine.session.get.uid(); 742 | ``` 743 | 744 | token is returned as a string or a null object user gets returnd as a string json or null object and uid is a string or a null object too. 745 | 746 | ----- 747 | ----- 748 | 749 | # Vegana Validate Api 750 | this api validates json and email id if you need to do it. 751 | 752 | ## Validate Json 753 | this api validates if a varibale is a json object and checks its keys and the data type that the key holds if you need to verify a json object.and takes the following params. 754 | 755 | ```sh 756 | //check if a user object is valid 757 | let user = { 758 | name:'akku', 759 | mobile:6665556665 760 | }; 761 | 762 | let schema = { 763 | name:{type:"string",min:5,max:255}, 764 | mobile:{type:"number",min:6500100100,max:9999899899} 765 | }; 766 | 767 | engine.validate.json(schema,user,'dynamic',2048); 768 | //engine.validate.json(schema,data,json_type,max_keys); 769 | //returns a bool and console logs an error 770 | 771 | ``` 772 | 773 | api takes the following arguments schema, data, json type and max keys. 774 | 775 | ### Schema 776 | this is the validation scheme for the data its an object of objects with the key to be matched with the key in data. the value of the key are the validation parameters to be checked which are data type,min and max length and elective.data type can be string,number,object,boolean and email. 777 | 778 | min&max properties on string is chekced on the length of the string. 779 | min&max properties on number will be checked by '>' & '<' operator. 780 | min&max properties on object will be checked on the number of keys in a object. 781 | min&max properties on array will be check on the length of the array. 782 | 783 | the elective tag makes a key elective meaning if the key doesnt exists on the data the validation will not fail.this param hold a boolean as a value 784 | 785 | ```sh 786 | {type:"string",min:3,max:3000,elective:true}, 787 | {type:'boolean'}, 788 | {type:"string"}, 789 | ``` 790 | 791 | all of these are valid.if no min and max properties are passed no checks will be performend on min and max property.boolean does support the elective property. 792 | 793 | ### Data 794 | this is the json object which will be validated with the scheme. 795 | 796 | ### Validation Type 797 | data can be hard checked meaning if any of the key is missing from the data the validation will be failed.but if your data is a little bit dynamic then you can check for the available keys or the nessesery keys by passing a elective param with a boolean in the schema object of the key,this will allow the json to be validated if the key dosent exists.validation types are static and dynamic. 798 | 799 | ### Max Data Keys 800 | this property checks the number of keys if the validation type is dynamic.please check the number of keys to be protective. 801 | 802 | --------- 803 | 804 | ## Validate a Email 805 | this api validates if a stirng is a valid email or not. 806 | 807 | ```sh 808 | engine.validate.email("akku@world.earth"); 809 | //this returns a bool 810 | ``` 811 | 812 | 813 | ----- 814 | ----- 815 | 816 | # Vegana Http Request Api 817 | this api makes http requests via the fetch web standard api and takes the following arguments. 818 | 819 | ```sh 820 | engine.request.send({ 821 | method:'post', 822 | url:'https://vegana.github.io', 823 | body:{ 824 | user:'sa8d7as89d7as89d7as8', 825 | name:'akku' 826 | }, 827 | headers:[{country:india}], 828 | }); 829 | ``` 830 | 831 | methods are standard http methods get post etc,url is a valid http url,body can be a empty json obejct and headers should be a array of objects with he key as header tag and value as the value of the header tag. 832 | 833 | ----- 834 | ----- 835 | 836 | # Wet Vegana Api 837 | this a the offical plugin for the wet api framework and is compatible with wet sessions and secure http requests. 838 | 839 | ## Set Base Wet Url 840 | this api sets the base wet url address and return a boolean. 841 | 842 | ```sh 843 | engine.wet.api.set('https://vegana.github.io'); 844 | ``` 845 | 846 | ## Get Base Wet Url 847 | this api returns the base wet url if already set else returns a null object. 848 | 849 | ```sh 850 | engine.wet.api.get(); 851 | ``` 852 | 853 | ## Make a Query 854 | this api makes a authenticated query with the session token as the 'tb-wet-token' with the following arguments. 855 | 856 | ```sh 857 | engine.wet.api.query({ 858 | url:'/albums', 859 | body:{ 860 | date:328497897328947324 861 | }, 862 | headers:[{ 863 | date_type:'since' 864 | }] 865 | }); 866 | ``` 867 | 868 | only url and body are necessary. 869 | 870 | ----- 871 | ----- 872 | 873 | # License - MIT 874 | 875 | ##### Vegana By Akku 876 | --------------------------------------------------------------------------------