From 14ec33e24c9304c88803d43342b217428ba39161 Mon Sep 17 00:00:00 2001 From: Peter Kim Date: Tue, 18 Jun 2013 13:59:07 -0400 Subject: [PATCH 1/6] testing --- test_folder/test file | 1 + 1 file changed, 1 insertion(+) create mode 100644 test_folder/test file diff --git a/test_folder/test file b/test_folder/test file new file mode 100644 index 0000000..bdf08de --- /dev/null +++ b/test_folder/test file @@ -0,0 +1 @@ +test file \ No newline at end of file From 96a874c3ca811eff69e117512cb5358010d9dff4 Mon Sep 17 00:00:00 2001 From: Peter Kim Date: Tue, 18 Jun 2013 14:02:24 -0400 Subject: [PATCH 2/6] switching to requirejs version --- README | 45 +-- examples/field.html | 54 ++- examples/lib/require.js | 34 ++ lib/Animator.js | 99 +++++ lib/App.js | 108 ++++++ lib/BrowserDetection.js | 138 +++++++ lib/Carousel.js | 524 +++++++++++++++++++++++++++ lib/Cookies.js | 84 +++++ lib/Favicon.js | 83 +++++ lib/GoogleAnalytics.js | 49 +++ lib/Merlin.js | 483 +++++++++++++++++++++++++ lib/Merlin2.js | 359 +++++++++++++++++++ lib/Overlay.js | 270 ++++++++++++++ lib/PushstateHelper.js | 143 ++++++++ lib/SocialRotator.js | 132 +++++++ lib/Tooltip.js | 557 ++++++++++++++++++++++++++++ lib/anim.js | 125 +++++++ lib/color.js | 42 +++ lib/featuredetection.js | 43 +++ lib/field.js | 368 +++++++++++++++++++ lib/field/Autocomplete.js | 508 ++++++++++++++++++++++++++ lib/field/Counter.js | 77 ++++ lib/field/Dropdown.js | 670 ++++++++++++++++++++++++++++++++++ lib/field/Hint.js | 114 ++++++ lib/field/SimpleTooltip.js | 100 ++++++ lib/field/Validator.js | 200 +++++++++++ lib/field/std.js | 678 +++++++++++++++++++++++++++++++++++ lib/flippanel.js | 132 +++++++ lib/fullscreen.js | 106 ++++++ lib/googleanalyticsheader.js | 26 ++ lib/merlin/MerlinAutosave.js | 107 ++++++ lib/merlin/MerlinCSRF.js | 58 +++ lib/merlin/MerlinData.js | 181 ++++++++++ lib/seed.js | 256 +++++++++++++ lib/validation.js | 500 ++++++++++++++++++++++++++ requirepaths.js | 42 +++ styleguide.md | 23 ++ 37 files changed, 7481 insertions(+), 37 deletions(-) create mode 100644 examples/lib/require.js create mode 100644 lib/Animator.js create mode 100644 lib/App.js create mode 100644 lib/BrowserDetection.js create mode 100644 lib/Carousel.js create mode 100644 lib/Cookies.js create mode 100644 lib/Favicon.js create mode 100644 lib/GoogleAnalytics.js create mode 100644 lib/Merlin.js create mode 100644 lib/Merlin2.js create mode 100644 lib/Overlay.js create mode 100644 lib/PushstateHelper.js create mode 100644 lib/SocialRotator.js create mode 100644 lib/Tooltip.js create mode 100644 lib/anim.js create mode 100644 lib/color.js create mode 100644 lib/featuredetection.js create mode 100644 lib/field.js create mode 100644 lib/field/Autocomplete.js create mode 100644 lib/field/Counter.js create mode 100644 lib/field/Dropdown.js create mode 100644 lib/field/Hint.js create mode 100644 lib/field/SimpleTooltip.js create mode 100644 lib/field/Validator.js create mode 100644 lib/field/std.js create mode 100644 lib/flippanel.js create mode 100644 lib/fullscreen.js create mode 100644 lib/googleanalyticsheader.js create mode 100644 lib/merlin/MerlinAutosave.js create mode 100644 lib/merlin/MerlinCSRF.js create mode 100644 lib/merlin/MerlinData.js create mode 100644 lib/seed.js create mode 100644 lib/validation.js create mode 100644 requirepaths.js create mode 100644 styleguide.md diff --git a/README b/README index df2e709..1cb86e0 100644 --- a/README +++ b/README @@ -1,39 +1,22 @@ - _____ _____ - /\ \ /\ \ - /::\ \ /::\ \ - \:::\ \ /::::\ \ - \:::\ \ /::::::\ \ - \:::\ \ /:::/\:::\ \ - \:::\ \ /:::/ \:::\ \ - /::::\ \ /:::/ \:::\ \ - /::::::\ \ /:::/ / \:::\ \ - /:::/\:::\ \ /:::/ / \:::\ \ - /:::/ \:::\____\/:::/____/ \:::\____\ - /:::/ \::/ /\:::\ \ \::/ / - /:::/ / \/____/ \:::\ \ \/____/ - /:::/ / \:::\ \ -/:::/ / \:::\ \ -\::/ / \:::\ \ - \/____/ \:::\ \ - \:::\ \ - \:::\____\ - \::/ / - \/____/ - TYPE/CODE - From 2010 till ∞ + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ -typecode-js UI Library v0.1 - -All components require jQuery and the seed file (tc.seed.js) to be loaded first. -Other dependencies are listed in individual source files. - +typecode-js UI Library v0.2 Versions 0.1 - first release version, only whole version with all files in top level directory - - -Some notes added as an example. \ No newline at end of file +0.2 - Experimenting with requirejs \ No newline at end of file diff --git a/examples/field.html b/examples/field.html index 1f4e069..6ab6d36 100644 --- a/examples/field.html +++ b/examples/field.html @@ -43,11 +43,53 @@ - - + + + - + - - + diff --git a/examples/lib/require.js b/examples/lib/require.js new file mode 100644 index 0000000..bbce91a --- /dev/null +++ b/examples/lib/require.js @@ -0,0 +1,34 @@ +/* + RequireJS 2.1.1 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved. + Available via the MIT or new BSD license. + see: http://github.com/jrburke/requirejs for details +*/ +var requirejs,require,define; +(function(W){function D(b){return M.call(b)==="[object Function]"}function E(b){return M.call(b)==="[object Array]"}function t(b,c){if(b){var d;for(d=0;d-1;d-=1)if(b[d]&&c(b[d],d,b))break}}function A(b,c){for(var d in b)if(b.hasOwnProperty(d)&&c(b[d],d))break}function O(b,c,d,g){c&&A(c,function(c,j){if(d||!F.call(b,j))g&&typeof c!=="string"?(b[j]||(b[j]={}),O(b[j],c,d,g)):b[j]=c});return b}function r(b,c){return function(){return c.apply(b, +arguments)}}function X(b){if(!b)return b;var c=W;t(b.split("."),function(b){c=c[b]});return c}function G(b,c,d,g){c=Error(c+"\nhttp://requirejs.org/docs/errors.html#"+b);c.requireType=b;c.requireModules=g;if(d)c.originalError=d;return c}function ba(){if(H&&H.readyState==="interactive")return H;N(document.getElementsByTagName("script"),function(b){if(b.readyState==="interactive")return H=b});return H}var g,s,u,y,q,B,H,I,Y,Z,ca=/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,da=/[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g, +$=/\.js$/,ea=/^\.\//;s=Object.prototype;var M=s.toString,F=s.hasOwnProperty,fa=Array.prototype.splice,v=!!(typeof window!=="undefined"&&navigator&&document),aa=!v&&typeof importScripts!=="undefined",ga=v&&navigator.platform==="PLAYSTATION 3"?/^complete$/:/^(complete|loaded)$/,R=typeof opera!=="undefined"&&opera.toString()==="[object Opera]",w={},n={},P=[],J=!1;if(typeof define==="undefined"){if(typeof requirejs!=="undefined"){if(D(requirejs))return;n=requirejs;requirejs=void 0}typeof require!=="undefined"&& +!D(require)&&(n=require,require=void 0);g=requirejs=function(b,c,d,p){var i,j="_";!E(b)&&typeof b!=="string"&&(i=b,E(c)?(b=c,c=d,d=p):b=[]);if(i&&i.context)j=i.context;(p=w[j])||(p=w[j]=g.s.newContext(j));i&&p.configure(i);return p.require(b,c,d)};g.config=function(b){return g(b)};g.nextTick=typeof setTimeout!=="undefined"?function(b){setTimeout(b,4)}:function(b){b()};require||(require=g);g.version="2.1.1";g.jsExtRegExp=/^\/|:|\?|\.js$/;g.isBrowser=v;s=g.s={contexts:w,newContext:function(b){function c(a, +f,x){var e,m,b,c,d,h,i,g=f&&f.split("/");e=g;var j=k.map,l=j&&j["*"];if(a&&a.charAt(0)===".")if(f){e=k.pkgs[f]?g=[f]:g.slice(0,g.length-1);f=a=e.concat(a.split("/"));for(e=0;f[e];e+=1)if(m=f[e],m===".")f.splice(e,1),e-=1;else if(m==="..")if(e===1&&(f[2]===".."||f[0]===".."))break;else e>0&&(f.splice(e-1,2),e-=2);e=k.pkgs[f=a[0]];a=a.join("/");e&&a===f+"/"+e.main&&(a=f)}else a.indexOf("./")===0&&(a=a.substring(2));if(x&&(g||l)&&j){f=a.split("/");for(e=f.length;e>0;e-=1){b=f.slice(0,e).join("/");if(g)for(m= +g.length;m>0;m-=1)if(x=j[g.slice(0,m).join("/")])if(x=x[b]){c=x;d=e;break}if(c)break;!h&&l&&l[b]&&(h=l[b],i=e)}!c&&h&&(c=h,d=i);c&&(f.splice(0,d,c),a=f.join("/"))}return a}function d(a){v&&t(document.getElementsByTagName("script"),function(f){if(f.getAttribute("data-requiremodule")===a&&f.getAttribute("data-requirecontext")===h.contextName)return f.parentNode.removeChild(f),!0})}function p(a){var f=k.paths[a];if(f&&E(f)&&f.length>1)return d(a),f.shift(),h.require.undef(a),h.require([a]),!0}function i(a){var f, +b=a?a.indexOf("!"):-1;b>-1&&(f=a.substring(0,b),a=a.substring(b+1,a.length));return[f,a]}function j(a,f,b,e){var m,K,d=null,g=f?f.name:null,j=a,l=!0,k="";a||(l=!1,a="_@r"+(M+=1));a=i(a);d=a[0];a=a[1];d&&(d=c(d,g,e),K=o[d]);a&&(d?k=K&&K.normalize?K.normalize(a,function(a){return c(a,g,e)}):c(a,g,e):(k=c(a,g,e),a=i(k),d=a[0],k=a[1],b=!0,m=h.nameToUrl(k)));b=d&&!K&&!b?"_unnormalized"+(N+=1):"";return{prefix:d,name:k,parentMap:f,unnormalized:!!b,url:m,originalName:j,isDefine:l,id:(d?d+"!"+k:k)+b}}function n(a){var f= +a.id,b=l[f];b||(b=l[f]=new h.Module(a));return b}function q(a,f,b){var e=a.id,m=l[e];if(F.call(o,e)&&(!m||m.defineEmitComplete))f==="defined"&&b(o[e]);else n(a).on(f,b)}function z(a,f){var b=a.requireModules,e=!1;if(f)f(a);else if(t(b,function(f){if(f=l[f])f.error=a,f.events.error&&(e=!0,f.emit("error",a))}),!e)g.onError(a)}function s(){P.length&&(fa.apply(C,[C.length-1,0].concat(P)),P=[])}function u(a,f,b){var e=a.map.id;a.error?a.emit("error",a.error):(f[e]=!0,t(a.depMaps,function(e,c){var d=e.id, +g=l[d];g&&!a.depMatched[c]&&!b[d]&&(f[d]?(a.defineDep(c,o[d]),a.check()):u(g,f,b))}),b[e]=!0)}function w(){var a,f,b,e,m=(b=k.waitSeconds*1E3)&&h.startTime+b<(new Date).getTime(),c=[],g=[],i=!1,j=!0;if(!S){S=!0;A(l,function(b){a=b.map;f=a.id;if(b.enabled&&(a.isDefine||g.push(b),!b.error))if(!b.inited&&m)p(f)?i=e=!0:(c.push(f),d(f));else if(!b.inited&&b.fetched&&a.isDefine&&(i=!0,!a.prefix))return j=!1});if(m&&c.length)return b=G("timeout","Load timeout for modules: "+c,null,c),b.contextName=h.contextName, +z(b);j&&t(g,function(a){u(a,{},{})});if((!m||e)&&i)if((v||aa)&&!T)T=setTimeout(function(){T=0;w()},50);S=!1}}function y(a){n(j(a[0],null,!0)).init(a[1],a[2])}function B(a){var a=a.currentTarget||a.srcElement,b=h.onScriptLoad;a.detachEvent&&!R?a.detachEvent("onreadystatechange",b):a.removeEventListener("load",b,!1);b=h.onScriptError;a.detachEvent&&!R||a.removeEventListener("error",b,!1);return{node:a,id:a&&a.getAttribute("data-requiremodule")}}function I(){var a;for(s();C.length;)if(a=C.shift(),a[0]=== +null)return z(G("mismatch","Mismatched anonymous define() module: "+a[a.length-1]));else y(a)}var S,U,h,L,T,k={waitSeconds:7,baseUrl:"./",paths:{},pkgs:{},shim:{},map:{},config:{}},l={},V={},C=[],o={},Q={},M=1,N=1;L={require:function(a){return a.require?a.require:a.require=h.makeRequire(a.map)},exports:function(a){a.usingExports=!0;if(a.map.isDefine)return a.exports?a.exports:a.exports=o[a.map.id]={}},module:function(a){return a.module?a.module:a.module={id:a.map.id,uri:a.map.url,config:function(){return k.config&& +k.config[a.map.id]||{}},exports:o[a.map.id]}}};U=function(a){this.events=V[a.id]||{};this.map=a;this.shim=k.shim[a.id];this.depExports=[];this.depMaps=[];this.depMatched=[];this.pluginMaps={};this.depCount=0};U.prototype={init:function(a,b,c,e){e=e||{};if(!this.inited){this.factory=b;if(c)this.on("error",c);else this.events.error&&(c=r(this,function(a){this.emit("error",a)}));this.depMaps=a&&a.slice(0);this.errback=c;this.inited=!0;this.ignore=e.ignore;e.enabled||this.enabled?this.enable():this.check()}}, +defineDep:function(a,b){this.depMatched[a]||(this.depMatched[a]=!0,this.depCount-=1,this.depExports[a]=b)},fetch:function(){if(!this.fetched){this.fetched=!0;h.startTime=(new Date).getTime();var a=this.map;if(this.shim)h.makeRequire(this.map,{enableBuildCallback:!0})(this.shim.deps||[],r(this,function(){return a.prefix?this.callPlugin():this.load()}));else return a.prefix?this.callPlugin():this.load()}},load:function(){var a=this.map.url;Q[a]||(Q[a]=!0,h.load(this.map.id,a))},check:function(){if(this.enabled&& +!this.enabling){var a,b,c=this.map.id;b=this.depExports;var e=this.exports,m=this.factory;if(this.inited)if(this.error)this.emit("error",this.error);else{if(!this.defining){this.defining=!0;if(this.depCount<1&&!this.defined){if(D(m)){if(this.events.error)try{e=h.execCb(c,m,b,e)}catch(d){a=d}else e=h.execCb(c,m,b,e);if(this.map.isDefine)if((b=this.module)&&b.exports!==void 0&&b.exports!==this.exports)e=b.exports;else if(e===void 0&&this.usingExports)e=this.exports;if(a)return a.requireMap=this.map, +a.requireModules=[this.map.id],a.requireType="define",z(this.error=a)}else e=m;this.exports=e;if(this.map.isDefine&&!this.ignore&&(o[c]=e,g.onResourceLoad))g.onResourceLoad(h,this.map,this.depMaps);delete l[c];this.defined=!0}this.defining=!1;if(this.defined&&!this.defineEmitted)this.defineEmitted=!0,this.emit("defined",this.exports),this.defineEmitComplete=!0}}else this.fetch()}},callPlugin:function(){var a=this.map,b=a.id,d=j(a.prefix);this.depMaps.push(d);q(d,"defined",r(this,function(e){var m, +d;d=this.map.name;var x=this.map.parentMap?this.map.parentMap.name:null,i=h.makeRequire(a.parentMap,{enableBuildCallback:!0,skipMap:!0});if(this.map.unnormalized){if(e.normalize&&(d=e.normalize(d,function(a){return c(a,x,!0)})||""),e=j(a.prefix+"!"+d,this.map.parentMap),q(e,"defined",r(this,function(a){this.init([],function(){return a},null,{enabled:!0,ignore:!0})})),d=l[e.id]){this.depMaps.push(e);if(this.events.error)d.on("error",r(this,function(a){this.emit("error",a)}));d.enable()}}else m=r(this, +function(a){this.init([],function(){return a},null,{enabled:!0})}),m.error=r(this,function(a){this.inited=!0;this.error=a;a.requireModules=[b];A(l,function(a){a.map.id.indexOf(b+"_unnormalized")===0&&delete l[a.map.id]});z(a)}),m.fromText=r(this,function(b,e){var f=a.name,c=j(f),d=J;e&&(b=e);d&&(J=!1);n(c);try{g.exec(b)}catch(x){throw Error("fromText eval for "+f+" failed: "+x);}d&&(J=!0);this.depMaps.push(c);h.completeLoad(f);i([f],m)}),e.load(a.name,i,m,k)}));h.enable(d,this);this.pluginMaps[d.id]= +d},enable:function(){this.enabling=this.enabled=!0;t(this.depMaps,r(this,function(a,b){var c,e;if(typeof a==="string"){a=j(a,this.map.isDefine?this.map:this.map.parentMap,!1,!this.skipMap);this.depMaps[b]=a;if(c=L[a.id]){this.depExports[b]=c(this);return}this.depCount+=1;q(a,"defined",r(this,function(a){this.defineDep(b,a);this.check()}));this.errback&&q(a,"error",this.errback)}c=a.id;e=l[c];!L[c]&&e&&!e.enabled&&h.enable(a,this)}));A(this.pluginMaps,r(this,function(a){var b=l[a.id];b&&!b.enabled&& +h.enable(a,this)}));this.enabling=!1;this.check()},on:function(a,b){var c=this.events[a];c||(c=this.events[a]=[]);c.push(b)},emit:function(a,b){t(this.events[a],function(a){a(b)});a==="error"&&delete this.events[a]}};h={config:k,contextName:b,registry:l,defined:o,urlFetched:Q,defQueue:C,Module:U,makeModuleMap:j,nextTick:g.nextTick,configure:function(a){a.baseUrl&&a.baseUrl.charAt(a.baseUrl.length-1)!=="/"&&(a.baseUrl+="/");var b=k.pkgs,c=k.shim,e={paths:!0,config:!0,map:!0};A(a,function(a,b){e[b]? +b==="map"?O(k[b],a,!0,!0):O(k[b],a,!0):k[b]=a});if(a.shim)A(a.shim,function(a,b){E(a)&&(a={deps:a});if(a.exports&&!a.exportsFn)a.exportsFn=h.makeShimExports(a);c[b]=a}),k.shim=c;if(a.packages)t(a.packages,function(a){a=typeof a==="string"?{name:a}:a;b[a.name]={name:a.name,location:a.location||a.name,main:(a.main||"main").replace(ea,"").replace($,"")}}),k.pkgs=b;A(l,function(a,b){if(!a.inited&&!a.map.unnormalized)a.map=j(b)});if(a.deps||a.callback)h.require(a.deps||[],a.callback)},makeShimExports:function(a){return function(){var b; +a.init&&(b=a.init.apply(W,arguments));return b||X(a.exports)}},makeRequire:function(a,f){function d(e,c,i){var k,p;if(f.enableBuildCallback&&c&&D(c))c.__requireJsBuild=!0;if(typeof e==="string"){if(D(c))return z(G("requireargs","Invalid require call"),i);if(a&&L[e])return L[e](l[a.id]);if(g.get)return g.get(h,e,a);k=j(e,a,!1,!0);k=k.id;return!F.call(o,k)?z(G("notloaded",'Module name "'+k+'" has not been loaded yet for context: '+b+(a?"":". Use require([])"))):o[k]}I();h.nextTick(function(){I();p= +n(j(null,a));p.skipMap=f.skipMap;p.init(e,c,i,{enabled:!0});w()});return d}f=f||{};O(d,{isBrowser:v,toUrl:function(b){var d=b.lastIndexOf("."),f=null;d!==-1&&(f=b.substring(d,b.length),b=b.substring(0,d));return h.nameToUrl(c(b,a&&a.id,!0),f)},defined:function(b){b=j(b,a,!1,!0).id;return F.call(o,b)},specified:function(b){b=j(b,a,!1,!0).id;return F.call(o,b)||F.call(l,b)}});if(!a)d.undef=function(b){s();var c=j(b,a,!0),d=l[b];delete o[b];delete Q[c.url];delete V[b];if(d){if(d.events.defined)V[b]= +d.events;delete l[b]}};return d},enable:function(a){l[a.id]&&n(a).enable()},completeLoad:function(a){var b,c,d=k.shim[a]||{},g=d.exports;for(s();C.length;){c=C.shift();if(c[0]===null){c[0]=a;if(b)break;b=!0}else c[0]===a&&(b=!0);y(c)}c=l[a];if(!b&&!o[a]&&c&&!c.inited)if(k.enforceDefine&&(!g||!X(g)))if(p(a))return;else return z(G("nodefine","No define call for "+a,null,[a]));else y([a,d.deps||[],d.exportsFn]);w()},nameToUrl:function(a,b){var c,d,i,h,j,l;if(g.jsExtRegExp.test(a))h=a+(b||"");else{c= +k.paths;d=k.pkgs;h=a.split("/");for(j=h.length;j>0;j-=1)if(l=h.slice(0,j).join("/"),i=d[l],l=c[l]){E(l)&&(l=l[0]);h.splice(0,j,l);break}else if(i){c=a===i.name?i.location+"/"+i.main:i.location;h.splice(0,j,c);break}h=h.join("/");h+=b||(/\?/.test(h)?"":".js");h=(h.charAt(0)==="/"||h.match(/^[\w\+\.\-]+:/)?"":k.baseUrl)+h}return k.urlArgs?h+((h.indexOf("?")===-1?"?":"&")+k.urlArgs):h},load:function(a,b){g.load(h,a,b)},execCb:function(a,b,c,d){return b.apply(d,c)},onScriptLoad:function(a){if(a.type=== +"load"||ga.test((a.currentTarget||a.srcElement).readyState))H=null,a=B(a),h.completeLoad(a.id)},onScriptError:function(a){var b=B(a);if(!p(b.id))return z(G("scripterror","Script error",a,[b.id]))}};h.require=h.makeRequire();return h}};g({});t(["toUrl","undef","defined","specified"],function(b){g[b]=function(){var c=w._;return c.require[b].apply(c,arguments)}});if(v&&(u=s.head=document.getElementsByTagName("head")[0],y=document.getElementsByTagName("base")[0]))u=s.head=y.parentNode;g.onError=function(b){throw b; +};g.load=function(b,c,d){var g=b&&b.config||{},i;if(v)return i=g.xhtml?document.createElementNS("http://www.w3.org/1999/xhtml","html:script"):document.createElement("script"),i.type=g.scriptType||"text/javascript",i.charset="utf-8",i.async=!0,i.setAttribute("data-requirecontext",b.contextName),i.setAttribute("data-requiremodule",c),i.attachEvent&&!(i.attachEvent.toString&&i.attachEvent.toString().indexOf("[native code")<0)&&!R?(J=!0,i.attachEvent("onreadystatechange",b.onScriptLoad)):(i.addEventListener("load", +b.onScriptLoad,!1),i.addEventListener("error",b.onScriptError,!1)),i.src=d,I=i,y?u.insertBefore(i,y):u.appendChild(i),I=null,i;else aa&&(importScripts(d),b.completeLoad(c))};v&&N(document.getElementsByTagName("script"),function(b){if(!u)u=b.parentNode;if(q=b.getAttribute("data-main")){if(!n.baseUrl)B=q.split("/"),Y=B.pop(),Z=B.length?B.join("/")+"/":"./",n.baseUrl=Z,q=Y;q=q.replace($,"");n.deps=n.deps?n.deps.concat(q):[q];return!0}});define=function(b,c,d){var g,i;typeof b!=="string"&&(d=c,c=b,b= +null);E(c)||(d=c,c=[]);!c.length&&D(d)&&d.length&&(d.toString().replace(ca,"").replace(da,function(b,d){c.push(d)}),c=(d.length===1?["require"]:["require","exports","module"]).concat(c));if(J&&(g=I||ba()))b||(b=g.getAttribute("data-requiremodule")),i=w[g.getAttribute("data-requirecontext")];(i?i.defQueue:P).push([b,c,d])};define.amd={jQuery:!0};g.exec=function(b){return eval(b)};g(n)}})(this); \ No newline at end of file diff --git a/lib/Animator.js b/lib/Animator.js new file mode 100644 index 0000000..157ed75 --- /dev/null +++ b/lib/Animator.js @@ -0,0 +1,99 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +define(['jquery', 'NIseed'], function($) { + + var window = this, + NI = window.NI; + + function Animator(options) { + var o, internal, animations, finished_animations, running; + + o = $.extend({ + preCalculate: false, + fps:30 + }, options); + + internal = { + interval:0.0 + }; + + animations = []; + finished_animations = []; + + function init(){ + internal.interval = 1000/o.fps; + } + + function start(){ + running = true; + setTimeout(run,internal.interval); + } + + function run(){ + var i, n_animations; + + if(!animations.length){ + astop(); + return; + } + + for(i in animations){ + //Check duration; + if(!animations[i].start_time){ + animations[i].start_time = Date.now(); + } else { + animations[i].pct = (Date.now() - animations[i].start_time) / animations[i].duration; + if(animations[i].pct > 1){ + if(animations[i].finish){ + animations[i].finish(animations[i]); + } + finished_animations.push(animations[i]); + animations.splice(i); + continue; + } + } + + if(animations[i].func){ + animations[i].func(animations[i]); + } + } + + setTimeout(run,internal.interval); + } + + function astop(){ + running = false; + } + + this.add_animation = function(name,animation){ + animation.pct = 0; + animation.start_time = null; + animations.push(animation); + if(!running){ + start(); + } + }; + + init(); + } + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + NI.Animator = Animator; + +}); \ No newline at end of file diff --git a/lib/App.js b/lib/App.js new file mode 100644 index 0000000..8c34364 --- /dev/null +++ b/lib/App.js @@ -0,0 +1,108 @@ +define(['jquery', 'NIseed'], function($) { + + var window = this, + NI = window.NI, + + App = function(options) { + var self = this, o; + + o = $.extend({ + page: { + _features: [], + add_feature: function(feature) { + this._features.push(feature); + } + }, + debug: true + }, options); + + window.console = NI.fn.get_console(o.debug); + + this.page = o.page; + this.events = $({}); + this.runtime = {}; + + this.contexts = {}; + + this.invoke_feature_set(this.page._features); + this.page.add_feature = function() { + self.invoke_feature.apply(self, arguments); + }; + + }; + + App.prototype.invoke_feature = function(feature, callback) { + var self = this; + + if (!$.isFunction(callback)) { + callback = $.noop; + } + + if ($.isFunction(feature)) { + feature(self); + callback(); + } else if (typeof feature === 'string') { + require([feature], function() { + callback(); + }); + } else if (typeof feature === 'object' && feature && $.isArray(feature.require)) { + require(feature.require, function() { + var args; + if ($.isFunction(feature.callback)) { + args = [self]; + $.each(arguments, function(i, arg) { + args.push(arg); + }); + feature.callback.apply(this, args); + } + callback(); + }); + } + }; + + App.prototype.invoke_feature_set = function(feature_set, callback) { + var self = this, + n_features, + n_initialized, + feature_init_callback; + + if (!feature_set || typeof feature_set !== 'object' || !feature_set.length) { + return false; + } + + n_features = feature_set.length; + n_initialized = 0; + + feature_init_callback = function() { + n_initialized += 1; + if (n_initialized === n_features) { + self.events.trigger('app.featuresInitialized'); + if ($.isFunction(callback)) { + callback(); + } + } + }; + + $.each(feature_set, function(i, feature) { + self.invoke_feature(feature, feature_init_callback); + }); + }; + + App.prototype.new_context = function(name){ + var self = this, context_runtime; + if(self.contexts[name]){ + for(context_runtime in self.contexts[name]){ + if($.isFunction(self.contexts[name][context_runtime].destroy)){ + self.contexts[name][context_runtime].destroy(); + } + } + } + self.contexts[name] = {}; + return self.contexts[name]; + }; + + NI.App = App; + + return App; + +}); \ No newline at end of file diff --git a/lib/BrowserDetection.js b/lib/BrowserDetection.js new file mode 100644 index 0000000..8e92a89 --- /dev/null +++ b/lib/BrowserDetection.js @@ -0,0 +1,138 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till infinity +typecode-js v 0.1 +*/ + +define(['jquery', 'NIseed'], function($) { + + var window = this, + NI = window.NI; + + function BrowserDetection(options) { + var o, elements; + + o = $.extend({ + orientation_listen: false, + detect_touch: true + }, options); + + elements = { + body:$('body') + }; + + function init(){ + var userAgent = navigator.userAgent; + var appVersion = navigator.appVersion; + var browser = {}; + + browser.mozilla = /mozilla/.test(userAgent.toLowerCase()) && !/webkit/.test(userAgent.toLowerCase()); + browser.webkit = /webkit/.test(userAgent.toLowerCase()); + browser.opera = /opera/.test(userAgent.toLowerCase()); + browser.msie = /msie/.test(userAgent.toLowerCase()); + + // check if browser is webkit... + if (browser.webkit) { + if(o.add_class_to_body){ + elements.body.addClass('browser-webkit'); + } + + // check if it's chrome, safari, or an iOS browser + if (userAgent.match(/iPad/i) !== null) { + elements.body.addClass('browser-ipad os-ios'); + if (window.navigator.standalone) { + elements.body.addClass('ios-webapp'); + } + if(o.orientation_listen){ + listenToOrientationChange(); + } + } else if(userAgent.match(/iPhone/i) || userAgent.match(/iPod/i)) { + elements.body.addClass('browser-iphone os-ios'); + if (window.navigator.standalone) { + elements.body.addClass('ios-webapp'); + } + if(o.orientation_listen){ + listenToOrientationChange(); + } + } else if(userAgent.match(/Chrome/i)) { + elements.body.addClass('browser-chrome'); + } else if(userAgent.match(/Safari/i)) { + elements.body.addClass('browser-safari'); + } + + // ...if browser is NOT webkit, run through the other browsers + } else { + if (browser.msie) { + elements.body.addClass('browser-ie'); + } else if (browser.mozilla) { + elements.body.addClass('browser-firefox'); + } else if (browser.opera) { + elements.body.addClass('browser-opera'); + } + } + + // detect operating systems + if (appVersion.indexOf("Mac")!=-1) { + elements.body.addClass('os-mac'); + } else if (appVersion.indexOf("Win")!=-1) { + elements.body.addClass('os-win'); + } else if (appVersion.indexOf("X11")!=-1) { + elements.body.addClass('os-unix'); + } else if (appVersion.indexOf("Linux")!=-1) { + elements.body.addClass('os-linux'); + } else { + elements.body.addClass('os-unknown'); + } + + // detect touch + if (o.detect_touch) { + if (!!('ontouchstart' in window) || !!('onmsgesturechange' in window)) { + elements.body.addClass('feature-touch'); + } + } + + + } + + + function listenToOrientationChange() { + + function changed(orientation) { + if (orientation === 0){ + elements.body.removeClass('portrait landscape').addClass('portrait'); + } else if (orientation === 180){ + elements.body.removeClass('portrait landscape').addClass('portrait'); + } else if (orientation === 90){ + elements.body.removeClass('portrait landscape').addClass('landscape'); + } else if (orientation === -90){ + elements.body.removeClass('portrait landscape').addClass('landscape'); + } + } + + changed(window.orientation); + + window.onorientationchange = function(){ + var orientation = window.orientation; + changed(orientation); + }; + } + + init(); + } + + NI.BrowserDetection = BrowserDetection; + + return BrowserDetection; + +}); \ No newline at end of file diff --git a/lib/Carousel.js b/lib/Carousel.js new file mode 100644 index 0000000..4289b72 --- /dev/null +++ b/lib/Carousel.js @@ -0,0 +1,524 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +// this carousel implementation is based on the jQuery Tools "scrollable" implementation: +// https://github.com/jquerytools/jquerytools/blob/master/src/scrollable/scrollable.js + +define(['jquery', 'NIseed'], function($) { + + var window = this, + NI = window.NI, + generate, + focussed; + + generate = { + carousel: function() { + return $(''); + }, + prev_btn: function(instance) { + var $btn; + $btn = $('Previous'); + if (instance) { + $btn.on('click.carousel', function(e) { + e.preventDefault(); + instance.prev(); + }); + } + return $btn; + }, + next_btn: function(instance) { + var $btn; + $btn = $('Next'); + if (instance) { + $btn.on('click.carousel', function(e) { + e.preventDefault(); + instance.next(); + }); + } + return $btn; + } + }; + + function Carousel(options) { + var me, o, $e, selectors, $elements, handlers, touch_info; + + me = this; + + o = $.extend({ + $e: null, + viewport_dimensions: null, // { width: null, height: null }, + viewport_class: 'viewport', + scroll_class: 'scroll', + panels: [], + panel_class: 'panel', + active_class: 'state-active', + disabled_class: 'state-disabled', + clone_class: 'clone', + speed: 400, + easing: 'swing', + vertical: false, + circular: true, + elastic: false, + elastic_delay: 100, + keyboard: true, + touch: true, + on_before_move: function(instance, info) {}, + on_move: function(instance, info) {} + }, options); + + function init() { + + var $viewport; + + if (o.$e) { + if (typeof o.$e === 'string') { + o.$e = $(o.$e); + } + $e = o.$e; + } else { + $e = generate.carousel(); + } + + selectors = { + panel: '.' + o.panel_class, + active: '.' + o.active_class, + clone: '.' + o.clone_class + }; + + $viewport = $e.find('.' + o.viewport_class); + + $elements = { + viewport: $viewport, + scroll: $viewport.find('.' + o.scroll_class), + current_target: null, + prev_btn: null, + next_btn: null + }; + + if (o.viewport_dimensions) { + if (o.elastic) { + o.viewport_dimensions = null; + } else { + if (typeof o.viewport_dimensions.width === 'number') { + $elements.viewport.width(o.viewport_dimensions.width); + + } + if (typeof o.viewport_dimensions.height === 'number') { + $elements.viewport.height(o.viewport_dimensions.height); + } + } + } + + if (o.keyboard) { + $(window.document).on('keydown.carousel', handlers.keydown); + } + + if (o.touch) { + touch_info = {}; + $elements.scroll[0].ontouchstart = handlers.touchstart; + $elements.scroll[0].ontouchmove = handlers.touchmove; + } + + if (o.elastic) { + elastic_panel_sync(); + $(window).on('resize', handlers.elastic_resize); + } + + if (o.panels && o.panels.length) { + $.each(o.panels, function(i, $panel) { + me.add($panel); + }); + } + + me.set_orientation(o.vertical); + me.begin(true); + } + + function current() { + return $elements.scroll.find(selectors.panel + selectors.active); + } + + function target_position($panel) { + if (o.vertical) { + if (o.viewport_dimensions && typeof o.viewport_dimensions.height === 'number') { + return {top: -($panel.index()*o.viewport_dimensions.height)}; + } + return {top: -($panel.position().top)}; + } + if (o.viewport_dimensions && typeof o.viewport_dimensions.width === 'number') { + return {left: -($panel.index()*o.viewport_dimensions.width)}; + } + return {left: -($panel.position().left)}; + } + + function move_to($panel, no_anim) { + var info, $clone_target = false; + + if (!$panel.length) { + return me; + } + + $elements.current_target = $panel; + + // Determine if the target panel is a clone. + // If it is, keep track of the real panel as $clone_target + if ($panel.hasClass(o.clone_class)) { + $clone_target = $elements.scroll.children(selectors.panel).not(selectors.clone)[$panel.hasClass('head') ? 'last' : 'first'](); + $clone_target.addClass(o.active_class).siblings().removeClass(o.active_class); + } else { + $panel.addClass(o.active_class).siblings().removeClass(o.active_class); + } + + info = me.info(); + + if ($clone_target) { + info.clone_target = $clone_target; + } else { + info.clone_target = null; + } + + if ($.isFunction(o.on_before_move)) { + if (o.on_before_move(me, info) === false) { + return me; + } + } + + $elements.scroll.stop(true, false).animate(target_position($panel), (no_anim ? 0 : o.speed), o.easing, function() { + + $elements.current_target = null; + + if ($clone_target) { + $elements.scroll.css(target_position($clone_target)); + } + + if (!o.circular) { + if ($elements.prev_btn.length) { + $elements.prev_btn[info.index === 0 ? 'addClass' : 'removeClass'](o.disabled_class); + } + if ($elements.next_btn.length) { + $elements.next_btn[info.index === info.total-1 ? 'addClass' : 'removeClass'](o.disabled_class); + } + } + + if ($.isFunction(o.on_move)) { + o.on_move(me, info); + } + + me.iteration++; + } + ); + + return me; + } + + function elastic_panel_sync($panel) { + var w, h; + w = $e.width(); + h = $e.height(); + if (!$panel) { + $panel = $elements.scroll.children(selectors.panel); + } + $panel.width(w).height(h); + } + + + function sync_current_animation() { + if ($elements.current_target) { + move_to($elements.current_target, true); + } else { + move_to(current(), true); + } + return me; + } + + function register_btn(key) { + var $btn; + $btn = generate[key](me); + + if ($elements[key]) { + $elements[key].add($btn); + } else { + $elements[key] = $btn; + } + + return $btn; + } + + handlers = { + keydown: function(e) { + if (focussed != me) { + return; + } + if (me.info().total < 2) { + return; + } + + switch (e.which) { + case NI.co.keyboard.LEFT: + e.preventDefault(); + me.prev(); + break; + case NI.co.keyboard.RIGHT: + e.preventDefault(); + me.next(); + break; + } + }, + touchstart: function(e) { + touch_info.x = e.touches[0].clientX; + touch_info.y = e.touches[0].clientY; + }, + touchmove: function(e) { + var dx, dy; + if (e.touches.length === 1 && !$elements.scroll.is(':animated')) { + e.preventDefault(); + dx = touch_info.x - e.touches[0].clientX; + dy = touch_info.y - e.touches[0].clientY; + me[o.vertical && dy > 0 || !o.vertical && dx > 0 ? 'next' : 'prev'](); + } + }, + elastic_resize: NI.fn.debounce(function(e) { + elastic_panel_sync(); + sync_current_animation(); + }, o.elastic_delay) + }; + + // return an object with a reference to the currently active panel, + // the current index, and the total number of panels + this.info = function() { + var $panels, $current, $current_clone, $next, $prev,index; + $panels_with_clones = $elements.scroll.children(selectors.panel); + $panels = $elements.scroll.children(selectors.panel).not(selectors.clone); + $panels.each(function(i, panel) { + var $p = $(panel); + if ($p.hasClass(o.active_class)) { + $prev = $p.prev(); + $next = $p.next(); + $current = $p; + index = i; + return false; + } + }); + return { + $current: $current, + $next: $next, + $prev: $prev, + index: index, + total: $panels.length, + $panels: $panels, + $panels_with_clones: $panels_with_clones + }; + }; + + // add a panel to the end of the carousel + // (chainable) + this.add = function($panel) { + $panel.addClass(o.panel_class); + //if (!o.vertical) { + // $panel.css('float', 'left'); + //} + if (o.elastic) { + elastic_panel_sync($panel); + } else if (o.viewport_dimensions) { + if (typeof o.viewport_dimensions.width === 'number') { + $panel.width(o.viewport_dimensions.width); + } + if (typeof o.viewport_dimensions.height === 'number') { + $panel.height(o.viewport_dimensions.height); + } + } + $elements.scroll.append($panel); + return this; + }; + + // remove a panel from the carousel, + // (return the removed panel) + this.remove = function($panel) { + var info, panel_index, current_index; + + if (!($.contains($elements.scroll[0], $panel[0])) || $panel.hasClass(o.clone_class)) { + return false; + } + + info = this.info(); + + if (info.total === 1) { + $elements.scroll.children(selectors.clone).remove(); + return $panel.detach(); + } + + panel_index = $panel.index(); + current_index = info.$current.index(); + + $panel.detach(); + + // if the removed panel came before the currently active panel, + // update the offset of the scroll element + if (panel_index < current_index) { + move_to(info.$current, true); + } + // if the removed panel was the currently active panel, + // activate the previous sibling panel + else if (panel_index === current_index) { + this.to_index(current_index - 1, true); + } + + return $panel; + }; + + // generate a 'previous' button bound to this instance + // return a headless jQuery element representing the button + this.register_prev_btn = function() { + return register_btn('prev_btn'); + }; + + // generate a 'next' button bound to this instance + // return a headless jQuery element representing the button + this.register_next_btn = function() { + return register_btn('next_btn'); + }; + + // return the jQuery element that represents the carousel + this.get$e = function() { + return $e; + }; + + // Tell the Carousel to check itself before it wr-wr-wrecks itself. + // If the Carousel is circular, generate its secret clone elements. + // The Carousel should be refreshed after panels have been added to or removed from it. + // add() and remove() do not automatically call refresh() (to allow for simultaneous calls + // to manipulate the Carousel in row, without consecutively refreshing). + // (chainable) + this.refresh = function() { + var $panels; + if (o.circular) { + $elements.scroll.children(selectors.clone).remove(); + $panels = $elements.scroll.children(selectors.panel); + $panels.last().clone(false).addClass(o.clone_class +' head').prependTo($elements.scroll); + $panels.first().clone(false).addClass(o.clone_class +' tail').appendTo($elements.scroll); + } + return this; + }; + + + // move to the first panel and automatically refresh + // (unless no_refresh is true) + // (chainable) + this.begin = function(no_anim, no_refresh) { + if (!no_refresh) { + this.refresh(); + } + return move_to($elements.scroll.children(selectors.panel).not(selectors.clone).first(), no_anim); + }; + + // move to the last panel + // (chainable) + this.end = function(no_anim) { + return move_to($elements.scroll.children(selectors.panel).not(selectors.clone).last(), no_anim); + }; + + // move to the panel at the specified index + // (chainable) + this.to_index = function(index, no_anim) { + $elements.scroll.children(selectors.panel).not(selectors.clone).each(function(i, panel) { + if (i === index) { + move_to($(panel), no_anim); + return false; + } + }); + return this; + }; + + // move to the next panel + // (chainable) + this.next = function(no_anim) { + return move_to(current().next(selectors.panel), no_anim); + }; + + // move to the previous panel + // (chainable) + this.prev = function(no_anim) { + return move_to(current().prev(selectors.panel), no_anim); + }; + + // set focus on this carousel + // (chainable) + this.focus = function() { + focussed = me; + return me; + }; + + // remove focus from this carousel + // (chainable) + this.blur = function() { + if (focussed == me) { + focussed = null; + } + return me; + }; + + // set the carousel to vertical or horizontal + // (chainable) + this.set_orientation = function(vertical) { + if (vertical === true) { + o.vertical = true; + $e.addClass('orientation-vertical'); + $e.removeClass('orientation-horizontal'); + } else { + o.vertical = false; + $e.removeClass('orientation-vertical'); + $e.addClass('orientation-horizontal'); + } + return me; + }; + + this.sync_current_animation = sync_current_animation; + + // destroy this instance + // (the carousel element is automatically removed from the DOM) + this.destroy = function() { + me.blur(); + if (o.elastic) { + $(window).off('resize', handlers.elastic_resize); + } + if (o.keyboard) { + $(window.document).off('keydown.carousel', handlers.keydown); + } + if ($elements.prev_btn && $elements.prev_btn.length) { + $elements.prev_btn.off('click.carousel'); + } + if ($elements.next_btn && $elements.next_btn.length) { + $elements.next_btn.off('click.carousel'); + } + $e.remove(); + }; + + this.iteration = 0; + + init(); + } + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + NI.Carousel = Carousel; + NI.Carousel.Generator = generate; + +}); diff --git a/lib/Cookies.js b/lib/Cookies.js new file mode 100644 index 0000000..4eee350 --- /dev/null +++ b/lib/Cookies.js @@ -0,0 +1,84 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +define(['jquery', 'NIseed'], function($) { + + var window = this, + NI = window.NI; + + function Cookies(options) { + var o, internal_functions; + + o = $.extend({ + namespace:'', + default_expires:new Date(((new Date()).getTime() + ((7)*24*60*60*1000))) + }, options); + + internal_functions = { + handleNamespace:function(key){ + if(o.namespace && o.namespace.length){ + key = o.namespace + '|' + key; + } + return key; + }, + constructCookieString:function(key, value, expires){ + var string; + string = this.handleNamespace(key) + '=' + value+'; expires=' + expires.toUTCString() + '; path=/'; + return string; + }, + extractCookiesForRegex:function(regex){ + var ca, i, cookies; + ca = document.cookie.split(';'); + cookies = []; + for(i=0; i4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +define(['jquery', 'NIseed'], function($) { + + var window = this, + NI = window.NI; + + function Favicon(options) { + var o; + + o = $.extend({ + fps:5 + }, options); + + internal = { + interval:0.0 + }; + + function init(){ + internal.interval = 1000/o.fps; + } + + var elements = { + head:document.getElementsByTagName('head')[0] + }; + + //following is from http://softwareas.com/dynamic-favicons + var functions = { + change: function(iconURL) { + if (arguments.length==2) { + document.title = optionalDocTitle; + } + this.addLink(iconURL, 'icon'); + this.addLink(iconURL, 'shortcut icon'); + }, + addLink: function(iconURL, relValue) { + var link = document.createElement('link'); + link.type = 'image/x-icon'; + link.rel = relValue; + link.href = iconURL; + this.removeLinkIfExists(relValue); + elements.head.appendChild(link); + }, + removeLinkIfExists: function(relValue) { + var links = elements.head.getElementsByTagName('link'); + for (var i=0; i4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +define(['jquery', 'NIseed'], function($) { + + var NI = window.NI; + + function GoogleAnalytics(options) { + var o; + + o = $.extend({ + account:null + }, options); + + if(!o.account){ + return; + } + + _gaq.push(['_setAccount', o.account]); + + //console.log(window._gat); + //if(window._gat){ + // this.tracker = window._gat._createTracker(o.account); + // console.log(this.tracker); + //} + // + //console.log(this.tracker); + + } + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + NI.GoogleAnalytics = GoogleAnalytics; + +}); \ No newline at end of file diff --git a/lib/Merlin.js b/lib/Merlin.js new file mode 100644 index 0000000..bc1ab65 --- /dev/null +++ b/lib/Merlin.js @@ -0,0 +1,483 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +define(['jquery', 'NIseed'], function($) { + + var window = this, + NI = window.NI; + + NI.co.Merlin = { + NEXT_STEP: 'next', + PREVIOUS_STEP: 'prev', + CURRENT_STEP: 'current' + }; + + function Merlin(options) { + var me, o, internal, control_handlers, step_input_handlers, step_event_handlers; + + me = this; + + o = $.extend({},{ + name:null, + + $e:null, + progress_element:null, + controls:{ + next:null, + prev:null + }, + + extensions:{}, + data:{}, + + watch_keypress:true, + allow_hash_override_onload:false, + use_hashchange:false, + return_triggers_next:true, + validation_watch_events: ['keyup', 'change'], + + transition:'none', // fade, slide, horiz_slide, none + transition_speed:400, + viewport:null, // for horiz_slide + + first_step:null, + steps:{} + }, options); + + internal = { + $e:o.$e, + steps:o.steps, + data:{}, + current_step:null, + last_step:null, + progress_element:null, + counters:{ + n_times_step_rendered:0 + } + }; + + this.extensions = o.extensions; + this.internal = internal; + this.events = $({}); + this.runtime = (o.runtime ? o.runtime : {}); + this.o = o; + + function init(me){ + internal.data = o.data; + internal.progress_element = o.progress_element; + internal.first_step = o.first_step; + if (o.use_hashchange) { + initialize_hashchange(me); + } + initialize_controls(me); + initialize_steps(me); + if(internal.first_step){ + show_step(internal.first_step); + } + } + + function initialize_hashchange(me){ + if(!$.fn.hashchange){ + //cannot use hashchange if it is not present. GHETTO-dep-checking! + o.use_hashchange = false; + return; + } + //$(window) + // .unbind('hashchange', {merlin:me}, window_event_handlers.hashchange) + // .bind('hashchange', {merlin:me}, window_event_handlers.hashchange); + } + + function initialize_controls(me){ + var i; + if(!o.controls){ return; } + for(i in o.controls){ + if(!o.controls[i]){ continue; } + if(!control_handlers[i]){ continue; } + if(typeof o.controls[i] == 'string' ){ + o.controls[i] = o.$e.find(o.controls[i]); + } + o.controls[i].bind('click', {merlin:me}, control_handlers[i]); + } + } + + function initialize_steps(me){ + var i, e_data; + $.each(o.steps,function(i){ + var k; + if(o.steps[i].$e || (o.steps[i].selector && o.$e)){ + o.steps[i].name = i; + o.steps[i].n_times_shown = 0; + + if (!o.steps[i].$e) { + o.steps[i].$e = o.$e.find(o.steps[i].selector); + } + + o.steps[i].$e.hide(); + + o.steps[i].initialize_fields = function(){ + if(o.steps[i].fields){ + + require(['NIvalidation'], function() { + + o.steps[i].validationManager = new NI.ValidationManager({ + $mother:o.steps[i].$e, + watchEvents: o.validation_watch_events + }); + + o.steps[i].$e.bind('managerValidationPass', {merlin:me}, step_event_handlers.managerValidationPass) + .bind('managerValidationFail', {merlin:me}, step_event_handlers.managerValidationFail); + + o.steps[i].valid = true; + + for(var j in o.steps[i].fields){ + if (o.steps[i].fields[j].options && o.steps[i].fields[j].options.extensions && o.steps[i].fields[j].options.extensions.Validator) { + o.steps[i].fields[j].options.extensions.Validator.manager = o.steps[i].validationManager; + } + o.steps[i].fields[j].component = NI.field.new_instance({ + element: o.steps[i].$e.find(o.steps[i].fields[j].selector), + preprocess: $.isFunction(o.steps[i].fields[j].preprocess) ? o.steps[i].fields[j].preprocess : null, + options: $.extend({ + handlers: { + focus: step_input_handlers.focus, + keyup: step_input_handlers.modify, + change: step_input_handlers.modify, + //keypress: step_input_handlers.keypress, + keydown: step_input_handlers.keydown, + blur: step_input_handlers.blur + }, + event_data:{ + merlin:me + } + }, o.steps[i].fields[j].options) + }); + + if(o.steps[i].fields[j].value || (o.steps[i].fields[j].value === '')){ + o.steps[i].fields[j].component.set_val(o.steps[i].fields[j].value); + } + } + + });// end require NIvalidation + + } + }; + o.steps[i].initialize_fields(); + + o.steps[i].validate = function(){ + var k; + if(o.steps[i].fields){ + for(k in o.steps[i].fields){ + if(o.steps[i].fields[k].component){ + o.steps[i].fields[k].component.event_receiver.trigger('tc-field-validate'); + } + } + } + }; + + o.steps[i].set_valid = function(state){ + o.steps[i].valid = state; + }; + + } + }); + } + + function show_step(step, nav_data){ + + var i, strip, viewport, step_width; + + if(internal.current_step && $.isFunction(internal.current_step.validate)){ + internal.current_step.validate(); + } + + if(step == NI.co.Merlin.NEXT_STEP){ + if(internal.current_step.valid === false){ + return false; + } + if(internal.current_step.next){ + show_step(internal.current_step.next); + } + return; + } else if(step == NI.co.Merlin.PREVIOUS_STEP){ + if(internal.current_step.prev){ + show_step(internal.current_step.prev); + } + return; + } else if(step == NI.co.Merlin.CURRENT_STEP){ + if(internal.current_step){ + show_step(internal.current_step.name); + } + return; + } + + if(typeof step == 'string' && !(o.steps[step])){ + if(o.use_hashchange){ + set_location(internal.current_step.name); + } + return false; + } + + if(internal.current_step && (step == internal.current_step.name)){ + if($.isFunction(internal.current_step.visible)){ + internal.current_step.visible(me); + } + return true; + } + + if(internal.current_step && $.isFunction(internal.current_step.finish)){ + if(internal.current_step.finish(me) === false){ + return false; + } + } + + if($.isFunction(step)){ + step = step(me); + } + + if(!o.steps[step]){ + if(o.use_hashchange){ + set_location(internal.current_step.name); + } + return false; + } + + if ( internal.current_step ) { + internal.last_step = internal.current_step; + } + internal.current_step = o.steps[step]; + + // begin transition handling + if (o.transition=='fade') { + if (internal.counters.n_times_step_rendered !== 0) { + internal.current_step.$e.fadeIn(o.transition_speed); + internal.last_step.$e.fadeOut(o.transition_speed); + } else { + toggle_step_visibility(internal.current_step.name); + } + } else if (o.transition=='slide') { + if (internal.counters.n_times_step_rendered !== 0) { + internal.last_step.$e.slideUp(o.transition_speed/2); + internal.current_step.$e.delay(o.transition_speed/2).slideDown(o.transition_speed); + } else { + toggle_step_visibility(internal.current_step.name); + } + } else if (o.transition=='horiz_slide') { + + strip = o.$e; + viewport = o.viewport; + step_width = viewport.width(); + + if (internal.counters.n_times_step_rendered !== 0) { + + $.each(internal.steps, function() { + this.$e.width(step_width); + }); + + strip.width( step_width * 2); + internal.current_step.$e.show(); + + if ( internal.current_step.step_number > internal.last_step.step_number ) { + strip.animate({ 'margin-left' : -step_width }, o.transition_speed, 'easeInOutQuad', + function(){ + internal.last_step.$e.hide(); + strip.css({ 'margin-left' : 0, 'width' : '' }); + $.each(internal.steps, function() { + this.$e.css('width', ''); + }); + } + ); + } else if ( internal.current_step.step_number < internal.last_step.step_number ) { + strip.css({ 'margin-left' : -step_width }); + strip.animate({ 'margin-left' : 0 }, o.transition_speed, 'easeInOutQuad', + function(){ + internal.last_step.$e.hide(); + strip.css({ 'width' : '' }); + $.each(internal.steps, function() { + this.$e.css('width', ''); + }); + } + ); + } + + } else { + + toggle_step_visibility(internal.current_step.name); + + } + + } else { + toggle_step_visibility(internal.current_step.name); + } + // end transition handling + + if(internal.current_step.n_times_shown === 0 && !internal.current_step.init_forced && $.isFunction(internal.current_step.init)){ + internal.current_step.init(me); + } + + // begin controls handling + if(o.controls.prev){ + if(internal.current_step.prev){ + o.controls.prev.removeClass('disabled'); + } else { + o.controls.prev.addClass('disabled'); + } + } + + if(o.controls.next){ + if(internal.current_step.next){ + o.controls.next.removeClass('disabled'); + } else { + o.controls.next.addClass('disabled'); + } + } + // end controls handling + + + //begin progress indicator + if(internal.current_step.progress_selector){ + internal.progress_element.find('.progress-unit') + .removeClass('current') + .filter(internal.current_step.progress_selector) + .addClass('current'); + } + //end progress indicator + + internal.current_step.nav_data = nav_data; + + if($.isFunction(internal.current_step.visible)){ + internal.counters.n_times_step_rendered++; + internal.current_step.visible(me); + } + + if (o.use_hashchange && !internal.current_step.supress_hash && internal.current_step.name) { + set_location(internal.current_step.name); + } + + internal.current_step.n_times_shown++; + } + + function set_location(step){ + window.location.hash = (o.name ? o.name + ':' : '') + step; + } + + function toggle_step_visibility(step) { + $.each(internal.steps, function() { + if (this.name == step) { + this.$e.show(); + } else { + this.$e.hide(); + } + }); + } + + control_handlers = { + next:function(e,d){ + if(e){ + e.preventDefault(); + } + //if(internal.current_step.valid === false){ + // return false; + //} + + if($(this).hasClass('disabled')){ + return false; + } + show_step(NI.co.Merlin.NEXT_STEP); + }, + prev:function(e,d){ + if(e){ + e.preventDefault(); + } + if($(this).hasClass('disabled')){ + return false; + } + show_step(NI.co.Merlin.PREVIOUS_STEP); + }, + refresh:function(e,d){ + if(e){ + e.preventDefault(); + } + show_step(NI.co.Merlin.CURRENT_STEP); + } + }; + + step_input_handlers = { + focus:function(e,d){ + + }, + modify:function(e,d){ + + }, + keypress:function(e,d){ + if(e.data.merlin.o.return_triggers_next){ + if(e.which && (e.which == NI.co.keyboard.ENTER)){ + control_handlers.next(e,d); + } + } + }, + keydown:function(e,d){ + if(e.data.merlin.o.return_triggers_next){ + if(e.which && (e.which == NI.co.keyboard.ENTER)){ + control_handlers.next(e,d); + } + } + }, + blur:function(e,d){ + + } + }; + + step_event_handlers = { + managerValidationPass:function(e,d){ + if(e.data.merlin.internal.current_step){ + e.data.merlin.internal.current_step.valid = true; + } + }, + managerValidationFail:function(e,d){ + if(e.data.merlin.internal.current_step){ + e.data.merlin.internal.current_step.valid = false; + } + } + }; + + this.show_step = function(step, nav_data){ + show_step(step, nav_data); + }; + + this.set_data = function(data){ + internal.data = data; + }; + + this.get_data = function(){ + return internal.data; + }; + + this.get_val = function(id){ + return internal.data[id]; + }; + + this.set_val = function(id,new_val){ + internal.data[id] = new_val; + }; + + init(this); + } + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + NI.Merlin = Merlin; + +}); \ No newline at end of file diff --git a/lib/Merlin2.js b/lib/Merlin2.js new file mode 100644 index 0000000..5e7de08 --- /dev/null +++ b/lib/Merlin2.js @@ -0,0 +1,359 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +define(['jquery', 'NIseed'], function($) { + + var window = this, + NI = window.NI; + + NI.co.Merlin = { + PREVIOUS_STEP: 'prev', + NEXT_STEP: 'next', + CURRENT_STEP: 'current', + + DISABLED_CLASS: 'state-disabled' + }; + + var Merlin = function(options) { + + var self = this, o, internal, fn, handlers; + + o = $.extend({ + name: null, + $e: null, + selector: '', + steps: {}, + data: {}, + controls: { + prev: null, + next: null + }, + transition: null, // function(last_step, current_step) {...} + first_step: null + }, options); + + internal = { + name: 'mod.Merlin' + (o.name ? ' ' + o.name : ''), + $e: (o.$e ? o.$e : $(o.selector)), + steps: o.steps, + data: o.data, + controls: o.controls, + last_step: null, + current_step: null, + n_step_renders: 0 + }; + + fn = { + init: function() { + fn.init_controls(); + fn.init_steps(); + fn.show_first_step(); + internal.$e.addClass('merlin-init'); + }, + init_controls: function() { + $.each(internal.controls, function(k, control) { + if (!control) { + return true; + } + if (handlers[k]) { + if (typeof control === 'string') { + control = $(control, internal.$e); + internal.controls[k] = control; + } + control.on('click.Merlin', handlers[k]); + } + }); + }, + init_steps: function() { + $.each(internal.steps, function(k, step) { + step.name = k; + step.n_times_shown = 0; + step.merlin = self; + if (!step.extensions){ + step.extensions = []; + } + if (!step.$e) { + if (step.selector) { + step.$e = internal.$e.find(step.selector); + } else { + return; + } + } + step.$e.hide(); + }); + }, + show_first_step: function() { + if (o.first_step) { + this.show_step(o.first_step); + } + }, + show_step: function(name, data) { + + // Sanity + + if (typeof name !== 'string' && !$.isFunction(name)) { + return false; + } + + // Validation + + if (internal.current_step && internal.current_step.valid === false) { + return false; + } + + // Provide Default Data + if(!data){ + data = { + + }; + } + + // Special names + + if ($.isFunction(name)) { + name = name(self); + } + + if (name === NI.co.Merlin.PREVIOUS_STEP) { + if (internal.current_step && internal.current_step.prev) { + fn.show_step(internal.current_step.prev); + } + return; + } else if (name === NI.co.Merlin.NEXT_STEP) { + if (internal.current_step && internal.current_step.next) { + fn.show_step(internal.current_step.next); + } + return; + } else if (name === NI.co.Merlin.CURRENT_STEP) { + if (internal.current_step) { + fn.show_step(internal.current_step.name); + } + return; + } + + if (!internal.steps[name]) { + return false; + } + + if (internal.current_step) { + if (name === internal.current_step.name) { + if ($.isFunction(internal.current_step.visible)) { + internal.current_step.visible.apply(internal.current_step, [self, data]); + } + for(i = 0; i < internal.current_step.extensions.length; i++){ + if($.isFunction(internal.current_step.extensions[i].visible)){ + internal.current_step.extensions[i].visible.apply(internal.current_step, [self, data]); + } + } + return true; + } + for(i = 0; i < internal.current_step.extensions.length; i++){ + if($.isFunction(internal.current_step.extensions[i].finish)){ + if(internal.current_step.extensions[i].finish.apply(internal.current_step, [self, data]) === false){ + return false; + } + } + } + if ($.isFunction(internal.current_step.finish)) { + if (internal.current_step.finish.apply(internal.current_step, [self, data]) === false) { + return false; + } + } + internal.last_step = internal.current_step; + } else { + internal.last_step = null; + } + + internal.current_step = internal.steps[name]; + + fn.transition_steps(); + + if (internal.current_step.n_times_shown === 0) { + if ($.isFunction(internal.current_step.init)) { + internal.current_step.init.apply(internal.current_step, [self, data]); + } + for(i = 0; i < internal.current_step.extensions.length; i++){ + if($.isFunction(internal.current_step.extensions[i].init)){ + internal.current_step.extensions[i].init.apply(internal.current_step, [self, data]); + } + } + } + + fn.update_controls(); + + if ($.isFunction(internal.current_step.visible)) { + internal.current_step.visible.apply(internal.current_step, [self, data]); + } + for(i = 0; i < internal.current_step.extensions.length; i++){ + if($.isFunction(internal.current_step.extensions[i].visible)){ + internal.current_step.extensions[i].visible.apply(internal.current_step, [self, data]); + } + } + internal.n_step_renders += 1; + + internal.current_step.n_times_shown += 1; + }, + prev: function() { + this.show_step(NI.co.Merlin.PREVIOUS_STEP); + }, + next: function() { + this.show_step(NI.co.Merlin.NEXT_STEP); + }, + transition_steps: function() { + var last_step = internal.last_step, + current_step = internal.current_step; + + if ($.isFunction(o.transition)) { + o.transition.apply(self, [last_step, current_step]); + } else { + Merlin.default_step_transition(last_step, current_step); + } + }, + get_current_step: function() { + return internal.current_step ? internal.current_step : false; + }, + update_controls: function() { + var current_step = internal.current_step; + if (internal.controls.prev) { + if (current_step.prev) { + internal.controls.prev.removeClass(NI.co.Merlin.DISABLED_CLASS); + } else { + internal.controls.prev.addClass(NI.co.Merlin.DISABLED_CLASS); + } + } + if (internal.controls.next) { + if (current_step.next) { + internal.controls.next.removeClass(NI.co.Merlin.DISABLED_CLASS); + } else { + internal.controls.next.addClass(NI.co.Merlin.DISABLED_CLASS); + } + } + }, + set_data: function(d) { + var data; + + if (!d || typeof d !== 'object') { + return; + } + + data = internal.data; + + $.each(d, function(k, v) { + data[k] = v; + }); + }, + get_data: function() { + var d = {}; + $.each(internal.data, function(k, v) { + d[k] = v; + }); + return d; + }, + set_val: function(k, v) { + internal.data[k] = v; + }, + get_val: function(k) { + return internal.data[k]; + }, + get_dom: function() { + return internal.$e; + }, + get_name: function() { + return o.name; + }, + get_n_step_renders: function(){ + return internal.n_step_renders; + }, + get_step: function(name){ + if(internal.steps[name]){ + return internal.steps[name]; + } + return null; + }, + destroy: function() { + $.each(internal.controls, function(k, control) { + if (handlers[k]) { + if (typeof control === 'string') { + control = $(control); + } + control.off('click.Merlin', handlers[k]); + } + }); + $.each(internal.steps, function() { + if ($.isFunction(this.destroy)) { + this.destroy.apply(this, [self]); + } + }); + } + }; + + handlers = { + prev: function(e) { + e.preventDefault(); + if ($(this).hasClass(NI.co.Merlin.DISABLED_CLASS)) { + return; + } + fn.show_step(NI.co.Merlin.PREVIOUS_STEP); + }, + next: function(e) { + e.preventDefault(); + if ($(this).hasClass(NI.co.Merlin.DISABLED_CLASS)) { + return; + } + fn.show_step(NI.co.Merlin.NEXT_STEP); + }, + refresh: function(e) { + e.preventDefault(); + fn.show_step(NI.co.Merlin.CURRENT_STEP); + } + }; + + this.show_first_step = fn.show_first_step; + this.show_step = fn.show_step; + this.prev = fn.prev; + this.next = fn.next; + this.get_current_step = fn.get_current_step; + this.set_data = fn.set_data; + this.get_data = fn.get_data; + this.set_val = fn.set_val; + this.get_val = fn.get_val; + this.get_dom = fn.get_dom; + this.get_name = fn.get_name; + this.get_step = fn.get_step; + this.get_n_step_renders = fn.get_n_step_renders; + this.destroy = fn.destroy; + + fn.init(); + console.log(internal); + }; + + Merlin.default_step_transition = function(last_step, current_step) { + if (last_step && last_step.$e) { + last_step.$e.hide(); + } + if(current_step.$e){ + current_step.$e.show(); + } + + }; + + + + NI.Merlin = Merlin; + + return Merlin; +}); \ No newline at end of file diff --git a/lib/Overlay.js b/lib/Overlay.js new file mode 100644 index 0000000..dadd9ff --- /dev/null +++ b/lib/Overlay.js @@ -0,0 +1,270 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +define(['jquery', 'NIseed'], function($) { + + var window = this, + NI = window.NI; + + function Overlay(options) { + var o, $e, $m, open, $elements, handlers, generate; + + o = $.extend({ + context: 'body', // Selector to element where overlay will be inserted. + autoflush: true, // If true, the Overlay automatically flushes its content when it is closed. + flavor: null, // Additional classnames for Mask and Overlay. + mask_click: true, // Hide Overlay if Mask is Clicked. + mask_fadeout_speed: 100, // Delay for mask Fade Out Animation. + escape: true, //ESC Keypress closes Overlay. + close_btn: false, // Appends Close Button to Overlay. + + // if true, the Overlay adjusts its behavior + // to be appropriate for touch devices + // (primarily by not using fixed positioning) + touch: false, + + open_transition: null, + on_open: function(instance) {}, // Callback after Overlay is opened. + on_close: function(instance) {} // Callback after Overlay is hidden. + }, options); + + function init(me) { + var $pane; + + $e = generate.overlay().hide().appendTo(o.context); + $m = generate.mask().hide(); + $e.before($m); + + if (typeof o.flavor === 'string') { + $e.addClass(o.flavor); + $m.addClass(o.flavor); + } else if ($.isArray(o.flavor)) { + $.each(o.flavor, function(i, flavor) { + $e.addClass(flavor); + $m.addClass(flavor); + }); + } + + $pane = $e.find('>.tier > .tier > .pane'); + $elements = { + pane: $pane, + hd: $pane.children('.hd'), + bd: $pane.children('.bd'), + ft: $pane.children('.ft') + }; + + if (o.mask_click) { + $e.on('click', {instance:me, $pane:$elements.pane, allowPaneClick: true}, handlers.click_close); + if (o.touch) { + $m.on('click', {instance: me}, handlers.click_close); + } + } + + open = false; + } + + handlers = { + keydown: function(e) { + var key; + key = e.keyCode || e.which; + switch (key) { + case NI.co.keyboard.ESCAPE: + if (e.data.escape === true) { + e.data.instance.close(); + } + break; + case NI.co.keyboard.ENTER: + e.data.$e.find(".button.ca").click(); + break; + } + }, + click_close: function(e) { + var pane; + if (e.data.$pane && e.data.allowPaneClick) { + pane = e.data.$pane[0]; + if (!$.contains(pane, e.target) && (pane != e.target) && $.contains(document.body, e.target)) { + e.preventDefault(); + e.data.instance.close(); + } + } else { + e.preventDefault(); + e.data.instance.close(); + } + } + }; + + generate = { + overlay: function() { + var $overlay = $( '
\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +
' ); + + if (o.touch) { + $overlay.css({ + position: 'absolute', + overflow: 'visible' + }); + } + + return $overlay; + }, + mask: function() { + var $mask = $( '
\ +
' ); + + if (o.touch) { + $mask.css({ + position: 'absolute' + }); + } + + return $mask; + }, + close_btn: function(instance) { + var $btn; + $btn = $('Close'); + if (instance) { + $btn.on('click', {instance:instance}, handlers.click_close); + } + return $btn; + } + }; + + this.flush = function() { + $elements.hd.empty(); + $elements.bd.empty(); + $elements.ft.empty(); + if (o.touch) { + $m.css({ height: '100%' }); + } + return this; + }; + + this.get$e = function(){ + return $e; + }; + + this.set_header = function($hd) { + $elements.hd.empty().append($hd); + return this; + }; + + this.get_header = function(){ + return $elements.hd; + }; + + this.set_body = function($bd) { + $elements.bd.empty().append($bd); + return this; + }; + + this.get_body = function(){ + return $elements.bd; + }; + + this.set_footer = function($ft) { + $elements.ft.empty().append($ft); + return this; + }; + + this.get_footer = function(){ + return $elements.ft; + }; + + this.open = function(options) { + var _o; + _o = $.extend({ + hd: null, + bd: null, + ft: null + }, options); + + if (_o.hd) { this.set_header(_o.hd); } + if (_o.bd) { this.set_body(_o.bd); } + if (_o.ft) { this.set_footer(_o.ft); } + + if (o.close_btn && !($elements.hd.find('.btn-close').length)) { + $elements.hd.append(generate.close_btn(this)); + } + + $e.find('.btn-close').on('click', {instance:this}, handlers.click_close); + + + if (o.open_transition && $.isFunction(o.open_transition)) { + o.open_transition($e, $m); + } else { + $m.fadeIn(); + $e.fadeIn().scrollTop(0).focus(); + } + + if (o.touch) { + $m.height( $(document).height() ); + } + + $(window.document).on('keydown.overlay', {instance:this, escape:o.escape, $e:$e}, handlers.keydown); + + open = true; + if ($.isFunction(o.on_open)) { + o.on_open(this); + } + return this; + }; + + this.close = function() { + if (!open) { return this; } + + if (o.closeTransition && $.isFunction(o.closeTransition)) { + o.closeTransition($e, $m); + } else { + $m.fadeOut(); + $e.hide().blur(); + } + + $(window.document).off('keydown.overlay', handlers.keydown); + + if (o.autoflush === true) { + this.flush(); + } + open = false; + if ($.isFunction(o.on_close)) { + o.on_close(this); + } + return this; + }; + + this.destroy = function() { + $e.blur().remove(); + $m.remove(); + }; + + init(this); + } + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + NI.Overlay = Overlay; + +}); \ No newline at end of file diff --git a/lib/PushstateHelper.js b/lib/PushstateHelper.js new file mode 100644 index 0000000..df73fa9 --- /dev/null +++ b/lib/PushstateHelper.js @@ -0,0 +1,143 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +define(['jquery'], function($) { + + var window = this, + NI = window.NI; + + function PushstateHelper(options) { + + var self = this, o, internal, fn, handlers; + + o = $.extend({ + app: null, + use_hash: false + }, options); + + internal = { + name: 'mod.PushstateHelper', + previous_path: window.location.pathname + }; + + fn = { + init: function() { + $(document).on('click', '.js-use-pushstate, .js-simulate-pushstate', handlers.doc_click); + $(window).on('popstate', handlers.popstate).on('pushstate', handlers.pushstate).on('simulate-pushstate', handlers.simulate_pushstate); + o.app.events.on('app.featuresInitialized', handlers.features_initialized); + if(o.use_hash){ + fn.statechange(window.location.hash); + } else { + fn.statechange(window.location.pathname); + } + }, + statechange: function(pathname, data){ + var i, path_components, position, _event_data; + + path_components = PushstateHelper.get_path_components(pathname); + + _event_data = { + path: pathname, + components: path_components, + data: data ? data : {} + }; + + _event_data.data.previous_path = internal.previous_path; + + o.app.events.trigger('navigationEvent:Pushstate', _event_data); + + internal.previous_path = _event_data.path; + }, + + get_path_components: function(){ + return internal.components; + } + }; + + handlers = { + features_initialized: function(e,d){ + //fn.statechange(window.location); + }, + doc_click: function(e, d) { + var _href, _data; + e.preventDefault(); + _href = $(this).attr('HREF'); + _data = $(this).data(); + if(!$(this).hasClass('js-simulate-pushstate')){ + if(o.use_hash){ + window.location.hash = _href; + fn.statechange(window.location.hash, _data); + } else { + history.pushState(null, null, _href); + fn.statechange(window.location.pathname, _data); + } + } else { + fn.statechange(_href, _data); + } + }, + popstate: function(e, d) { + if(o.use_hash){ + fn.statechange(window.location.hash, d); + } else { + fn.statechange(window.location.pathname, d); + } + }, + pushstate: function(e, d) { + if(o.use_hash){ + if(window.location.hash != d.pathname){ + window.location.hash = d.pathname; + } + } else { + if(window.location.pathname != d.pathname){ + history.pushState(null, null, d.pathname); + } + } + if(!d.prevent_propagation){ + fn.statechange(d.pathname, d); + } + }, + simulate_pushstate: function(e, d) { + if(!d.prevent_propagation){ + fn.statechange(d.pathname, d); + } + } + }; + + this.get_path_components = fn.get_path_components; + + fn.init(); + console.log(internal); + } + + PushstateHelper.get_path_components = function(path){ + var components, position; + components = []; + components = path.split('/'); + position = components.length; + while(position--){ + if(!components[position].length){ + components.splice(position,1); + } + } + return components; + }; + + NI.PushstateHelper = PushstateHelper; + + return PushstateHelper; + +}); \ No newline at end of file diff --git a/lib/SocialRotator.js b/lib/SocialRotator.js new file mode 100644 index 0000000..d6c7ea3 --- /dev/null +++ b/lib/SocialRotator.js @@ -0,0 +1,132 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +define(['jquery', 'NIseed'], function($) { + + var window = this, + NI = window.NI; + + //var SocialButtons = { + // twitter:function(options){ + // var o, button; + // o = $.extend({ + // + // }, options); + // + // button = $(''); + // + // return button; + // }, + // facebook:function(options){ + // + // }, + // gplus:function(options){ + // + // } + //} + + function SocialRotator(options) { + var o, internal; + + o = $.extend({ + element:null, + button_class:'spread-button', + cycle_length:3000, + fade_speed:600 + }, options); + + NI.ex.checkJQ(o.element); + + internal = { + element_zIndex:o.element.css('zIndex'), + spread_timer:null, + spread_buttons: o.element.find('.'+o.button_class), + cycle_counter:0, + current_button:0, + buttons:{} + }; + + this.o = o; + this.internal = internal; + + internal.spread_buttons.css({ + 'opacity':0.0, + 'zIndex':internal.element_zIndex + 1 + }).show(); + + function cycleButtons() { + internal.spread_buttons.stop(true,true).animate({ + 'opacity':0.0 + },o.fade_speed,function(){ + internal.spread_buttons.css({ + 'zIndex':internal.element_zIndex + 1 + }); + }); + internal.cycle_counter++; + internal.current_button = (internal.cycle_counter % 3); + internal.spread_buttons.eq(internal.current_button).stop(true, true).animate({ + opacity:1.0 + },o.fade_speed,function(){ + internal.spread_buttons.eq(internal.current_button).css({ + 'zIndex':internal.element_zIndex + 2 + }); + }); + internal.spread_timer = setTimeout(cycleButtons, o.cycle_length); + } + + o.element.hover( + function () { + if(internal.spread_timer){ + clearTimeout(internal.spread_timer); + } + }, + function () { + if(internal.spread_timer){ + clearTimeout(internal.spread_timer); + } + internal.spread_timer = setTimeout(cycleButtons, (o.cycle_length/2)); + } + ); + + cycleButtons(); + } + + //SocialRotator.prototype.set_social = function(social){ + // var i, temp_button; + // for(i in social){ + // if($.isFunction(SocialButtons[i])){ + // temp_button = SocialButtons[i](social[i]); + // temp_button.addClass('social-' + i).addClass(this.o.button_class); + // if(this.internal.spread_buttons.filter('.social-'+i).length){ + // this.internal.spread_buttons.filter('.social-'+i).replaceWith(temp_button); + // } else { + // this.o.element.prepend(temp_button); + // } + // $(document).trigger('readystatechange'); + // } + // } + // this.internal.spread_buttons = this.o.element.find('.'+this.o.button_class); + //} + + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + NI.SocialRotator = SocialRotator; + +}); \ No newline at end of file diff --git a/lib/Tooltip.js b/lib/Tooltip.js new file mode 100644 index 0000000..554faf3 --- /dev/null +++ b/lib/Tooltip.js @@ -0,0 +1,557 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +define(['jquery', 'NIseed'], function($) { + + var window = this, + NI = window.NI; + + // remove 'px' from a string representing a css pixel dimension + // and cast as a Number (i.e. trimpx('10px') returns 10) + // Used to parse px dimension values from CSS properties, + // such as 'width' and 'height' + //TODO probably should just be replaced with parseInt (?) + function trimPX(s) { + if (s) { + return Number(s.substring(0, s.length - 2)); + } + return 0; + } + + function Tooltip(options) { + + var me, o, internal, handlers, calculate_position; + + me = this; + o = $.extend({ + triggers: $('.tooltip_trigger'), + tooltip:null, + reactive_tooltip: true, + modal_tooltip: false, + markup_generator:null, + animate_slide:true, + animate_opacity:true, + offset_top: 0, + offset_left: 0, + tail_offset_top: 0, + tail_offset_left: 0, + use_mousepos:true, + positions:['top','right','bottom','left'], + container:$('body'), + hide_delay:200, + resize_response_delay: 50 + }, options); + + internal = { + guid: NI.fn.guid('tooltip'), + window:$(window), + tooltip:(o.tooltip ? o.tooltip.appendTo(o.container) : $('
').appendTo(o.container)), + tooltip_content:null, + tails:null, + triggers:o.triggers, + has_been_shown:false, + current_trigger:null, + animating:false, + visible:false, + mousepos:null, + visibility_timer:null, + resize_timer: null + }; + + function init(){ + var event_data = {me: me}; + + if (o.modal_tooltip) { + internal.triggers.bind('click.'+internal.guid, event_data, handlers.trigger_click); + } else { + internal.triggers.bind('mouseenter.'+internal.guid, event_data, handlers.trigger_mouseenter); + internal.triggers.bind('mouseleave.'+internal.guid, event_data, handlers.trigger_mouseleave); + } + + if (o.reactive_tooltip) { + internal.tooltip.bind('mouseenter.'+internal.guid, event_data, handlers.tooltip_mouseenter); + internal.tooltip.bind('mouseleave.'+internal.guid, event_data, handlers.tooltip_mouseleave); + } + + generate_tails(); + + internal.tooltip_content = $('
'); + internal.tooltip.append(internal.tooltip_content); + + if(o.use_mousepos){ + $(document).bind('mousemove.'+internal.guid,function(e,d){ + if(d && d.mousepos){ + internal.mousepos = d.mousepos; + } else { + internal.mousepos = { + x:e.pageX, + y:e.pageY + }; + } + }); + } + } + + function generate_tails(){ + var i, my_tail; + + var css_fn = { + top:function(container){ + var h = container.children('.tooltip-tail').css('height'); + return { + //border: '1px solid red', + width:'100%', + height: h, + bottom: '-' + h, + left: '0px' + }; + }, + right:function(container){ + var w = container.children('.tooltip-tail').css('width'); + return { + //border: '1px solid green', + width: w, + height: '100%', + top: '0px', + left: '-' + w + }; + }, + bottom:function(container){ + var h = container.children('.tooltip-tail').css('height'); + return { + //border: '1px solid yellow', + width: '100%', + height: h, + top: '-' + h, + left: '0px' + }; + }, + left:function(container){ + var w = container.children('.tooltip-tail').css('width'); + return { + //border: '1px solid blue', + width: w, + height: '100%', + top: '0px', + right: '-' + w + }; + } + }; + + for (i = 0; i < o.positions.length; i += 1) { + my_tail = $('
'); + internal.tooltip.append(my_tail); + if ($.isFunction(css_fn[o.positions[i]])) { + my_tail.css($.extend(css_fn[o.positions[i]](my_tail),{ + position: 'absolute', + zIndex: 100 + })); + } + } + + internal.tails = internal.tooltip.find('.tooltip-tail-container'); + } + + // the default markup generator + // (if none is provided by the user) + function markup_generator(markup) { + var output; + if (markup instanceof $) { + output = markup; + } else if (typeof markup === 'string') { + output = $(markup); + } else { + output = $('

No Data.

'); + } + return output; + } + + function show(data) { + internal.tooltip_content.empty().append( + ($.isFunction(o.markup_generator) ? o.markup_generator(data) : markup_generator(data)) + ); + move_to_target( calculate_target_position() ); + } + + function reposition() { + if (!internal.animating) { + move_to_target( calculate_target_position() ); + } + } + + function get_source_position(){ + var offset; + if(o.use_mousepos){ + return { + left: internal.mousepos.x, + top: internal.mousepos.y + }; + } else { + offset = internal.current_trigger.offset(); + return { + left: offset.left + o.container.scrollLeft(), + top: offset.top + o.container.scrollTop() + }; + } + } + + function get_trigger_size(){ + if(o.use_mousepos){ + return { + width:0, + height:0 + }; + } else { + // current_trigger must be rendered + return { + width: internal.current_trigger.outerWidth(), + height: internal.current_trigger.outerHeight() + }; + } + } + + function get_tooltip_size(){ + return { + width:internal.tooltip.outerWidth(), + height:internal.tooltip.outerHeight() + }; + } + + calculate_position = { + // sp -- source_position + // trs -- trigger_size + // tts -- tooltip_size + + top:function(sp,trs,tts){ + var tail = get_tail('top'); + return { + className:'top', + top:(sp.top - (tts.height) - o.tail_offset_top - (tail ? trimPX(tail.css('height')) : 0)) + o.offset_top, + left:((sp.left + (trs.width/2)) - (tts.width/2) + o.tail_offset_left) + o.offset_left + }; + }, + bottom:function(sp,trs,tts){ + var tail = get_tail('bottom'); + return { + className:'bottom', + top:(sp.top + trs.height + o.tail_offset_top + (tail ? trimPX(tail.css('height')) : 0) ) - o.offset_top, + left:((sp.left + (trs.width/2)) - (tts.width/2) + o.tail_offset_left) + o.offset_left + }; + }, + right:function(sp,trs,tts){ + var tail = get_tail('right'); + return { + className:'right', + top: (sp.top + (trs.height/2) - (tts.height/2)) + o.offset_top, + left: (sp.left + (trs.width) + o.tail_offset_top + (tail ? trimPX(tail.css('width')) : 0)) + o.offset_left + }; + }, + left:function(sp,trs,tts){ + var tail = get_tail('left'); + return { + className:'left', + top: (sp.top + (trs.height/2) - (tts.height/2)) + o.offset_top, + left: (sp.left - (tts.width) - o.tail_offset_top - (tail ? trimPX(tail.css('width')) : 0)) - o.offset_left + }; + } + }; + + function get_tail(position){ + var tail = internal.tails.filter('.'+position).children('.tooltip-tail'); + return tail.length ? tail : null; + } + + function get_edge_collisions(tp, tts){ + // tp -- target_position + // tts -- tooltip_size + + var collisions = []; + + //check top + if((tp.top - internal.window.scrollTop()) < 0){ + collisions.push('top'); + } + + //check bottom + if((tp.top + tts.height) > internal.window.height()){ + collisions.push('bottom'); + } + + //check left + if((tp.left - internal.window.scrollLeft()) < 0){ + collisions.push('left'); + } + + //check right + if((tp.left + tts.width) > internal.window.width()){ + collisions.push('right'); + } + + return collisions; + } + + function calculate_target_position(){ + var source_position, trigger_size, tooltip_size, target_position, i; + + source_position = get_source_position(); + trigger_size = get_trigger_size(); + tooltip_size = get_tooltip_size(); + + for (i = 0; i < o.positions.length; i += 1) { + if($.isFunction(calculate_position[o.positions[i]])){ + target_position = calculate_position[o.positions[i]](source_position, trigger_size, tooltip_size); + } + if (!get_edge_collisions(target_position, tooltip_size).length) { + return target_position; + } + } + + return null; + } + + function move_to_target(target_pos){ + var me = this, css_change, animate_change, tail, tail_css_change, tail_animate_change; + + if (!target_pos) { + return; + } + + internal.tooltip.removeClass('position-top position-right position-bottom position-left').addClass('position-' + target_pos.className); + internal.tails.css('visibility','hidden').filter('.' + target_pos.className).css('visibility','visible'); + + css_change = {}; + animate_change = {}; + + tail = get_tail(target_pos.className); + tail_css_change = {}; + tail_animate_change = {}; + + if(o.animate_slide){ + animate_change.top = target_pos.top; + animate_change.left = target_pos.left; + switch(target_pos.className){ + case 'top': + case 'bottom': + tail_animate_change.left = (internal.tooltip.width()/2) - o.tail_offset_left - (trimPX(tail.css('width'))/2); + break; + case 'left': + case 'right': + tail_animate_change.top = (internal.tooltip.height()/2) + o.tail_offset_top - (trimPX(tail.css('height'))/2); + break; + } + } else { + css_change.top = target_pos.top; + css_change.left = target_pos.left; + + switch(target_pos.className){ + case 'top': + case 'bottom': + tail_css_change.left = (internal.tooltip.width()/2) - o.tail_offset_left - (trimPX(tail.css('width'))/2); + break; + case 'left': + case 'right': + tail_css_change.top = (internal.tooltip.height()/2) + o.tail_offset_top - (trimPX(tail.css('height'))/2); + break; + } + } + + if(o.animate_opacity){ + if(!internal.has_been_shown){ + css_change.opacity = '0.0'; + } + animate_change.opacity = '1.0'; + } else { + css_change.opacity = '1.0'; + } + + internal.animating = true; + + tail.css(tail_css_change).stop(true).show().animate(tail_animate_change,500,'easeOutCubic',function(){}); + + internal.tooltip.stop().show().css(css_change).animate(animate_change,500,'easeOutCubic',function(){ + internal.animating = false; + internal.visible = true; + }); + + $(window).bind('resize.'+ internal.guid, handlers.window_resize); + if (o.modal_tooltip) { + $(document).bind('click.'+ internal.guid, handlers.doc_click); + } + + internal.has_been_shown = true; + } + + function hide(){ + internal.animating = true; + internal.visible = false; + internal.tooltip.stop().animate({ + 'opacity':0.0 + },200,'easeOutCirc',function(){ + internal.tooltip.hide(); + internal.animating = false; + internal.current_trigger = null; + }); + $(window).unbind('resize.'+internal.guid); + if (o.modal_tooltip) { + $(document).unbind('click.'+ internal.guid); + } + } + + handlers = { + trigger_mouseenter:function(e){ + if(internal.visibility_timer){ + clearTimeout(internal.visibility_timer); + internal.visibility_timer = null; + } + internal.current_trigger = $(this); + show(); + }, + trigger_mouseleave:function(e){ + if(internal.visibility_timer){ + clearTimeout(internal.visibility_timer); + internal.visibility_timer = null; + } + internal.visibility_timer = setTimeout(hide,o.hide_delay); + }, + trigger_click: function(e) { + if (internal.visible) { + hide(); + } else { + internal.current_trigger = $(this); + show(); + } + }, + tooltip_mouseenter:function(e){ + if(internal.visibility_timer){ + clearTimeout(internal.visibility_timer); + internal.visibility_timer = null; + } + if(!o.use_mousepos && internal.current_trigger && !internal.visible){ + show(); + } + }, + tooltip_mouseleave:function(e,d){ + if(internal.animating){ + return; + } + if(internal.visibility_timer){ + clearTimeout(internal.visibility_timer); + internal.visibility_timer = null; + } + internal.visibility_timer = setTimeout(hide,o.hide_delay); + }, + window_resize: function(e) { + if (internal.resize_timer) { + clearTimeout(internal.resize_timer); + internal.resize_timer = null; + } + internal.resize_timer = setTimeout(reposition, o.resize_response_delay); + }, + doc_click: function(e) { + if (internal.tooltip[0] === e.target || $.contains(internal.tooltip[0], e.target)) { + return; + } + if (internal.current_trigger && + (internal.current_trigger[0] === e.target || $.contains(internal.current_trigger[0], e.target))) { + return; + } + // if the click didn't occur on the tooltip or the current trigger --> hide + hide(); + } + }; + + this.add_trigger = function(trigger){ + var event_data = {me: this}; + + if (o.modal_tooltip) { + trigger.bind('click.'+internal.guid, event_data, handlers.trigger_click); + } else { + trigger.bind('mouseenter.'+internal.guid, event_data, this.handlers.trigger_mouseenter); + trigger.bind('mouseleave.'+internal.guid, event_data, this.handlers.trigger_mouseleave); + } + + if(!internal.triggers.length){ + internal.triggers = trigger; + } else { + internal.triggers.add(trigger); + } + }; + + this.clear_triggers = function() { + internal.triggers.each(function(i,j){ + $(j).unbind('mouseenter.'+internal.guid).unbind('mouseleave.'+internal.guid).unbind('click.'+internal.guid); + }); + internal.triggers = $({}); + }; + + this.show_tooltip = function(_options){ + var _o = $.extend({ + trigger:null, + data:null + },_options); + + if(!_o.trigger){ + return false; + } + + if(internal.visibility_timer){ + clearTimeout(internal.visibility_timer); + internal.visibility_timer = null; + } + + internal.current_trigger = _o.trigger; + internal.tooltip.stop(true); + + show(_o.data); + }; + + this.hide_tooltip = function(delay){ + if(internal.visibility_timer){ + clearTimeout(internal.visibility_timer); + internal.visibility_timer = null; + } + internal.visibility_timer = setTimeout(hide,(delay ? delay : o.hide_delay)); + }; + + this.get_tooltip = function(){ + return internal.tooltip; + }; + + this.destroy = function() { + if(internal.visibility_timer){ + clearTimeout(internal.visibility_timer); + internal.visibility_timer = null; + } + internal.tooltip.remove(); + this.clear_triggers(); + if (o.use_mousepos) { + $(document).unbind('mousemove.'+internal.guid); + } + $(window).unbind('resize.'+internal.guid); + if (o.modal_tooltip) { + $(document).unbind('click.'+ internal.guid); + } + }; + + init(); + } + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + NI.Tooltip = Tooltip; + +}); \ No newline at end of file diff --git a/lib/anim.js b/lib/anim.js new file mode 100644 index 0000000..c6c5e5f --- /dev/null +++ b/lib/anim.js @@ -0,0 +1,125 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +define(['jquery', 'NIseed'], function($) { + + var window = this, + NI = window.NI, + TWO_PI = 2*window.Math.PI; + + var request_anim_frame = (function() { + var fn; + + fn = window.requestAnimationFrame || + window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame || + window.oRequestAnimationFrame || + window.msRequestAnimationFrame || + function(/* function */ callback, /* DOMElement */ element){ + window.setTimeout(callback, 1000 / 60); + }; + + return function() { + fn.apply(window, arguments); + }; + + }()); + + function Cycler(options) { + + var me, o, internal; + + me = this; + o = $.extend({ + speed: window.Math.PI / 600, + cycling: false, + + // callbacks + on_play: $.noop, + on_pause: $.noop, + on_before_update: $.noop, //return false to cancel an update + on_update: $.noop, + on_cycle_complete: $.noop + }, options); + + function init() { + internal = { + cycling: false, + theta: 0, + speed: null + }; + me.set_speed(o.speed); + me[o.cycling ? 'play' : 'pause'](); + } + + function loop() { + if (internal.cycling) { + request_anim_frame(loop); + } else { + return; + } + if (o.on_before_update.apply(me) !== false) { + internal.theta += internal.speed; + if (internal.theta >= TWO_PI) { + internal.theta -= TWO_PI; + o.on_cycle_complete.apply(me); + } + o.on_update.apply(me, [internal.theta]); + } + } + + this.play = function() { + if (!internal.cycling) { + o.on_play.apply(me); + internal.cycling = true; + loop(); + } + return this; + }; + + this.pause = function() { + internal.cycling = false; + o.on_pause.apply(me); + return this; + }; + + this.is_cycling = function() { + return internal.cycling; + }; + + this.reset = function() { + internal.theta = 0; + return this; + }; + + this.set_speed = function(speed) { + if (typeof speed === 'number') { + internal.speed = speed; + } + return this; + }; + + init(); + } + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + NI.anim = NI.anim || {}; + NI.anim.request_anim_frame = request_anim_frame; + NI.anim.Cycler = Cycler; + +}); diff --git a/lib/color.js b/lib/color.js new file mode 100644 index 0000000..24f0daa --- /dev/null +++ b/lib/color.js @@ -0,0 +1,42 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +define(['jquery', 'NIseed'], function($) { + + var window = this, + NI = window.NI, + + color = { + get_rgb_from_hex:function(index,hex){ + if(index.toLowerCase() == 'r'){ + return parseInt((this.cut_hex(hex)).substring(0,2),16); + } else if(index.toLowerCase() == 'g'){ + return parseInt((this.cut_hex(hex)).substring(2,4),16); + } else if(index.toLowerCase() == 'b'){ + return parseInt((this.cut_hex(hex)).substring(4,6),16); + } + }, + cut_hex:function(h){ + return (h.charAt(0)=='#') ? h.substring(1,7) : h; + } + }; + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + NI.color = color; + +}); \ No newline at end of file diff --git a/lib/featuredetection.js b/lib/featuredetection.js new file mode 100644 index 0000000..3cb3444 --- /dev/null +++ b/lib/featuredetection.js @@ -0,0 +1,43 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +define(['jquery', 'NIseed'], function($) { + + var window = this, + NI = window.NI, + cache = {}, + is = { + touch: function() { + if (typeof cache.is_touch === 'boolean') { + return cache.is_touch; + } + + if (('ontouchstart' in window) || (window.DocumentTouch && document instanceof DocumentTouch)) { + cache.is_touch = true; + } else { + cache.is_touch = false; + } + + return cache.is_touch; + } + }; + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + NI.is = $.extend(NI.is || {}, is); + +}); \ No newline at end of file diff --git a/lib/field.js b/lib/field.js new file mode 100644 index 0000000..853c86e --- /dev/null +++ b/lib/field.js @@ -0,0 +1,368 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +define(['jquery', 'NIseed'], function($) { + + var NI = window.NI, + field = { + extensions: {} + }, + console = NI.fn.get_console(true); + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +// constants + + field.co = { + + BASE_CLASS: "tc-field", + LABEL_CLASS: "tc-field-label", + HINT_CLASS: "tc-field-hint", + MSG_CLASS: "tc-field-message", + + MULTI_CLASS: "tc-multiple", + + ACTIVE_CLASS: "state-active", + DISABLED_CLASS: "state-disabled", + EMPTY_CLASS: "state-empty", + OPEN_CLASS: "state-open", + + VALUE: "data-value", + TEXT: "data-text", + + SET_VAL_EVENT: "tc-field-event-set-val", + RESET_EVENT: "tc-field-reset", + VALIDATE_EVENT:"tc-field-validate", + + STANDARD_NODES: ["input", "textarea", "select"] + }; + + + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +// utils, factories, etc + + field.get_display_text = function($f) { + return $f.attr(field.co.TEXT) ? + $f.attr(field.co.TEXT) : $f.text(); + }; + + // synthesize a new field type + field.synthesize = function(options) { + var o = $.extend({ + name: null, + props: null, // static + base: field._Base, + proto: {} + }, options); + + field[o.name] = function(user_options) { + this._name = o.name; + this._base = o.base.prototype; + + this.$e = null; + this.elements = {}; + this.events = {}; + + if (o.base && o.base.prototype && o.base.prototype.options) { + this.internal = { + o: $.extend({}, (o.base.prototype.options || {}), + (this.options || {}), + user_options) + }; + } else { + //throw new Error("invalid base object:"); + console.error("invalid base object:"); + console.log(o.base); + } + + this[this.internal.o.$e ? "generate_from_dom" : "generate_from_scratch"](this.internal.o); + + this._init(); + + if (!this.event_receiver) { + this.event_receiver = this.$e; + } + + if (this.internal.o.handlers) { + this.add_handlers(this.internal.o.handlers, $.extend(this.internal.o.event_data, {me: this})); + } + + if (this.internal.o.val || this.internal.o.val === "") { + this.set_val(this.internal.o.val, true); + } + + if (this.internal.o.extensions) { + this.apply_extensions(this.internal.o.extensions); + } + + return this; + }; + field[o.name].prototype = $.extend({}, o.base.prototype, o.proto); + + if (o.props && typeof o.props === "object") { + $.each(o.props, function(k, v) { + field[o.name][k] = v; + }); + } + + return field[o.name]; + }; + + field.prep_element = function(element, preprocess) { + var $f, $e, is_std, is_fset; + + $f = element instanceof $ ? element : $(element); + + if ($.isFunction(preprocess)) { + $f = preprocess($f) || $f; + } + + if (!($f instanceof $) || !$f.length) { + //throw new Error("Missing field element"); + console.warn("error preparing field element"); + return; + } + + // if the element is not a generic field container + // assume it's a "standard" field (see tc.field.std.js) + // (this approach is questionable) + //is_std = !($f.hasClass(field.co.BASE_CLASS)); + + is_std = ($.inArray($f[0].nodeName.toLowerCase(), field.co.STANDARD_NODES) > -1); + + + // if the jQuery collection contains multiple DOM elements + // it is a field "set" + is_fset = $f.length > 1; + + if (!is_std) { + $e = $f; + } else { + $f.each(function(i) { + if (!($f.eq(i).parent().hasClass(field.co.BASE_CLASS))) { + $f.eq(i).wrap("
"); + } + }); + $e = $f.parent(); + } + + return { + $e: $e, + $f: $f, + is_std: is_std, + is_fset: is_fset + }; + }; + + // field factory + field.new_instance = function(options) { + var o, field_info, field_type; + + o = $.extend({ + element: null, // ($ obj or selector) + preprocess: null, + options: {} // gets passed through to the field instance + }, options); + + field_info = field.prep_element(o.element, o.preprocess); + + if(!field_info){ + console.warn('field not found'); + console.log(o); + return; + } + + if (o.options.is_fset) { + field_info.is_fset = true; + } + + if (!field_info.is_std) { + if (field_info.$e.hasClass(field.Dropdown.CONTAINER_CLASS)) { + if (field_info.$e.hasClass(field.co.MULTI_CLASS)) { + field_type = "MultiDropdown"; + } else { + field_type = "Dropdown"; + } + } + } else { + + switch (field_info.$f[0].nodeName.toLowerCase()) { + case "input": + switch (field_info.$f.attr("type") ? field_info.$f.attr("type").toLowerCase() : "text") { + case "text": + field_type = "TextInput"; + break; + case "password": + field_type = "Password"; + break; + case "radio": + field_type = field_info.is_fset ? "RadioSet" : "Radio"; + break; + case "checkbox": + field_type = field_info.is_fset ? "CheckboxSet" : "Checkbox"; + break; + case "file": + field_type = "Upload"; + break; + case "hidden": + field_type = "TextInput"; + break; + } + break; + case "textarea": + field_type = "TextArea"; + break; + case "select": + field_type = "Select"; + break; + } + } + + if (!field_type) { + //throw new Error("field.new_instance: failed to determine field type"); + field_type = "_Base"; + } + if (! $.isFunction(field[field_type])) { + console.error('Field type ' + field_type + ' is not defined'); + } + return new field[field_type]($.extend(o.options, {$e: field_info.$e})); + }; + + + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +// base field + +// all field types inherit from _Base + + field.synthesize({ + name: "_Base", + + base: {}, + proto: { + + options: { + $e: null, + val: null, + label: null, + handlers: null, + event_data: null, + extensions: null + }, + + _init: function() {}, + + // (chainable) + apply_extensions: function(extensions) { + var me = this; + $.each(extensions, function(extension, options) { + if ($.isFunction(field.extensions[extension])) { + me.internal[extension] = new field.extensions[extension](me, options); + } + }); + return this; + }, + + generate_from_dom: function(options) { + this.$e = options.$e.addClass(field.co.BASE_CLASS); + }, + + generate_from_scratch: function(options) {}, + + // (chainable) + append_to: function() { + if (!NI.ex.isHeadless(this.$e)) { + this.$e = this.$e.detach(); + } + + if (typeof arguments[0] === "string") { + $(arguments[0]).append(this.$e); + } else if (arguments[0] instanceof $) { + arguments[0].append(this.$e); + } + + return this; + }, + + get_val: function() { + return null; + }, + + // (chainable) + set_val: function(val, prevent_change) { + var from, to; + from = this.get_val(); + + if (this._set_val(val) !== false) { + if (!prevent_change) { + to = this.get_val(); + if (from !== to) { + this.event_receiver.trigger("change", { + from: from, + to: to + }); + } + } + } + + this.event_receiver.trigger(field.co.SET_VAL_EVENT); + + return this; + }, + + _set_val: function(val) {}, + + reset: function(){ + this.set_val(''); + this.event_receiver.trigger(field.co.RESET_EVENT); + }, + + // (chainable) + bind: function(type, data, fn, replace) { + if (replace) { + this.event_receiver.unbind(type); + } + this.event_receiver.bind(type, data, fn); + return this; + }, + + // (chainable) + add_handlers: function(handlers, data, replace) { + var i; + for (i in handlers) { + this.bind(i, data, handlers[i], replace); + } + return this; + }, + + // (chainable) + set_enabled: function(enabled) { + return this; + }, + + destroy: function() { + this.$e.remove(); + } + } + }); + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + NI.field = field; + + return NI.field; +}); \ No newline at end of file diff --git a/lib/field/Autocomplete.js b/lib/field/Autocomplete.js new file mode 100644 index 0000000..3b4f2eb --- /dev/null +++ b/lib/field/Autocomplete.js @@ -0,0 +1,508 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +// Dependencies: +// NI.field + +define(['jquery', 'NIseed', 'NIfield'], function($) { + + var window = this, + NI = window.NI, + delegates = {}; + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + // TODO + delegates.DropdownAutocomplete = function(field, options) { + var me, o; + + me = this; + o = $.extend({ + + }, options); + + function init() { + + } + + init(); + }; + + delegates.TextInputAutocomplete = function(field, options) { + var me, o, internal; + + me = this; + o = $.extend({ + menu_class: "autocomplete menu", + menu_markup: null, + + item_generator: null, + event_data: {}, + on_item_pick: function(e, d) {}, + on_populate: function(d, val) {}, + item_class: "tc-menu-item", + + auto_match: { + key: "value", + allow_different: false, + value_transform: null + }, + + data_source: null, + request_filter_param: "term", + + circular: true, + highlight: true, + activate_after_highlight_n: false, + + delay: 100, + animation: 'slide', + speed: 100 + }, options); + + internal = { + menu_open: false, + menu_engaged: false, + data_source: o.data_source, + request: null, + timeout: null + }; + + function init() { + + field.elements.menu = $((o.menu_markup ? o.menu_markup : "
")); + if(!field.elements.menu.hasClass(o.menu_class)){ + field.elements.menu.addClass(o.menu_class); + } + field.elements.item_wrapper = (field.elements.menu.hasClass('item-wrapper') ? field.elements.menu : field.elements.menu.find('.item-wrapper')); + + hide(); + field.$e.append(field.elements.menu); + + field.add_handlers({ + "keyup.autocomplete": events.keyup, + "keydown.autocomplete": events.keydown, + "focus.autocomplete": events.focus, + "blur.autocomplete": events.blur, + "change.autocomplete": events.change + }, $.extend({field: field}, o.event_data)); + + field.elements.menu.bind("mouseover.autocomplete", function() { + internal.menu_engaged = true; + }).bind("mouseout.autocomplete", function() { + internal.menu_engaged = false; + }); + } + + var events = { + keyup: function(e) { + var key, val; + + key = e.which; + val = e.data.field.get_val(); + + if (NI.ex.isEmpty(val)) { + hide(); + return; + } + if (!(key >= 48 && key <= 90)) { + if (key != NI.co.keyboard.BACKSPACE && key != NI.co.keyboard.DELETE) { + return; + } + } + + dispatch(val); + }, + keydown: function(e) { + var prevent_default, key; + + prevent_default = true; + key = e.which; + + switch (key) { + case NI.co.keyboard.UP: + case NI.co.keyboard.LEFT: + if (internal.menu_open) { + move_selection(NI.co.directions.UP); + } + break; + + case NI.co.keyboard.DOWN: + case NI.co.keyboard.RIGHT: + case NI.co.keyboard.TAB: + if (internal.menu_open) { + move_selection(NI.co.directions.DOWN); + } + break; + + case NI.co.keyboard.ENTER: + if (e.data.field.select_active_item() === true) { + // don't let the enter keydown trip up + // other handlers (namely, from Merlin) + e.stopImmediatePropagation(); + } + break; + + case NI.co.keyboard.ESCAPE: + if (internal.menu_open) { + hide(); + } + break; + + default: + prevent_default = false; + break; + } + + if (prevent_default) { + e.preventDefault(); + } + }, + focus: function(e) { + var val; + val = e.data.field.get_val(); + if (NI.ex.isEmpty(val)) { + hide(); + return; + } + dispatch(val); + }, + blur: function(e) { + if (!internal.menu_engaged) { + hide(); + } + }, + change: function(e){ + if ($.isFunction(o.on_change) && o.on_change.apply(this, arguments) !== false) { + + } + }, + // callback when the menu is shown + visible: function() { + + } + }; + + function dispatch(val) { + if (internal.timeout) { + window.clearTimeout(internal.timeout); + internal.timeout = null; + } + internal.timeout = window.setTimeout(function() { + if (typeof internal.data_source === "string") { //URL + request_data(val); + } else if ($.isArray(internal.data_source)) { + filter_array(val); + } + }, o.delay); + } + + function request_data(val) { + var data = {}; + + if (internal.request) { + internal.request.abort(); + } + + data[o.request_filter_param] = val; + internal.request = $.getJSON(internal.data_source, data, function(d) { + internal.request = null; + if(populate_menu(d, val)){ + show(); + } else { + hide(); + } + }); + } + + function filter_array(val) { + var data, filter, t_start; + data = []; + filter = new RegExp(val,"gi"); + + $.each(internal.data_source,function(i,j){ + var my_start; + my_start = j.label.search(filter); + if(my_start == -1){ + return; + } + data.push(j); + }); + + if(populate_menu(data, val)){ + show(); + } else { + hide(); + } + } + + function populate_menu(d, val) { + var wrap, items_added, $auto_match_item; + items_added = 0; + $auto_match_item = false; + + wrap = field.elements.item_wrapper; + wrap.empty(); + + $.each(d, function(i, item) { + var $item; + if ($.isFunction(o.item_generator)) { + $item = o.item_generator(item, field.get_val()); + } else { + $item = (function(my_item){ + return $('
'+my_item.label+'
'); + })(item); + } + if(!$item){ + return; + } + if(!$item.hasClass(o.item_class) && !$item.find('.'+o.item_class).length){ + $item.addClass(o.item_class); + } + + if (o.highlight && val) { + highlight($item, val); + } + + wrap.append($item); + items_added++; + + if (o.auto_match && !$auto_match_item) { + $auto_match_item = auto_match($item, val); + } + }); + + if (o.auto_match && $auto_match_item !== false) { + wrap.append($auto_match_item); + } + + wrap.find("."+ o.item_class). + bind("click", $.extend({field: field}, o.event_data), function(e, d) { + if (o.on_item_pick.apply(this, arguments) !== false) { + hide(); + internal.menu_engaged = false; + } + }). // auto-activate the first highlighted item, if it exists + filter(".auto-activate").first().addClass(NI.field.co.ACTIVE_CLASS); + + o.on_populate.apply(field, [d, val]); + + if (items_added > 0) { + return true; + } else { + return false; + } + } + + function highlight($item, val) { + if (!val) { + return; + } + $item.each(function() { + innerHighlight($item, this, val.toUpperCase()); + }); + } + + // HTML node highlighting routine based on Johann Burkard's jQuery highlight v3: + // http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html + + function innerHighlight($item, node, pat) { + var skip = 0; + if (node.nodeType == NI.co.node_types.TEXT_NODE) { + var pos = node.data.toUpperCase().indexOf(pat); + if (pos >= 0) { + var spannode = document.createElement('span'); + spannode.className = 'hili'; + var middlebit = node.splitText(pos); + var endbit = middlebit.splitText(pat.length); + var middleclone = middlebit.cloneNode(true); + spannode.appendChild(middleclone); + middlebit.parentNode.replaceChild(spannode, middlebit); + skip = 1; + + if (o.activate_after_highlight_n && pat.length >= o.activate_after_highlight_n) { + $item.addClass("auto-activate"); + } + + } + } else if (node.nodeType == NI.co.node_types.ELEMENT_NODE && node.childNodes && !/(script|style)/i.test(node.tagName)) { + for (var i = 0; i < node.childNodes.length; ++i) { + i += innerHighlight($item, node.childNodes[i], pat); + } + } + return skip; + } + + // if an element is "auto matched", return a $ object + // representing an 'Add a different ...' control, + // otherwise, return false + function auto_match($item, val) { + var item_val, $diff_item; + + item_val = $item.attr("data-"+ o.auto_match.key); + if (!item_val || !val) { + return; + } + + if ($.isFunction(o.auto_match.value_transform)) { + item_val = o.auto_match.value_transform(item_val); + if (!item_val) { + return; + } + } + + if (!$item.hasClass(NI.field.co.ACTIVE_CLASS) && item_val.toLowerCase() == val.toLowerCase()) { + + $item.addClass(NI.field.co.ACTIVE_CLASS); + + if (o.auto_match.allow_different !== false) { + $diff_item = $("
Add a different "+ item_val +"
").addClass(o.item_class +" "+ o.item_class+"-diff"); + $diff_item.attr("data-"+ o.auto_match.key, item_val); + return $diff_item; + } + } + + return false; + } + + function move_selection(direction) { + var $t, $items, $active_item, index; + + $items = field.elements.item_wrapper.find("."+ o.item_class); + if (!$items.length) { + return; + } + $active_item = $items.filter("."+ NI.field.co.ACTIVE_CLASS); + + if (!$active_item.length) { + if (direction === NI.co.directions.UP) { + $t = $items.last(); + } else { + $t = $items.first(); + } + } else { + + index = $items.index($active_item.last()); + + if (direction === NI.co.directions.UP) { + $t = $items.eq(index - 1); + if (!$t.length) { + $t = o.circular ? $items.last() : $items.first(); + } + } else { + $t = $items.eq(index + 1); + if (!$t.length) { + $t = o.circular ? $items.first() : $items.last(); + } + } + } + + $items.removeClass(NI.field.co.ACTIVE_CLASS); + $t.addClass(NI.field.co.ACTIVE_CLASS); + } + + function show(callback) { + if (internal.menu_open) { + events.visible(); + return; + } + if (o.animation == 'slide') { + field.elements.menu.slideDown(o.speed, function() { + events.visible(); + }); + } else { + field.elements.menu.show(); + events.visible(); + } + internal.menu_open = true; + } + + function hide() { + /*if (o.animation == 'slide') { + field.elements.menu.slideUp(o.speed); + } else { + field.elements.menu.hide(); + };*/ + + if (internal.request) { + internal.request.abort(); + } + + field.elements.menu.hide(); + internal.menu_open = false; + } + + field.set_data_source = function(data_source){ + internal.data_source = data_source; + }; + + field.has_active_item = function(){ + if(field.elements.item_wrapper.find("."+ o.item_class).filter("."+ NI.field.co.ACTIVE_CLASS).length){ + return true; + } + return false; + }; + + field.select_active_item = function() { + // return true if an active item exists, + // otherwise return false + + var $items, $active_item; + + $items = field.elements.item_wrapper.find("."+ o.item_class); + if (!$items.length) { + return false; + } + $active_item = $items.filter("."+ NI.field.co.ACTIVE_CLASS); + if (!$active_item.length) { + return false; + } + $active_item.last().trigger("click"); + return true; + }; + + field.is_open = function(){ + return internal.menu_open; + }; + + init(); + }; + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + NI.field.extensions.Autocomplete = function(field, options) { + var me, o, delegate; + + me = this; + o = $.extend({ + + }, options); + + function init() { + + if ($.isFunction(delegates[field._name + "Autocomplete"])) { + delegate = new delegates[field._name + "Autocomplete"](field, o); + } else { + throw new Error("Autocomplete does not support field type: "+ field._name); + } + + } + + init(); + }; + +}); \ No newline at end of file diff --git a/lib/field/Counter.js b/lib/field/Counter.js new file mode 100644 index 0000000..9125577 --- /dev/null +++ b/lib/field/Counter.js @@ -0,0 +1,77 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +// Dependencies: +// NI.field + +define(['jquery', 'NIseed', 'NIfield'], function($) { + + var window = this, + NI = window.NI; + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + NI.field.extensions.Counter = function(field, options) { + var me, o, internal, elements, event_handlers; + + me = this; + o = $.extend({ + max:100, + difference:0, + updated:function(e,d){}, + count_element:'.count', + total_element:'.total' + + }, options); + + internal = { + name:'TC.field Extension.SimpleTooltip', + $e:null + }; + + elements = { + count:(o.count_element instanceof $ ? o.count_element : field.$e.find(o.count_element)), + total:(o.total_element instanceof $ ? o.total_element : field.$e.find(o.total_element)) + }; + + function init(){ + field.event_receiver.bind('focus keyup change', {field:field}, event_handlers.updated); + } + + event_handlers = { + updated:function(e,d){ + o.difference = o.max - field.get_val().length; + + elements.count.text(o.difference); + //elements.total.text(o.max); + + if (o.difference < 0) { + elements.count.parent().addClass('too-many'); + } else { + elements.count.parent().removeClass('too-many'); + } + } + }; + + + init(); + + }; + + return NI.field.extensions.Counter; + +}); \ No newline at end of file diff --git a/lib/field/Dropdown.js b/lib/field/Dropdown.js new file mode 100644 index 0000000..87438fe --- /dev/null +++ b/lib/field/Dropdown.js @@ -0,0 +1,670 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +// Dependencies: +// NI.field + +define(['jquery', 'NIseed', 'NIfield'], function($) { + + var window = this, + NI = window.NI, + field = NI.field; + + field.synthesize({ + name: "Dropdown", + + props: { + CONTAINER_CLASS: "tc-dropdown", + DISPLAY_CLASS: "display", + TRIGGER_ARROW_CLASS: "trigarr", + MENU_CLASS: "menu", + ITEM_CLASS: "item", + + morph_native_select: function($f) { + var $e, buf; + + if(!$f[0]){ + return $f; + } + + if ($f[0].nodeName.toLowerCase() != "select") { + return $f; + } + + $e = $("
") + .addClass(field.co.BASE_CLASS+ " " +field.Dropdown.CONTAINER_CLASS) + .html("
"+ + "
"); + + buf = ""; + $f.find("option").each(function() { + var $option = $(this); + buf += "
"+ + field.get_display_text($option) +"
"; + }); + $e.find("."+ field.Dropdown.MENU_CLASS).html(buf); + + if (!NI.ex.isHeadless($f)) { + $f.replaceWith($e); + } + + return $e; + } + + }, + + proto: { + + options: { + item_generator: null, + item_handlers: { + click: function(e) { + e.data.me.set_val(e.data.$item.attr(field.co.VALUE)).close(); + } + }, + + empty_val: "-1", + empty_text: " ", + + circular: true, + filtering: true, + rolling: false, + enable_update_display: true, + + on_open: function(instance) {}, + on_close: function(instance) {}, + on_keydown: function(e) {}, + + fx: { + open: function($menu, callback) { + $menu.slideDown(100, function() { + if ($.isFunction(callback)) { + callback(); + } + }); + }, + close: function($menu) { + $menu.slideUp(100); + } + } + }, + + _init: function() { + + this.events.click = function(e) { + var me = e.data.me; + + if (me.$e[0] === e.target || $.contains(me.$e[0], e.target)) { + // clicked somewhere on the dropdown + + if (me.elements.display[0] === e.target || + $.contains(me.elements.display[0], e.target) || + (me.elements.trigarr && me.elements.trigarr[0] === e.target)) { + + // clicked somewhere on the dropdown display area + me[me.internal.open ? "close" : "open"](); + } + + } else { + // clicked somewhere off the dropdown + if (me.internal.open) { + me.close(); + } + } + }; + + this.events.keydown = function(e) { + var me, prevent_default, key; + + me = e.data.me; + if ($.isFunction(me.internal.o.on_keydown)) { + if (me.internal.o.on_keydown(e) === false) { + return; + } + } + prevent_default = true; + key = e.keyCode || e.which; + + if (key >= 48 && key <= 90) { + if (me.internal.o.filtering) { + me.internal.filter_str += String.fromCharCode(key); + me.filter(me.internal.filter_str); + } + + } else if (key == NI.co.keyboard.BACKSPACE || + key == NI.co.keyboard.DELETE) { + if (me.internal.filter_str.length) { + me.clear_filter(); + } + + } else { + switch (key) { + case NI.co.keyboard.LEFT: + case NI.co.keyboard.UP: + me.move_selection(NI.co.directions.UP); + break; + + case NI.co.keyboard.RIGHT: + case NI.co.keyboard.DOWN: + me.move_selection(NI.co.directions.DOWN); + break; + + case NI.co.keyboard.ENTER: + case NI.co.keyboard.ESCAPE: + me.close(); + break; + + default: + prevent_default = false; + break; + } + } + if (prevent_default) { + e.preventDefault(); + } + }; + + $(window.document).bind("click."+ this._name, {me: this}, this.events.click); + + this.internal.filter_str = ""; + this._update_display(this.get_active_item()); + this.close(); + }, + + generate_from_dom: function(options) { + var me, $items; + me = this; + + if (options.$e[0].nodeName.toLowerCase() == "select") { + this.$e = field.Dropdown.morph_native_select(options.$e); + } else { + this.$e = options.$e; + } + + this.$e.addClass(field.co.BASE_CLASS); + this.$e.addClass(field.Dropdown.CONTAINER_CLASS); + + this._init_elements(); + $items = this.get_items(true); + if (typeof(this.internal.o.item_handlers) === "object") { + $.each(this.internal.o.item_handlers, function(type, fn) { + $items.each(function() { + var $item, empty_val; + $item = $(this); + if ($item.hasClass(field.co.EMPTY_CLASS)) { + empty_val = $item.attr(field.co.VALUE); + if (empty_val) { + me.internal.o.empty_val = empty_val; + } + me.internal.o.empty_text = field.get_display_text($item); + $item.remove(); + return true; + } + $item.bind(type, {me: me, $item: $item}, fn); + }); + }); + } + }, + + generate_from_scratch: function(options) { + this.$e = $("
") + .addClass(field.co.BASE_CLASS+ " " +field.Dropdown.CONTAINER_CLASS) + .html("
"+ + "
"); + this._init_elements(); + if (options.value_list) { + this.populate(options.value_list); + } + }, + + _init_elements: function() { + var trigarr; + this.elements.display = $("."+ field.Dropdown.DISPLAY_CLASS, this.$e); + this.elements.menu = $("."+ field.Dropdown.MENU_CLASS, this.$e); + trigarr = $("."+field.Dropdown.TRIGGER_ARROW_CLASS , this.$e); + if (trigarr.length) { + this.elements.trigarr = trigarr; + } + this.events.visible = function() { + + }; + }, + + // (chainable) + populate: function(value_list) { + var me; + me = this; + this.elements.menu.empty(); + + if ($.isFunction(value_list)) { + this.elements.menu.append(value_list()); + return this; + } + + if (value_list instanceof $) { + this.add_item(value_list); + return this; + } + + $.each(value_list, function(value, text) { + me.add_item(value, text); + }); + + return this; + }, + + // (chainable) + // arguments can be: + // + // 1 arg => jQuery object + // OR + // arguments for an item_generator + // OR + // 2 args => value, text + add_item: function() { + var me, $item; + me = this; + + if (arguments[0] instanceof $) { + $item = arguments[0]; + + } else if ($.isFunction(this.internal.o.item_generator)) { + $item = this.internal.o.item_generator(arguments); + + } else { + $item = $("
"+ arguments[1] +"
"); + } + + $item.addClass(field.Dropdown.ITEM_CLASS); + + if (typeof(this.internal.o.item_handlers) === "object") { + $.each(this.internal.o.item_handlers, function(type, fn) { + $item.bind(type, {me: me, $item: $item}, fn); + }); + } + + this.elements.menu.append($item); + return this; + }, + + get_items: function(include_secrets) { + var $items = this.elements.menu.find("."+ field.Dropdown.ITEM_CLASS); + if ($.isFunction(include_secrets)) { + $items = $items.filter(include_secrets); + } else if (!include_secrets) { + $items = $items.filter(function() { + return ($(this).css("display") !== "none"); + }); + } + return $items; + }, + + get_active_item: function() { + var $item; + $item = this.get_items(true).filter("."+ field.co.ACTIVE_CLASS); + return $item.length ? $item : false; + }, + + reset: function(){ + this.set_val('-1'); + this.event_receiver.trigger(field.co.RESET_EVENT); + }, + + get_val: function() { + var $item; + $item = this.get_active_item(); + if ($item) { + return $item.attr(field.co.VALUE); + } + return this.internal.o.empty_val; + }, + + _set_val: function(val) { + var me, $items; + me = this; + + if (val === this.internal.o.empty_val) { + this.clear(); + return; + } + + $items = this.get_items(true); + + $items.each(function(i) { + var $item = $(this); + if ($item.attr(field.co.VALUE) == val) { + if (!me.internal.multi) { + $items.removeClass(field.co.ACTIVE_CLASS); + } else { + $item.children("input").attr("checked", true); + } + $item.addClass(field.co.ACTIVE_CLASS); + if(me.internal.o.enable_update_display){ + me._update_display($item); + } + return false; + } + }); + }, + + // (chainable) + move_selection: function(direction) { + var me, $t, $items, $active_item, index; + me = this; + + $items = this.get_items(this.internal.o.rolling ? true : false); + if (!$items.length) { + return this; + } + + $active_item = this.get_active_item(); + + if (!$active_item || $active_item === this.internal.o.empty_val) { + if (direction === NI.co.directions.UP) { + $t = $items.last(); + } else { + $t = $items.first(); + } + } else { + index = $items.index($active_item.last()); + if (direction === NI.co.directions.UP) { + $t = $items.eq(index - 1); + if (!$t.length) { + $t = this.internal.o.circular ? $items.last() : $items.first(); + } + } else { + $t = $items.eq(index + 1); + if (!$t.length) { + $t = this.internal.o.circular ? $items.first() : $items.last(); + } + } + } + + return this.internal.multi ? this.toggle_item($t) : this.set_val($t.attr(field.co.VALUE)); + }, + + // (chainable) + clear: function() { + this.get_items(true).removeClass(field.co.ACTIVE_CLASS); + this._update_display(false); + return this; + }, + + // arguments can be: + // + // $ obj => the active item to display + // OR + // str => arbitrary message to display + // OR + // false => display the empty state + _update_display: function() { + + if (arguments[0] instanceof $) { + this.elements.display.html(field.get_display_text(arguments[0])); + return; + } + + if (typeof arguments[0] === "string") { + this.elements.display.html(""+ arguments[0] +""); + return; + } + + if (arguments[0] === false) { + this.elements.display.html(""+ this.internal.o.empty_text +""); + return; + } + }, + + // (chainable) + set_enabled: function(enabled) { + if (enabled) { + this.internal.enabled = true; + this.$e.removeClass(field.co.DISABLED_CLASS); + } else { + this.close(); + this.internal.enabled = false; + this.$e.addClass(field.co.DISABLED_CLASS); + } + return this; + }, + + // (chainable) + open: function() { + if (this.internal.enabled === false) { + return this; + } + if (this.get_items()) { + if (this.internal.o.fx && $.isFunction(this.internal.o.fx.open)) { + this.internal.o.fx.open(this.elements.menu, this.events.visible); + } else { + this.elements.menu.show(); + this.events.visible(); + } + this.$e.addClass(field.co.OPEN_CLASS); + $(window.document).bind("keydown."+ this._name, {me: this}, this.events.keydown); + this.internal.open = true; + this.$e.trigger('tc-field-dropdown-open'); + if ($.isFunction(this.internal.o.on_open)) { + this.internal.o.on_open(this); + } + } + return this; + }, + + // (chainable) + close: function() { + if (this.internal.o.fx && $.isFunction(this.internal.o.fx.close)) { + this.internal.o.fx.close(this.elements.menu); + } else { + this.elements.menu.hide(); + } + this.$e.removeClass(field.co.OPEN_CLASS); + $(window.document).unbind("keydown."+ this._name, this.events.keydown); + this.internal.open = false; + this.clear_filter(); + this.$e.trigger('tc-field-dropdown-close'); + if ($.isFunction(this.internal.o.on_close)) { + this.internal.o.on_close(this); + } + return this; + }, + + // (chainable) + filter: function(text) { + var me, $items, s; + me = this; + $items = this.get_items(function() { + var $item = $(this); + return ($item.hasClass("state-filtered") || ($item.css("display") !== "none")); + }); + if (!$items.length) { + return this; + } + if (!text) { + $items.each(function() { + $(this).removeClass("state-filtered").show(); + }); + return this; + } + s = new RegExp(text, "gi"); + $items.each(function() { + var $item = $(this); + if (field.get_display_text($item).search(s) === -1) { + $item.addClass("state-filtered").hide(); + } else { + $item.removeClass("state-filtered").show(); + } + }); + return this; + }, + + // (chainable) + clear_filter: function() { + this.internal.filter_str = ""; + return this.filter(); + }, + + destroy: function() { + this.close(); + $(window.document).unbind("click."+ this._name, this.events.click); + this._base.destroy.apply(this, arguments); + } + } + }); + + field.synthesize({ + name: "MultiDropdown", + + base: field.Dropdown, + proto: { + + options: { + item_handlers: { + click: function(e) { + e.data.me.toggle_item(e.data.$item); + } + }, + + empty_val: [], + + circular: false, + filtering: false + }, + + _init: function() { + this.internal.multi = true; + this._base._init.apply(this, arguments); + this.get_items(true).each(function() { + var $item = $(this); + if ($item.hasClass(field.co.ACTIVE_CLASS)) { + $item.children("input").attr("checked", true); + } else { + $item.children("input").removeAttr("checked"); + } + }); + }, + + get_val: function() { + var $active, value_list; + $active = this.get_active_item(); + if ($active) { + value_list = []; + $active.each(function() { + value_list.push($(this).attr(field.co.VALUE)); + }); + return value_list; + } + return this.internal.o.empty_val; + }, + + // (chainable) + toggle_item: function($item) { + var value_list, val, index; + + value_list = this.get_val(); + val = $item.attr(field.co.VALUE); + if (value_list === this.internal.o.empty_val) { + return this.set_val(val); + } + index = $.inArray(val, value_list); + if (index > -1) { + value_list.splice(index, 1); + } else { + value_list.push(val); + } + return this.set_val(value_list); + }, + + _set_val: function(val) { + var me = this, $items; + + if (!$.isArray(val)) { + this._base._set_val.apply(this, arguments); + return; + } + + $items = this.get_items(true); + + $items.each(function() { + var $item = $(this); + $item.removeClass(field.co.ACTIVE_CLASS); + $item.children("input").removeAttr("checked"); + }); + + $.each(val, function(i, v) { + $items.each(function(i) { + var $item = $(this); + if ($item.attr(field.co.VALUE) == v) { + $item.addClass(field.co.ACTIVE_CLASS); + $item.children("input").attr("checked", true); + return false; + } + }); + }); + + if(me.internal.o.enable_update_display){ + this._update_display(); + } + }, + + clear: function() { + this.get_items(true).removeClass(field.co.ACTIVE_CLASS).children("input").removeAttr("checked"); + this._update_display(false); + return this; + }, + + _update_display: function() { + var display_list, $active, buf, i; + + if (arguments[0] instanceof $ && arguments[0].length > 1) { + display_list = []; + $.each(arguments[0], function() { + display_list.push(field.get_display_text($(this))); + }); + + } else if (arguments[0] !== false && !arguments[0]) { + $active = this.get_active_item(); + if ($active) { + display_list = []; + $active.each(function() { + display_list.push(field.get_display_text($(this))); + }); + + } else { + this._base._update_display.apply(this, [false]); + return; + } + + } else { + this._base._update_display.apply(this, arguments); + return; + } + + buf = ""; + for (i = 0; i < display_list.length; i += 1) { + buf += ""+ display_list[i] +""; + if (i < display_list.length - 1) { + buf += ", "; + } + } + this.elements.display.html(buf); + } + + } + }); + +}); \ No newline at end of file diff --git a/lib/field/Hint.js b/lib/field/Hint.js new file mode 100644 index 0000000..7b85397 --- /dev/null +++ b/lib/field/Hint.js @@ -0,0 +1,114 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +// Dependencies: +// NI.field + +define(['jquery', 'NIseed', 'NIfield'], function($) { + + var window = this, + NI = window.NI; + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + NI.field.extensions.Hint = function(field, options) { + var me, o, $e; + + me = this; + o = $.extend({ + content: null, + html_content: false, + css: {}, + fx: { + in_fx: 200, + out_fx: 200 + }, + watch_events: { + in_event: ['blur', 'keyup', 'change', NI.field.co.SET_VAL_EVENT, NI.field.co.RESET_EVENT].join(' '), + out_event: "focus" + } + }, options); + + function init() { + $e = $("
"); + $e.css($.extend({ + position: "absolute", + top: 0, + left: 0, + display: "none" + }, o.css)); + $e.prependTo(field.$e); + + $e.click(events.hint_click); + field.event_receiver.bind(o.watch_events.in_event, events.in_fn); + field.event_receiver.bind(o.watch_events.out_event, events.out_fn); + + me.set(o.content); + + if (!field.get_val() || !field.get_val().length) { + $e.show(); + } + } + + var events = { + hint_click: function(e, d) { + field.event_receiver.trigger('focus'); + }, + in_fn: function(e, d) { + //if (NI.ex.isEmpty(field.get_val())) { + if (!field.get_val() || !field.get_val().length) { + if (e.type === "blur" || e.type == NI.field.co.RESET_EVENT) { + $e.fadeIn(o.fx.in_fx); + } + } else { + $e.fadeOut(o.fx.out_fx); + } + }, + out_fn: function(e, d) { + $e.fadeOut(o.fx.out); + } + }; + + // (chainable) + this.set = function(content) { + if (content instanceof $) { + $e.empty().append(content); + } else if (typeof content === "string") { + //if (!NI.ex.isEmpty(content)) { + if (!field.get_val() || !field.get_val().length) { + if (o.html_content === true) { + $e.empty().html(content); + } else { + $e.empty().text(content); + } + } + } + return this; + }; + + this.destroy = function() { + $e.remove(); + field.event_receiver.unbind(o.watch_events.in_event, events.in_fn); + field.event_receiver.unbind(o.watch_events.out_event, events.out_fn); + }; + + init(); + }; + + return NI.field.extensions.Hint; + +}); \ No newline at end of file diff --git a/lib/field/SimpleTooltip.js b/lib/field/SimpleTooltip.js new file mode 100644 index 0000000..af7be53 --- /dev/null +++ b/lib/field/SimpleTooltip.js @@ -0,0 +1,100 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +// Dependencies: +// NI.field + +define(['jquery', 'NIseed', 'NIfield'], function($) { + + var window = this, + NI = window.NI; + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + NI.field.co.SIMPLE_TOOLTIP_CLASS = 'tc-field-simple-toolip'; + + NI.field.extensions.SimpleTooltip = function(field, options) { + var me, o, internal, event_handlers; + + me = this; + o = $.extend({ + content: null, + orientation:'left',//'top' + css: {}, + fx: { + in_fx: 200, + out_fx: 50 + }, + watch_events: { + in_event: "focus", + out_event: "blur" + } + }, options); + + internal = { + name:'TC.field Extension.SimpleTooltip', + $e:$("
") + }; + + function init() { + + internal.$e.addClass(o.orientation); + internal.$e.css($.extend({ + + }, o.css)); + internal.$e.prependTo(field.$e); + + internal.$e.html(o.content); + + field.event_receiver.bind(o.watch_events.in_event, event_handlers.in_fn); + field.event_receiver.bind(o.watch_events.out_event, event_handlers.out_fn); + + field.set_tooltip_content = function(new_content){ + internal.$e.html(new_content); + }; + + field.get_tooltip_content = function(new_content){ + return internal.$e; + }; + + } + + event_handlers = { + in_fn: function(e,d){ + if (! internal.$e.is(":empty")) { + internal.$e.fadeIn(o.fx.in_fx); + } + }, + out_fn: function(e,d){ + internal.$e.fadeOut(o.fx.out_fx); + } + }; + + this.show = function(){ + event_handlers.in_fn(); + }; + + this.hide = function(){ + event_handlers.out_fn(); + }; + + init(); + }; + + return NI.field.extensions.SimpleTooltip; + +}); \ No newline at end of file diff --git a/lib/field/Validator.js b/lib/field/Validator.js new file mode 100644 index 0000000..f37c684 --- /dev/null +++ b/lib/field/Validator.js @@ -0,0 +1,200 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +// Dependencies: +// NI.field + +define(['jquery', 'NIseed', 'NIfield', 'NIvalidation'], function($) { + + var NI = window.NI, + field = NI.field; + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + + function Validator(field, options) { + var me, o, internal; + + me = this; + o = $.extend({ + validators: null, + manager: null, + on_valid:function(e,d){}, + on_invalid:function(e,d){} + }, options); + + internal = { + managed_field:null + }; + + if (!o.manager || !(o.manager instanceof NI.ValidationManager)) { + o.manager = new NI.ValidationManager({ + watchEvents:['keyup', 'change', NI.field.co.SET_VAL_EVENT] + }); + } + + field.event_receiver.bind(NI.field.co.RESET_EVENT, {}, function(e,d){ + field.event_receiver.trigger('validationReset'); + }); + + field.event_receiver.bind(NI.field.co.VALIDATE_EVENT, {}, function(e,d){ + field.event_receiver.trigger('validate'); + }); + + field.event_receiver.bind('validationPass', {}, o.on_valid); + field.event_receiver.bind('validationFail', {field: field}, o.on_invalid); + field.event_receiver.data("master", field); + + internal.managed_field = o.manager.addField({ + element: field.event_receiver, + master: field, + validators: o.validators + }); + + this.get_managed_field = function(){ + return internal.managed_field; + }; + + this.add_validator = function(validator){ + var i, validators; + if($.isArray(validator)){ + for(i = 0; i < validator.length; i++){ + this.add_validator(validator[i]); + } + } else { + validators = internal.managed_field.data("validators"); + if($.inArray(validator, validators) == -1){ + validators.push(validator); + internal.managed_field.data("validators", validators); + } + } + + }; + + this.remove_validator = function(validator) { + var validators, index; + validators = internal.managed_field.data("validators"); + index = $.inArray(validator, validators); + if (index > -1) { + validators.splice(index, 1); + internal.managed_field.data("validators", validators); + } + }; + + } + + + function SimpleTooltipValidatorError(field, options){ + return new ValidatorError(field,$.extend({ + append_to: '.'+NI.field.co.SIMPLE_TOOLTIP_CLASS + }, options, { + hide_parent:true, + hide_siblings:true, + class_target: '.'+NI.field.co.SIMPLE_TOOLTIP_CLASS, + invalid_class:'invalid' + }) + ); + } + + function ValidatorError(field, options) { + var me, o, internal; + + me = this; + o = $.extend({ + append_to: field.$e, + hide_parent:false, + hide_siblings: false, + class_target:null, + invalid_class:'tc-field-validator-error-invalid' + }, options); + + internal = { + parent: null, + class_target:null, + $e: $('
'), + parent_was_hidden:null + }; + + internal.$e.hide(); + + function construct(){ + if(!internal.parent && o.append_to){ + internal.parent = (o.append_to instanceof $ ? o.append_to : field.$e.find(o.append_to)); + if(!$.contains(internal.parent.get(0), internal.$e.get(0))){ + internal.$e.appendTo(internal.parent); + } + } + if(!internal.class_target && o.class_target){ + internal.class_target = ( o.class_target instanceof $) ? o.class_target : field.$e.find(o.class_target); + } + } + + field.event_receiver.bind('validationPass validationReset', {field: field}, function(e, d){ + + if(internal.$e.parent().length){ + internal.$e.hide(); + + if(o.hide_parent && internal.parent_was_hidden === true){ + internal.parent.hide(); + } + internal.parent_was_hidden = null; + if(o.hide_siblings){ + internal.$e.siblings().show(); + } + } + + if(internal.class_target){ + internal.class_target.removeClass(o.invalid_class); + } + }); + + field.event_receiver.bind('validationFail', {field: field}, function(e, d){ + construct(); + + if(internal.$e.parent().length){ + internal.$e.text(d.errors.join(', ')); + internal.$e.show(); + + if(o.hide_parent && internal.parent.filter(':visible').length === 0){ + internal.parent_was_hidden = true; + internal.parent.show(); + } + + if(o.hide_siblings){ + internal.$e.siblings().hide(); + } + } + + if(internal.class_target){ + internal.class_target.addClass(o.invalid_class); + } + }); + + field.event_receiver.bind(NI.field.co.RESET_EVENT, {}, function(e,d){ + internal.$e.empty(); + }); + + } + + + field.extensions.Validator = Validator; + field.extensions.SimpleTooltipValidatorError = SimpleTooltipValidatorError; + field.extensions.ValidatorError = ValidatorError; + + return Validator; + +}); \ No newline at end of file diff --git a/lib/field/std.js b/lib/field/std.js new file mode 100644 index 0000000..06bc65f --- /dev/null +++ b/lib/field/std.js @@ -0,0 +1,678 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +// Dependencies: +// NI.field + +define(['jquery', 'NIseed', 'NIfield'], function($) { + + var window = this, + NI = window.NI, + field = NI.field; + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +// standard field type + +// field type names starting with "_Base" are abstract + + field.synthesize({ + name: "_BaseText", + + proto: { + _init: function() { + this.event_receiver = this.elements.input; + }, + + get_val: function() { + return this.elements.input.val(); + }, + + _set_val: function(val) { + this.elements.input.val(val ? val : ""); + }, + + set_enabled: function(enabled) { + if (enabled) { + this.elements.input.attr("disabled", true); + } else { + this.elements.input.removeAttr("disabled"); + } + return this; + } + } + }); + + field.synthesize({ + name: "TextInput", + + base: field._BaseText, + proto: { + generate_from_dom: function(options) { + this._base.generate_from_dom.apply(this, arguments); + //this.elements.input = $("input[type='text']", this.$e); + this.elements.input = $("input", this.$e); + }, + + generate_from_scratch: function(options) { + this.$e = $("
").addClass(field.co.BASE_CLASS); + this.elements.input = $("input[type='text']", this.$e); + } + } + }); + + field.synthesize({ + name: "Password", + + base: field._BaseText, + proto: { + generate_from_dom: function(options) { + this._base.generate_from_dom.apply(this, arguments); + this.elements.input = $("input[type='password']", this.$e); + }, + + generate_from_scratch: function(options) { + this.$e = $("
").addClass(field.co.BASE_CLASS); + this.elements.input = $("input[type='password']", this.$e); + } + } + }); + + field.synthesize({ + name: "TextArea", + + base: field._BaseText, + proto: { + generate_from_dom: function(options) { + this._base.generate_from_dom.apply(this, arguments); + this.elements.input = $("textarea", this.$e); + }, + + generate_from_scratch: function(options) { + this.$e = $("
").addClass(field.co.BASE_CLASS); + this.elements.input = $("textarea", this.$e); + } + } + }); + + field.synthesize({ + name: "_BaseControl", + + proto: { + + options: { + sexy: true + }, + + _init: function() { + this.event_receiver = //this.elements.input; + this.event_receiver = this.$e; + this._init_label(); + this._init_sexy(); + }, + + // looks for a nearby label for this control + // if there is a label whose "for" attribute + // corresponds to the control's "id" attribute + // that's the label regardless of where it is in the DOM, + // otherwise, we will for the label that is a sibling + // of the control element + _init_label: function() { + var me, label_set, $label; + + me = this; + label_set = false; + + function try_to_set_label() { + if (($label instanceof $) && $label.length) { + if ($label.attr("for") == me.elements.input.attr("id")) { + $label = $label.detach(); + if (me.internal.o.label) { + $label.text(me.internal.o.label); + } + label_set = true; + return true; + } + } + return false; + } + + if (this.elements.input.attr("id")) { + $label = $("label[for='"+ this.elements.input.attr("id") +"']"); + } + if (!try_to_set_label()) { + $label = this.$e.next("label"); + if (!$label.length) { + $label = this.$e.prev("label"); + } + if (!try_to_set_label()) { + $label = this.elements.input.next("label"); + if (!$label.length) { + $label = this.elements.input.prev("label"); + } + try_to_set_label(); + } + } + + if (!label_set && this.internal.o.label) { + $label = $(""); + label_set = true; + } + + if (label_set) { + $label.bind("click", {me: this}, function(e) { + e.preventDefault(); + if(e.data.me.internal.o.set){ + e.data.me.internal.o.set.set_val(e.data.me.elements.input.attr('value')); + } else { + e.data.me.set_val(e.data.me.get_val() !== "true"); + } + }); + this.elements.input.after($label); + } + }, + + //if we have sexyboxes enabled, we will get them setup here. + _init_sexy: function(){ + if (this.internal.o.sexy) { + this.elements.sexy_input = $("
"); + this.elements.sexy_input.bind("click", {me: this}, function(e) { + if(e.data.me.internal.o.set){ + e.data.me.internal.o.set.set_val(e.data.me.elements.input.attr('value')); + } else { + e.data.me.set_val(e.data.me.get_val() !== "true"); + } + }); + this.event_receiver.bind("change " + NI.field.co.SET_VAL_EVENT, {me: this}, function(e) { + e.data.me._sexy_update(); + }); + this._sexy_update(); + this.elements.input.hide().before(this.elements.sexy_input); + } + }, + + _sexy_update: function() { + if (!this.elements.sexy_input) { + return; + } + this.elements.sexy_input[this.get_val() === "true" ? "addClass" : "removeClass"](field.co.ACTIVE_CLASS); + }, + + get_val: function() { + return this.elements.input.prop("checked") ? "true" : "false"; + }, + + _set_val: function(val) { + if (val) { + this.elements.input.prop("checked", true); + } else { + this.elements.input.prop("checked", false); + } + }, + + set_enabled: function(enabled) { + return field._BaseText.prototype.set_enabled.apply(this, arguments); + } + } + }); + + field.synthesize({ + name: "Radio", + + base: field._BaseControl, + proto: { + generate_from_dom: function(options) { + this._base.generate_from_dom.apply(this, arguments); + this.elements.input = $("input[type='radio']", this.$e); + }, + + generate_from_scratch: function(options) { + this.$e = $("
").addClass(field.co.BASE_CLASS); + this.elements.input = $("input[type='radio']", this.$e); + } + } + }); + + field.synthesize({ + name: "Checkbox", + + base: field._BaseControl, + proto: { + generate_from_dom: function(options) { + this._base.generate_from_dom.apply(this, arguments); + this.elements.input = $("input[type='checkbox']", this.$e); + options.$e.addClass('tc-sexy-checkbox'); + }, + + generate_from_scratch: function(options) { + this.$e = $("
").addClass(field.co.BASE_CLASS); + this.elements.input = $("input[type='checkbox']", this.$e); + } + } + }); + + field.synthesize({ + name: "_BaseControlSet", + + proto: { + _init: function() { + this.event_receiver = $({}); + }, + + generate_from_dom: function(options) { + var me; + me = this; + + field._Base.prototype.generate_from_dom.apply(this, arguments); + this.$e.addClass(field[this._name].CONTAINER_CLASS); + this.elements.inputs = $("input[type='"+ field[this._name].INPUT_TYPE.toLowerCase() +"']", this.$e); + + this.internal.fields = []; + this.elements.inputs.each(function() { + + var $f, my_subfield_options, my_options; + $f = $(this); + my_subfield_options = {}; + + if(options.subfield_options){ + $.each(options.subfield_options,function(i, j){ + if($f.filter(j.selector).length){ + $.extend(my_subfield_options, j.options); + } + }); + } + + my_options = $.extend({}, options, my_subfield_options, + {$e: field.prep_element($f).$e, set:me} + ); + + me.internal.fields.push( new field[field[me._name].INPUT_TYPE](my_options) ); + }); + }, + + _set_val: function(val) { + $.each(this.internal.fields, function(i, f) { + f.set_val(false); + if (f.elements.input.attr("value") == val) { + f.set_val(true); + } + }); + }, + + _sexy_update: function(val) { + $.each(this.internal.fields, function(i, f) { + if (!f.elements.sexy_input) { + return true; + } + if (f.elements.input.attr("value") == val) { + f.elements.sexy_input.addClass(field.co.ACTIVE_CLASS); + } else { + f.elements.sexy_input.removeClass(field.co.ACTIVE_CLASS); + } + }); + }, + + set_enabled: function(enabled) { + $.each(this.internal.fields, function(i, f) { + f.set_enabled(enabled); + }); + return field._BaseText.prototype.set_enabled.apply(this, arguments); + } + } + }); + + field.synthesize({ + name: "RadioSet", + + props: { + CONTAINER_CLASS: "tc-radio-set", + INPUT_TYPE: "Radio" + }, + + base: field._BaseControlSet, + proto: { + generate_from_scratch: function(options) { + //TODO + console.warn('RadioSet.generate_from_scratch is not yet implemented'); + }, + + get_val: function() { + var val; + + $.each(this.internal.fields, function(i, f) { + if (f.get_val() === "true") { + val = f.elements.input.attr("value"); + return false; + } + }); + + if (val === false || typeof val === "undefined") { + val = "-1"; + } + + return val; + }, + + _set_val: function(val) { + $.each(this.internal.fields, function(i, f) { + f.set_val(false); + if (f.elements.input.attr("value") == val) { + f.set_val(true); + } + }); + } + } + }); + + field.synthesize({ + name: "CheckboxSet", + + props: { + CONTAINER_CLASS: "tc-checkbox-set", + INPUT_TYPE: "Checkbox" + }, + + base: field._BaseControlSet, + proto: { + generate_from_scratch: function(options) { + // TODO + console.warn('CheckboxSet.generate_from_scratch is not fully implemented'); + }, + + get_val: function() { + var i, val; + val = []; + + $.each(this.internal.fields, function(i, f) { + if (f.get_val() == "true") { + val.push(f.elements.input.attr("value")); + } + }); + + return val; + }, + + _set_val: function(val) { + var me; + me = this; + + if ($.isArray(val)) { + $.each(this.internal.fields, function(i, f) { + f.set_val(false); + }); + + $.each(val, function(i, v) { + $.each(me.internal.fields, function(j, f) { + if (f.elements.input.attr("value") == v) { + f.set_val(true); + } + }); + }); + } else { + $.each(me.internal.fields, function(j, f) { + if (f.elements.input.attr("value") == val) { + f.set_val(f.get_val() !== 'true'); + } + }); + } + + + } + } + }); + + field.synthesize({ + name: "Select", + + proto: { + + options: { + empty_val: "-1", + value_list: {} + }, + + _init: function() { + this.event_receiver = this.elements.select; + }, + + generate_from_dom: function(options) { + this._base.generate_from_dom.apply(this, arguments); + this.elements.select = $("select", this.$e); + }, + + generate_from_scratch: function(options) { + this.$e = $("
").addClass(field.co.BASE_CLASS); + this.elements.select = $("select", this.$e); + if (options.value_list) { + this.populate(options.value_list); + } + }, + + // (chainable) + populate: function(value_list) { + var buf; + this.elements.select.empty(); + + if ($.isFunction(value_list)) { + this.elements.select.append(value_list()); + return this; + } + + buf = ""; + $.each(value_list, function(value, text) { + buf += ""; + }); + this.elements.select.append(buf); + return this; + }, + + get_val: function() { + var $option; + $option = this.elements.select.find("option:selected"); + if ($option.length) { + return $option.attr("value"); + } + return this.internal.o.empty_val; + }, + + _set_val: function(val) { + if (val) { + this.elements.select.find("option[value="+ val +"]").attr("selected", true); + } else { + this.elements.select.find("option").attr("selected", false); + } + }, + + set_enabled: function(enabled) { + if (enabled) { + this.elements.select.attr("disabled", true); + } else { + this.elements.select.removeAttr("disabled"); + } + return this; + } + } + }); + + field.synthesize({ + name: "Upload", + + proto: { + + options: { + url:null + }, + + _init: function() { + + }, + + generate_from_dom: function(options) { + var me, random, i; + + me = this; + + this._base.generate_from_dom.apply(this, arguments); + + random = NI.math.round(NI.math.random(10000,99999),0); + + this.internal.iframe_id = 'upload_iframe'+random; + this.internal.form_id = 'upload_form'+random; + + this.elements.input = this.$e.find('input[type=file]'); + + if(this.internal.o.loader){ + this.elements.loader = $(this.internal.o.loader); + } else { + this.elements.loader = $('

Loading...

'); + } + + this.elements.loader.css({ + display:'none' + }).appendTo(this.$e); + + if(this.internal.o.trigger){ + this.elements.trigger = $(this.internal.o.trigger); + + this.elements.input.css({ + position: 'absolute', + // in Opera only 'browse' button + // is clickable and it is located at + // the right side of the input + right: 0, + top: 0, + fontFamily: 'Arial', + // 4 persons reported this, the max values that worked for them were 243, 236, 236, 118 + fontSize: '118px', + margin: 0, + padding: 0, + cursor: 'pointer', + opacity: 0 + }); + + this.elements.input.bind('mouseover', {trigger:this.elements.trigger}, function(e,d){ + e.data.trigger.addClass('hover'); + }); + this.elements.input.bind('mouseout', {trigger:this.elements.trigger}, function(e,d){ + e.data.trigger.removeClass('hover'); + }); + this.elements.input.bind('mousedown', {trigger:this.elements.trigger}, function(e,d){ + e.data.trigger.addClass('down'); + }); + this.elements.input.bind('mouseup', {trigger:this.elements.trigger}, function(e,d){ + e.data.trigger.removeClass('down'); + }); + this.$e.append(this.elements.trigger); + } + + this.elements.iframe = $('') + .attr({ + id:this.internal.iframe_id, + name:this.internal.iframe_id, + src:'' + }).css({ + display:'none' + }); + + this.elements.form = $('
') + .attr({ + id:this.internal.form_id, + name:this.internal.form_id, + action:this.internal.o.url, + method:'POST', + enctype:'multipart/form-data', + target:this.internal.iframe_id + }); + + this.elements.input.wrap(this.elements.form); + this.elements.form = this.elements.input.parent(); + this.event_receiver = this.elements.form; + + if(this.internal.o.additional_values){ + for(i in this.internal.o.additional_values){ + this.elements.form.append(''); + } + } + + //window.file_input = this.elements.input.get(0); + + //console.log(this.elements.input); + + this.elements.input.bind('change',{},function(e,d){ + + e.stopPropagation(); + e.stopImmediatePropagation(); + + if(me.internal.o.trigger){ + me.elements.trigger.hide(); + } else { + //me.elements.input.hide(); + } + me.elements.loader.show(); + + me.elements.iframe.bind('load',{},function(e,d){ + var mydoc, mycontent, mytext; + + window.onbeforeunload = null; + me.elements.loader.hide(); + if(me.internal.o.trigger){ + me.elements.trigger.show(); + } else { + me.elements.input.show(); + } + me.elements.iframe.unbind('load'); + + if (this.contentDocument) { // DOM + mydoc = this.contentDocument; + } else if (iframeObject.contentWindow) { // IE win + mydoc = this.contentWindow.document; + } + if (mydoc) { + mycontent = mydoc.getElementsByTagName('body')[0]; + if(typeof mycontent.textContent != 'undefined'){ + mytext = mycontent.textContent; + } else if(typeof mycontent.innerText != 'sundefined'){ + mytext = mycontent.innerText; + } + } + + me.event_receiver.trigger('change',{data:$.parseJSON(mytext)}); + }); + + window.onbeforeunload = me.window_unload_handler; + document.getElementById(me.internal.form_id).submit(); + }); + + + + this.$e.append(this.elements.iframe); + + }, + + window_unload_handler: function(e){ + e = e || window.event; + // For IE and Firefox prior to version 4 + if (e) { + e.returnValue = false; + } + // For Safari + return false; + } + } + }); + + +}); \ No newline at end of file diff --git a/lib/flippanel.js b/lib/flippanel.js new file mode 100644 index 0000000..f29805b --- /dev/null +++ b/lib/flippanel.js @@ -0,0 +1,132 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +define(['jquery', 'NIseed'], function($) { + + /* to use, the selector of the element with class .flip-panel must be passed. + + .flip-panel must have two direct children, .front and .back, as well as two triggers, + .front-trigger and .back-trigger. + + as a direct child of both .front and .back, there must be a div with class .inner + */ + this.NI.flip_panel = function(eleContainer) { + + // variables + var flipContainer, frontBox, frontInner, backBox, backInner, + frontTrigger, backTrigger, innerOuterDiff, speed, slideDelay, webkitPerspective; + + speed = 300; // speed of height change when flipping + slideDelay = 200; // delay after flip starts before changing height + + applyWebkitCSSinJS = true; + webkitPerspective = 600; + + + flipContainer = $(eleContainer); + frontBox = flipContainer.children('.front'); + frontInner = frontBox.children('.inner'); + frontTrigger = flipContainer.find('.front-trigger'); + backBox = flipContainer.children('.back'); + backInner = backBox.children('.inner'); + backTrigger = flipContainer.find('.back-trigger'); + + innerOuterDiff = frontBox.height() - frontInner.height(); + + + + + // events + frontTrigger.click(function(){ + frontBox.show(); + + if(applyWebkitCSSinJS) { + flipContainer.css('-webkit-perspective', webkitPerspective); + frontBox.css('-webkit-transform-style','preserve-3d'); + backBox.css('-webkit-transform-style','preserve-3d'); + } + + backBox.find('.btn-edu').css('opacity','0'); + + backBox.css({ + 'height': frontBox.height(), + 'position': 'absolute', + 'overflow': 'hidden' + }).show(0, function(){ + flipContainer.addClass('flip'); + }); + + frontBox.delay(slideDelay).hide(0, function(){ + frontBox.css('display','none'); + backBox.css('position','relative').animate({ + height: backInner.height() + innerOuterDiff + }, speed, function(){ + backBox.css({'height':'auto', 'overflow':'visible'}); + + if(applyWebkitCSSinJS) { + // if speed + slideDelay is less than the CSS transition // speed (400ms), additional delay should be put on this + flipContainer.css('-webkit-perspective','none'); + frontBox.css('-webkit-transform-style','flat'); + backBox.css('-webkit-transform-style','flat'); + } + + backBox.find('.btn-edu').animate({'opacity':'1'}, 400); + }); + }); + }); + + + + backTrigger.click(function(){ + backBox.css('position','absolute').show(); + + if(applyWebkitCSSinJS) { + flipContainer.css('-webkit-perspective', webkitPerspective); + frontBox.css('-webkit-transform-style','preserve-3d'); + backBox.css('-webkit-transform-style','preserve-3d'); + } + + frontBox.css({ + 'height': backBox.height(), + 'overflow': 'hidden' + }).show(0, function(){ + flipContainer.removeClass('flip'); + }); + + backBox.delay(slideDelay).hide(0, function(){ + frontBox.animate({ + height: frontInner.height() + innerOuterDiff + }, speed, function(){ + frontBox.css({'height':'auto', 'overflow':'visible'}); + + if(applyWebkitCSSinJS) { + // if speed + slideDelay is less than the CSS transition + // speed (400ms), additional delay should be put on this + flipContainer.css('-webkit-perspective','none'); + frontBox.css('-webkit-transform-style','flat'); + backBox.css('-webkit-transform-style','flat'); + } + + backBox.find('.btn-edu').css('opacity','0'); + }); + }); + }); + + + }; + +}); \ No newline at end of file diff --git a/lib/fullscreen.js b/lib/fullscreen.js new file mode 100644 index 0000000..5c40028 --- /dev/null +++ b/lib/fullscreen.js @@ -0,0 +1,106 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +define(['jquery', 'NIseed'], function($) { + + var window = this, + NI = window.NI, + + fullscreen = { + + request: function(dom) { + dom = dom || document.documentElement; + if (dom.requestFullscreen) { + dom.requestFullscreen(); + } else if (dom.mozRequestFullScreen) { + dom.mozRequestFullScreen(); + } else if (dom.webkitRequestFullScreen) { + dom.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT); + } + }, + + cancel: function() { + if (document.exitFullscreen) { + document.exitFullscreen(); + } else if (document.mozCancelFullScreen) { + document.mozCancelFullScreen(); + } else if (document.webkitCancelFullScreen) { + document.webkitCancelFullScreen(); + } + }, + + toggle: function() { + var fs; + + if (typeof document.fullscreen === 'boolean') { + fs = document.fullscreen; + } else if (typeof document.mozFullScreen === 'boolean') { + fs = document.mozFullScreen; + } else if (typeof document.webkitIsFullScreen === 'boolean') { + fs = document.webkitIsFullScreen; + } + + if (typeof fs === 'boolean') { + if (fs) { + this.cancel(); + } else { + this.request(); + } + } + }, + + register_change_handler: function(handler, event_data) { + var guid; + if (!$.isFunction(handler)) { + return null; + } + if (!event_data || typeof event_data !== 'object') { + event_data = {}; + } + guid = NI.fn.guid('fullscreen_'); + $(document).on('fullscreenchange.'+guid +' mozfullscreenchange.'+guid +' webkitfullscreenchange.'+guid, function(e, d) { + var fullscreen; + switch (e.type) { + case 'fullscreenchange': + fullscreen = document.fullscreen; + break; + case 'mozfullscreenchange': + fullscreen = document.mozFullScreen; + break; + case 'webkitfullscreenchange': + fullscreen = document.webkitIsFullScreen; + break; + } + e.data = $.extend(event_data, { + fullscreen: fullscreen + }); + handler.apply(this, [e, d]); + }); + return guid; + }, + + destroy_change_handler: function(id) { + var guid = id ? '.'+ id : ''; + $(document).off('fullscreenchange'+guid +' mozfullscreenchange'+guid +' webkitfullscreenchange'+guid); + } + }; + + NI.fullscreen = fullscreen; + + return fullscreen; + +}); \ No newline at end of file diff --git a/lib/googleanalyticsheader.js b/lib/googleanalyticsheader.js new file mode 100644 index 0000000..5548f58 --- /dev/null +++ b/lib/googleanalyticsheader.js @@ -0,0 +1,26 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +define([], function() { + + var window = this; + window._gaq = window._gaq || []; + + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); +}); \ No newline at end of file diff --git a/lib/merlin/MerlinAutosave.js b/lib/merlin/MerlinAutosave.js new file mode 100644 index 0000000..5aab65a --- /dev/null +++ b/lib/merlin/MerlinAutosave.js @@ -0,0 +1,107 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +define(['jquery', 'NIseed', 'NIMerlin'], function($) { + + var window = this, + NI = window.NI; + + function MerlinAutosave(options){ + + var o, internal, _me; + + o = $.extend({ + keyup_delay:300, + change_delay:200, + saved_delay:1500, + prevent_invalid:false + },options); + + internal = { + save_timeout:null, + functions:null + }; + + _me = this; + + this.init = function(me, functions){ + var i; + + internal.functions = functions; + + for(i in me.internal.current_step.fields){ + + if(!me.internal.current_step.fields[i].component){ + continue; + } + + me.internal.current_step.fields[i].component.event_receiver.bind('change keyup',{ name:i },function(e,d){ + + if(internal.save_timeout){ clearTimeout(internal.save_timeout); } + + if(o.prevent_invalid){ + if(me.internal.current_step.$e.hasClass('state-invalid')){ + return; + } + } + + me.internal.current_step.$e.addClass('merlin-autosave-state-unsaved') + .removeClass('merlin-autosave-state-unsaved') + .removeClass('merlin-autosave-state-saved'); + + internal.save_timeout = setTimeout(function(){ + _me.save(me, functions); + },((e.type == 'keyup') ? o.keyup_delay : o.change_delay)); + }); + } + + }; + + this.save = function(me){ + if(internal.save_timeout){ clearTimeout(internal.save_timeout); } + + function saved(){ + me.internal.current_step.$e.addClass('merlin-autosave-state-saved') + .removeClass('merlin-autosave-state-unsaved') + .removeClass('merlin-autosave-state-saving'); + if($.isFunction(internal.functions.saved)){ + internal.functions.saved(); + } + } + + me.internal.current_step.$e.addClass('merlin-autosave-state-saving') + .removeClass('merlin-autosave-state-unsaved') + .removeClass('merlin-autosave-state-saved'); + + if($.isFunction(internal.functions.save)){ + internal.functions.save(saved); + } else { + saved(); + } + }; + + this.visible = function(me){ + + }; + + } + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + NI.MerlinAutosave = MerlinAutosave; + +}); \ No newline at end of file diff --git a/lib/merlin/MerlinCSRF.js b/lib/merlin/MerlinCSRF.js new file mode 100644 index 0000000..33e3c73 --- /dev/null +++ b/lib/merlin/MerlinCSRF.js @@ -0,0 +1,58 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +define(['jquery', 'NIseed', 'NIMerlin'], function($) { + + var window = this, + NI = window.NI; + + function MerlinCSRF(options){ + + var o, internal; + + o = $.extend({ + csrf_input_name:'csrfmiddlewaretoken' + },options); + + internal = { + data:{} + }; + + + this.init = function(me){ + var csrf_input; + + csrf_input = me.internal.current_step.$e.find('input[name="'+o.csrf_input_name+'"]'); + + if(csrf_input.length){ + internal.data[o.csrf_input_name] = csrf_input.val(); + me.set_val(o.csrf_input_name,csrf_input.val()); + } + + }; + + this.get_data = function(){ + return internal.data; + }; + + } + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + NI.MerlinCSRF = MerlinCSRF; + +}); \ No newline at end of file diff --git a/lib/merlin/MerlinData.js b/lib/merlin/MerlinData.js new file mode 100644 index 0000000..47ef828 --- /dev/null +++ b/lib/merlin/MerlinData.js @@ -0,0 +1,181 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +define(['jquery', 'NIseed', 'NIMerlin'], function($) { + + var window = this, + NI = window.NI; + + function MerlinData(options){ + + var o, internal; + + o = $.extend({ + uri:'', + data:{}, + post_unchanged_data:true, + post_method:'POST' + },options); + + internal = { + uri:o.uri, + base_data:$.extend({},o.data), + data:$.extend({},o.data) + }; + + this.init = function(me){ + var i; + + if(me.data){ + internal.data = $.extend(internal.data,me.data); + } + + me.get_data = this.get_data; + me.set_data = this.set_data; + + me.get_val = this.get_val; + me.set_val = this.set_val; + }; + + this.populate_fields = function(me,fields){ + + var i; + + if(fields){ + for(i in fields){ + if(me.internal.current_step.fields[fields[i]] && internal.data[fields[i]]){ + if(me.internal.current_step.fields[fields[i]].component.get_val() != this.get_val(fields[i])){ + me.internal.current_step.fields[fields[i]].component.set_val(this.get_val(fields[i]),true); + } + } + } + } else { + for(i in this.get_data()){ + + if(me.internal.current_step.fields[i]){ + if(!me.internal.current_step.fields[i].component){ + continue; + } + if(me.internal.current_step.fields[i].component.get_val() != this.get_val(i)){ + me.internal.current_step.fields[i].component.set_val(this.get_val(i),true); + } + } + } + } + + }; + + this.collect_fields = function(me, fields){ + + var i, temp_name, changed; + + changed =[]; + + if(fields){ + for(i in fields){ + if(me.internal.current_step.fields[fields[i]]){ + if(me.internal.current_step.fields[fields[i]].component.get_val() != internal.base_data[i] && i != 'csrfmiddlewaretoken'){ + changed.push(i); + } + this.set_val(fields[i], me.internal.current_step.fields[fields[i]].component.get_val()); + } + } + } else { + for(i in this.get_data()){ + if(me.internal.current_step.fields[i]){ + if(!me.internal.current_step.fields[i].component){ + continue; + } + if(me.internal.current_step.fields[i].component.get_val() != internal.base_data[i] && i != 'csrfmiddlewaretoken'){ + changed.push(i); + } + this.set_val(i, me.internal.current_step.fields[i].component.get_val()); + } + } + } + + return changed; + + }; + + this.get_uri = function(){ + return internal.uri; + }; + + this.set_uri = function(uri){ + internal.uri = uri; + }; + + this.get_data = function(){ + return internal.data; + }; + + this.set_data = function(new_data,use_for_base_data){ + internal.data = new_data; + if(use_for_base_data){ + internal.base_data = $.extend({},new_data); + } + }; + + this.get_val = function(id){ + return internal.data[id]; + }; + + this.set_val = function(id,new_val){ + internal.data[id] = new_val; + }; + + this.post_data = function(callback,options){ + + var cleaned_data, i; + + cleaned_data = $.extend({},this.get_data()); + + for(i in cleaned_data){ + if(cleaned_data[i] === null){ + delete cleaned_data[i]; + } + if(o.post_unchanged_data === false){ + if(cleaned_data[i] === internal.base_data[i] && i != 'csrfmiddlewaretoken'){ + delete cleaned_data[i]; + } + } + } + + $.ajax({ + type:o.post_method, + url:internal.uri, + data:cleaned_data, + success:function(d,ts,xhr){ + internal.base_data = $.extend(internal.base_data,cleaned_data); + callback(d); + }, + error: function(){ + d = false; + callback(d); + } + }); + + }; + + } + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + NI.MerlinData = MerlinData; + +}); \ No newline at end of file diff --git a/lib/seed.js b/lib/seed.js new file mode 100644 index 0000000..8c608be --- /dev/null +++ b/lib/seed.js @@ -0,0 +1,256 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +define(['jquery'], function($) { + + var window = this, + NI = {}, + fakeConsole, + _id = 0; + + NI.ex = { + + checkStr: function(s) { + var t = typeof s; + if (t === 'string') { return true; } + console.error('Expected string, but found "'+ String(t) +'" instead'); + }, + + checkFn: function(fn) { + if ($.isFunction(fn)) { return true; } + console.error('Expected function, but found "'+ typeof fn +'" instead'); + }, + + checkJQ: function(o) { + if (o instanceof $) { return true; } + console.error('Expected jQuery object, but found "'+ typeof o +'" instead'); + }, + + checkJQNode: function($e, type) { + NI.ex.checkJQ($e); + type = type.toLowerCase(); + if ($e.length === 1) { + if ($e[0].nodeName.toLowerCase() === type) { + return true; + } + } + throw new TypeError('Expected jQuery object holding single '+ type +' element'); + }, + + typeOf: function(v) { + var s = typeof v; + if (s === 'object') { + if (v) { + if (typeof v.length === 'number' && + !(v.propertyIsEnumerable('length')) && + typeof v.splice === 'function') { + s = 'array'; + } + } else { + s = 'null'; + } + } + return s; + }, + + isEmpty: function(v) { + NI.ex.checkStr(v); + return $.trim(v) ? + false : true; + }, + + isHeadless: function($e) { + var node = $e[0]; + if (!node.parentNode) { + return true; + } + if (node.parentNode === NI.co.node_types.DOCUMENT_NODE) { + return true; + } + return false; + } + }; + + NI.fn = { + + get_console: function(debug) { + if (debug && typeof window.console !== 'undefined') { + return window.console; + } + if (!fakeConsole) { + fakeConsole = {}; + $.each(('assert,count,debug,dir,dirxml,error,exception,\ + group,groupCollapsed,groupEnd,info,log,markTimeline,\ + profile,profileEnd,time,timeEnd,trace,warn').split(','), function() { + fakeConsole[this] = $.noop; + }); + } + return fakeConsole; + }, + + // via http://www.nczonline.net/blog/2009/07/28/the-best-way-to-load-external-javascript/ + load_script: function(url, callback) { + var script = window.document.createElement('script'); + script.type = 'text/javascript'; + if (script.readyState) { + script.onreadystatechange = function() { + if (script.readyState == 'loaded' || script.readyState == 'complete') { + script.onreadystatechange = null; + if ($.isFunction(callback)) { + callback(); + } + } + }; + } else { + script.onload = function() { + if ($.isFunction(callback)) { + callback(); + } + }; + } + script.src = url; + window.document.getElementsByTagName('head')[0].appendChild(script); + }, + + guid: function(prefix) { + var id = _id++; + return (prefix || 'obj_')+ id; + }, + + random_element: function(array) { + if (NI.ex.typeOf(array) === 'array' && array.length > 0) { + return array[window.Math.floor(NI.math.random(array.length))]; + } + }, + + // debounce implementation from Underscore.js + // http://documentcloud.github.com/underscore/ + debounce: function(fn, delay) { + var timer; + return function() { + var self = this, args = arguments, + execute = function() { + timer = null; + fn.apply(self, args); + }; + window.clearTimeout(timer); + timer = window.setTimeout(execute, delay); + }; + }, + + once_visible: function($e, fn) { + if ($e.is(':visible')) { + fn(); + } else { + setTimeout(function() { + NI.fn.once_visible($e, fn); + }, 10); + } + }, + + // String interpolation + // var s = interpolate('Hello %', ['world']) + interpolate: function(str, args) { + var i; + if (args) { + for (i = 0; i < args.length; i += 1) { + str = str.replace('%', args[i]); + } + } + return str; + } + }; + + NI.co = { + + keyboard: { + + BACKSPACE: 8, + CAPS_LOCK: 20, + COMMA: 188, + CONTROL: 17, + DELETE: 46, + DOWN: 40, + END: 35, + ENTER: 13, + ESCAPE: 27, + HOME: 36, + INSERT: 45, + LEFT: 37, + NUMPAD_ADD: 107, + NUMPAD_DECIMAL: 110, + NUMPAD_DIVIDE: 111, + NUMPAD_ENTER: 108, + NUMPAD_MULTIPLY: 106, + NUMPAD_SUBTRACT: 109, + PAGE_DOWN: 34, + PAGE_UP: 33, + PERIOD: 190, + RIGHT: 39, + SHIFT: 16, + SPACE: 32, + TAB: 9, + UP: 38 + }, + + node_types: { + + ELEMENT_NODE: 1, + ATTRIBUTE_NODE: 2, + TEXT_NODE: 3, + CDATA_SECTION_NODE: 4, + ENTITY_REFERENCE_NODE: 5, + ENTITY_NODE: 6, + PROCESSING_INSTRUCTION_NODE: 7, + COMMENT_NODE: 8, + DOCUMENT_NODE: 9, + DOCUMENT_TYPE_NODE: 10, + DOCUMENT_FRAGMENT_NODE: 11, + NOTATION_NODE: 12 + }, + + directions: { + + UP: 0, + RIGHT: 1, + DOWN: 2, + LEFT: 3 + } + }; + + NI.math = { + + random: function() { + if (arguments.length === 0) { + return window.Math.random(); + } else if (arguments.length === 1) { + return window.Math.random()*arguments[0]; + } + return window.Math.random()*(arguments[1] - arguments[0]) + arguments[0]; + }, + + round: function(n, places) { + var p = window.Math.pow(10, places); + return window.Math.round(n*p)/p; + } + }; + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + window.NI = NI; + +}); \ No newline at end of file diff --git a/lib/validation.js b/lib/validation.js new file mode 100644 index 0000000..200674f --- /dev/null +++ b/lib/validation.js @@ -0,0 +1,500 @@ +/* ============================================================================ + + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ +typecode-js v 0.1 +*/ + +define(['jquery', 'NIseed'], function($) { + + var window = this, + NI = window.NI, + console = NI.app.getConsole(true); + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +// regular expressions + + var regex = { + email: /^[a-zA-Z0-9\+._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/, + + url: /^((ht|f)tps?:\/\/)?[a-zA-Z0-9-\.]+\.[a-zA-Z]{2,4}\/?([^\s<>\%"\,\{\}\\|\\\^\[\]`]+)?$/, + + alphanumeric: /^\s*[a-z\d\.]+([a-z\d\.]*\.|\s*\-\s*[a-z\d\.]+)?(\s+[a-z\d\.]+(\.|\s*\-\s*[a-z\d\.]+)?)*\s*$/i, + + number: /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/, + + hex_color: /^(#)?([0-9a-fA-F]{3})([0-9a-fA-F]{3})?$/ + }; + + function regTest(s, key) { + return regex[key].test(s); + } + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +// tests + + var is = { + + empty: function(s) { + return NI.ex.isEmpty(s); + }, + + alphaNumeric: function(s) { + return regTest(s, "alphanumeric"); + }, + + email: function(s) { + return regTest(s, "email"); + }, + + url: function(s) { + return regTest(s, "url"); + }, + + num: function(s) { + return regTest(s, "number"); + }, + + hex_color: function(s) { + return regTest(s, "hex_color"); + }, + + numNonNegative: function(s) { + return isNum(s) && Number(s) >= 0; + }, + + numPositive: function(s) { + return isNum(s) && Number(s) > 0; + }, + + date: function(s) { + var day, month, year, buf, date; + if (s) { + buf = s.split("/"); + if (buf.length == 3) { + month = buf[0].replace(/^0+/,''); + day = buf[1].replace(/^0+/,''); + year = buf[2].replace(/^0+/,''); + if (!(year.length == 2 || year.length == 4)) { + return false; + } + try { + date = new Date(); + month = (month*1) - 1; + date.setFullYear(year, month, day); + if (date.getMonth() == month && + date.getDate() == day && + date.getFullYear() == year) { + return true; + } + } catch(err) { + // ignore + } + } + return false; + } + return false; + } + }; + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +// built-in validators + + var error_messages = { + + required: "This is a required field", + + alphanumeric: "This is not a valid alpha-numeric value", + + email: "This is not a valid Email address", + + url: "This is not a valid URL", + + number: "This is not a valid number", + + date: "This is not a valid date", + + hex_color: "This is not a valid hex value" + }; + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +// field validation + + + //begin ValidationToken + function ValidationToken() { + this.clean(); + } + + ValidationToken.prototype = { + errors: function() { + return this.errs.length ? + this.errs : false; + }, + addError: function(str) { + this.errs.push(str); + return this; + }, + clean: function() { + this.errs = []; + return this; + } + }; + //end ValidationToken + + + //begin validate + function validate(field, validators) { + var value, token, errors, type, master; + + master = field.data("master"); + + if (master && $.isFunction(master.get_val)) { + // the field is an instance of NI.Field + value = master.get_val(); + if (master._name) { + type = master._name; + } + } else { + switch (field[0].nodeName.toLowerCase()) { + case "input": + value = "false"; + switch (field.attr("type")) { + case "radio": + case "checkbox": + type = "bool"; + if (field.prop("checked")) { + value = "true"; + } + break; + default: + value = field.val(); + break; + } + break; + case "textarea": + value = field.val(); + break; + case "select": + type = "select"; + value = field.find("option:selected").attr("value"); + break; + default: + value = false; + break; + } + } + + //NI.ex.checkStr(value); + + if (!validators) { + validators = field.data("validators"); + } + token = field.data("vtoken"); + + if (!validators || !token) { + throw new Error("Field not prepared for validation"); + } + token.clean(); + + $.each(validators, function(j, v) { + var t, validation; + t = typeof v; + if (t === "string") { + v = v.toLowerCase(); + if ($.isFunction(ValidationManager.validators[v])) { + validation = ValidationManager.validators[v](value); + if (validation && validation.errors && validation.errors.length) { + $.each(validation.errors, function(k, err) { + token.addError(err); + }); + } + } else if (v.indexOf("maxlen") === 0) { + (function(max) { + if (value.length > max) { + token.addError("This cannot exceed "+ max +" characters"); + } + }(v.split("=")[1])); + } else if (v.indexOf("minlen") === 0) { + (function(min) { + if (value.length < min) { + token.addError("This must be at least "+ min +" characters"); + } + }(v.split("=")[1])); + } else { + switch (v) { + case "required": + (function() { + var err; + err = error_messages["required"]; + if (type === "bool" || type == "Checkbox") { + if (value === "false") { + token.addError(err); + } + } else if (type === "select" || type == "Dropdown" || type == "RadioSet") { + if (value === "-1") { + token.addError(err); + } + } else if (type == "CheckboxSet") { + if (!value.length) { + token.addError(err); + } + } else { + if (NI.ex.isEmpty(value)) { + token.addError(err); + } + } + }()); + break; + case "alphanumeric": + if (value && !is.alphaNumeric(value)) { + token.addError(error_messages["alphanumeric"]); + } + break; + case "email": + if (value && !is.email(value)) { + token.addError(error_messages["email"]); + } + break; + case "url": + if (value && !is.url(value)) { + token.addError(error_messages["url"]); + } + break; + case "number": + if (value && !is.num(value)) { + token.addError(error_messages["number"]); + } + break; + case "date": + if (value && !is.date(value)) { + token.addError(error_messages["date"]); + } + break; + case "hex_color": + if (value && !is.hex_color(value)){ + token.addError(error_messages["hex_color"]); + } + break; + default: + break; + } + } + } else if (t === "function") { + validation = v(value); + if (validation.errors && validation.errors.length) { + $.each(validation.errors, function(k, err) { + token.addError(err); + }); + } + } + }); + + errors = token.errors(); + if (errors) { + field.trigger("validationFail", { errors: errors }); + return { valid: false, errors: errors }; + } + field.trigger("validationPass"); + return { valid: true }; + } + //end validate + + + //begin reset + function reset(field) { + var token; + + token = field.data("vtoken"); + + if (!token) { + throw new Error("Field not prepared for validation"); + } + + token.clean(); + + field.trigger("validationReset"); + return { }; + } + //end reset + + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +// manager + + var events = { + fieldValidationPass: function(e, d) { + e.data.master.removeClass("state-invalid").addClass("state-valid"); + e.data.manager.internal.eventTarget.trigger("fieldValidationPass", d); + e.data.manager.isValid(); + return false; + }, + fieldValidationFail: function(e, d) { + e.data.master.removeClass("state-valid").addClass("state-invalid"); + e.data.manager.internal.eventTarget.trigger("fieldValidationFail", d); + e.data.manager.isValid(); + return false; + }, + fieldValidationReset: function(e, d) { + e.data.master.removeClass("state-valid state-invalid"); + return false; + }, + watchEventHandler: function(e, d){ + validate($(this)); + }, + managerValidationPass: function(e, d){ + e.data.manager.internal.eventTarget.removeClass("state-invalid").addClass("state-valid"); + }, + managerValidationFail: function(e, d){ + e.stopPropagation(); + e.data.manager.internal.eventTarget.removeClass("state-valid").addClass("state-invalid"); + } + }; + + function ValidationManager(options) { + var me = this; + + this.o = $.extend({ + $mother: null, + spec: [], + watchEvents:['keyup', 'change'] + }, options); + + this.internal = { + eventTarget: this.o.$mother || $({}) + }; + + this.fields = []; + + $.each(this.o.spec, function(i, item) { + me.addField(item); + }); + + this.internal.eventTarget.bind("managerValidationFail", { manager:this }, events.managerValidationFail) + .bind("managerValidationPass", { manager:this }, events.managerValidationPass); + } + + ValidationManager.prototype = { + addField: function(item) { + var field, i; + field = typeof item.element === "string" ? $(item.element) : item.element; + if (!field.length) { + return false; + } + + field.data("validators", item.validators); + field.data("vtoken", new ValidationToken()); + + if (item.master) { + field.data("master", item.master); + } + + field.bind("validationPass", { manager:this, master:(item.master ? item.master.$e : field) }, events.fieldValidationPass) + .bind("validationFail", { manager:this, master:(item.master ? item.master.$e : field) }, events.fieldValidationFail) + .bind("validationReset", { manager:this, master:(item.master ? item.master.$e : field) }, events.fieldValidationReset) + .bind("validate", { manager:this, field:field }, function(e,d){ + validate(e.data.field); + }); + + for (i in this.o.watchEvents) { + field.bind(this.o.watchEvents[i], { manager:this }, events.watchEventHandler); + } + + this.fields.push(field); + return field; + //validate(field); + }, + validate: function() { + var errorCount = 0; + + $.each(this.fields, function(i, field) { + var validation = validate(field); + if (!validation.valid) { + errorCount += validation.errors.length; + } + }); + + return errorCount === 0; + }, + isValid: function() { + var i, errors; + errors = []; + for (i = 0; i < this.fields.length; i += 1) { + if (this.fields[i].data("vtoken").errors()) { + errors.push({ + field:this.fields[i], + token:this.fields[i].data("vtoken") + }); + } + } + if(errors.length){ + this.internal.eventTarget.trigger('managerValidationFail', {errors:errors}); + return false; + } + this.internal.eventTarget.trigger('managerValidationPass', {errors:errors}); + return true; + }, + reset: function() { + $.each(this.fields, function(i, field) { + field.data("vtoken").clean(); + field.trigger("validationReset"); + }); + if (this.o.$mother instanceof $) { + this.$e.removeClass("state-valid state-invalid"); + } + this.invalidFieldCount = 0; + return this; + } + }; + + ValidationManager.validators = {}; + + ValidationManager.registerValidator = function(key, fn) { + NI.ex.checkStr(key); + NI.ex.checkFn(fn); + key = key.toLowerCase(); + if (error_messages[key]) { + console.warn("Warning: you are overriding the built-in validator: "+ key); + //console.warn("Cannot override the built-in validator: "+ key); + //return; + } + ValidationManager.validators[key] = fn; + }; + + ValidationManager.registerErrorMessage = function(key, note) { + NI.ex.checkStr(key); + NI.ex.checkStr(note); + if (error_messages[key]) { + error_messages[key] = note; + } else { + + } + }; + + ValidationManager.makeRangeValidator = function(low, high, note) { + note = note || "This must be between "+ low +" and "+ high; + return function(value) { + value = Number(value); + if (value < low || value > high) { + return { valid: false, errors: [note] }; + } + return { valid: true }; + }; + }; + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + NI.ValidationManager = ValidationManager; + NI.is = $.extend(NI.is || {}, is); + +}); \ No newline at end of file diff --git a/requirepaths.js b/requirepaths.js new file mode 100644 index 0000000..6ff44fb --- /dev/null +++ b/requirepaths.js @@ -0,0 +1,42 @@ +require = { + paths: { + 'jquery': 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min', + + 'NIanim': 'lib/anim', + 'NIAnimator': 'lib/Animator', + 'NIApp': 'lib/App', + 'NIBrowserDetection': 'lib/BrowserDetection', + 'NICarousel': 'lib/Carousel', + 'NIcolor': 'lib/color', + 'NICookies': 'lib/Cookies', + 'NIFavicon': 'lib/Favicon', + 'NIfeaturedetection': 'lib/featuredetection', + + 'NIfield': 'lib/field', + 'NIfield.Autocomplete': 'lib/field/Autocomplete', + 'NIfield.Counter': 'lib/field/Counter', + 'NIfield.Dropdown': 'lib/field/Dropdown', + 'NIfield.Hint': 'lib/field/Hint', + 'NIfield.SimpleTooltip': 'lib/field/SimpleTooltip', + 'NIfield.std': 'lib/field/std', + 'NIfield.Validator': 'lib/field/Validator', + + 'NIflippanel': 'lib/flippanel', + 'NIfullscreen': 'lib/fullscreen', + 'NIGoogleAnalytics': 'lib/GoogleAnalytics', + 'NIgoogleanalyticsheader': 'lib/googleanalyticsheader', + + 'NIMerlin': 'lib/Merlin', + 'NIMerlin.Autosave': 'lib/merlin/MerlinAutosave', + 'NIMerlin.CSRF': 'lib/merlin/MerlinCSRF', + 'NIMerlin.Data': 'lib/merlin/MerlinData', + + 'NIOverlay': 'lib/Overlay', + 'NIseed': 'lib/seed', + 'NISocialRotator': 'lib/SocialRotator', + 'NITooltip': 'lib/Tooltip', + 'NIvalidation': 'lib/validation', + + 'NIPushstateHelper': 'lib/PushstateHelper' + } +}; \ No newline at end of file diff --git a/styleguide.md b/styleguide.md new file mode 100644 index 0000000..9600138 --- /dev/null +++ b/styleguide.md @@ -0,0 +1,23 @@ + >4SESz., _, ,gSEE2zx.,_ .azx ,w. +@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ +\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. + ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ + :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 + {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, + \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F + ,ss :EE7 ;EEF L,szzw.. ,., `` + \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL + ```` `` JEEE. `"45EEEhw.,,,] + +From 2010 till ∞ + +Javascript Code Style Guide +=========================== + +Okay, this is not a big deal or anything, but for the sake of code consistency, let's have some guidelines. When adding new code to a file, the new code should stay consistent with what's already there (even if that breaks these following rules). + +* Spaces, not tabs. 4 spaces per indentation. +* No restriction for line length, but suggested ballpark is 100 characters. +* Use under_scores for variable names (including functions). Use hy-phens for CSS class names. +* Constructor functions (i.e. intended to be used with new operator) are an exception to the underscore rule. They are CamelCase and begin with a Capital letter. +* Prefer single quotes (i.e. first use single quotes, then double when needed). \ No newline at end of file From 3437ec4194a97d6e89adf634070251904d30cc3c Mon Sep 17 00:00:00 2001 From: Peter Kim Date: Tue, 18 Jun 2013 14:11:55 -0400 Subject: [PATCH 3/6] erased test file --- test_folder/test_file | 1 + 1 file changed, 1 insertion(+) create mode 100644 test_folder/test_file diff --git a/test_folder/test_file b/test_folder/test_file new file mode 100644 index 0000000..bdf08de --- /dev/null +++ b/test_folder/test_file @@ -0,0 +1 @@ +test file \ No newline at end of file From ab9605ba3b8dd36529bc534eaaf17eb58cfa4f8b Mon Sep 17 00:00:00 2001 From: Peter Kim Date: Tue, 18 Jun 2013 14:14:18 -0400 Subject: [PATCH 4/6] cleaning up --- test_folder/test_file | 1 - 1 file changed, 1 deletion(-) delete mode 100644 test_folder/test_file diff --git a/test_folder/test_file b/test_folder/test_file deleted file mode 100644 index bdf08de..0000000 --- a/test_folder/test_file +++ /dev/null @@ -1 +0,0 @@ -test file \ No newline at end of file From aab32bdf42d58ce9f79104febf281015223f6a9b Mon Sep 17 00:00:00 2001 From: Peter Kim Date: Tue, 18 Jun 2013 17:06:30 -0400 Subject: [PATCH 5/6] deleted test file --- test_folder/test file | 1 - 1 file changed, 1 deletion(-) delete mode 100644 test_folder/test file diff --git a/test_folder/test file b/test_folder/test file deleted file mode 100644 index bdf08de..0000000 --- a/test_folder/test file +++ /dev/null @@ -1 +0,0 @@ -test file \ No newline at end of file From 27ab434e402ec479a84d3352554ffc3182808d5f Mon Sep 17 00:00:00 2001 From: Peter Kim Date: Tue, 18 Jun 2013 17:11:20 -0400 Subject: [PATCH 6/6] clean up --- lib/field/tc.field.autocomplete.js | 506 -------------------- lib/field/tc.field.counter.js | 74 --- lib/field/tc.field.dropdown.js | 660 -------------------------- lib/field/tc.field.hint.js | 111 ----- lib/field/tc.field.simple_tooltip.js | 97 ---- lib/field/tc.field.std.js | 677 --------------------------- lib/field/tc.field.validator.js | 197 -------- lib/merlin/tc.merlin.autosave.js | 105 ----- lib/merlin/tc.merlin.csrf.js | 57 --- lib/merlin/tc.merlin.data.js | 182 ------- lib/particle/tc.particle.context.js | 201 -------- lib/particle/tc.particle.particle.js | 238 ---------- lib/tc.anim_util.js | 124 ----- lib/tc.animator.js | 98 ---- lib/tc.app.js | 88 ---- lib/tc.browser_detection.js | 151 ------ lib/tc.carousel.js | 501 -------------------- lib/tc.color.js | 45 -- lib/tc.cookies.js | 83 ---- lib/tc.favicon.js | 83 ---- lib/tc.feature_detection.js | 44 -- lib/tc.field.js | 361 -------------- lib/tc.flippanel.js | 129 ----- lib/tc.google_analytics.header.js | 26 - lib/tc.google_analytics.js | 58 --- lib/tc.merlin.js | 472 ------------------- lib/tc.merlin.js.old | 535 --------------------- lib/tc.overlay.js | 272 ----------- lib/tc.seed.js | 323 ------------- lib/tc.seed.js.orig | 312 ------------ lib/tc.social_rotator.js | 131 ------ lib/tc.tooltip.js | 555 ---------------------- lib/tc.validation.js | 505 -------------------- 33 files changed, 8001 deletions(-) delete mode 100644 lib/field/tc.field.autocomplete.js delete mode 100644 lib/field/tc.field.counter.js delete mode 100644 lib/field/tc.field.dropdown.js delete mode 100644 lib/field/tc.field.hint.js delete mode 100644 lib/field/tc.field.simple_tooltip.js delete mode 100644 lib/field/tc.field.std.js delete mode 100644 lib/field/tc.field.validator.js delete mode 100644 lib/merlin/tc.merlin.autosave.js delete mode 100644 lib/merlin/tc.merlin.csrf.js delete mode 100644 lib/merlin/tc.merlin.data.js delete mode 100644 lib/particle/tc.particle.context.js delete mode 100644 lib/particle/tc.particle.particle.js delete mode 100644 lib/tc.anim_util.js delete mode 100644 lib/tc.animator.js delete mode 100644 lib/tc.app.js delete mode 100644 lib/tc.browser_detection.js delete mode 100644 lib/tc.carousel.js delete mode 100644 lib/tc.color.js delete mode 100644 lib/tc.cookies.js delete mode 100644 lib/tc.favicon.js delete mode 100644 lib/tc.feature_detection.js delete mode 100644 lib/tc.field.js delete mode 100644 lib/tc.flippanel.js delete mode 100644 lib/tc.google_analytics.header.js delete mode 100644 lib/tc.google_analytics.js delete mode 100644 lib/tc.merlin.js delete mode 100644 lib/tc.merlin.js.old delete mode 100644 lib/tc.overlay.js delete mode 100644 lib/tc.seed.js delete mode 100644 lib/tc.seed.js.orig delete mode 100644 lib/tc.social_rotator.js delete mode 100644 lib/tc.tooltip.js delete mode 100644 lib/tc.validation.js diff --git a/lib/field/tc.field.autocomplete.js b/lib/field/tc.field.autocomplete.js deleted file mode 100644 index 5dfaba2..0000000 --- a/lib/field/tc.field.autocomplete.js +++ /dev/null @@ -1,506 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -// Dependencies: -// NI.field - -(function(window, $) { - - var NI = window.NI, delegates = {}; - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - // TODO - delegates.DropdownAutocomplete = function(field, options) { - var me, o; - - me = this; - o = $.extend({ - - }, options); - - function init() { - - } - - init(); - }; - - delegates.TextInputAutocomplete = function(field, options) { - var me, o, internal; - - me = this; - o = $.extend({ - menu_class: "autocomplete menu", - menu_markup: null, - - item_generator: null, - event_data: {}, - on_item_pick: function(e, d) {}, - on_populate: function(d, val) {}, - item_class: "tc-menu-item", - - auto_match: { - key: "value", - allow_different: false, - value_transform: null - }, - - data_source: null, - request_filter_param: "term", - - circular: true, - highlight: true, - activate_after_highlight_n: false, - - delay: 100, - animation: 'slide', - speed: 100 - }, options); - - internal = { - menu_open: false, - menu_engaged: false, - data_source: o.data_source, - request: null, - timeout: null - }; - - function init() { - - field.elements.menu = $((o.menu_markup ? o.menu_markup : "
")); - if(!field.elements.menu.hasClass(o.menu_class)){ - field.elements.menu.addClass(o.menu_class); - } - field.elements.item_wrapper = (field.elements.menu.hasClass('item-wrapper') ? field.elements.menu : field.elements.menu.find('.item-wrapper')); - - hide(); - field.$e.append(field.elements.menu); - - field.add_handlers({ - "keyup.autocomplete": events.keyup, - "keydown.autocomplete": events.keydown, - "focus.autocomplete": events.focus, - "blur.autocomplete": events.blur, - "change.autocomplete": events.change - }, $.extend({field: field}, o.event_data)); - - field.elements.menu.bind("mouseover.autocomplete", function() { - internal.menu_engaged = true; - }).bind("mouseout.autocomplete", function() { - internal.menu_engaged = false; - }); - } - - var events = { - keyup: function(e) { - var key, val; - - key = e.which; - val = e.data.field.get_val(); - - if (NI.ex.isEmpty(val)) { - hide(); - return; - } - if (!(key >= 48 && key <= 90)) { - if (key != NI.co.keyboard.BACKSPACE && key != NI.co.keyboard.DELETE) { - return; - } - } - - dispatch(val); - }, - keydown: function(e) { - var prevent_default, key; - - prevent_default = true; - key = e.which; - - switch (key) { - case NI.co.keyboard.UP: - case NI.co.keyboard.LEFT: - if (internal.menu_open) { - move_selection(NI.co.directions.UP); - } - break; - - case NI.co.keyboard.DOWN: - case NI.co.keyboard.RIGHT: - case NI.co.keyboard.TAB: - if (internal.menu_open) { - move_selection(NI.co.directions.DOWN); - } - break; - - case NI.co.keyboard.ENTER: - if (e.data.field.select_active_item() === true) { - // don't let the enter keydown trip up - // other handlers (namely, from Merlin) - e.stopImmediatePropagation(); - } - break; - - case NI.co.keyboard.ESCAPE: - if (internal.menu_open) { - hide(); - } - break; - - default: - prevent_default = false; - break; - } - - if (prevent_default) { - e.preventDefault(); - } - }, - focus: function(e) { - var val; - val = e.data.field.get_val(); - if (NI.ex.isEmpty(val)) { - hide(); - return; - } - dispatch(val); - }, - blur: function(e) { - if (!internal.menu_engaged) { - hide(); - } - }, - change: function(e){ - if ($.isFunction(o.on_change) && o.on_change.apply(this, arguments) !== false) { - - } - }, - // callback when the menu is shown - visible: function() { - - } - }; - - function dispatch(val) { - if (internal.timeout) { - window.clearTimeout(internal.timeout); - internal.timeout = null; - } - internal.timeout = window.setTimeout(function() { - if (typeof internal.data_source === "string") { //URL - request_data(val); - } else if ($.isArray(internal.data_source)) { - filter_array(val); - } - }, o.delay); - } - - function request_data(val) { - var data = {}; - - if (internal.request) { - internal.request.abort(); - } - - data[o.request_filter_param] = val; - internal.request = $.getJSON(internal.data_source, data, function(d) { - internal.request = null; - if(populate_menu(d, val)){ - show(); - } else { - hide(); - } - }); - } - - function filter_array(val) { - var data, filter, t_start; - data = []; - filter = new RegExp(val,"gi"); - - $.each(internal.data_source,function(i,j){ - var my_start; - my_start = j.label.search(filter); - if(my_start == -1){ - return; - } - data.push(j); - }); - - if(populate_menu(data, val)){ - show(); - } else { - hide(); - } - } - - function populate_menu(d, val) { - var wrap, items_added, $auto_match_item; - items_added = 0; - $auto_match_item = false; - - wrap = field.elements.item_wrapper; - wrap.empty(); - - $.each(d, function(i, item) { - var $item; - if ($.isFunction(o.item_generator)) { - $item = o.item_generator(item, field.get_val()); - } else { - $item = (function(my_item){ - return $('
'+my_item.label+'
'); - })(item); - } - if(!$item){ - return; - } - if(!$item.hasClass(o.item_class) && !$item.find('.'+o.item_class).length){ - $item.addClass(o.item_class); - } - - if (o.highlight && val) { - highlight($item, val); - } - - wrap.append($item); - items_added++; - - if (o.auto_match && !$auto_match_item) { - $auto_match_item = auto_match($item, val); - } - }); - - if (o.auto_match && $auto_match_item !== false) { - wrap.append($auto_match_item); - } - - wrap.find("."+ o.item_class). - bind("click", $.extend({field: field}, o.event_data), function(e, d) { - if (o.on_item_pick.apply(this, arguments) !== false) { - hide(); - internal.menu_engaged = false; - } - }). // auto-activate the first highlighted item, if it exists - filter(".auto-activate").first().addClass(NI.field.co.ACTIVE_CLASS); - - o.on_populate.apply(field, [d, val]); - - if (items_added > 0) { - return true; - } else { - return false; - } - } - - function highlight($item, val) { - if (!val) { - return; - } - $item.each(function() { - innerHighlight($item, this, val.toUpperCase()); - }); - } - - // HTML node highlighting routine based on Johann Burkard's jQuery highlight v3: - // http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html - - function innerHighlight($item, node, pat) { - var skip = 0; - if (node.nodeType == NI.co.nodeTypes.TEXT_NODE) { - var pos = node.data.toUpperCase().indexOf(pat); - if (pos >= 0) { - var spannode = document.createElement('span'); - spannode.className = 'hili'; - var middlebit = node.splitText(pos); - var endbit = middlebit.splitText(pat.length); - var middleclone = middlebit.cloneNode(true); - spannode.appendChild(middleclone); - middlebit.parentNode.replaceChild(spannode, middlebit); - skip = 1; - - if (o.activate_after_highlight_n && pat.length >= o.activate_after_highlight_n) { - $item.addClass("auto-activate"); - } - - } - } else if (node.nodeType == NI.co.nodeTypes.ELEMENT_NODE && node.childNodes && !/(script|style)/i.test(node.tagName)) { - for (var i = 0; i < node.childNodes.length; ++i) { - i += innerHighlight($item, node.childNodes[i], pat); - } - } - return skip; - } - - // if an element is "auto matched", return a $ object - // representing an 'Add a different ...' control, - // otherwise, return false - function auto_match($item, val) { - var item_val, $diff_item; - - item_val = $item.attr("data-"+ o.auto_match.key); - if (!item_val || !val) { - return; - } - - if ($.isFunction(o.auto_match.value_transform)) { - item_val = o.auto_match.value_transform(item_val); - if (!item_val) { - return; - } - } - - if (!$item.hasClass(NI.field.co.ACTIVE_CLASS) && item_val.toLowerCase() == val.toLowerCase()) { - - $item.addClass(NI.field.co.ACTIVE_CLASS); - - if (o.auto_match.allow_different !== false) { - $diff_item = $("
Add a different "+ item_val +"
").addClass(o.item_class +" "+ o.item_class+"-diff"); - $diff_item.attr("data-"+ o.auto_match.key, item_val); - return $diff_item; - } - } - - return false; - } - - function move_selection(direction) { - var $t, $items, $active_item, index; - - $items = field.elements.item_wrapper.find("."+ o.item_class); - if (!$items.length) { - return; - } - $active_item = $items.filter("."+ NI.field.co.ACTIVE_CLASS); - - if (!$active_item.length) { - if (direction === NI.co.directions.UP) { - $t = $items.last(); - } else { - $t = $items.first(); - } - } else { - - index = $items.index($active_item.last()); - - if (direction === NI.co.directions.UP) { - $t = $items.eq(index - 1); - if (!$t.length) { - $t = o.circular ? $items.last() : $items.first(); - } - } else { - $t = $items.eq(index + 1); - if (!$t.length) { - $t = o.circular ? $items.first() : $items.last(); - } - } - } - - $items.removeClass(NI.field.co.ACTIVE_CLASS); - $t.addClass(NI.field.co.ACTIVE_CLASS); - } - - function show(callback) { - if (internal.menu_open) { - events.visible(); - return; - } - if (o.animation == 'slide') { - field.elements.menu.slideDown(o.speed, function() { - events.visible(); - }); - } else { - field.elements.menu.show(); - events.visible(); - } - internal.menu_open = true; - } - - function hide() { - /*if (o.animation == 'slide') { - field.elements.menu.slideUp(o.speed); - } else { - field.elements.menu.hide(); - };*/ - - if (internal.request) { - internal.request.abort(); - } - - field.elements.menu.hide(); - internal.menu_open = false; - } - - field.set_data_source = function(data_source){ - internal.data_source = data_source; - }; - - field.has_active_item = function(){ - if(field.elements.item_wrapper.find("."+ o.item_class).filter("."+ NI.field.co.ACTIVE_CLASS).length){ - return true; - } - return false; - }; - - field.select_active_item = function() { - // return true if an active item exists, - // otherwise return false - - var $items, $active_item; - - $items = field.elements.item_wrapper.find("."+ o.item_class); - if (!$items.length) { - return false; - } - $active_item = $items.filter("."+ NI.field.co.ACTIVE_CLASS); - if (!$active_item.length) { - return false; - } - $active_item.last().trigger("click"); - return true; - }; - - field.is_open = function(){ - return internal.menu_open; - }; - - init(); - }; - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - NI.field.extensions.Autocomplete = function(field, options) { - var me, o, delegate; - - me = this; - o = $.extend({ - - }, options); - - function init() { - - if ($.isFunction(delegates[field._name + "Autocomplete"])) { - delegate = new delegates[field._name + "Autocomplete"](field, o); - } else { - throw new Error("Autocomplete does not support field type: "+ field._name); - } - - } - - init(); - }; - -}(this, this.jQuery)); \ No newline at end of file diff --git a/lib/field/tc.field.counter.js b/lib/field/tc.field.counter.js deleted file mode 100644 index 78a09b4..0000000 --- a/lib/field/tc.field.counter.js +++ /dev/null @@ -1,74 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -// Dependencies: -// NI.field - -(function(window, $) { - - var NI = window.NI; - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - NI.field.extensions.Counter = function(field, options) { - var me, o, internal, elements, event_handlers; - - me = this; - o = $.extend({ - max:100, - difference:0, - updated:function(e,d){}, - count_element:'.count', - total_element:'.total' - - }, options); - - internal = { - name:'TC.field Extension.SimpleTooltip', - $e:null - }; - - elements = { - count:(o.count_element instanceof $ ? o.count_element : field.$e.find(o.count_element)), - total:(o.total_element instanceof $ ? o.total_element : field.$e.find(o.total_element)) - }; - - function init(){ - field.event_receiver.bind('focus keyup change', {field:field}, event_handlers.updated); - }; - - event_handlers = { - updated:function(e,d){ - o.difference = o.max - field.get_val().length; - - elements.count.text(o.difference); - //elements.total.text(o.max); - - if (o.difference < 0) { - elements.count.parent().addClass('too-many') - } else { - elements.count.parent().removeClass('too-many') - }; - } - }; - - - init(); - - }; - -}(this, this.jQuery)); \ No newline at end of file diff --git a/lib/field/tc.field.dropdown.js b/lib/field/tc.field.dropdown.js deleted file mode 100644 index 5284e6d..0000000 --- a/lib/field/tc.field.dropdown.js +++ /dev/null @@ -1,660 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -// Dependencies: -// NI.field - -(function(window, $) { - - var NI = window.NI, - field = NI.field; - - field.synthesize({ - name: "Dropdown", - - props: { - CONTAINER_CLASS: "tc-dropdown", - DISPLAY_CLASS: "display", - TRIGGER_ARROW_CLASS: "trigarr", - MENU_CLASS: "menu", - ITEM_CLASS: "item", - - morph_native_select: function($f) { - var $e, buf; - - if(!$f[0]){ - return $f; - } - - if (!($f[0].nodeName.toLowerCase() == "select")) { - return $f; - } - - $e = $("
") - .addClass(field.co.BASE_CLASS+ " " +field.Dropdown.CONTAINER_CLASS) - .html("
"+ - "
"); - - buf = ""; - $f.find("option").each(function() { - var $option = $(this); - buf += "
"+ - field.get_display_text($option) +"
"; - }); - $e.find("."+ field.Dropdown.MENU_CLASS).html(buf); - - if (!NI.ex.isHeadless($f)) { - $f.replaceWith($e); - } - - return $e; - } - - }, - - proto: { - - options: { - item_generator: null, - item_handlers: { - click: function(e) { - e.data.me.set_val(e.data.$item.attr(field.co.VALUE)).close(); - } - }, - - empty_val: "-1", - empty_text: " ", - - circular: true, - filtering: true, - rolling: false, - enable_update_display: true, - - on_open: function(instance) {}, - on_close: function(instance) {}, - on_keydown: function(e) {}, - - fx: { - open: function($menu, callback) { - $menu.slideDown(100, function() { - if ($.isFunction(callback)) { - callback(); - } - }); - }, - close: function($menu) { - $menu.slideUp(100); - } - } - }, - - _init: function() { - - this.events.click = function(e) { - var me = e.data.me; - - if (me.$e[0] === e.target || $.contains(me.$e[0], e.target)) { - // clicked somewhere on the dropdown - - if (me.elements.display[0] === e.target || - $.contains(me.elements.display[0], e.target) || - (me.elements.trigarr && me.elements.trigarr[0] === e.target)) { - - // clicked somewhere on the dropdown display area - me[me.internal.open ? "close" : "open"](); - } - - } else { - // clicked somewhere off the dropdown - if (me.internal.open) { - me.close(); - } - } - }; - - this.events.keydown = function(e) { - var me, prevent_default, key; - - me = e.data.me; - if ($.isFunction(me.internal.o.on_keydown)) { - if (me.internal.o.on_keydown(e) === false) { - return; - } - } - prevent_default = true; - key = e.keyCode || e.which; - - if (key >= 48 && key <= 90) { - if (me.internal.o.filtering) { - me.internal.filter_str += String.fromCharCode(key); - me.filter(me.internal.filter_str); - } - - } else if (key == NI.co.keyboard.BACKSPACE || - key == NI.co.keyboard.DELETE) { - if (me.internal.filter_str.length) { - me.clear_filter(); - } - - } else { - switch (key) { - case NI.co.keyboard.LEFT: - case NI.co.keyboard.UP: - me.move_selection(NI.co.directions.UP); - break; - - case NI.co.keyboard.RIGHT: - case NI.co.keyboard.DOWN: - me.move_selection(NI.co.directions.DOWN); - break; - - case NI.co.keyboard.ENTER: - case NI.co.keyboard.ESCAPE: - me.close(); - break; - - default: - prevent_default = false; - break; - } - } - if (prevent_default) { - e.preventDefault(); - } - }; - - $(window.document).bind("click."+ this._name, {me: this}, this.events.click); - - this.internal.filter_str = ""; - this._update_display(this.get_active_item()); - this.close(); - }, - - generate_from_dom: function(options) { - var me, $items; - me = this; - field._Base.prototype.generate_from_dom.apply(this, arguments); - this.$e.addClass(field.Dropdown.CONTAINER_CLASS); - this._init_elements(); - $items = this.get_items(true); - if (typeof(this.internal.o.item_handlers) === "object") { - $.each(this.internal.o.item_handlers, function(type, fn) { - $items.each(function() { - var $item, empty_val; - $item = $(this); - if ($item.hasClass(field.co.EMPTY_CLASS)) { - empty_val = $item.attr(field.co.VALUE); - if (empty_val) { - me.internal.o.empty_val = empty_val; - } - me.internal.o.empty_text = field.get_display_text($item); - $item.remove(); - return true; - } - $item.bind(type, {me: me, $item: $item}, fn); - }); - }); - } - }, - - generate_from_scratch: function(options) { - this.$e = $("
") - .addClass(field.co.BASE_CLASS+ " " +field.Dropdown.CONTAINER_CLASS) - .html("
"+ - "
"); - this._init_elements(); - if (options.value_list) { - this.populate(options.value_list); - } - }, - - _init_elements: function() { - var trigarr; - this.elements.display = $("."+ field.Dropdown.DISPLAY_CLASS, this.$e); - this.elements.menu = $("."+ field.Dropdown.MENU_CLASS, this.$e); - trigarr = $("."+field.Dropdown.TRIGGER_ARROW_CLASS , this.$e); - if (trigarr.length) { - this.elements.trigarr = trigarr; - } - this.events.visible = function() { - - }; - }, - - // (chainable) - populate: function(value_list) { - var me; - me = this; - this.elements.menu.empty(); - - if ($.isFunction(value_list)) { - this.elements.menu.append(value_list()); - return this; - } - - if (value_list instanceof $) { - this.add_item(value_list); - return this; - } - - $.each(value_list, function(value, text) { - me.add_item(value, text); - }); - - return this; - }, - - // (chainable) - // arguments can be: - // - // 1 arg => jQuery object - // OR - // arguments for an item_generator - // OR - // 2 args => value, text - add_item: function() { - var me, $item; - me = this; - - if (arguments[0] instanceof $) { - $item = arguments[0]; - - } else if ($.isFunction(this.internal.o.item_generator)) { - $item = this.internal.o.item_generator(arguments); - - } else { - $item = $("
"+ arguments[1] +"
"); - } - - $item.addClass(field.Dropdown.ITEM_CLASS); - - if (typeof(this.internal.o.item_handlers) === "object") { - $.each(this.internal.o.item_handlers, function(type, fn) { - $item.bind(type, {me: me, $item: $item}, fn); - }); - } - - this.elements.menu.append($item); - return this; - }, - - get_items: function(include_secrets) { - var $items = this.elements.menu.find("."+ field.Dropdown.ITEM_CLASS); - if ($.isFunction(include_secrets)) { - $items = $items.filter(include_secrets); - } else if (!include_secrets) { - $items = $items.filter(function() { - return !($(this).css("display") === "none"); - }); - } - return $items; - }, - - get_active_item: function() { - var $item; - $item = this.get_items(true).filter("."+ field.co.ACTIVE_CLASS); - return $item.length ? $item : false; - }, - - reset: function(){ - this.set_val('-1'); - this.event_receiver.trigger(field.co.RESET_EVENT); - }, - - get_val: function() { - var $item; - $item = this.get_active_item(); - if ($item) { - return $item.attr(field.co.VALUE); - } - return this.internal.o.empty_val; - }, - - _set_val: function(val) { - var me, $items; - me = this; - - if (val === this.internal.o.empty_val) { - this.clear(); - return; - } - - $items = this.get_items(true); - - $items.each(function(i) { - var $item = $(this); - if ($item.attr(field.co.VALUE) == val) { - if (!me.internal.multi) { - $items.removeClass(field.co.ACTIVE_CLASS); - } else { - $item.children("input").attr("checked", true); - } - $item.addClass(field.co.ACTIVE_CLASS); - if(me.internal.o.enable_update_display){ - me._update_display($item); - } - return false; - } - }); - }, - - // (chainable) - move_selection: function(direction) { - var me, $t, $items, $active_item, index; - me = this; - - $items = this.get_items(this.internal.o.rolling ? true : false); - if (!$items.length) { - return this; - } - - $active_item = this.get_active_item(); - - if (!$active_item || $active_item === this.internal.o.empty_val) { - if (direction === NI.co.directions.UP) { - $t = $items.last(); - } else { - $t = $items.first(); - } - } else { - index = $items.index($active_item.last()); - if (direction === NI.co.directions.UP) { - $t = $items.eq(index - 1); - if (!$t.length) { - $t = this.internal.o.circular ? $items.last() : $items.first(); - } - } else { - $t = $items.eq(index + 1); - if (!$t.length) { - $t = this.internal.o.circular ? $items.first() : $items.last(); - } - } - } - - return this.internal.multi ? this.toggle_item($t) : this.set_val($t.attr(field.co.VALUE)); - }, - - // (chainable) - clear: function() { - this.get_items(true).removeClass(field.co.ACTIVE_CLASS); - this._update_display(false); - return this; - }, - - // arguments can be: - // - // $ obj => the active item to display - // OR - // str => arbitrary message to display - // OR - // false => display the empty state - _update_display: function() { - - if (arguments[0] instanceof $) { - this.elements.display.html(field.get_display_text(arguments[0])); - return; - } - - if (typeof arguments[0] === "string") { - this.elements.display.html(""+ arguments[0] +""); - return; - } - - if (arguments[0] === false) { - this.elements.display.html(""+ this.internal.o.empty_text +""); - return; - } - }, - - // (chainable) - set_enabled: function(enabled) { - if (enabled) { - this.internal.enabled = true; - this.$e.removeClass(field.co.DISABLED_CLASS); - } else { - this.close(); - this.internal.enabled = false; - this.$e.addClass(field.co.DISABLED_CLASS); - } - return this; - }, - - // (chainable) - open: function() { - if (this.internal.enabled === false) { - return this; - } - if (this.get_items()) { - if (this.internal.o.fx && $.isFunction(this.internal.o.fx.open)) { - this.internal.o.fx.open(this.elements.menu, this.events.visible); - } else { - this.elements.menu.show(); - this.events.visible(); - } - this.$e.addClass(field.co.OPEN_CLASS); - $(window.document).bind("keydown."+ this._name, {me: this}, this.events.keydown); - this.internal.open = true; - this.$e.trigger('tc-field-dropdown-open'); - if ($.isFunction(this.internal.o.on_open)) { - this.internal.o.on_open(this); - } - } - return this; - }, - - // (chainable) - close: function() { - if (this.internal.o.fx && $.isFunction(this.internal.o.fx.close)) { - this.internal.o.fx.close(this.elements.menu); - } else { - this.elements.menu.hide(); - } - this.$e.removeClass(field.co.OPEN_CLASS); - $(window.document).unbind("keydown."+ this._name, this.events.keydown); - this.internal.open = false; - this.clear_filter(); - this.$e.trigger('tc-field-dropdown-close'); - if ($.isFunction(this.internal.o.on_close)) { - this.internal.o.on_close(this); - } - return this; - }, - - // (chainable) - filter: function(text) { - var me, $items, s; - me = this; - $items = this.get_items(function() { - var $item = $(this); - return ($item.hasClass("state-filtered") || !($item.css("display") === "none")); - }); - if (!$items.length) { - return this; - } - if (!text) { - $items.each(function() { - $(this).removeClass("state-filtered").show(); - }); - return this; - } - s = new RegExp(text, "gi"); - $items.each(function() { - var $item = $(this); - if (field.get_display_text($item).search(s) === -1) { - $item.addClass("state-filtered").hide(); - } else { - $item.removeClass("state-filtered").show(); - } - }); - return this; - }, - - // (chainable) - clear_filter: function() { - this.internal.filter_str = ""; - return this.filter(); - }, - - destroy: function() { - this.close(); - $(window.document).unbind("click."+ this._name, this.events.click); - this._base.destroy.apply(this, arguments); - } - } - }); - - field.synthesize({ - name: "MultiDropdown", - - base: field.Dropdown, - proto: { - - options: { - item_handlers: { - click: function(e) { - e.data.me.toggle_item(e.data.$item); - } - }, - - empty_val: [], - - circular: false, - filtering: false - }, - - _init: function() { - this.internal.multi = true; - this._base._init.apply(this, arguments); - this.get_items(true).each(function() { - var $item = $(this); - if ($item.hasClass(field.co.ACTIVE_CLASS)) { - $item.children("input").attr("checked", true); - } else { - $item.children("input").removeAttr("checked"); - } - }); - }, - - get_val: function() { - var $active, value_list; - $active = this.get_active_item(); - if ($active) { - value_list = []; - $active.each(function() { - value_list.push($(this).attr(field.co.VALUE)); - }); - return value_list; - } - return this.internal.o.empty_val; - }, - - // (chainable) - toggle_item: function($item) { - var value_list, val, index; - - value_list = this.get_val(); - val = $item.attr(field.co.VALUE); - if (value_list === this.internal.o.empty_val) { - return this.set_val(val); - } - index = $.inArray(val, value_list); - if (index > -1) { - value_list.splice(index, 1); - } else { - value_list.push(val); - } - return this.set_val(value_list); - }, - - _set_val: function(val) { - var me = this, $items; - - if (!$.isArray(val)) { - this._base._set_val.apply(this, arguments); - return; - } - - $items = this.get_items(true); - - $items.each(function() { - var $item = $(this); - $item.removeClass(field.co.ACTIVE_CLASS); - $item.children("input").removeAttr("checked"); - }); - - $.each(val, function(i, v) { - $items.each(function(i) { - var $item = $(this); - if ($item.attr(field.co.VALUE) == v) { - $item.addClass(field.co.ACTIVE_CLASS); - $item.children("input").attr("checked", true); - return false; - } - }); - }); - if(me.internal.o.enable_update_display){ - this._update_display(); - } - }, - - clear: function() { - this.get_items(true).removeClass(field.co.ACTIVE_CLASS).children("input").removeAttr("checked"); - this._update_display(false); - return this; - }, - - _update_display: function() { - var display_list, $active, buf, i; - - if (arguments[0] instanceof $ && arguments[0].length > 1) { - display_list = []; - $.each(arguments[0], function() { - display_list.push(field.get_display_text($(this))); - }); - - } else if (arguments[0] !== false && !arguments[0]) { - $active = this.get_active_item(); - if ($active) { - display_list = []; - $active.each(function() { - display_list.push(field.get_display_text($(this))); - }); - - } else { - this._base._update_display.apply(this, [false]); - return; - } - - } else { - this._base._update_display.apply(this, arguments); - return; - } - - buf = ""; - for (i = 0; i < display_list.length; i += 1) { - buf += ""+ display_list[i] +""; - if (i < display_list.length - 1) { - buf += ", "; - } - } - this.elements.display.html(buf); - } - - } - }); - -}(this, this.jQuery)); \ No newline at end of file diff --git a/lib/field/tc.field.hint.js b/lib/field/tc.field.hint.js deleted file mode 100644 index 13f439c..0000000 --- a/lib/field/tc.field.hint.js +++ /dev/null @@ -1,111 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -// Dependencies: -// NI.field - -(function(window, $) { - - var NI = window.NI; - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - NI.field.extensions.Hint = function(field, options) { - var me, o, $e; - - me = this; - o = $.extend({ - content: null, - html_content: false, - css: {}, - fx: { - in_fx: 200, - out_fx: 200 - }, - watch_events: { - in_event: ['blur', 'keyup', 'change', NI.field.co.SET_VAL_EVENT, NI.field.co.RESET_EVENT].join(' '), - out_event: "focus" - } - }, options); - - function init() { - $e = $("
"); - $e.css($.extend({ - position: "absolute", - top: 0, - left: 0, - display: "none" - }, o.css)); - $e.prependTo(field.$e); - - $e.click(events.hint_click); - field.event_receiver.bind(o.watch_events.in_event, events.in_fn); - field.event_receiver.bind(o.watch_events.out_event, events.out_fn); - - me.set(o.content); - - if (!field.get_val() || !field.get_val().length) { - $e.show(); - } - } - - var events = { - hint_click: function(e, d) { - field.event_receiver.trigger('focus'); - }, - in_fn: function(e, d) { - //if (NI.ex.isEmpty(field.get_val())) { - if (!field.get_val() || !field.get_val().length) { - if (e.type === "blur" || e.type == NI.field.co.RESET_EVENT) { - $e.fadeIn(o.fx.in_fx); - } - } else { - $e.fadeOut(o.fx.out_fx); - } - }, - out_fn: function(e, d) { - $e.fadeOut(o.fx.out); - } - }; - - // (chainable) - this.set = function(content) { - if (content instanceof $) { - $e.empty().append(content); - } else if (typeof content === "string") { - //if (!NI.ex.isEmpty(content)) { - if (!field.get_val() || !field.get_val().length) { - if (o.html_content === true) { - $e.empty().html(content); - } else { - $e.empty().text(content); - } - } - } - return this; - }; - - this.destroy = function() { - $e.remove(); - field.event_receiver.unbind(o.watch_events.in_event, events.in_fn); - field.event_receiver.unbind(o.watch_events.out_event, events.out_fn); - }; - - init(); - }; - -}(this, this.jQuery)); \ No newline at end of file diff --git a/lib/field/tc.field.simple_tooltip.js b/lib/field/tc.field.simple_tooltip.js deleted file mode 100644 index 3d3aeba..0000000 --- a/lib/field/tc.field.simple_tooltip.js +++ /dev/null @@ -1,97 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -// Dependencies: -// NI.field - -(function(window, $) { - - var NI = window.NI; - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - NI.field.co.SIMPLE_TOOLTIP_CLASS = 'tc-field-simple-toolip'; - - NI.field.extensions.SimpleTooltip = function(field, options) { - var me, o, internal, event_handlers; - - me = this; - o = $.extend({ - content: null, - orientation:'left',//'top' - css: {}, - fx: { - in_fx: 200, - out_fx: 50 - }, - watch_events: { - in_event: "focus", - out_event: "blur" - } - }, options); - - internal = { - name:'TC.field Extension.SimpleTooltip', - $e:$("
") - }; - - function init() { - - internal.$e.addClass(o.orientation); - internal.$e.css($.extend({ - - }, o.css)); - internal.$e.prependTo(field.$e); - - internal.$e.html(o.content); - - field.event_receiver.bind(o.watch_events.in_event, event_handlers.in_fn); - field.event_receiver.bind(o.watch_events.out_event, event_handlers.out_fn); - - field.set_tooltip_content = function(new_content){ - internal.$e.html(new_content); - }; - - field.get_tooltip_content = function(new_content){ - return internal.$e; - }; - - } - - event_handlers = { - in_fn: function(e,d){ - if (! internal.$e.is(":empty")) { - internal.$e.fadeIn(o.fx.in_fx); - } - }, - out_fn: function(e,d){ - internal.$e.fadeOut(o.fx.out_fx); - } - }; - - this.show = function(){ - event_handlers.in_fn(); - }; - - this.hide = function(){ - event_handlers.out_fn(); - }; - - init(); - }; - -}(this, this.jQuery)); \ No newline at end of file diff --git a/lib/field/tc.field.std.js b/lib/field/tc.field.std.js deleted file mode 100644 index b77df12..0000000 --- a/lib/field/tc.field.std.js +++ /dev/null @@ -1,677 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -// Dependencies: -// NI.field - -(function(window, $) { - - var NI = window.NI, - field = NI.field; - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -// standard field type - -// field type names starting with "_Base" are abstract - - field.synthesize({ - name: "_BaseText", - - proto: { - _init: function() { - this.event_receiver = this.elements.input; - }, - - get_val: function() { - return this.elements.input.val(); - }, - - _set_val: function(val) { - this.elements.input.val(val ? val : ""); - }, - - set_enabled: function(enabled) { - if (enabled) { - this.elements.input.attr("disabled", true); - } else { - this.elements.input.removeAttr("disabled"); - } - return this; - } - } - }); - - field.synthesize({ - name: "TextInput", - - base: field._BaseText, - proto: { - generate_from_dom: function(options) { - this._base.generate_from_dom.apply(this, arguments); - //this.elements.input = $("input[type='text']", this.$e); - this.elements.input = $("input", this.$e); - }, - - generate_from_scratch: function(options) { - this.$e = $("
").addClass(field.co.BASE_CLASS); - this.elements.input = $("input[type='text']", this.$e); - } - } - }); - - field.synthesize({ - name: "Password", - - base: field._BaseText, - proto: { - generate_from_dom: function(options) { - this._base.generate_from_dom.apply(this, arguments); - this.elements.input = $("input[type='password']", this.$e); - }, - - generate_from_scratch: function(options) { - this.$e = $("
").addClass(field.co.BASE_CLASS); - this.elements.input = $("input[type='password']", this.$e); - } - } - }); - - field.synthesize({ - name: "TextArea", - - base: field._BaseText, - proto: { - generate_from_dom: function(options) { - this._base.generate_from_dom.apply(this, arguments); - this.elements.input = $("textarea", this.$e); - }, - - generate_from_scratch: function(options) { - this.$e = $("
").addClass(field.co.BASE_CLASS); - this.elements.input = $("textarea", this.$e); - } - } - }); - - field.synthesize({ - name: "_BaseControl", - - proto: { - - options: { - sexy: true - }, - - _init: function() { - this.event_receiver = //this.elements.input; - this.event_receiver = this.$e; - this._init_label(); - this._init_sexy(); - }, - - // looks for a nearby label for this control - // if there is a label whose "for" attribute - // corresponds to the control's "id" attribute - // that's the label regardless of where it is in the DOM, - // otherwise, we will for the label that is a sibling - // of the control element - _init_label: function() { - var me, label_set, $label; - - me = this; - label_set = false; - - function try_to_set_label() { - if (($label instanceof $) && $label.length) { - if ($label.attr("for") == me.elements.input.attr("id")) { - $label = $label.detach(); - if (me.internal.o.label) { - $label.text(me.internal.o.label); - } - label_set = true; - return true; - } - } - return false; - } - - if (this.elements.input.attr("id")) { - $label = $("label[for='"+ this.elements.input.attr("id") +"']"); - } - if (!try_to_set_label()) { - $label = this.$e.next("label"); - if (!$label.length) { - $label = this.$e.prev("label"); - } - if (!try_to_set_label()) { - $label = this.elements.input.next("label"); - if (!$label.length) { - $label = this.elements.input.prev("label"); - } - try_to_set_label(); - } - } - - if (!label_set && this.internal.o.label) { - $label = $(""); - label_set = true; - } - - if (label_set) { - $label.bind("click", {me: this}, function(e) { - e.preventDefault(); - if(e.data.me.internal.o.set){ - e.data.me.internal.o.set.set_val(e.data.me.elements.input.attr('value')); - } else { - e.data.me.set_val(e.data.me.get_val() !== "true"); - } - }); - this.elements.input.after($label); - } - }, - - //if we have sexyboxes enabled, we will get them setup here. - _init_sexy: function(){ - if (this.internal.o.sexy) { - this.elements.sexy_input = $("
"); - this.elements.sexy_input.bind("click", {me: this}, function(e) { - if(e.data.me.internal.o.set){ - e.data.me.internal.o.set.set_val(e.data.me.elements.input.attr('value')); - } else { - e.data.me.set_val(e.data.me.get_val() !== "true"); - } - }); - this.event_receiver.bind("change " + NI.field.co.SET_VAL_EVENT, {me: this}, function(e) { - e.data.me._sexy_update(); - }); - this._sexy_update(); - this.elements.input.hide().before(this.elements.sexy_input); - } - }, - - _sexy_update: function() { - if (!this.elements.sexy_input) { - return; - } - this.elements.sexy_input[this.get_val() === "true" ? "addClass" : "removeClass"](field.co.ACTIVE_CLASS); - }, - - get_val: function() { - return this.elements.input.prop("checked") ? "true" : "false"; - }, - - _set_val: function(val) { - if (val) { - this.elements.input.prop("checked", true); - } else { - this.elements.input.prop("checked", false); - } - }, - - set_enabled: function(enabled) { - return field._BaseText.prototype.set_enabled.apply(this, arguments); - } - } - }); - - field.synthesize({ - name: "Radio", - - base: field._BaseControl, - proto: { - generate_from_dom: function(options) { - this._base.generate_from_dom.apply(this, arguments); - this.elements.input = $("input[type='radio']", this.$e); - }, - - generate_from_scratch: function(options) { - this.$e = $("
").addClass(field.co.BASE_CLASS); - this.elements.input = $("input[type='radio']", this.$e); - } - } - }); - - field.synthesize({ - name: "Checkbox", - - base: field._BaseControl, - proto: { - generate_from_dom: function(options) { - this._base.generate_from_dom.apply(this, arguments); - this.elements.input = $("input[type='checkbox']", this.$e); - options.$e.addClass('tc-sexy-checkbox'); - }, - - generate_from_scratch: function(options) { - this.$e = $("
").addClass(field.co.BASE_CLASS); - this.elements.input = $("input[type='checkbox']", this.$e); - } - } - }); - - field.synthesize({ - name: "_BaseControlSet", - - proto: { - _init: function() { - this.event_receiver = $({}); - }, - - generate_from_dom: function(options) { - var me; - me = this; - - field._Base.prototype.generate_from_dom.apply(this, arguments); - this.$e.addClass(field[this._name].CONTAINER_CLASS); - this.elements.inputs = $("input[type='"+ field[this._name].INPUT_TYPE.toLowerCase() +"']", this.$e); - - this.internal.fields = []; - this.elements.inputs.each(function() { - - var $f, my_subfield_options, my_options; - $f = $(this); - my_subfield_options = {}; - - if(options.subfield_options){ - $.each(options.subfield_options,function(i, j){ - if($f.filter(j.selector).length){ - $.extend(my_subfield_options, j.options); - } - }); - } - - my_options = $.extend({}, options, my_subfield_options, - {$e: field.prep_element($f).$e, set:me} - ); - - me.internal.fields.push( new field[field[me._name].INPUT_TYPE](my_options) ); - }); - }, - - _set_val: function(val) { - $.each(this.internal.fields, function(i, f) { - f.set_val(false); - if (f.elements.input.attr("value") == val) { - f.set_val(true); - } - }); - }, - - _sexy_update: function(val) { - $.each(this.internal.fields, function(i, f) { - if (!f.elements.sexy_input) { - return true; - } - if (f.elements.input.attr("value") == val) { - f.elements.sexy_input.addClass(field.co.ACTIVE_CLASS); - } else { - f.elements.sexy_input.removeClass(field.co.ACTIVE_CLASS); - } - }); - }, - - set_enabled: function(enabled) { - $.each(this.internal.fields, function(i, f) { - f.set_enabled(enabled); - }); - return field._BaseText.prototype.set_enabled.apply(this, arguments); - } - } - }); - - field.synthesize({ - name: "RadioSet", - - props: { - CONTAINER_CLASS: "tc-radio-set", - INPUT_TYPE: "Radio" - }, - - base: field._BaseControlSet, - proto: { - generate_from_scratch: function(options) { - //TODO - console.warn('RadioSet.generate_from_scratch is not yet implemented'); - }, - - get_val: function() { - var val; - - $.each(this.internal.fields, function(i, f) { - if (f.get_val() === "true") { - val = f.elements.input.attr("value"); - return false; - } - }); - - if (val === false || typeof val === "undefined") { - val = "-1"; - } - - return val; - }, - - _set_val: function(val) { - $.each(this.internal.fields, function(i, f) { - f.set_val(false); - if (f.elements.input.attr("value") == val) { - f.set_val(true); - } - }); - } - } - }); - - field.synthesize({ - name: "CheckboxSet", - - props: { - CONTAINER_CLASS: "tc-checkbox-set", - INPUT_TYPE: "Checkbox" - }, - - base: field._BaseControlSet, - proto: { - generate_from_scratch: function(options) { - // TODO - console.warn('CheckboxSet.generate_from_scratch is not fully implemented'); - }, - - get_val: function() { - var i, val; - val = []; - - $.each(this.internal.fields, function(i, f) { - if (f.get_val() == "true") { - val.push(f.elements.input.attr("value")); - } - }); - - return val; - }, - - _set_val: function(val) { - var me; - me = this; - - if ($.isArray(val)) { - $.each(this.internal.fields, function(i, f) { - f.set_val(false); - }); - - $.each(val, function(i, v) { - $.each(me.internal.fields, function(j, f) { - if (f.elements.input.attr("value") == v) { - f.set_val(true); - } - }); - }); - } else { - $.each(me.internal.fields, function(j, f) { - if (f.elements.input.attr("value") == val) { - f.set_val(f.get_val() !== 'true'); - } - }); - } - - - } - } - }); - - field.synthesize({ - name: "Select", - - proto: { - - options: { - empty_val: "-1", - value_list: {} - }, - - _init: function() { - this.event_receiver = this.elements.select; - }, - - generate_from_dom: function(options) { - this._base.generate_from_dom.apply(this, arguments); - this.elements.select = $("select", this.$e); - }, - - generate_from_scratch: function(options) { - this.$e = $("
").addClass(field.co.BASE_CLASS); - this.elements.select = $("select", this.$e); - if (options.value_list) { - this.populate(options.value_list); - } - }, - - // (chainable) - populate: function(value_list) { - var buf; - this.elements.select.empty(); - - if ($.isFunction(value_list)) { - this.elements.select.append(value_list()); - return this; - } - - buf = ""; - $.each(value_list, function(value, text) { - buf += ""; - }); - this.elements.select.append(buf); - return this; - }, - - get_val: function() { - var $option; - $option = this.elements.select.find("option:selected"); - if ($option.length) { - return $option.attr("value"); - } - return this.internal.o.empty_val; - }, - - _set_val: function(val) { - if (val) { - this.elements.select.find("option[value="+ val +"]").attr("selected", true); - } else { - this.elements.select.find("option").attr("selected", false); - } - }, - - set_enabled: function(enabled) { - if (enabled) { - this.elements.select.attr("disabled", true); - } else { - this.elements.select.removeAttr("disabled"); - } - return this; - } - } - }); - - field.synthesize({ - name: "Upload", - - proto: { - - options: { - url:null - }, - - _init: function() { - - }, - - generate_from_dom: function(options) { - var me, random, i; - - me = this; - - this._base.generate_from_dom.apply(this, arguments); - - random = NI.math.round(NI.math.random(10000,99999),0); - - this.internal.iframe_id = 'upload_iframe'+random; - this.internal.form_id = 'upload_form'+random; - - this.elements.input = this.$e.find('input[type=file]'); - - if(this.internal.o.loader){ - this.elements.loader = $(this.internal.o.loader); - } else { - this.elements.loader = $('

Loading...

'); - } - - this.elements.loader.css({ - display:'none' - }).appendTo(this.$e); - - if(this.internal.o.trigger){ - this.elements.trigger = $(this.internal.o.trigger); - - this.elements.input.css({ - position: 'absolute', - // in Opera only 'browse' button - // is clickable and it is located at - // the right side of the input - right: 0, - top: 0, - fontFamily: 'Arial', - // 4 persons reported this, the max values that worked for them were 243, 236, 236, 118 - fontSize: '118px', - margin: 0, - padding: 0, - cursor: 'pointer', - opacity: 0 - }); - - this.elements.input.bind('mouseover', {trigger:this.elements.trigger}, function(e,d){ - e.data.trigger.addClass('hover'); - }); - this.elements.input.bind('mouseout', {trigger:this.elements.trigger}, function(e,d){ - e.data.trigger.removeClass('hover'); - }); - this.elements.input.bind('mousedown', {trigger:this.elements.trigger}, function(e,d){ - e.data.trigger.addClass('down'); - }); - this.elements.input.bind('mouseup', {trigger:this.elements.trigger}, function(e,d){ - e.data.trigger.removeClass('down'); - }); - this.$e.append(this.elements.trigger); - } - - this.elements.iframe = $('') - .attr({ - id:this.internal.iframe_id, - name:this.internal.iframe_id, - src:'' - }).css({ - display:'none' - }); - - this.elements.form = $('
') - .attr({ - id:this.internal.form_id, - name:this.internal.form_id, - action:this.internal.o.url, - method:'POST', - enctype:'multipart/form-data', - target:this.internal.iframe_id - }); - - this.elements.input.wrap(this.elements.form); - this.elements.form = this.elements.input.parent(); - this.event_receiver = this.elements.form; - - if(this.internal.o.additional_values){ - for(i in this.internal.o.additional_values){ - this.elements.form.append(''); - } - } - - //window.file_input = this.elements.input.get(0); - - //console.log(this.elements.input); - - this.elements.input.bind('change',{},function(e,d){ - - e.stopPropagation(); - e.stopImmediatePropagation(); - - if(me.internal.o.trigger){ - me.elements.trigger.hide(); - } else { - //me.elements.input.hide(); - } - me.elements.loader.show(); - - me.elements.iframe.bind('load',{},function(e,d){ - var mydoc, mycontent, mytext; - - window.onbeforeunload = null; - me.elements.loader.hide(); - if(me.internal.o.trigger){ - me.elements.trigger.show(); - } else { - me.elements.input.show(); - } - me.elements.iframe.unbind('load'); - - if (this.contentDocument) { // DOM - mydoc = this.contentDocument; - } else if (iframeObject.contentWindow) { // IE win - mydoc = this.contentWindow.document; - } - if (mydoc) { - mycontent = mydoc.getElementsByTagName('body')[0]; - if(typeof mycontent.textContent != 'undefined'){ - mytext = mycontent.textContent; - } else if(typeof mycontent.innerText != 'sundefined'){ - mytext = mycontent.innerText; - } - } - - me.event_receiver.trigger('change',{data:$.parseJSON(mytext)}); - }); - - window.onbeforeunload = me.window_unload_handler; - document.getElementById(me.internal.form_id).submit(); - }); - - - - this.$e.append(this.elements.iframe); - - }, - - window_unload_handler: function(e){ - e = e || window.event; - // For IE and Firefox prior to version 4 - if (e) { - e.returnValue = false; - } - // For Safari - return false; - } - } - }); - - -}(this, this.jQuery)); \ No newline at end of file diff --git a/lib/field/tc.field.validator.js b/lib/field/tc.field.validator.js deleted file mode 100644 index 89c798e..0000000 --- a/lib/field/tc.field.validator.js +++ /dev/null @@ -1,197 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -// Dependencies: -// NI.field - -(function(window, $) { - - var NI = window.NI, - field = NI.field; - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - - function Validator(field, options) { - var me, o, internal; - - me = this; - o = $.extend({ - validators: null, - manager: null, - on_valid:function(e,d){}, - on_invalid:function(e,d){} - }, options); - - internal = { - managed_field:null - }; - - if (!o.manager || !(o.manager instanceof NI.ValidationManager)) { - o.manager = new NI.ValidationManager({ - watchEvents:['keyup', 'change', NI.field.co.SET_VAL_EVENT] - }); - } - - field.event_receiver.bind(NI.field.co.RESET_EVENT, {}, function(e,d){ - field.event_receiver.trigger('validationReset'); - }); - - field.event_receiver.bind(NI.field.co.VALIDATE_EVENT, {}, function(e,d){ - field.event_receiver.trigger('validate'); - }); - - field.event_receiver.bind('validationPass', {}, o.on_valid); - field.event_receiver.bind('validationFail', {field: field}, o.on_invalid); - field.event_receiver.data("master", field); - - internal.managed_field = o.manager.addField({ - element: field.event_receiver, - master: field, - validators: o.validators - }); - - this.get_managed_field = function(){ - return internal.managed_field; - }; - - this.add_validator = function(validator){ - var i, validators; - if($.isArray(validator)){ - for(i = 0; i < validator.length; i++){ - this.add_validator(validator[i]); - } - } else { - validators = internal.managed_field.data("validators"); - if($.inArray(validator, validators) == -1){ - validators.push(validator); - internal.managed_field.data("validators", validators); - } - } - - }; - - this.remove_validator = function(validator) { - var validators, index; - validators = internal.managed_field.data("validators"); - index = $.inArray(validator, validators); - if (index > -1) { - validators.splice(index, 1); - internal.managed_field.data("validators", validators); - } - }; - - } - - - function SimpleTooltipValidatorError(field, options){ - return new ValidatorError(field,$.extend({ - append_to: '.'+NI.field.co.SIMPLE_TOOLTIP_CLASS - }, options, { - hide_parent:true, - hide_siblings:true, - class_target: '.'+NI.field.co.SIMPLE_TOOLTIP_CLASS, - invalid_class:'invalid' - }) - ); - } - - function ValidatorError(field, options) { - var me, o, internal; - - me = this; - o = $.extend({ - append_to: field.$e, - hide_parent:false, - hide_siblings: false, - class_target:null, - invalid_class:'tc-field-validator-error-invalid' - }, options); - - internal = { - parent: null, - class_target:null, - $e: $('
'), - parent_was_hidden:null - }; - - internal.$e.hide(); - - function construct(){ - if(!internal.parent && o.append_to){ - internal.parent = (o.append_to instanceof $ ? o.append_to : field.$e.find(o.append_to)); - if(!$.contains(internal.parent.get(0), internal.$e.get(0))){ - internal.$e.appendTo(internal.parent); - } - } - if(!internal.class_target && o.class_target){ - internal.class_target = ( o.class_target instanceof $) ? o.class_target : field.$e.find(o.class_target); - } - } - - field.event_receiver.bind('validationPass validationReset', {field: field}, function(e, d){ - - if(internal.$e.parent().length){ - internal.$e.hide(); - - if(o.hide_parent && internal.parent_was_hidden === true){ - internal.parent.hide(); - } - internal.parent_was_hidden = null; - if(o.hide_siblings){ - internal.$e.siblings().show(); - } - } - - if(internal.class_target){ - internal.class_target.removeClass(o.invalid_class); - } - }); - - field.event_receiver.bind('validationFail', {field: field}, function(e, d){ - construct(); - - if(internal.$e.parent().length){ - internal.$e.text(d.errors.join(', ')); - internal.$e.show(); - - if(o.hide_parent && internal.parent.filter(':visible').length === 0){ - internal.parent_was_hidden = true; - internal.parent.show(); - } - - if(o.hide_siblings){ - internal.$e.siblings().hide(); - } - } - - if(internal.class_target){ - internal.class_target.addClass(o.invalid_class); - } - }); - - field.event_receiver.bind(NI.field.co.RESET_EVENT, {}, function(e,d){ - internal.$e.empty(); - }); - - } - - field.extensions.Validator = Validator; - field.extensions.SimpleTooltipValidatorError = SimpleTooltipValidatorError; - field.extensions.ValidatorError = ValidatorError; - -}(this, this.jQuery)); \ No newline at end of file diff --git a/lib/merlin/tc.merlin.autosave.js b/lib/merlin/tc.merlin.autosave.js deleted file mode 100644 index 9f9db2b..0000000 --- a/lib/merlin/tc.merlin.autosave.js +++ /dev/null @@ -1,105 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -(function(window, $) { - - var NI = window.NI; - - function MerlinAutosave(options){ - - var o, internal, _me; - - o = $.extend({ - keyup_delay:300, - change_delay:200, - saved_delay:1500, - prevent_invalid:false - },options); - - internal = { - save_timeout:null, - functions:null - }; - - _me = this; - - this.init = function(me, functions){ - - internal.functions = functions; - - for(i in me.internal.current_step.fields){ - - if(!me.internal.current_step.fields[i].component){ - continue; - } - - me.internal.current_step.fields[i].component.event_receiver.bind('change keyup',{ name:i, },function(e,d){ - - if(internal.save_timeout){ clearTimeout(internal.save_timeout); } - - if(o.prevent_invalid){ - if(me.internal.current_step.$e.hasClass('state-invalid')){ - return; - } - } - - me.internal.current_step.$e.addClass('merlin-autosave-state-unsaved') - .removeClass('merlin-autosave-state-unsaved') - .removeClass('merlin-autosave-state-saved'); - - internal.save_timeout = setTimeout(function(){ - _me.save(me, functions); - },((e.type == 'keyup') ? o.keyup_delay : o.change_delay)); - }); - } - - }; - - this.save = function(me){ - if(internal.save_timeout){ clearTimeout(internal.save_timeout); } - - function saved(){ - me.internal.current_step.$e.addClass('merlin-autosave-state-saved') - .removeClass('merlin-autosave-state-unsaved') - .removeClass('merlin-autosave-state-saving'); - if($.isFunction(internal.functions.saved)){ - internal.functions.saved(); - } - } - - me.internal.current_step.$e.addClass('merlin-autosave-state-saving') - .removeClass('merlin-autosave-state-unsaved') - .removeClass('merlin-autosave-state-saved'); - - if($.isFunction(internal.functions.save)){ - internal.functions.save(saved); - } else { - saved(); - } - }; - - this.visible = function(me){ - - }; - - }; - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - NI.MerlinAutosave = MerlinAutosave; - -}(this, this.jQuery)); \ No newline at end of file diff --git a/lib/merlin/tc.merlin.csrf.js b/lib/merlin/tc.merlin.csrf.js deleted file mode 100644 index a969616..0000000 --- a/lib/merlin/tc.merlin.csrf.js +++ /dev/null @@ -1,57 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -(function(window, $) { - - var NI = window.NI; - - function MerlinCSRF(options){ - - var o, internal; - - o = $.extend({ - csrf_input_name:'csrfmiddlewaretoken' - },options); - - internal = { - data:{} - }; - - - this.init = function(me){ - var csrf_input; - - csrf_input = me.internal.current_step.$e.find('input[name="'+o.csrf_input_name+'"]'); - - if(csrf_input.length){ - internal.data[o.csrf_input_name] = csrf_input.val(); - me.set_val(o.csrf_input_name,csrf_input.val()); - } - - }; - - this.get_data = function(){ - return internal.data; - }; - - }; - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - NI.MerlinCSRF = MerlinCSRF; - -}(this, this.jQuery)); \ No newline at end of file diff --git a/lib/merlin/tc.merlin.data.js b/lib/merlin/tc.merlin.data.js deleted file mode 100644 index 7f9d0c6..0000000 --- a/lib/merlin/tc.merlin.data.js +++ /dev/null @@ -1,182 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -(function(window, $) { - - var NI = window.NI; - - function MerlinData(options){ - - var o, internal; - - o = $.extend({ - uri:'', - data:{}, - post_unchanged_data:true, - post_method:'POST' - },options); - - internal = { - uri:o.uri, - base_data:$.extend({},o.data), - data:$.extend({},o.data) - }; - - this.init = function(me){ - var i; - - if(me.data){ - internal.data = $.extend(internal.data,me.data); - } - - me.get_data = this.get_data; - me.set_data = this.set_data; - - me.get_val = this.get_val; - me.set_val = this.set_val; - } - - this.populate_fields = function(me,fields){ - - var i; - - if(fields){ - for(i in fields){ - if(me.internal.current_step.fields[fields[i]] && internal.data[fields[i]]){ - if(me.internal.current_step.fields[fields[i]].component.get_val() != this.get_val(fields[i])){ - me.internal.current_step.fields[fields[i]].component.set_val(this.get_val(fields[i]),true); - } - } - } - } else { - for(i in this.get_data()){ - - if(me.internal.current_step.fields[i]){ - if(!me.internal.current_step.fields[i].component){ - continue; - } - if(me.internal.current_step.fields[i].component.get_val() != this.get_val(i)){ - me.internal.current_step.fields[i].component.set_val(this.get_val(i),true); - } - } - } - } - - }; - - this.collect_fields = function(me, fields){ - - var i, temp_name, changed; - - changed =[]; - - if(fields){ - for(i in fields){ - if(me.internal.current_step.fields[fields[i]]){ - if(me.internal.current_step.fields[fields[i]].component.get_val() != internal.base_data[i] && i != 'csrfmiddlewaretoken'){ - changed.push(i); - } - this.set_val(fields[i], me.internal.current_step.fields[fields[i]].component.get_val()); - } - } - } else { - for(i in this.get_data()){ - if(me.internal.current_step.fields[i]){ - if(!me.internal.current_step.fields[i].component){ - continue; - } - if(me.internal.current_step.fields[i].component.get_val() != internal.base_data[i] && i != 'csrfmiddlewaretoken'){ - changed.push(i); - } - this.set_val(i, me.internal.current_step.fields[i].component.get_val()); - } - } - } - - return changed; - - }; - - this.get_uri = function(){ - return internal.uri; - }; - - this.set_uri = function(uri){ - internal.uri = uri; - }; - - this.get_data = function(){ - return internal.data; - }; - - this.set_data = function(new_data,use_for_base_data){ - internal.data = new_data; - if(use_for_base_data){ - internal.base_data = $.extend({},new_data); - } - }; - - this.get_val = function(id){ - return internal.data[id]; - }; - - this.set_val = function(id,new_val){ - internal.data[id] = new_val; - }; - - this.post_data = function(callback,options){ - - var cleaned_data, i; - - cleaned_data = $.extend({},this.get_data()); - - for(i in cleaned_data){ - if(cleaned_data[i] === null){ - delete cleaned_data[i]; - } - if(o.post_unchanged_data === false){ - if(cleaned_data[i] === internal.base_data[i] && i != 'csrfmiddlewaretoken'){ - delete cleaned_data[i]; - } - } - } - - $.ajax({ - type:o.post_method, - url:internal.uri, - data:cleaned_data, - success:function(d,ts,xhr){ - internal.base_data = $.extend(internal.base_data,cleaned_data); - callback(d); - }, - error: function(){ - d = false; - callback(d); - } - }); - - }; - - - - }; - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - NI.MerlinData = MerlinData; - -}(this, this.jQuery)); \ No newline at end of file diff --git a/lib/particle/tc.particle.context.js b/lib/particle/tc.particle.context.js deleted file mode 100644 index b6f4601..0000000 --- a/lib/particle/tc.particle.context.js +++ /dev/null @@ -1,201 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -if(!tc){ var tc = {}; } - -(function(tc) { - - - (function requestAnimationFrame() { - var lastTime = 0; - var vendors = ['ms', 'moz', 'webkit', 'o']; - for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { - window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; - window.cancelAnimationFrame = - window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame']; - } - - if(!window.requestAnimationFrame) - window.requestAnimationFrame = function(callback, element) { - var currTime = new Date().getTime(); - var timeToCall = Math.max(0, 16 - (currTime - lastTime)); - var id = window.setTimeout(function() { callback(currTime + timeToCall); }, timeToCall); - lastTime = currTime + timeToCall; - return id; - }; - - if(!window.cancelAnimationFrame) - window.cancelAnimationFrame = function(id) { - clearTimeout(id); - }; - }()); - - if(!tc.particle){ tc.particle = {}; } - - tc.particle.context = function(dom,options){ - var _me, o; - _me = dom; - - o = $.extend({ - fps:30, - bounds: { - min_x: 0, - max_x: 1000, - min_y: 0, - max_y: 1000 - }, - bg_image:null - },options); - - this.initialize = function(){ - _me.context = _me.get(0).getContext('2d'); - _me.forces = []; - _me.particles = []; - _me.frame = 0; - _me.stopped = true; - _me.timer = null; - _me.mouse_pos = null; - _me.mouse_down_pos = null; - - _me.bounds = o.bounds; - _me.net_energy = 0; - if(o.bg_image){ - _me.bg_image = new Image(); - _me.bg_image.src = o.bg_image; - } - return _me; - } - - _me.setSize = function(size){ - _me.bounds = { - min_x: 0, - max_x: size.width, - min_y: 0, - max_y: size.height - }; - _me.css(size).attr('width',size.width).attr('height',size.height); - _me.anchor_offset = { - x:size.width/2, - y:size.height/3 - } - for(i = 0; i < _me.particles.length; i++){ - _me.particles[i]['set_anchor_offset'](_me.anchor_offset); - } - } - - _me.add_particle = function(particle){ - _me.particles.push(particle); - return _me.particles[_me.particles.length-1]; - } - - _me.add_global_force = function(pos, strength, radius){ - var force; - if(pos.x && pos.y){ - force = { - pos:Vector.create([pos.x,pos.y]), - strength:strength, - radius:radius - }; - _me.forces.push(force); - return _me.forces[_me.forces.length-1]; - } - } - - _me.update = function(){ - _me.frame++; - _me.net_energy = 0; - for(i = 0; i < _me.forces.length; i++){ - _me.forces[i].radius = (_me.forces[i].radius * 0.98); - } - if(_me.stopped){ - window.cancelAnimationFrame(); - } else { - window.requestAnimationFrame(_me.update); - for(i = 0; i < _me.particles.length; i++){ - _me.particles[i]['reset_forces'](); - _me.particles[i]['add_forces'](_me.forces); - _me.particles[i]['bounce_off_walls'](_me.bounds); - _me.particles[i]['handle_anchor'](); - //_me.particles[i]['collide_with_particles'](_me.particles,i); - _me.particles[i]['add_damping'](); - _me.particles[i]['update'](); - _me.net_energy = _me.net_energy + _me.particles[i].norm_dist_from_anchor; - } - _me.net_energy = _me.net_energy / _me.particles.length; - _me.mouse_down_pos = null; - _draw(); - } - - } - - _me.start = function(){ - _me.mouse_pos = null; - _me.mouse_down_pos = null; - if(_me.stopped){ - _me.stopped = false; - window.requestAnimationFrame(_me.update); - } - } - - _me.stop = function(){ - _me.stopped = true; - } - - function _draw(drawing_context){ - var opacity, i, alpha; - - _me.context.globalAlpha = 1.0; - _me.context.fillStyle = 'rgba(252,252,252,0.45)'; - _me.context.fillRect( - 0, - 0, - _me.bounds.max_x, - _me.bounds.max_y - ); - - if(_me.net_energy < 0.2 && _me.bg_image){ - opacity = (0.2/(_me.net_energy < 0.01 ? 0.01 : _me.net_energy)/20); - _me.context.globalAlpha = opacity - 0.01; - _me.context.drawImage( - _me.bg_image, - _me.anchor_offset.x-358, - _me.anchor_offset.y - ); - } - - if(opacity){ - alpha = 1.0 - opacity + 0.01; - } else { - alpha = 1.0; - } - - _me.context.globalAlpha = alpha; - - _me.context.fillStyle = '#000000'; - for(i = 0; i < _me.particles.length; i++){ - _me.particles[i].draw(_me.context); - } - } - - function _render(){ - - } - - return this.initialize(); - } - -})(tc); \ No newline at end of file diff --git a/lib/particle/tc.particle.particle.js b/lib/particle/tc.particle.particle.js deleted file mode 100644 index dd62a7f..0000000 --- a/lib/particle/tc.particle.particle.js +++ /dev/null @@ -1,238 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -if(!tc){ var tc = {}; } - -(function(tc) { - if(!tc.particle){ tc.particle = {}; } - - tc.particle.particle = function(options){ - var _me, o, damping, color; - _me = this; - - var pos, - vel, - frc; - - color = new NI.Color(); - - this.options = $.extend({ - pos:{x:0,y:0}, - vel:{x:0,y:0}, - frc:{x:0,y:0}, - anchored:false, - anchor:{x:0,y:0}, - damping:0.89, - radius:5, - draw:function(context){ - context.beginPath(); - context.arc(this.pos.elements[0], this.pos.elements[1], this.o.radius, 0, (2*Math.PI), false); - context.fill(); - context.closePath(); - }, - color:"000000", - opacity:0.65, - attraction_coefficient: 1.0, - data:{}, - anchor_offset:{ - x:0, - y:0 - } - },options); - - o = this.options; - - this.initialize = function(){ - _me.pos = Vector.create([o.pos.x, o.pos.y]); - vel = Vector.create([o.vel.x, o.vel.y]); - frc = Vector.create([o.frc.x, o.frc.y]); - _me.anchor = Vector.create([ - (0+o.anchor.x+o.anchor_offset.x), - (0+o.anchor.y+o.anchor_offset.y) - ]); - _me.radius = o.radius; - _me.diameter = o.radius*2; - if(_me.options.opacity < 1.0){ - _me.fill = "rgba("+color.getRGBFromHex('r',o.color)+","+color.getRGBFromHex('g',o.color)+","+color.getRGBFromHex('b',o.color)+","+o.opacity+")"; - } else { - _me.fill = "#"+o.color; - } - _me.jitter = null; - _me.norm_dist_from_anchor = 0; - } - - _me.set_anchor_offset = function(offset){ - _me.anchor.elements[0] = (0+o.anchor.x+offset.x); - _me.anchor.elements[1] = (0+o.anchor.y+offset.y); - } - - _me.worker = function(new_worker){ - if(new_worker){ - _me.worker = new_worker; - } else { - return _me.worker; - } - } - - _me.name = function(new_name){ - if(new_name){ - _me.options.name = new_name; - } else { - return _me.options.name; - } - } - - _me.pos = function(new_pos){ - if(new_pos){ - _me.pos = new_pos; - } else { - return _me.pos; - } - } - - _me.vel = function(new_vel){ - if(new_vel){ - vel = new_vel; - } else { - return vel; - } - } - - _me.frc = function(new_frc){ - if(new_frc){ - frc = new_frc; - } else { - return frc; - } - } - - _me.radius = function(new_radius){ - if(new_radius){ - _me.options.radius = new_radius; - } else { - return _me.options.radius; - } - } - - _me.reset_forces = function(){ - frc.setElements([0, 0]); - damping = _me.options.damping; - } - - _me.add_forces = function(forces){ - var distance, length, pct, normal_distance; - for(var i = 0; i < forces.length; i++){ - distance = _me.pos.subtract(forces[i].pos); - length = Math.sqrt(distance.dot(distance)); - if(length < forces[i].radius){ - pct = (1 - (length / forces[i].radius)) * 20/o.radius ; - normal_distance = distance.multiply(1/length); - frc.elements[0] = frc.elements[0] - normal_distance.elements[0] * - forces[i].strength * pct * o.attraction_coefficient; - frc.elements[1] = frc.elements[1] - normal_distance.elements[1] * - forces[i].strength * pct * o.attraction_coefficient; - } - } - } - - _me.bounce_off_walls = function(bounds){ - var b_did_i_collide; - b_did_i_collide = false; - - if(_me.pos.elements[0] < bounds.min_x + o.radius){ - _me.pos.elements[0] = o.radius; - b_did_i_collide = true; - vel.elements[0] = vel.elements[0] * -1.0; - }else if(_me.pos.elements[0] > bounds.max_x - o.radius){ - _me.pos.elements[0] = bounds.max_x - o.radius; - b_did_i_collide = true; - vel.elements[0] = vel.elements[0] * -1.0; - } - - if(_me.pos.elements[1] < bounds.min_y + o.radius){ - _me.pos.elements[1] = o.radius; - b_did_i_collide = true; - vel.elements[1] = vel.elements[1] * -1.0; - }else if(_me.pos.elements[1] > bounds.max_y - o.radius){ - _me.pos.elements[1] = bounds.max_y - o.radius; - b_did_i_collide = true; - vel.elements[1] = vel.elements[1] * -1.0; - } - - if(b_did_i_collide){ - vel = vel.multiply(0.3); - } - } - - _me.handle_anchor = function(){ - if(!_me.anchor){ return; } - var distance, length, pct, normal_distance; - distance = _me.pos.subtract(_me.anchor); - length = Math.sqrt(distance.dot(distance)); - - if(length <= 0.5){ - return; - } - - pct = (length / 1000); - normal_distance = distance.multiply(1/length); - _me.norm_dist_from_anchor = (length / 100); - frc.elements[0] = frc.elements[0] - normal_distance.elements[0] * 10 * pct; - frc.elements[1] = frc.elements[1] - normal_distance.elements[1] * 10 * pct; - } - - _me.collide_with_particles = function(particles,j){ - for(var i = 0; i < particles.length; i++){ - if(i != j){ - var distance = _me.pos.subtract(particles[i].pos) - var length = Math.sqrt(distance.dot(distance)) - if(length < (o.radius + particles[i].radius())+2){ - var pct = 1 - (length / (o.radius + particles[i].radius() + 2)) - var normal_distance = distance.multiply((1/(length/4))) - frc.elements[0] = frc.elements[0] - normal_distance.elements[0] * -0.7// * pct - frc.elements[1] = frc.elements[1] - normal_distance.elements[1] * -0.7// * pct - } - } - } - } - - _me.stop = function(){ - frc.setElements([0, 0]) - vel.setElements([0, 0]) - } - - _me.add_damping = function(){ - vel = vel.multiply(damping); - } - - _me.update = function(){ - vel = vel.add(frc); - _me.pos = _me.pos.add(vel); - if(_me.jitter){ - _me.pos.elements[0] += _me.jitter.x; - _me.pos.elements[1] += _me.jitter.y; - _me.jitter = null; - } - } - - _me.draw = function(context){ - this.options.draw.call(_me,context); - } - - return this.initialize(); - } -})(tc); diff --git a/lib/tc.anim_util.js b/lib/tc.anim_util.js deleted file mode 100644 index d95899c..0000000 --- a/lib/tc.anim_util.js +++ /dev/null @@ -1,124 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -(function(window) { - - var NI = window.NI, - TWO_PI = 2*window.Math.PI; - - var requestAnimFrame = (function() { - var fn; - - fn = window.requestAnimationFrame || - window.webkitRequestAnimationFrame || - window.mozRequestAnimationFrame || - window.oRequestAnimationFrame || - window.msRequestAnimationFrame || - function(/* function */ callback, /* DOMElement */ element){ - window.setTimeout(callback, 1000 / 60); - }; - - return function() { - fn.apply(window, arguments); - }; - - }()); - - function Cycler(options) { - - var me, o, internal; - - me = this; - o = $.extend({ - speed: window.Math.PI / 600, - cycling: false, - - // callbacks - on_play: $.noop, - on_pause: $.noop, - on_before_update: $.noop, //return false to cancel an update - on_update: $.noop, - on_cycle_complete: $.noop - }, options); - - function init() { - internal = { - cycling: false, - theta: 0, - speed: null - }; - me.setSpeed(o.speed); - me[o.cycling ? "play" : "pause"](); - } - - function loop() { - if (internal.cycling) { - requestAnimFrame(loop); - } else { - return; - } - if (o.on_before_update.apply(me) !== false) { - internal.theta += internal.speed; - if (internal.theta >= TWO_PI) { - internal.theta -= TWO_PI; - o.on_cycle_complete.apply(me); - } - o.on_update.apply(me, [internal.theta]); - } - } - - this.play = function() { - if (!internal.cycling) { - o.on_play.apply(me); - internal.cycling = true; - loop(); - } - return this; - }; - - this.pause = function() { - internal.cycling = false; - o.on_pause.apply(me); - return this; - }; - - this.isCycling = function() { - return internal.cycling; - }; - - this.reset = function() { - internal.theta = 0; - return this; - }; - - this.setSpeed = function(speed) { - if (typeof speed === "number") { - internal.speed = speed; - } - return this; - }; - - init(); - } - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - NI.anim = NI.anim || {}; - NI.anim.requestAnimFrame = requestAnimFrame; - NI.anim.Cycler = Cycler; - -}(this)); diff --git a/lib/tc.animator.js b/lib/tc.animator.js deleted file mode 100644 index 779c094..0000000 --- a/lib/tc.animator.js +++ /dev/null @@ -1,98 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -(function(window, $) { - - var NI = window.NI; - - function Animator(options) { - var o, internal, animations, finished_animations, running; - - o = $.extend({ - preCalculate: false, - fps:30 - }, options); - - internal = { - interval:0.0 - }; - - animations = []; - finished_animations = []; - - function init(){ - internal.interval = 1000/o.fps; - } - - function start(){ - running = true; - setTimeout(run,internal.interval); - } - - function run(){ - var i, n_animations; - - if(!animations.length){ - astop(); - return; - } - - for(i in animations){ - //Check duration; - if(!animations[i].start_time){ - animations[i].start_time = Date.now(); - } else { - animations[i].pct = (Date.now() - animations[i].start_time) / animations[i].duration; - if(animations[i].pct > 1){ - if(animations[i].finish){ - animations[i].finish(animations[i]); - } - finished_animations.push(animations[i]); - animations.splice(i); - continue; - } - } - - if(animations[i].func){ - animations[i].func(animations[i]); - } - } - - setTimeout(run,internal.interval); - } - - function astop(){ - running = false; - } - - this.addAnimation = function(name,animation){ - animation.pct = 0; - animation.start_time = null; - animations.push(animation); - if(!running){ - start(); - } - }; - - init(); - } - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - NI.Animator = Animator; - -}(this, this.jQuery)); \ No newline at end of file diff --git a/lib/tc.app.js b/lib/tc.app.js deleted file mode 100644 index 2ef5986..0000000 --- a/lib/tc.app.js +++ /dev/null @@ -1,88 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -if(!window.NI){ - window.NI = { - constants: {} - }; - window.console = (function() { - if (typeof window.console !== "undefined" && typeof window.console.debug !== "undefined") { - return window.console; - } - window.console = {}; - $.each(("assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn").split(","), function() { - window.console[this] = $.noop; - }); - })(); -} - -window.page = { - classes:{}, - features:[] -}; - -//window.console = NI.app.getConsole(true); - -(function(window, $) { - - var NI = window.NI; - - function App(options) { - var o, i; - - o = $.extend({ - name:'', - page:{ - classes: {}, - features: [] - }, - inner_page: { - classes: {}, - features: [] - } - }, options); - - this.classes = o.page.classes; - this.events = $({}); - this.runtime = {}; - - this.initialize_features(o.page.features); - this.initialize_features(o.inner_page.features); - o.page.initialized = true; - - this.events.trigger('app.featuresInitialized'); - } - - App.prototype.initialize_features = function(features) { - var i; - - if(features.length){ - for(i = 0; i < features.length; i += 1){ - if($.isFunction(features[i])){ - if(features[i](this) === false){ - break; - } - } - } - } - }; - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - NI.App = App; - -}(this, this.jQuery)); \ No newline at end of file diff --git a/lib/tc.browser_detection.js b/lib/tc.browser_detection.js deleted file mode 100644 index 58aa836..0000000 --- a/lib/tc.browser_detection.js +++ /dev/null @@ -1,151 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -(function(window, $) { - - var NI = window.NI; - - function BrowserDetection(options) { - var o, elements; - - o = $.extend({ - addClassToBody:true, - orientationListen:false, - detectWebApp:true - }, options); - - elements = { - body:$('body') - }; - - function init(){ - var userAgent = navigator.userAgent; - var appVersion = navigator.appVersion; - var browser = $.browser; - - // check if browser is webkit... - if (browser.webkit) { - if(o.addClassToBody){ - elements.body.addClass('browser-webkit'); - }; - - // check if it's chrome, safari, or an iOS browser - if (userAgent.match(/iPad/i) != null) { - if(o.addClassToBody){ - elements.body.addClass('browser-ipad os-ios'); - }; - if(o.orientationListen){ - listenToOrientationChange(); - }; - if(o.detectWebApp){ - if (window.navigator.standalone) { elements.body.addClass('ios-webapp') } - } - } else if(userAgent.match(/iPhone/i) || userAgent.match(/iPod/i)) { - if(o.addClassToBody){ - elements.body.addClass('browser-iphone os-ios'); - }; - if(o.orientationListen){ - listenToOrientationChange(); - }; - if(o.detectWebApp){ - if (window.navigator.standalone) { elements.body.addClass('ios-webapp') } - } - } else if(userAgent.match(/Chrome/i)) { - if(o.addClassToBody){ - elements.body.addClass('browser-chrome'); - }; - } else if(userAgent.match(/Safari/i)) { - if(o.addClassToBody){ - elements.body.addClass('browser-safari'); - }; - } - - // ...if browser is NOT webkit, run through the other browsers - } else { - if (browser.msie) { - if(o.addClassToBody){ - elements.body.addClass('browser-ie'); - }; - } else if (browser.mozilla) { - if(o.addClassToBody){ - elements.body.addClass('browser-firefox'); - }; - } else if (browser.opera) { - if(o.addClassToBody){ - elements.body.addClass('browser-opera'); - }; - } - }; - - - // now, detect operating systems - if (appVersion.indexOf("Mac")!=-1) { - if(o.addClassToBody){ - elements.body.addClass('os-mac'); - }; - } else if (appVersion.indexOf("Win")!=-1) { - if(o.addClassToBody){ - elements.body.addClass('os-win'); - }; - } else if (appVersion.indexOf("X11")!=-1) { - if(o.addClassToBody){ - elements.body.addClass('os-unix'); - }; - } else if (appVersion.indexOf("Linux")!=-1) { - if(o.addClassToBody){ - elements.body.addClass('os-linux'); - }; - } else { - if(o.addClassToBody){ - elements.body.addClass('os-unknown'); - }; - }; - - }; - - - - function listenToOrientationChange() { - - function orientationChanged(orientation) { - if (orientation === 0){ - elements.body.removeClass('portrait landscape').addClass('portrait'); - } else if (orientation === 180){ - elements.body.removeClass('portrait landscape').addClass('portrait'); - } else if (orientation === 90){ - elements.body.removeClass('portrait landscape').addClass('landscape'); - } else if (orientation === -90){ - elements.body.removeClass('portrait landscape').addClass('landscape'); - } - } - - orientationChanged(window.orientation); - - window.onorientationchange = function(){ - var orientation = window.orientation; - orientationChanged(orientation) - }; - } - - init(); - } - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - NI.BrowserDetection = BrowserDetection; - -}(this, this.jQuery)); \ No newline at end of file diff --git a/lib/tc.carousel.js b/lib/tc.carousel.js deleted file mode 100644 index 3e8154c..0000000 --- a/lib/tc.carousel.js +++ /dev/null @@ -1,501 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -// this carousel implementation is based on the jQuery Tools "scrollable" implementation: -// https://github.com/jquerytools/jquerytools/blob/master/src/scrollable/scrollable.js - -(function(window, $) { - - var NI = window.NI, - generate, - focussed; - - generate = { - carousel: function() { - return $(""); - }, - prevBtn: function(instance) { - var $btn; - $btn = $("Previous"); - if (instance) { - $btn.click(function(e) { - e.preventDefault(); - instance.prev(); - }); - } - return $btn; - }, - nextBtn: function(instance) { - var $btn; - $btn = $("Next"); - if (instance) { - $btn.click(function(e) { - e.preventDefault(); - instance.next(); - }); - } - return $btn; - } - }; - - function Carousel(options) { - var me, o, $e, selectors, $elements, events, touchInfo; - - me = this; - o = $.extend({ - container: null, - viewportDimensions: null, // { width: null, height: null }, - panels: [], - panelClass: "panel", - activeClass: "state-active", - disabledClass: "state-disabled", - cloneClass: "clone", - speed: 400, - easing: "swing", - vertical: false, - circular: true, - elastic: false, - keyboard: true, - touch: true, - onBeforeMove: function(instance, info) {}, - onMove: function(instance, info) {} - }, options); - - function init() { - var $viewport; - - if (o.container) { - if (typeof o.container === "string") { - o.container = $(o.container); - } - $e = o.container; - } else { - $e = generate.carousel(); - } - - selectors = { - panel: "."+o.panelClass, - active: "."+o.activeClass, - clone: "."+o.cloneClass - }; - - $viewport = $e.find(".viewport"); - $elements = { - viewport: $viewport, - scroll: $viewport.children(".scroll"), - currentTarget: null, - prevBtn: null, - nextBtn: null - }; - - if (o.viewportDimensions) { - if (o.elastic) { - o.viewportDimensions = null; - } else { - if (typeof o.viewportDimensions.width === "number") { - $elements.viewport.width(o.viewportDimensions.width); - - } - if (typeof o.viewportDimensions.height === "number") { - $elements.viewport.height(o.viewportDimensions.height); - } - } - } - - if (o.keyboard) { - $(window.document).bind("keydown.carousel", events.keydown); - } - - if (o.touch) { - touchInfo = {}; - $elements.scroll[0].ontouchstart = events.touchstart; - $elements.scroll[0].ontouchmove = events.touchmove; - } - - if (o.elastic) { - syncElasticPanels(); - $(window).bind("resize", events.elasticResize); - } - - if (o.panels && o.panels.length) { - $.each(o.panels, function(i, $panel) { - me.add($panel); - }); - } - - me.setOrientation(o.vertical); - me.begin(true); - } - - function current() { - return $elements.scroll.children(selectors.panel + selectors.active); - } - - function targetPosition($panel) { - if (o.vertical) { - if (o.viewportDimensions && typeof o.viewportDimensions.height === "number") { - return {top: -($panel.index()*o.viewportDimensions.height)}; - } - return {top: -($panel.position().top)}; - } - if (o.viewportDimensions && typeof o.viewportDimensions.width === "number") { - return {left: -($panel.index()*o.viewportDimensions.width)}; - } - return {left: -($panel.position().left)}; - } - - function moveTo($panel, noAnimate) { - var $cloneTarget = false, info; - - if (!$panel.length) { - return me; - } - - $elements.currentTarget = $panel; - - // Determine if the target panel is a clone. - // If it is, keep track of the real panel as $cloneTarget - if ($panel.hasClass(o.cloneClass)) { - $cloneTarget = $elements.scroll.children(selectors.panel).not(selectors.clone)[$panel.hasClass("head") ? "last" : "first"](); - $cloneTarget.addClass(o.activeClass).siblings().removeClass(o.activeClass); - } else { - $panel.addClass(o.activeClass).siblings().removeClass(o.activeClass); - } - - info = me.info(); - - if ($.isFunction(o.onBeforeMove)) { - if (o.onBeforeMove(me, info) === false) { - return me; - } - } - - $elements.scroll.stop(true, false).animate(targetPosition($panel), (noAnimate ? 0 : o.speed), o.easing, function() { - - $elements.currentTarget = null; - - if ($cloneTarget) { - $elements.scroll.css(targetPosition($cloneTarget)); - } - - if (!o.circular) { - if ($elements.prevBtn.length) { - $elements.prevBtn[info.index === 0 ? "addClass" : "removeClass"](o.disabledClass); - } - if ($elements.nextBtn.length) { - $elements.nextBtn[info.index === info.total-1 ? "addClass" : "removeClass"](o.disabledClass); - } - } - - if ($.isFunction(o.onMove)) { - o.onMove(me, info); - } - } - ); - - return me; - } - - function syncElasticPanels($panel) { - var w, h; - w = $e.width(); - h = $e.height(); - if (!$panel) { - $panel = $elements.scroll.children(selectors.panel); - } - $panel.width(w).height(h); - } - - events = { - keydown: function(e) { - var key; - - if (focussed != me) { - return; - } - - if (me.info().total < 2) { - return; - } - - key = e.which; - - switch (key) { - case NI.co.keyboard.LEFT: - e.preventDefault(); - me.prev(); - break; - case NI.co.keyboard.RIGHT: - e.preventDefault(); - me.next(); - break; - } - }, - touchstart: function(e) { - touchInfo.x = e.touches[0].clientX; - touchInfo.y = e.touches[0].clientY; - }, - touchmove: function(e) { - var dx, dy; - if (e.touches.length === 1 && !$elements.scroll.is(":animated")) { - e.preventDefault(); - dx = touchInfo.x - e.touches[0].clientX; - dy = touchInfo.y - e.touches[0].clientY; - me[o.vertical && dy > 0 || !o.vertical && dx > 0 ? "next" : "prev"](); - } - }, - elasticResize: NI.fn.debounce(function(e) { - syncElasticPanels(); - me.syncCurrentAnimation(); - }, 100) - }; - - function registerBtn(key) { - var $btn; - $btn = generate[key](me); - - if ($elements[key]) { - $elements[key].add($btn); - } else { - $elements[key] = $btn; - } - - return $btn; - } - - // return an object with a reference to the currently active panel, - // the current index, and the total number of panels - this.info = function() { - var $panels, $current, index; - $panels = $elements.scroll.children(selectors.panel).not(selectors.clone); - $panels.each(function(i, panel) { - var $p = $(panel); - if ($p.hasClass(o.activeClass)) { - $current = $p; - index = i; - return false; - } - }); - return { - $current: $current, - index: index, - total: $panels.length - }; - }; - - // add a panel to the end of the carousel - // (chainable) - this.add = function($panel) { - $panel.addClass(o.panelClass); - if (!o.vertical) { - $panel.css("float", "left"); - } - if (o.elastic) { - syncElasticPanels($panel); - } else if (o.viewportDimensions) { - if (typeof o.viewportDimensions.width === "number") { - $panel.width(o.viewportDimensions.width); - } - if (typeof o.viewportDimensions.height === "number") { - $panel.height(o.viewportDimensions.height); - } - } - $elements.scroll.append($panel); - return this; - }; - - // remove a panel from the carousel, - // (return the removed panel) - this.remove = function($panel) { - var info, panelIndex, currentIndex; - - if (!($.contains($elements.scroll[0], $panel[0])) || $panel.hasClass(o.cloneClass)) { - return false; - } - - info = this.info(); - - if (info.total === 1) { - $elements.scroll.children(selectors.clone).remove(); - return $panel.detach(); - } - - panelIndex = $panel.index(); - currentIndex = info.$current.index(); - - $panel.detach(); - - // if the removed panel came before the currently active panel, - // update the offset of the scroll element - if (panelIndex < currentIndex) { - moveTo(info.$current, true); - } - // if the removed panel was the currently active panel, - // activate the previous sibling panel - else if (panelIndex === currentIndex) { - this.toIndex(currentIndex-1, true); - } - - return $panel; - }; - - // generate a "previous" button bound to this instance - // return a headless jQuery element representing the button - this.registerPrevBtn = function() { - return registerBtn("prevBtn"); - }; - - // generate a "next" button bound to this instance - // return a headless jQuery element representing the button - this.registerNextBtn = function() { - return registerBtn("nextBtn"); - }; - - // return the jQuery container element that represents the carousel - this.get = function() { - return $e; - }; - - // Tell the Carousel to check itself before it wr-wr-wrecks itself. - // If the Carousel is circular, generate its secret clone elements. - // The Carousel should be refreshed after panels have been added to or removed from it. - // add() and remove() do not automatically call refresh() (to allow for simultaneous calls - // to manipulate the Carousel in row, without consecutively refreshing). - // (chainable) - this.refresh = function() { - var $panels; - if (o.circular) { - $elements.scroll.children(selectors.clone).remove(); - $panels = $elements.scroll.children(selectors.panel); - $panels.last().clone(false).addClass(o.cloneClass +" head").prependTo($elements.scroll); - $panels.first().clone(false).addClass(o.cloneClass +" tail").appendTo($elements.scroll); - } - return this; - }; - - - // move to the first panel and automatically refresh - // (unless noRefresh is true) - // (chainable) - this.begin = function(noAnimate, noRefresh) { - if (!noRefresh) { - this.refresh(); - } - return moveTo($elements.scroll.children(selectors.panel).not(selectors.clone).first(), noAnimate); - }; - - // move to the last panel - // (chainable) - this.end = function(noAnimate) { - return moveTo($elements.scroll.children(selectors.panel).not(selectors.clone).last(), noAnimate); - }; - - // move to the panel at the specified index - // (chainable) - this.toIndex = function(index, noAnimate) { - $elements.scroll.children(selectors.panel).not(selectors.clone).each(function(i, panel) { - if (i === index) { - moveTo($(panel), noAnimate); - return false; - } - }); - return this; - }; - - // move to the next panel - // (chainable) - this.next = function(noAnimate) { - return moveTo(current().next(selectors.panel), noAnimate); - }; - - // move to the previous panel - // (chainable) - this.prev = function(noAnimate) { - return moveTo(current().prev(selectors.panel), noAnimate); - }; - - // set focus on this carousel - // (chainable) - this.focus = function() { - focussed = me; - return me; - }; - - // remove focus from this carousel - // (chainable) - this.blur = function() { - if (focussed == me) { - focussed = null; - } - return me; - }; - - // set the carousel to vertical or horizontal - // (chainable) - this.setOrientation = function(vertical) { - if (vertical === true) { - o.vertical = true; - $e.addClass('orientation-vertical'); - $e.removeClass('orientation-horizontal'); - } else { - o.vertical = false; - $e.removeClass('orientation-vertical'); - $e.addClass('orientation-horizontal'); - } - return me; - }; - - this.syncCurrentAnimation = function() { - if ($elements.currentTarget) { - moveTo($elements.currentTarget, true); - } else { - moveTo(current(), true); - } - }; - - // destroy this instance - // (the carousel element is automatically removed from the DOM) - this.destroy = function() { - me.blur(); - if (o.elastic) { - $(window).unbind("resize", events.elasticResize); - } - if (o.keyboard) { - $(window.document).unbind("keydown.carousel", events.keydown); - } - if ($elements.prevBtn && $elements.prevBtn.length) { - $elements.prevBtn.unbind("click"); - } - if ($elements.nextBtn && $elements.nextBtn.length) { - $elements.nextBtn.unbind("click"); - } - $e.remove(); - }; - - init(); - } - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - NI.Carousel = Carousel; - NI.Carousel.Generator = generate; - -}(this, this.jQuery)); \ No newline at end of file diff --git a/lib/tc.color.js b/lib/tc.color.js deleted file mode 100644 index 1eab26d..0000000 --- a/lib/tc.color.js +++ /dev/null @@ -1,45 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -(function(window, $) { - - var NI = window.NI; - - function Color(options) { - - } - - Color.prototype = { - getRGBFromHex:function(index,hex){ - if(index.toLowerCase() == "r"){ - return parseInt((this.cutHex(hex)).substring(0,2),16); - } else if(index.toLowerCase() == "g"){ - return parseInt((this.cutHex(hex)).substring(2,4),16); - } else if(index.toLowerCase() == "b"){ - return parseInt((this.cutHex(hex)).substring(4,6),16); - } - }, - cutHex:function(h){ - return (h.charAt(0)=="#") ? h.substring(1,7) : h; - } - }; - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - NI.Color = Color; - -}(this, this.jQuery)); \ No newline at end of file diff --git a/lib/tc.cookies.js b/lib/tc.cookies.js deleted file mode 100644 index 463bf85..0000000 --- a/lib/tc.cookies.js +++ /dev/null @@ -1,83 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -(function(window, $) { - - var NI = window.NI; - - function Cookies(options) { - var o, internal_functions; - - o = $.extend({ - namespace:'', - default_expires:new Date(((new Date()).getTime() + ((7)*24*60*60*1000))) - }, options); - - internal_functions = { - handleNamespace:function(key){ - if(o.namespace && o.namespace.length){ - key = o.namespace + '|' + key; - } - return key; - }, - constructCookieString:function(key, value, expires){ - var string; - string = this.handleNamespace(key) + '=' + value+'; expires=' + expires.toUTCString() + '; path=/'; - return string; - }, - extractCookiesForRegex:function(regex){ - var ca, i, cookies; - ca = document.cookie.split(';'); - cookies = []; - for(i=0; i4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -(function(window, $) { - - var NI = window.NI; - - function Favicon(options) { - var o; - - o = $.extend({ - fps:5 - }, options); - - internal = { - interval:0.0 - }; - - function init(){ - internal.interval = 1000/o.fps; - } - - var elements = { - head:document.getElementsByTagName("head")[0] - }; - - //following is from http://softwareas.com/dynamic-favicons - var functions = { - change: function(iconURL) { - if (arguments.length==2) { - document.title = optionalDocTitle; - } - this.addLink(iconURL, "icon"); - this.addLink(iconURL, "shortcut icon"); - }, - addLink: function(iconURL, relValue) { - var link = document.createElement("link"); - link.type = "image/x-icon"; - link.rel = relValue; - link.href = iconURL; - this.removeLinkIfExists(relValue); - elements.head.appendChild(link); - }, - removeLinkIfExists: function(relValue) { - var links = elements.head.getElementsByTagName("link"); - for (var i=0; i4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -(function(window, $) { - - var NI = window.NI, - cache = {}, - is; - - is = { - touch: function() { - if (typeof cache.isTouch === "boolean") { - return cache.isTouch; - } - - if (("ontouchstart" in window) || (window.DocumentTouch && document instanceof DocumentTouch)) { - cache.isTouch = true; - } else { - cache.isTouch = false; - } - - return cache.isTouch; - } - }; - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - NI.is = $.extend(NI.is || {}, is); - -}(this, this.jQuery)); \ No newline at end of file diff --git a/lib/tc.field.js b/lib/tc.field.js deleted file mode 100644 index f1b89e4..0000000 --- a/lib/tc.field.js +++ /dev/null @@ -1,361 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -(function(window, $) { - - var NI = window.NI, - field = { extensions: {} }; - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -// constants - - field.co = { - - BASE_CLASS: "tc-field", - LABEL_CLASS: "tc-field-label", - HINT_CLASS: "tc-field-hint", - MSG_CLASS: "tc-field-message", - - MULTI_CLASS: "tc-multiple", - - ACTIVE_CLASS: "state-active", - DISABLED_CLASS: "state-disabled", - EMPTY_CLASS: "state-empty", - OPEN_CLASS: "state-open", - - VALUE: "data-value", - TEXT: "data-text", - - SET_VAL_EVENT: "tc-field-event-set-val", - RESET_EVENT: "tc-field-reset", - VALIDATE_EVENT:"tc-field-validate", - - STANDARD_NODES: ["input", "textarea", "select"] - }; - - - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -// utils, factories, etc - - field.get_display_text = function($f) { - return $f.attr(field.co.TEXT) ? - $f.attr(field.co.TEXT) : $f.text(); - }; - - // synthesize a new field type - field.synthesize = function(options) { - var o = $.extend({ - name: null, - props: null, // static - base: field._Base, - proto: {} - }, options); - - field[o.name] = function(user_options) { - this._name = o.name; - this._base = o.base.prototype; - - this.$e = null; - this.elements = {}; - this.events = {}; - - if (o.base && o.base.prototype && o.base.prototype.options) { - this.internal = { - o: $.extend({}, (o.base.prototype.options || {}), - (this.options || {}), - user_options) - }; - } else { - //throw new Error("invalid base object:"); - console.error("invalid base object:"); - console.log(o.base); - } - - this[this.internal.o.$e ? "generate_from_dom" : "generate_from_scratch"](this.internal.o); - - this._init(); - - if (!this.event_receiver) { - this.event_receiver = this.$e; - } - - if (this.internal.o.handlers) { - this.add_handlers(this.internal.o.handlers, $.extend(this.internal.o.event_data, {me: this})); - } - - if (this.internal.o.val || this.internal.o.val === "") { - this.set_val(this.internal.o.val, true); - } - - if (this.internal.o.extensions) { - this.apply_extensions(this.internal.o.extensions); - } - - return this; - }; - field[o.name].prototype = $.extend({}, o.base.prototype, o.proto); - - if (o.props && typeof o.props === "object") { - $.each(o.props, function(k, v) { - field[o.name][k] = v; - }); - } - - return field[o.name]; - }; - - field.prep_element = function(element, preprocess) { - var $f, $e, is_std, is_fset; - - $f = element instanceof $ ? element : $(element); - - if ($.isFunction(preprocess)) { - $f = preprocess($f) || $f; - } - - if (!($f instanceof $) || !$f.length) { - //throw new Error("Missing field element"); - console.warn("error preparing field element"); - return; - } - - // if the element is not a generic field container - // assume it's a "standard" field (see tc.field.std.js) - // (this approach is questionable) - //is_std = !($f.hasClass(field.co.BASE_CLASS)); - - is_std = ($.inArray($f[0].nodeName.toLowerCase(), field.co.STANDARD_NODES) > -1); - - - // if the jQuery collection contains multiple DOM elements - // it is a field "set" - is_fset = $f.length > 1; - - if (!is_std) { - $e = $f; - } else { - $f.each(function(i) { - if (!($f.eq(i).parent().hasClass(field.co.BASE_CLASS))) { - $f.eq(i).wrap("
"); - } - }); - $e = $f.parent(); - } - - return { - $e: $e, - $f: $f, - is_std: is_std, - is_fset: is_fset - }; - }; - - // field factory - field.new_instance = function(options) { - var o, field_info, field_type; - - o = $.extend({ - element: null, // ($ obj or selector) - preprocess: null, - options: {} // gets passed through to the field instance - }, options); - - field_info = field.prep_element(o.element, o.preprocess); - - if(!field_info){ - console.warn('field not found'); - console.log(o); - return; - } - - if (o.options.is_fset) { - field_info.is_fset = true; - } - - if (!field_info.is_std) { - if (field_info.$e.hasClass(field.Dropdown.CONTAINER_CLASS)) { - if (field_info.$e.hasClass(field.co.MULTI_CLASS)) { - field_type = "MultiDropdown"; - } else { - field_type = "Dropdown"; - } - } - } else { - - switch (field_info.$f[0].nodeName.toLowerCase()) { - case "input": - switch (field_info.$f.attr("type") ? field_info.$f.attr("type").toLowerCase() : "text") { - case "text": - field_type = "TextInput"; - break; - case "password": - field_type = "Password"; - break; - case "radio": - field_type = field_info.is_fset ? "RadioSet" : "Radio"; - break; - case "checkbox": - field_type = field_info.is_fset ? "CheckboxSet" : "Checkbox"; - break; - case "file": - field_type = "Upload"; - break; - case "hidden": - field_type = "TextInput"; - break; - } - break; - case "textarea": - field_type = "TextArea"; - break; - case "select": - field_type = "Select"; - break; - } - } - - if (!field_type) { - //throw new Error("field.new_instance: failed to determine field type"); - field_type = "_Base"; - } - return new field[field_type]($.extend(o.options, {$e: field_info.$e})); - }; - - - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -// base field - -// all field types inherit from _Base - - field.synthesize({ - name: "_Base", - - base: {}, - proto: { - - options: { - $e: null, - val: null, - label: null, - handlers: null, - event_data: null, - extensions: null - }, - - _init: function() {}, - - // (chainable) - apply_extensions: function(extensions) { - var me = this; - $.each(extensions, function(extension, options) { - if ($.isFunction(field.extensions[extension])) { - me.internal[extension] = new field.extensions[extension](me, options); - } - }); - return this; - }, - - generate_from_dom: function(options) { - this.$e = options.$e.addClass(field.co.BASE_CLASS); - }, - - generate_from_scratch: function(options) {}, - - // (chainable) - append_to: function() { - if (!NI.ex.isHeadless(this.$e)) { - this.$e = this.$e.detach(); - } - - if (typeof arguments[0] === "string") { - $(arguments[0]).append(this.$e); - } else if (arguments[0] instanceof $) { - arguments[0].append(this.$e); - } - - return this; - }, - - get_val: function() { - return null; - }, - - // (chainable) - set_val: function(val, prevent_change) { - var from, to; - from = this.get_val(); - - if (this._set_val(val) !== false) { - if (!prevent_change) { - to = this.get_val(); - if (from !== to) { - this.event_receiver.trigger("change", { - from: from, - to: to - }); - } - } - } - - this.event_receiver.trigger(field.co.SET_VAL_EVENT); - - return this; - }, - - _set_val: function(val) {}, - - reset: function(){ - this.set_val(''); - this.event_receiver.trigger(field.co.RESET_EVENT); - }, - - // (chainable) - bind: function(type, data, fn, replace) { - if (replace) { - this.event_receiver.unbind(type); - } - this.event_receiver.bind(type, data, fn); - return this; - }, - - // (chainable) - add_handlers: function(handlers, data, replace) { - var i; - for (i in handlers) { - this.bind(i, data, handlers[i], replace); - } - return this; - }, - - // (chainable) - set_enabled: function(enabled) { - return this; - }, - - destroy: function() { - this.$e.remove(); - } - } - }); - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - NI.field = field; - -}(this, this.jQuery)); \ No newline at end of file diff --git a/lib/tc.flippanel.js b/lib/tc.flippanel.js deleted file mode 100644 index 37a0935..0000000 --- a/lib/tc.flippanel.js +++ /dev/null @@ -1,129 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -/* to use, the selector of the element with class .flip-panel must be passed. - - .flip-panel must have two direct children, .front and .back, as well as two triggers, - .front-trigger and .back-trigger. - - as a direct child of both .front and .back, there must be a div with class .inner -*/ -function flipPanel(eleContainer) { - - // variables - var flipContainer, frontBox, frontInner, backBox, backInner, - frontTrigger, backTrigger, innerOuterDiff, speed, slideDelay, webkitPerspective; - - speed = 300; // speed of height change when flipping - slideDelay = 200; // delay after flip starts before changing height - - applyWebkitCSSinJS = true; - webkitPerspective = 600; - - - flipContainer = $(eleContainer); - frontBox = flipContainer.children('.front'); - frontInner = frontBox.children('.inner'); - frontTrigger = flipContainer.find('.front-trigger'); - backBox = flipContainer.children('.back'); - backInner = backBox.children('.inner'); - backTrigger = flipContainer.find('.back-trigger'); - - innerOuterDiff = frontBox.height() - frontInner.height(); - - - - - // events - frontTrigger.click(function(){ - frontBox.show(); - - if(applyWebkitCSSinJS) { - flipContainer.css('-webkit-perspective', webkitPerspective); - frontBox.css('-webkit-transform-style','preserve-3d'); - backBox.css('-webkit-transform-style','preserve-3d'); - }; - - backBox.find('.btn-edu').css('opacity','0'); - - backBox.css({ - 'height': frontBox.height(), - 'position': 'absolute', - 'overflow': 'hidden' - }).show(0, function(){ - flipContainer.addClass('flip'); - }); - - frontBox.delay(slideDelay).hide(0, function(){ - frontBox.css('display','none'); - backBox.css('position','relative').animate({ - height: backInner.height() + innerOuterDiff - }, speed, function(){ - backBox.css({'height':'auto', 'overflow':'visible'}); - - if(applyWebkitCSSinJS) { - // if speed + slideDelay is less than the CSS transition speed (400ms), - // additional delay should be put on this - flipContainer.css('-webkit-perspective','none'); - frontBox.css('-webkit-transform-style','flat'); - backBox.css('-webkit-transform-style','flat'); - }; - - backBox.find('.btn-edu').animate({'opacity':'1'}, 400); - }); - }); - }); - - - - backTrigger.click(function(){ - backBox.css('position','absolute').show(); - - if(applyWebkitCSSinJS) { - flipContainer.css('-webkit-perspective', webkitPerspective); - frontBox.css('-webkit-transform-style','preserve-3d'); - backBox.css('-webkit-transform-style','preserve-3d'); - }; - - frontBox.css({ - 'height': backBox.height(), - 'overflow': 'hidden' - }).show(0, function(){ - flipContainer.removeClass('flip'); - }); - - backBox.delay(slideDelay).hide(0, function(){ - frontBox.animate({ - height: frontInner.height() + innerOuterDiff - }, speed, function(){ - frontBox.css({'height':'auto', 'overflow':'visible'}); - - if(applyWebkitCSSinJS) { - // if speed + slideDelay is less than the CSS transition speed (400ms), - // additional delay should be put on this - flipContainer.css('-webkit-perspective','none'); - frontBox.css('-webkit-transform-style','flat'); - backBox.css('-webkit-transform-style','flat'); - }; - - backBox.find('.btn-edu').css('opacity','0'); - }); - }); - }); - - -}; \ No newline at end of file diff --git a/lib/tc.google_analytics.header.js b/lib/tc.google_analytics.header.js deleted file mode 100644 index 923a31b..0000000 --- a/lib/tc.google_analytics.header.js +++ /dev/null @@ -1,26 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -//Does not rely on tc.seed.js - -var _gaq = _gaq || []; - -(function() { - var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; - ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; - var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); -})(); \ No newline at end of file diff --git a/lib/tc.google_analytics.js b/lib/tc.google_analytics.js deleted file mode 100644 index c7f2934..0000000 --- a/lib/tc.google_analytics.js +++ /dev/null @@ -1,58 +0,0 @@ -/* _____ _____ - /\ \ /\ \ - /::\ \ /::\ \ - \:::\ \ /::::\ \ - \:::\ \ /::::::\ \ - \:::\ \ /:::/\:::\ \ - \:::\ \ /:::/ \:::\ \ - /::::\ \ /:::/ \:::\ \ - /::::::\ \ /:::/ / \:::\ \ - /:::/\:::\ \ /:::/ / \:::\ \ - /:::/ \:::\____\/:::/____/ \:::\____\ - /:::/ \::/ /\:::\ \ \::/ / - /:::/ / \/____/ \:::\ \ \/____/ - /:::/ / \:::\ \ -/:::/ / \:::\ \ -\::/ / \:::\ \ - \/____/ \:::\ \ - \:::\ \ - \:::\____\ - \::/ / - \/____/ - TYPE/CODE - From 2010 till ∞ - typecode-js v0.1 - */ - -(function(window, $) { - - var NI = window.NI; - - function GoogleAnalytics(options) { - var o; - - o = $.extend({ - account:null - }, options); - - if(!o.account){ - return; - } - - _gaq.push(['_setAccount', o.account]); - - //console.log(window._gat); - //if(window._gat){ - // this.tracker = window._gat._createTracker(o.account); - // console.log(this.tracker); - //} - // - //console.log(this.tracker); - - } - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - NI.GoogleAnalytics = GoogleAnalytics; - -}(this, this.jQuery)); \ No newline at end of file diff --git a/lib/tc.merlin.js b/lib/tc.merlin.js deleted file mode 100644 index 3b3e6c2..0000000 --- a/lib/tc.merlin.js +++ /dev/null @@ -1,472 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -(function(window, $) { - - var NI = window.NI; - - NI.co.Merlin = { - NEXT_STEP:'next', - PREVIOUS_STEP:'prev', - CURRENT_STEP:'current' - }; - - function Merlin(options) { - var me, o, internal, control_handlers, step_input_handlers, step_event_handlers; - - me = this; - - o = $.extend({},{ - name:null, - - $e:null, - progress_element:null, - controls:{ - next:null, - prev:null - }, - - extensions:{}, - data:{}, - - watch_keypress:true, - allow_hash_override_onload:false, - use_hashchange:false, - return_triggers_next:true, - validation_watch_events: ['keyup', 'change'], - - transition:'none', // fade, slide, horiz_slide, or none - transition_speed:400, - viewport:null, // for horiz_slide - - first_step:null, - steps:{} - }, options); - - internal = { - $e:o.$e, - steps:o.steps, - data:{}, - current_step:null, - last_step:null, - progress_element:null, - counters:{ - n_times_step_rendered:0 - } - }; - - this.extensions = o.extensions; - this.internal = internal; - this.events = $({}); - this.runtime = (o.runtime ? o.runtime : {}); - this.o = o; - - function init(me){ - internal.data = o.data; - internal.progress_element = o.progress_element; - internal.first_step = o.first_step; - if(o.use_hashchange){ - initialize_hashchange(me); - } - initialize_controls(me); - initialize_steps(me); - if(internal.first_step){ - show_step(internal.first_step); - } - } - - function initialize_hashchange(me){ - if(!$.fn.hashchange){ - //cannot use hashchange if it is not present. GHETTO-dep-checking! - o.use_hashchange = false; - return; - } - //$(window) - // .unbind('hashchange', {merlin:me}, window_event_handlers.hashchange) - // .bind('hashchange', {merlin:me}, window_event_handlers.hashchange); - } - - function initialize_controls(me){ - var i; - if(!o.controls){ return; } - for(i in o.controls){ - if(!o.controls[i]){ continue; } - if(!control_handlers[i]){ continue; } - if(typeof o.controls[i] == 'string' ){ - o.controls[i] = o.$e.find(o.controls[i]); - } - o.controls[i].bind('click', {merlin:me}, control_handlers[i]); - } - } - - function initialize_steps(me){ - var i, e_data; - $.each(o.steps,function(i){ - var k; - if(o.steps[i].selector && o.$e){ - o.steps[i].name = i; - o.steps[i].n_times_shown = 0; - o.steps[i].$e = o.$e.find(o.steps[i].selector); - o.steps[i].$e.hide(); - - o.steps[i].initialize_fields = function(){ - if(o.steps[i].fields){ - - o.steps[i].validationManager = new NI.ValidationManager({ - $mother:o.steps[i].$e, - watchEvents: o.validation_watch_events - }); - - o.steps[i].$e.bind('managerValidationPass', {merlin:me}, step_event_handlers.managerValidationPass) - .bind('managerValidationFail', {merlin:me}, step_event_handlers.managerValidationFail); - - o.steps[i].valid = true; - - for(var j in o.steps[i].fields){ - if (o.steps[i].fields[j].options && o.steps[i].fields[j].options.extensions && o.steps[i].fields[j].options.extensions.Validator) { - o.steps[i].fields[j].options.extensions.Validator.manager = o.steps[i].validationManager; - } - o.steps[i].fields[j].component = NI.field.new_instance({ - element: o.steps[i].$e.find(o.steps[i].fields[j].selector), - preprocess: $.isFunction(o.steps[i].fields[j].preprocess) ? o.steps[i].fields[j].preprocess : null, - options: $.extend({ - handlers: { - focus: step_input_handlers.focus, - keyup: step_input_handlers.modify, - change: step_input_handlers.modify, - //keypress: step_input_handlers.keypress, - keydown: step_input_handlers.keydown, - blur: step_input_handlers.blur - }, - event_data:{ - merlin:me - } - }, o.steps[i].fields[j].options) - }); - - if(o.steps[i].fields[j].value || (o.steps[i].fields[j].value === '')){ - o.steps[i].fields[j].component.set_val(o.steps[i].fields[j].value); - } - } - } - }; - o.steps[i].initialize_fields(); - - o.steps[i].validate = function(){ - var k; - if(o.steps[i].fields){ - for(k in o.steps[i].fields){ - if(o.steps[i].fields[k].component){ - o.steps[i].fields[k].component.event_receiver.trigger('tc-field-validate'); - } - } - } - }; - - o.steps[i].set_valid = function(state){ - o.steps[i].valid = state; - }; - - } - }); - for(i in o.steps){ - - } - } - - function show_step(step, nav_data){ - - var i, strip, viewport, step_width; - - if(internal.current_step && $.isFunction(internal.current_step.validate)){ - internal.current_step.validate(); - } - - if(step == NI.co.Merlin.NEXT_STEP){ - if(internal.current_step.valid === false){ - return false; - } - if(internal.current_step.next){ - show_step(internal.current_step.next); - } - return; - } else if(step == NI.co.Merlin.PREVIOUS_STEP){ - if(internal.current_step.prev){ - show_step(internal.current_step.prev); - } - return; - } else if(step == NI.co.Merlin.CURRENT_STEP){ - if(internal.current_step){ - show_step(internal.current_step.name); - } - return; - } - - if(typeof step == 'string' && !(o.steps[step])){ - if(o.use_hashchange){ - set_location(internal.current_step.name); - } - return false; - } - - if(internal.current_step && (step == internal.current_step.name)){ - if($.isFunction(internal.current_step.visible)){ - internal.current_step.visible(me); - } - return true; - } - - if(internal.current_step && $.isFunction(internal.current_step.finish)){ - if(internal.current_step.finish(me) === false){ - return false; - } - } - - if($.isFunction(step)){ - step = step(me); - } - - if(internal.current_step && (step == internal.current_step.name)){ - if($.isFunction(internal.current_step.visible)){ - internal.current_step.visible(me); - } - return true; - } - - if(!o.steps[step]){ - if(o.use_hashchange){ - set_location(internal.current_step.name); - } - return false; - } - - if ( internal.current_step ) { - internal.last_step = internal.current_step; - } - internal.current_step = o.steps[step]; - - // begin transition handling - if (o.transition=='fade') { - if (internal.counters.n_times_step_rendered !== 0) { - o.$e.find(internal.current_step.selector).fadeIn(o.transition_speed); - o.$e.find(internal.last_step.selector).fadeOut(o.transition_speed); - } else { - o.$e.find(internal.current_step.selector).show().siblings('.step').hide(); - } - } else if (o.transition=='slide') { - if (internal.counters.n_times_step_rendered !== 0) { - o.$e.find(internal.current_step.selector).siblings('.step').slideUp(o.transition_speed/2); - o.$e.find(internal.current_step.selector).delay(o.transition_speed/2).slideDown(o.transition_speed); - } else { - o.$e.find(internal.current_step.selector).show().siblings('.step').hide(); - } - } else if (o.transition=='horiz_slide') { - - strip = o.$e; - viewport = o.viewport; - step_width = viewport.width(); - - if (internal.counters.n_times_step_rendered !== 0) { - - strip.children('.step').width( step_width ); - strip.width( step_width * 2); - strip.find(internal.current_step.selector).show(); - - if ( internal.current_step.step_number > internal.last_step.step_number ) { - strip.animate({ 'margin-left' : -step_width }, o.transition_speed, 'easeInOutQuad', - function(){ - strip.find(internal.last_step.selector).hide(); - strip.css({ 'margin-left' : 0, 'width' : '' }); - strip.children('.step').css('width', ''); - } - ); - } else if ( internal.current_step.step_number < internal.last_step.step_number ) { - strip.css({ 'margin-left' : -step_width }); - strip.animate({ 'margin-left' : 0 }, o.transition_speed, 'easeInOutQuad', - function(){ - strip.find(internal.last_step.selector).hide(); - strip.css({ 'width' : '' }); - strip.children('.step').css('width', ''); - } - ); - } - - } else { - - o.$e.find(internal.current_step.selector).show().siblings('.step').hide(); - - } - - } else { - o.$e.find(internal.current_step.selector).show().siblings('.step').hide(); - } - // end transition handling - - if(internal.current_step.n_times_shown === 0 && !internal.current_step.init_forced && $.isFunction(internal.current_step.init)){ - internal.current_step.init(me); - } - - // begin controls handling - if(o.controls.prev){ - if(internal.current_step.prev){ - o.controls.prev.removeClass('disabled'); - } else { - o.controls.prev.addClass('disabled'); - } - } - - if(o.controls.next){ - if(internal.current_step.next){ - o.controls.next.removeClass('disabled'); - } else { - o.controls.next.addClass('disabled'); - } - } - // end controls handling - - - //begin progress indicator - if(internal.current_step.progress_selector){ - internal.progress_element.find('.progress-unit') - .removeClass('current') - .filter(internal.current_step.progress_selector) - .addClass('current'); - } - //end progress indicator - - internal.current_step.nav_data = nav_data; - - if($.isFunction(internal.current_step.visible)){ - internal.counters.n_times_step_rendered++; - internal.current_step.visible(me); - } - - if (o.use_hashchange && !internal.current_step.supress_hash && internal.current_step.name) { - set_location(internal.current_step.name); - } - - //if(internal.current_step.fields){ - // for(i in internal.current_step.fields){ - // internal.current_step.fields[i].component.event_receiver.trigger('change'); - // } - //} - - internal.current_step.n_times_shown++; - } - - function set_location(step){ - window.location.hash = (o.name ? o.name + ':' : '') + step; - } - - control_handlers = { - next:function(e,d){ - if(e){ - e.preventDefault(); - } - //if(internal.current_step.valid === false){ - // return false; - //} - - if($(this).hasClass('disabled')){ - return false; - } - show_step(NI.co.Merlin.NEXT_STEP); - }, - prev:function(e,d){ - if(e){ - e.preventDefault(); - } - if($(this).hasClass('disabled')){ - return false; - } - show_step(NI.co.Merlin.PREVIOUS_STEP); - }, - refresh:function(e,d){ - if(e){ - e.preventDefault(); - } - show_step(NI.co.Merlin.CURRENT_STEP); - } - }; - - step_input_handlers = { - focus:function(e,d){ - - }, - modify:function(e,d){ - - }, - keypress:function(e,d){ - if(e.data.merlin.o.return_triggers_next){ - if(e.which && (e.which == NI.co.keyboard.ENTER)){ - control_handlers.next(e,d); - } - } - }, - keydown:function(e,d){ - if(e.data.merlin.o.return_triggers_next){ - if(e.which && (e.which == NI.co.keyboard.ENTER)){ - control_handlers.next(e,d); - } - } - }, - blur:function(e,d){ - - } - }; - - step_event_handlers = { - managerValidationPass:function(e,d){ - if(e.data.merlin.internal.current_step){ - e.data.merlin.internal.current_step.valid = true; - } - }, - managerValidationFail:function(e,d){ - if(e.data.merlin.internal.current_step){ - e.data.merlin.internal.current_step.valid = false; - } - } - }; - - this.show_step = function(step, nav_data){ - show_step(step, nav_data); - }; - - this.set_data = function(data){ - internal.data = data; - }; - - this.get_data = function(){ - return internal.data; - }; - - this.get_val = function(id){ - return internal.data[id]; - }; - - this.set_val = function(id,new_val){ - internal.data[id] = new_val; - }; - - init(this); - } - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - NI.Merlin = Merlin; - -}(this, this.jQuery)); \ No newline at end of file diff --git a/lib/tc.merlin.js.old b/lib/tc.merlin.js.old deleted file mode 100644 index 1308f24..0000000 --- a/lib/tc.merlin.js.old +++ /dev/null @@ -1,535 +0,0 @@ -if(!tc){ var tc = {}; } - -tc.merlin = makeClass(); - -tc.merlin.prototype.options = { - name:null, - dom:null, - progress_element:null, - next_button:null, - back_button:null, - watch_keypress:true, - first_step:'start', - allow_hash_override_onload:false, - use_hashchange:true, - steps:{ - 'start':{ - progress_selector:'.1', - selector:'.start', - prev_step:null, - next_step:null - } - } -}; - -tc.merlin.prototype.init = function(app,options){ - tc.util.log('tc.merlin.init'); - this.options = tc.jQ.extend({},this.options,options); - this.app = app; - if(this.options.dom instanceof String){ - this.options.dom = tc.jQ(options.dom); - } - this.dom = this.options.dom; - this.magic = null; - this.event_data = {app:app,me:this}; - this.handle_steps(); - this.handle_controls(options.controls); - this.setup_events(app); - tc.util.dump(this.options); - if(this.options.use_hashchange && this.options.allow_hash_override_onload){ - this.set_address(window.location.hash.substring(1,window.location.hash.length)); - } else { - if(this.options.first_step){ - this.show_step(this.options.first_step); - //if(this.options.name){ - // window.location.hash = this.options.name+','+this.options.first_step; - //} else { - // window.location.hash = this.options.first_step; - //} - } - } - - this.current_hash = null; -}; - -tc.merlin.prototype.setup_events = function(app){ - tc.util.log('tc.merlin.setup_events'); - if (this.options.use_hashchange) { - tc.jQ(window) - .unbind('hashchange',this.event_data,this.handlers.hashchange) - .bind('hashchange',this.event_data,this.handlers.hashchange); - } - if(this.dom){ - this.dom.find('a.step_link').unbind('click').bind('click',this.event_data,this.handlers.a_click); - this.dom.bind('merlin-step-valid',this.event_data,this.handlers.valid); - this.dom.bind('merlin-step-invalid',this.event_data,this.handlers.invalid); - } - if(this.options.back_button){ - this.options.back_button.unbind('click').bind('click',this.event_data,this.handlers.prev_step); - } - if(this.options.next_button){ - this.options.next_button.addClass('disabled'); - this.options.next_button.unbind('click').bind('click',this.event_data,this.handlers.next_step); - } -}; - -tc.merlin.prototype.deallocate_magic = function() { - if (this.options.use_hashchange) { - tc.jQ(window).unbind('hashchange', this.handlers.hashchange); - } - if (this.dom) { - this.dom.find('a.step_link').unbind('click', this.handlers.a_click); - this.dom.unbind('merlin-step-valid', this.handlers.valid); - this.dom.unbind('merlin-step-invalid', this.handlers.invalid); - } - if (this.options.back_button) { - this.options.back_button.unbind('click', this.handlers.prev_step); - } - if (this.options.next_button) { - this.options.next_button.unbind('click', this.handlers.next_step); - } -}; - -tc.merlin.prototype.handle_controls = function(controls){ - tc.util.log('tc.merlin.handle_controls'); - if(this.options.progress_element){ - this.options.progress_element.find('a.indicator').bind('click',this.event_data,this.handlers.indicator_click); - } - if(this.options.error_indicator){ - this.options.error_indicator.html(''); - } -}; - -tc.merlin.prototype.handle_steps = function(){ - tc.util.log('tc.merlin.handle_steps'); - if(this.options.magic){ - this.magic = this.magic_spell(); - } - var i; - for(i in this.options.steps){ - if(this.options.steps[i].selector && this.dom){ - this.options.steps[i].dom = this.dom.find(this.options.steps[i].selector); - } - } -}; -/* Magic!! - __________________ - .-' \ _.-''-._ / '-. - .-/\ .'. .'. /\-. - _'/ \.' '. .' './ \'_ -:======:======::======:======: - '. '. \ '' / .' .' - '. . \ : : / . .' - '.' \ ' ' / '.' - ': \: :/ :' - '. \ / .' - '.\ /.' - '\/' -*/ -tc.merlin.prototype.magic_spell = function(){ - tc.util.log('tc.merlin.magic_spell'); - var i, magic_dust; - tc.util.dump(this.options); - tc.util.dump(this.dom); - tc.util.dump(this.options.steps); - - magic_dust = ({ - n_items:0, - overall_width:0, - page_width:0, - item_metadata:{ - max_width:0, - min_width:100000, - max_height:0, - min_height:100000, - marginLeft:0 - }, - $items:[], - init:function(merlin){ - tc.util.log('tc.merlin.magic_spell[magic_dust].init'); - this.merlin = merlin; - - for(i in this.merlin.options.steps){ - this.merlin.options.steps[i].magic_dom = this.merlin.dom.children().filter(this.merlin.options.steps[i].selector); - if(this.merlin.options.steps[i].magic_dom.length){ - this.$items.push(this.merlin.options.steps[i].magic_dom.get(0)); - - if(this.merlin.options.steps[i].magic_dom.outerWidth() < this.item_metadata.min_width){ - this.item_metadata.min_width = this.merlin.options.steps[i].magic_dom.outerWidth(); - } - if(this.merlin.options.steps[i].magic_dom.outerWidth() > this.item_metadata.max_width){ - this.item_metadata.max_width = this.merlin.options.steps[i].magic_dom.outerWidth(); - } - - if(this.merlin.options.steps[i].magic_dom.outerHeight() < this.item_metadata.min_height){ - this.item_metadata.min_height = this.merlin.options.steps[i].magic_dom.outerHeight(); - } - if(this.merlin.options.steps[i].magic_dom.outerHeight() > this.item_metadata.max_height){ - this.item_metadata.max_height = this.merlin.options.steps[i].magic_dom.outerHeight(); - } - } - } - - this.n_items = this.$items.length; - this.$items = tc.jQ(this.$items); - this.page_width = tc.jQ(window).width(); - this.overall_width = (this.page_width * this.n_items); - this.item_metadata.marginLeft = (this.page_width - this.item_metadata.max_width)/2 - - this.merlin.dom.css({ - 'width':this.overall_width + 'px', - 'height':this.item_metadata.max_height + 'px' - //'marginLeft':-1 * this.item_metadata.marginLeft - }); - this.$items.show().css({ - 'float':'left', - 'clear':'none', - 'width':this.item_metadata.max_width+'px', - 'marginLeft':this.item_metadata.marginLeft - }).removeClass('clearfix'); - - return this; - }, - resize_handler:function(e){ - tc.util.log('tc.merlin.magic_spell[magic_dust].resize_handler'); - - }, - show_step:function(step){ - tc.util.log('tc.merlin.magic_spell[magic_dust].show_step'); - if(!step.magic_dom){ - return; - } - tc.util.dump(step.magic_dom); - tc.util.dump(step.magic_dom.position().left); - tc.util.dump(this.item_metadata.marginLeft); - - tc.util.dump( (-1 * this.item_metadata.marginLeft) - ( step.magic_dom.position().left ) ); - - this.merlin.dom.css({ - //'marginLeft': ((-1 * this.item_metadata.marginLeft) - ( step.magic_dom.position().left )) + 'px' - 'marginLeft': (( step.magic_dom.position().left )) + 'px' - }); - - - } - }).init(this); - - tc.util.dump('----'); - tc.util.dump('----'); - tc.util.dump(magic_dust); - tc.util.dump('----'); - tc.util.dump('----'); - - return magic_dust; -}; -/* ** * * end magic * * ** */ - -tc.merlin.prototype.show_step = function(step,force){ - tc.util.log('tc.merlin.show_step['+step+']'); - var i, j, temp_e_data; - - tc.util.dump(step); - - if(this.current_step && !force){ - //this.current_step.dom.find('input, textarea').unbind('keyup change'); - - tc.util.dump(step); - tc.util.dump(this.current_step.step_name); - - if(step == this.current_step.step_name){ - if(!this.current_step.dom.filter(':visible').length){ - this.current_step.dom.show(); - } - return; - } - if(this.current_step){ - if(tc.jQ.isFunction(this.current_step.finish)){ - this.current_step.finish(this,this.current_step.dom); - //if(this.current_step.finish(this,this.current_step.dom) === false){ - // return; - //}; - } - } - } - if(force && this.current_step){ - if(tc.jQ.isFunction(this.current_step.finish)){ - this.current_step.finish(this,this.current_step.dom); - //if(this.current_step.finish(this,this.current_step.dom) === false){ - // return; - //}; - } - } - - if(!this.options.steps[step]){ - return; - } - - this.options.steps[step].step_name = step; - if(this.current_step && this.current_step.use_for_history){ - this.options.steps[step].prev_step = this.current_step.step_name; - } else if(this.current_step){ - this.options.steps[step].prev_step = this.current_step.prev_step; - } - this.current_step = this.options.steps[step]; - if(this.options.next_button){ - this.options.next_button.removeClass('disabled'); - } - if(this.current_step.progress_selector){ - if(this.options.progress_element){ - this.options.progress_element.find(this.current_step.progress_selector) - .addClass('cur') - .attr('href','#'+this.current_step.step_name) - .nextAll().removeClass('cur').attr('href','#'); - } - } - if(this.current_step.title && this.options.title){ - this.options.title.html(this.current_step.title); - } - if(this.current_step.sub_title && this.options.sub_title){ - this.options.sub_title.html(this.current_step.sub_title); - } - if(tc.jQ.isFunction(this.current_step)){ - this.current_step(this); - return; - } - - if(tc.jQ.isFunction(this.current_step.transition)){ - this.current_step.transition(this); - } else if(this.magic){ - this.magic.show_step(this.current_step); - } else if(this.dom && !this.magic){ - this.dom.find('.step').hide(); - this.dom.find(this.current_step.selector).show(); - } - - if(this.current_step.inputs && !this.current_step.has_been_initialized){ - for(i in this.current_step.inputs){ - temp_e_data = tc.jQ.extend({},this.event_data,{input:this.current_step.inputs[i]}); - if(!this.current_step.inputs[i].dom && this.current_step.inputs[i].selector){ - this.current_step.inputs[i].dom = this.current_step.dom.find(this.current_step.inputs[i].selector); - if(!this.current_step.inputs[i].dom.length){ - tc.util.dump(this.current_step.inputs[i].selector); - } - } - if(this.current_step.inputs[i].counter && !this.current_step.inputs[i].counter.dom){ - this.current_step.inputs[i].counter.dom = this.current_step.dom.find(this.current_step.inputs[i].counter.selector) - this.current_step.inputs[i].counter.dom.text('0/'+this.current_step.inputs[i].counter.limit); - } - this.current_step.inputs[i].dom - .bind('focus',temp_e_data,this.handlers.focus) - .bind('keyup change',temp_e_data,this.handlers.keypress) - .bind('blur',temp_e_data,this.handlers.blur) - .data({merlin:this,input:this.current_step.inputs[i]}) - .each(function(i,j){ - var $j; - $j = tc.jQ(j); - if($j.data().input.hint || ($j.data().input.hint === "")){ - j.value = $j.data().input.hint; - } - }); - if(this.current_step.inputs[i].handlers){ - for(j in this.current_step.inputs[i].handlers){ - this.current_step.inputs[i].dom.bind(j,this.event_data,this.current_step.inputs[i].handlers[j]); - } - } - if(this.current_step.inputs[i].focus_first){ - //this.current_step.inputs[i].dom.focus(); - } - } - } - - if (this.options.use_hashchange && !this.current_step.supress_hash) { - if(this.options.name){ - window.location.hash = this.options.name+','+step; - } else { - window.location.hash = step; - } - } - - if(tc.jQ.isFunction(this.current_step.init)){ - this.current_step.init(this,this.current_step.dom); - } - this.validate(false); - this.current_step.has_been_initialized = true; -}; - -tc.merlin.prototype.set_address = function(hash) { - tc.util.log("tc.merlin.set_address"); - var hash_buffer, force; - hash_buffer = hash.split(","); - if (this.options.name) { - if (hash_buffer[0] !== this.options.name) { - this.current_hash = null; - return; - } - hash = hash_buffer[1]; - force = true; - } else if (this.current_hash !== hash) { - force = false; - } - this.current_hash = hash; - this.show_step(this.current_hash, force); -}; - -tc.merlin.prototype.validate = function(on_submit){ - tc.util.log('tc.merlin.validate1'); - var i, valid, temp_valid; - if(!this.current_step.inputs){ - return true; - } - valid = true; - this.current_step.errors = []; - for(i in this.current_step.inputs){ - if(!this.current_step.inputs[i].validators){ - continue; - } - if(on_submit){ - this.current_step.inputs[i].dom.addClass('has-been-focused has-attempted-submit'); - if(this.current_step.inputs[i].hint && (this.current_step.inputs[i].dom.val() == this.current_step.inputs[i].hint)){ - this.current_step.inputs[i].dom.val(''); - } - } - if(tc.jQ.isFunction(this.current_step.inputs[i].validators)){ - temp_valid = this.current_step.inputs[i].validators(this,this.current_step.inputs[i].dom,this.current_step); - } else { - temp_valid = tc.validate(this.current_step.inputs[i].dom,this.current_step.inputs[i].validators); - } - - - if(!temp_valid.valid){ - tc.util.dump(temp_valid); - valid = false; - if(this.current_step.inputs[i].counter && this.current_step.inputs[i].dom.hasClass('has-been-focused')){ - this.current_step.inputs[i].counter.dom.addClass('invalid').removeClass('valid'); - } - } else{ - if(this.current_step.inputs[i].counter && this.current_step.inputs[i].counter.dom.hasClass('invalid')){ - this.current_step.inputs[i].counter.dom.addClass('valid').removeClass('invalid'); - } - } - } - if(valid){ - if(this.dom){ - this.dom.trigger('merlin-step-valid',{ - step:this.current_step - }); - } - this.current_step.dom.removeClass('invalid').addClass('valid'); - return true; - } else { - if(this.dom){ - this.dom.trigger('merlin-step-invalid',{ - step:this.current_step - }); - } - this.current_step.dom.removeClass('valid').addClass('invalid'); - return false; - } -}; - -tc.merlin.prototype.handlers = { - hashchange:function(e,d){ - tc.util.log('tc.merlin.handlers.hashchange['+window.location.hash+']'); - e.data.me.set_address(window.location.hash.substring(1,window.location.hash.length)); - }, - indicator_click:function(e,d){ - tc.util.log('tc.merlin.handlers.indicator_click'); - if(tc.jQ(e.target).parent().attr('href') == '#'){ e.preventDefault(); } - }, - a_click:function(e,d){ - tc.util.log('tc.merlin.handlers.a_click'); - }, - prev_step:function(e,d){ - tc.util.log('tc.merlin.handlers.prev_step'); - e.preventDefault(); - if(e.data.me.current_step && e.data.me.current_step.prev_step){ - if (e.data.me.options.use_hashchange) { - window.location.hash = e.data.me.current_step.prev_step; - } else { - e.data.me.show_step( e.data.me.current_step.prev_step ); - } - } - }, - next_step:function(e,d){ - tc.util.log('tc.merlin.handlers.next_step'); - var valid; - e.preventDefault(); - valid = e.data.me.validate(true); - if(!valid){ - if(e.data.me.options.error_indicator){ - e.data.me.options.error_indicator.html('Oops! Please fill in the fields marked in red.').show(); - } - return; - } else { - if(e.data.me.options.error_indicator){ - e.data.me.options.error_indicator.hide(); - } - } - if(e.target.className.indexOf('disabled') > 0){ - return; - } - if(e.data.me.current_step && e.data.me.current_step.next_step){ - - e.data.me.show_step( e.data.me.current_step.next_step ); - - //if (e.data.me.options.use_hashchange) { - // if(e.data.me.options.name){ - // window.location.hash = e.data.me.options.name+','+e.data.me.current_step.next_step; - // } else { - // window.location.hash = e.data.me.current_step.next_step; - // } - //} else { - // e.data.me.show_step( e.data.me.current_step.next_step ); - //} - } - }, - focus:function(e,d){ - var $t; - if(e.target.className.indexOf('has-been-focused') == -1){ - $t = tc.jQ(e.target); - $t.addClass('has-been-focused').removeClass('valid invalid'); //.filter('[type=text], textarea').val(''); - if (e.target.nodeName == "TEXTAREA" || (e.target.nodeName == "INPUT" && ($t.attr("type") == "text"))) { - if ($t.data().input.hint || $t.data().input.hint === "") { - $t.val(""); - } - } - } - }, - keypress:function(e,d){ - e.data.me.validate(false); - if(e.which == 13 && e.target.nodeName != 'TEXTAREA'){ - if(e.data.me.options.next_button && e.data.me.options.next_button.hasClass('enabled')){ - e.data.me.options.next_button.click(); - } - } - if(e.data.input.counter && e.data.input.counter.dom){ - e.data.input.counter.dom.text(e.data.input.dom.val().length+'/'+e.data.input.counter.limit); - } - }, - blur:function(e,d){ - var $t; - $t = tc.jQ(e.target); - if(!e.target.value.length){ - tc.jQ(e.target).removeClass('has-been-focused'); - if($t.data().input.hint || ($t.data().input.hint === "")){ - $t.val($t.data().input.hint); - } - } - }, - valid:function(e,d){ - tc.util.log('tc.merlin.handlers.valid'); - if(e.data.me.options.next_button){ - e.data.me.options.next_button.removeClass('disabled').addClass('enabled'); - } - if(e.data.me.options.error_indicator){ - e.data.me.options.error_indicator.hide(); - } - }, - invalid:function(e,d){ - tc.util.log('tc.merlin.handlers.invalid'); - if(e.data.me.options.next_button){ - e.data.me.options.next_button.removeClass('enabled').addClass('disabled'); - } - } -}; - diff --git a/lib/tc.overlay.js b/lib/tc.overlay.js deleted file mode 100644 index 93b34c0..0000000 --- a/lib/tc.overlay.js +++ /dev/null @@ -1,272 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -(function(window, $) { - - var NI = window.NI; - - function Overlay(options) { - var o, $e, $m, open, $elements; - - o = $.extend({ - context: "body", // Selector to element where overlay will be inserted. - autoflush: true, // If true, the Overlay automatically flushes its content when it is closed. - flavor: null, // Additional classnames for Mask and Overlay. - maskClick: true, // Hide Overlay if Mask is Clicked. - maskFadeOutSpeed: 100, // Delay for mask Fade Out Animation. - escape: true, //ESC Keypress closes Overlay. - closeBtn: false, // Appends Close Button to Overlay. - isTouchDevice: false, // if true, the Overlay adjusts its behavior - // to be appropriate for touch devices - // (primarily by not using fixed positioning) - - onOpen: function(instance) {}, // Callback after Overlay is opened. - onClose: function(instance) {} // Callback after Overlay is hidden. - }, options); - - function init(me){ - var $pane; - - $e = generate.overlay().hide().appendTo(o.context); - $m = generate.mask().hide(); - $e.before($m); - - if (typeof o.flavor === "string") { - $e.addClass(o.flavor); - $m.addClass(o.flavor); - } else if ($.isArray(o.flavor)) { - $.each(o.flavor, function(i, flavor) { - $e.addClass(flavor); - $m.addClass(flavor); - }); - } - - $pane = $e.find(">.tier > .tier > .pane"); - $elements = { - pane: $pane, - hd: $pane.children(".hd"), - bd: $pane.children(".bd"), - ft: $pane.children(".ft") - }; - - if (o.maskClick) { - $e.bind("click", {instance:me, $pane:$elements.pane, allowPaneClick: true}, events.clickClose); - if (o.isTouchDevice) { - $m.bind("click", {instance: me}, events.clickClose); - } - } - - open = false; - } - - var events = { - keydown: function(e) { - var key; - key = e.keyCode || e.which; - switch (key) { - case NI.co.keyboard.ESCAPE: - if (e.data.escape === true) { - e.data.instance.close(); - } - break; - case NI.co.keyboard.ENTER: - e.data.$e.find(".button.ca").click(); - break; - } - }, - clickClose: function(e) { - var pane; - if (e.data.$pane && e.data.allowPaneClick) { - pane = e.data.$pane[0]; - if (!$.contains(pane, e.target) && (pane != e.target) && $.contains(document.body, e.target)) { - e.preventDefault(); - e.data.instance.close(); - } - } else { - e.preventDefault(); - e.data.instance.close(); - } - } - }; - - var generate = { - overlay:function(){ - var $overlay = $( '
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
' ); - - if (o.isTouchDevice) { - $overlay.css({ - position: "absolute", - overflow: "visible" - }); - } - - return $overlay; - }, - mask:function(){ - var $mask = $( '
\ -
' ); - - if (o.isTouchDevice) { - $mask.css({ - position: "absolute" - }); - } - - return $mask; - }, - closeBtn:function(instance){ - var $btn; - $btn = $( "Close" ); - if (instance) { - $btn.bind("click", {instance:instance}, events.clickClose); - } - return $btn; - } - }; - - this.flush = function() { - $elements.hd.empty(); - $elements.bd.empty(); - $elements.ft.empty(); - if (o.isTouchDevice) { - $m.css({ height: "100%" }); - } - return this; - }; - - this.getOverlay = function(){ - return $e; - }; - - this.setHeader = function($hd) { - $elements.hd.empty().append($hd); - return this; - }; - - this.getHeader = function(){ - return $elements.hd; - }; - - this.setBody = function($bd) { - $elements.bd.empty().append($bd); - return this; - }; - - this.getBody = function(){ - return $elements.bd; - }; - - this.setFooter = function($ft) { - $elements.ft.empty().append($ft); - return this; - }; - - this.getFooter = function(){ - return $elements.ft; - }; - - this.open = function(options) { - var _o; - _o = $.extend({ - hd:null, - bd:null, - ft:null - },options); - - if (_o.hd) { this.setHeader(_o.hd); } - if (_o.bd) { this.setBody(_o.bd); } - if (_o.ft) { this.setFooter(_o.ft); } - - if (o.closeBtn && !($elements.hd.find(".btn-close").length)) { - $elements.hd.append(generate.closeBtn(this)); - } - - $e.find('.btn-close').bind("click", {instance:this}, events.clickClose); - - - if(o.openTransition && $.isFunction(o.openTransition)){ - o.openTransition($e, $m); - } else { - $m.fadeIn(); - $e.fadeIn().scrollTop(0).focus(); - } - - if (o.isTouchDevice) { - $m.height( $(document).height() ); - } - - $(window.document).bind("keydown.overlay", {instance:this, escape:o.escape, $e:$e}, events.keydown); - - open = true; - if ($.isFunction(o.onOpen)) { - o.onOpen(this); - } - return this; - }; - - this.close = function() { - if (!open) { return this; } - - if(o.closeTransition && $.isFunction(o.closeTransition)){ - o.closeTransition($e, $m); - } else { - $m.fadeOut(); - $e.hide().blur(); - } - - $(window.document).unbind("keydown.overlay", events.keydown); - - if (o.autoflush === true) { - this.flush(); - } - open = false; - if ($.isFunction(o.onClose)) { - o.onClose(this); - } - return this; - }; - - this.destroy = function() { - $e.blur().remove(); - $m.remove(); - }; - - init(this); - } - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - NI.Overlay = Overlay; - - if(window.define){ - define([], function(){ - return Overlay; - }); - } - -}(this, this.jQuery)); \ No newline at end of file diff --git a/lib/tc.seed.js b/lib/tc.seed.js deleted file mode 100644 index 837850e..0000000 --- a/lib/tc.seed.js +++ /dev/null @@ -1,323 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -(function(window) { - - var NI = {}, - fakeConsole; - - NI.ex = { - - checkStr: function(s) { - var t = typeof s; - if (t === "string") { return true; } - //throw new TypeError("Expected string, but found "+ t +" instead"); - console.error("Expected string, but found '"+ String(t) +"' instead"); - }, - - checkFn: function(fn) { - if ($.isFunction(fn)) { return true; } - //throw new TypeError("Expected function, but found "+ typeof fn +" instead"); - console.error("Expected function, but found '"+ typeof fn +"' instead"); - }, - - checkJQ: function(o) { - if (o instanceof $) { return true; } - //throw new TypeError("Expected jQuery object, but found"+ typeof o +" instead"); - console.error("Expected jQuery object, but found '"+ typeof o +"' instead"); - }, - - checkJQNode: function($e, type) { - NI.ex.checkJQ($e); - type = type.toLowerCase(); - if ($e.length === 1) { - if ($e[0].nodeName.toLowerCase() === type) { - return true; - } - } - throw new TypeError("Expected jQuery object holding single "+ type +" element"); - }, - - typeOf: function(v) { - var s = typeof v; - if (s === "object") { - if (v) { - if (typeof v.length === "number" && - !(v.propertyIsEnumerable("length")) && - typeof v.splice === "function") { - s = "array"; - } - } else { - s = "null"; - } - } - return s; - }, - - isEmpty: function(v) { - NI.ex.checkStr(v); - return $.trim(v) ? - false : true; - }, - - isHeadless: function($e) { - var node = $e[0]; - if (!node.parentNode) { - return true; - } - if (node.parentNode === NI.co.nodeTypes.DOCUMENT_NODE) { - return true; - } - return false; - } - }; - - NI.app = { - - bootstrap: function(app, options) { - var o; - o = $.extend({ - debug: false - }, options); - - app.console = NI.app.getConsole(o.debug); - app.classes = {}; - app.runtime = {}; - NI.fn.eventPool(app); - - app.console.info("::::::::::::: Starting application :::::::::::::"); - app.console.info((app.name || "") + " " + (app.version || "")); - app.console.info("::::::::::::::::::::::::::::::::::::::::::::::::"); - - return app; - }, - - getConsole: function(debug) { - if (debug && typeof window.console !== "undefined" && - typeof window.console.debug !== "undefined") { - - return window.console; - } - if (!fakeConsole) { - fakeConsole = {}; - $.each(("assert,count,debug,dir,dirxml,error,exception,\ - group,groupCollapsed,groupEnd,info,log,markTimeline,\ - profile,profileEnd,time,timeEnd,trace,warn").split(","), function() { - fakeConsole[this] = $.noop; - }); - } - return fakeConsole; - }, - - /** - * Initialize environment-specific components - * from an array of "feature" objects, each one - * of the form { feature: "foo", options: {} }, - * which invokes app[foo](options) - */ - initAppFeatures: function(app, env) { - if (!app.runtime) { - app.runtime = {}; - } - if ($.isArray(env.features)) { - $.each(env.features, function(i, o) { - if (app.runtime[o.feature]) { - NI.app.getConsole(true).warn(o.feature +" already initialized"); - } else if ($.isFunction(app[o.feature])) { - app.runtime[o.feature] = app[o.feature].call(app, o.options); - } - }); - } - } - }; - - NI.fn = { - - // via http://www.nczonline.net/blog/2009/07/28/the-best-way-to-load-external-javascript/ - loadScript: function(url, callback) { - var script = window.document.createElement("script"); - script.type = "text/javascript"; - if (script.readyState) { - script.onreadystatechange = function() { - if (script.readyState == "loaded" || script.readyState == "complete") { - script.onreadystatechange = null; - if ($.isFunction(callback)) { - callback(); - } - } - }; - } else { - script.onload = function() { - if ($.isFunction(callback)) { - callback(); - } - }; - } - script.src = url; - window.document.getElementsByTagName("head")[0].appendChild(script); - }, - - extend: function(sub, base) { - var F = function() {}; - F.prototype = base.prototype; - sub.prototype = new F(); - sub.prototype.constructor = sub; - sub.base = base.prototype; - if (base.prototype.constructor === Object.prototype.constructor) { - base.prototype.constructor = base; - } - }, - - clone: function(o) { - var F = function() {}; - F.prototype = o; - return new F(); - }, - - augment: function(dest, src) { - var i; - if (arguments[2]) { - for (i = 2; i < arguments.length; i += 1) { - dest.prototype[arguments[i]] = src.prototype[arguments[i]]; - } - } else { - for (i in src.prototype) { - if (!dest.prototype[i]) { - dest.prototype[i] = src.prototype[i]; - } - } - } - }, - - eventPool: function(target) { - var events = $({}); - target.bind = function() { - events.bind.apply(events, arguments); - }; - target.unbind = function() { - events.unbind.apply(events, arguments); - }; - target.trigger = function() { - events.trigger.apply(events, arguments); - }; - return target; - }, - - guid: function(prefix) { - return (prefix || "obj_")+ new Date().getTime(); - }, - - randomElement: function(array) { - if (NI.ex.typeOf(array) === "array" && array.length > 0) { - return array[window.Math.floor(NI.math.random(array.length))]; - } - }, - - // debounce implementation from Underscore.js - // http://documentcloud.github.com/underscore/ - debounce: function(fn, delay) { - var timer; - return function() { - var self = this, args = arguments, - execute = function() { - timr = null; - fn.apply(self, args); - }; - window.clearTimeout(timer); - timer = window.setTimeout(execute, delay); - }; - } - }; - - NI.co = { - - keyboard: { - - BACKSPACE: 8, - CAPS_LOCK: 20, - COMMA: 188, - CONTROL: 17, - DELETE: 46, - DOWN: 40, - END: 35, - ENTER: 13, - ESCAPE: 27, - HOME: 36, - INSERT: 45, - LEFT: 37, - NUMPAD_ADD: 107, - NUMPAD_DECIMAL: 110, - NUMPAD_DIVIDE: 111, - NUMPAD_ENTER: 108, - NUMPAD_MULTIPLY: 106, - NUMPAD_SUBTRACT: 109, - PAGE_DOWN: 34, - PAGE_UP: 33, - PERIOD: 190, - RIGHT: 39, - SHIFT: 16, - SPACE: 32, - TAB: 9, - UP: 38 - }, - - nodeTypes: { - - ELEMENT_NODE: 1, - ATTRIBUTE_NODE: 2, - TEXT_NODE: 3, - CDATA_SECTION_NODE: 4, - ENTITY_REFERENCE_NODE: 5, - ENTITY_NODE: 6, - PROCESSING_INSTRUCTION_NODE: 7, - COMMENT_NODE: 8, - DOCUMENT_NODE: 9, - DOCUMENT_TYPE_NODE: 10, - DOCUMENT_FRAGMENT_NODE: 11, - NOTATION_NODE: 12 - }, - - directions: { - UP: 0, - RIGHT: 1, - DOWN: 2, - LEFT: 3 - } - }; - - NI.math = { - - random: function() { - if (arguments.length === 0) { - return window.Math.random(); - } else if (arguments.length === 1) { - return window.Math.random()*arguments[0]; - } - return window.Math.random()*(arguments[1] - arguments[0]) + arguments[0]; - }, - - round: function(n, places) { - var p = window.Math.pow(10, places); - return window.Math.round(n*p)/p; - } - }; - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - window.NI = NI; - -}(this)); \ No newline at end of file diff --git a/lib/tc.seed.js.orig b/lib/tc.seed.js.orig deleted file mode 100644 index 135557d..0000000 --- a/lib/tc.seed.js.orig +++ /dev/null @@ -1,312 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -(function(window) { - - var NI = {}, - fakeConsole; - - NI.ex = { - - checkStr: function(s) { - var t = typeof s; - if (t === "string") { return true; } - //throw new TypeError("Expected string, but found "+ t +" instead"); - console.error("Expected string, but found '"+ String(t) +"' instead"); - }, - - checkFn: function(fn) { - if ($.isFunction(fn)) { return true; } - //throw new TypeError("Expected function, but found "+ typeof fn +" instead"); - console.error("Expected function, but found '"+ typeof fn +"' instead"); - }, - - checkJQ: function(o) { - if (o instanceof $) { return true; } - //throw new TypeError("Expected jQuery object, but found"+ typeof o +" instead"); - console.error("Expected jQuery object, but found '"+ typeof o +"' instead"); - }, - - checkJQNode: function($e, type) { - NI.ex.checkJQ($e); - type = type.toLowerCase(); - if ($e.length === 1) { - if ($e[0].nodeName.toLowerCase() === type) { - return true; - } - } - throw new TypeError("Expected jQuery object holding single "+ type +" element"); - }, - - typeOf: function(v) { - var s = typeof v; - if (s === "object") { - if (v) { - if (typeof v.length === "number" && - !(v.propertyIsEnumerable("length")) && - typeof v.splice === "function") { - s = "array"; - } - } else { - s = "null"; - } - } - return s; - }, - - isEmpty: function(v) { - NI.ex.checkStr(v); - return $.trim(v) ? - false : true; - }, - - isHeadless: function($e) { - var node = $e[0]; - if (!node.parentNode) { - return true; - } - if (node.parentNode === NI.co.nodeTypes.DOCUMENT_NODE) { - return true; - } - return false; - } - }; - - NI.app = { - - bootstrap: function(app, options) { - var o; - o = $.extend({ - debug: false - }, options); - - app.console = NI.app.getConsole(o.debug); - app.classes = {}; - app.runtime = {}; - NI.fn.eventPool(app); - - app.console.info("::::::::::::: Starting application :::::::::::::"); - app.console.info((app.name || "") + " " + (app.version || "")); - app.console.info("::::::::::::::::::::::::::::::::::::::::::::::::"); - - return app; - }, - - getConsole: function(debug) { -<<<<<<< HEAD - if (debug && typeof window.console !== "undefined") { -======= - if (debug && typeof window.console !== "undefined" && - typeof window.console.debug !== "undefined") { - ->>>>>>> 56ef44ebc94eeab2e805403cb2f3c09e97bded6f - return window.console; - } - if (!fakeConsole) { - fakeConsole = {}; - $.each(("assert,count,debug,dir,dirxml,error,exception,\ - group,groupCollapsed,groupEnd,info,log,markTimeline,\ - profile,profileEnd,time,timeEnd,trace,warn").split(","), function() { - fakeConsole[this] = $.noop; - }); - } - return fakeConsole; - }, - - /** - * Initialize environment-specific components - * from an array of "feature" objects, each one - * of the form { feature: "foo", options: {} }, - * which invokes app[foo](options) - */ - initAppFeatures: function(app, env) { - if (!app.runtime) { - app.runtime = {}; - } - if ($.isArray(env.features)) { - $.each(env.features, function(i, o) { - if (app.runtime[o.feature]) { - NI.app.getConsole(true).warn(o.feature +" already initialized"); - } else if ($.isFunction(app[o.feature])) { - app.runtime[o.feature] = app[o.feature].call(app, o.options); - } - }); - } - } - }; - - NI.fn = { - - // via http://www.nczonline.net/blog/2009/07/28/the-best-way-to-load-external-javascript/ - loadScript: function(url, callback) { - var script = window.document.createElement("script"); - script.type = "text/javascript"; - if (script.readyState) { - script.onreadystatechange = function() { - if (script.readyState == "loaded" || script.readyState == "complete") { - script.onreadystatechange = null; - if ($.isFunction(callback)) { - callback(); - } - } - }; - } else { - script.onload = function() { - if ($.isFunction(callback)) { - callback(); - } - }; - } - script.src = url; - window.document.getElementsByTagName("head")[0].appendChild(script); - }, - - extend: function(sub, base) { - var F = function() {}; - F.prototype = base.prototype; - sub.prototype = new F(); - sub.prototype.constructor = sub; - sub.base = base.prototype; - if (base.prototype.constructor === Object.prototype.constructor) { - base.prototype.constructor = base; - } - }, - - clone: function(o) { - var F = function() {}; - F.prototype = o; - return new F(); - }, - - augment: function(dest, src) { - var i; - if (arguments[2]) { - for (i = 2; i < arguments.length; i += 1) { - dest.prototype[arguments[i]] = src.prototype[arguments[i]]; - } - } else { - for (i in src.prototype) { - if (!dest.prototype[i]) { - dest.prototype[i] = src.prototype[i]; - } - } - } - }, - - eventPool: function(target) { - var events = $({}); - target.bind = function() { - events.bind.apply(events, arguments); - }; - target.unbind = function() { - events.unbind.apply(events, arguments); - }; - target.trigger = function() { - events.trigger.apply(events, arguments); - }; - return target; - }, - - guid: function(prefix) { - return (prefix || "obj_")+ new Date().getTime(); - }, - - randomElement: function(array) { - if (NI.ex.typeOf(array) === "array" && array.length > 0) { - return array[window.Math.floor(NI.math.random(array.length))]; - } - } - }; - - NI.co = { - - keyboard: { - - BACKSPACE: 8, - CAPS_LOCK: 20, - COMMA: 188, - CONTROL: 17, - DELETE: 46, - DOWN: 40, - END: 35, - ENTER: 13, - ESCAPE: 27, - HOME: 36, - INSERT: 45, - LEFT: 37, - NUMPAD_ADD: 107, - NUMPAD_DECIMAL: 110, - NUMPAD_DIVIDE: 111, - NUMPAD_ENTER: 108, - NUMPAD_MULTIPLY: 106, - NUMPAD_SUBTRACT: 109, - PAGE_DOWN: 34, - PAGE_UP: 33, - PERIOD: 190, - RIGHT: 39, - SHIFT: 16, - SPACE: 32, - TAB: 9, - UP: 38 - }, - - nodeTypes: { - - ELEMENT_NODE: 1, - ATTRIBUTE_NODE: 2, - TEXT_NODE: 3, - CDATA_SECTION_NODE: 4, - ENTITY_REFERENCE_NODE: 5, - ENTITY_NODE: 6, - PROCESSING_INSTRUCTION_NODE: 7, - COMMENT_NODE: 8, - DOCUMENT_NODE: 9, - DOCUMENT_TYPE_NODE: 10, - DOCUMENT_FRAGMENT_NODE: 11, - NOTATION_NODE: 12 - }, - - directions: { - UP: 0, - RIGHT: 1, - DOWN: 2, - LEFT: 3 - } - }; - - NI.math = { - - random: function() { - if (arguments.length === 0) { - return window.Math.random(); - } else if (arguments.length === 1) { - return window.Math.random()*arguments[0]; - } - return window.Math.random()*(arguments[1] - arguments[0]) + arguments[0]; - }, - - round: function(n, places) { - var p = window.Math.pow(10, places); - return window.Math.round(n*p)/p; - } - }; - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - window.NI = NI; - -}(this)); \ No newline at end of file diff --git a/lib/tc.social_rotator.js b/lib/tc.social_rotator.js deleted file mode 100644 index 5cc0e23..0000000 --- a/lib/tc.social_rotator.js +++ /dev/null @@ -1,131 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -(function(window, $) { - - var NI = window.NI; - - //var SocialButtons = { - // twitter:function(options){ - // var o, button; - // o = $.extend({ - // - // }, options); - // - // button = $(''); - // - // return button; - // }, - // facebook:function(options){ - // - // }, - // gplus:function(options){ - // - // } - //} - - function SocialRotator(options) { - var o, internal; - - o = $.extend({ - element:null, - button_class:'spread-button', - cycle_length:3000, - fadeSpeed:600 - }, options); - - NI.ex.checkJQ(o.element); - - internal = { - element_zIndex:o.element.css('zIndex'), - spread_timer:null, - spread_buttons: o.element.find('.'+o.button_class), - cycle_counter:0, - current_button:0, - buttons:{} - }; - - this.o = o; - this.internal = internal; - - internal.spread_buttons.css({ - 'opacity':0.0, - 'zIndex':internal.element_zIndex + 1 - }).show(); - - function cycleButtons() { - internal.spread_buttons.stop(true,true).animate({ - 'opacity':0.0 - },o.fadeSpeed,function(){ - internal.spread_buttons.css({ - 'zIndex':internal.element_zIndex + 1 - }); - }); - internal.cycle_counter++; - internal.current_button = (internal.cycle_counter % 3); - internal.spread_buttons.eq(internal.current_button).stop(true, true).animate({ - opacity:1.0 - },o.fadeSpeed,function(){ - internal.spread_buttons.eq(internal.current_button).css({ - 'zIndex':internal.element_zIndex + 2 - }); - }); - internal.spread_timer = setTimeout(cycleButtons, o.cycle_length); - }; - - o.element.hover( - function () { - if(internal.spread_timer){ - clearTimeout(internal.spread_timer) - } - }, - function () { - if(internal.spread_timer){ - clearTimeout(internal.spread_timer); - } - internal.spread_timer = setTimeout(cycleButtons, (o.cycle_length/2)); - } - ); - - cycleButtons(); - } - - //SocialRotator.prototype.set_social = function(social){ - // var i, temp_button; - // for(i in social){ - // if($.isFunction(SocialButtons[i])){ - // temp_button = SocialButtons[i](social[i]); - // temp_button.addClass('social-' + i).addClass(this.o.button_class); - // if(this.internal.spread_buttons.filter('.social-'+i).length){ - // this.internal.spread_buttons.filter('.social-'+i).replaceWith(temp_button); - // } else { - // this.o.element.prepend(temp_button); - // } - // $(document).trigger('readystatechange'); - // } - // } - // this.internal.spread_buttons = this.o.element.find('.'+this.o.button_class); - //} - - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - NI.SocialRotator = SocialRotator; - -}(this, this.jQuery)); \ No newline at end of file diff --git a/lib/tc.tooltip.js b/lib/tc.tooltip.js deleted file mode 100644 index ec0ed1b..0000000 --- a/lib/tc.tooltip.js +++ /dev/null @@ -1,555 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -(function(window, $) { - - var NI = window.NI; - - // remove "px" from a string representing a css pixel dimension - // and cast as a Number (i.e. trimpx("10px") returns 10) - // Used to parse px dimension values from CSS properties, - // such as "width" and "height" - function trimPX(s) { - if (s) { - return Number(s.substring(0, s.length - 2)); - } - return 0; - } - - function Tooltip(options) { - - var me, o, internal, handlers, calculate_position; - - me = this; - o = $.extend({ - triggers: $('.tooltip_trigger'), - tooltip:null, - reactive_tooltip: true, - modal_tooltip: false, - markup_generator:null, - animate_slide:true, - animate_opacity:true, - offset_top: 0, - offset_left: 0, - tail_offset_top: 0, - tail_offset_left: 0, - use_mousepos:true, - positions:['top','right','bottom','left'], - container:$('body'), - hide_delay:200, - resize_response_delay: 50 - }, options); - - internal = { - guid: NI.fn.guid("tooltip"), - window:$(window), - tooltip:(o.tooltip ? o.tooltip.appendTo(o.container) : $('
').appendTo(o.container)), - tooltip_content:null, - tails:null, - triggers:o.triggers, - has_been_shown:false, - current_trigger:null, - animating:false, - visible:false, - mousepos:null, - visibility_timer:null, - resize_timer: null - }; - - function init(){ - var event_data = {me: me}; - - if (o.modal_tooltip) { - internal.triggers.bind('click.'+internal.guid, event_data, handlers.trigger_click); - } else { - internal.triggers.bind('mouseenter.'+internal.guid, event_data, handlers.trigger_mouseenter); - internal.triggers.bind('mouseleave.'+internal.guid, event_data, handlers.trigger_mouseleave); - } - - if (o.reactive_tooltip) { - internal.tooltip.bind('mouseenter.'+internal.guid, event_data, handlers.tooltip_mouseenter); - internal.tooltip.bind('mouseleave.'+internal.guid, event_data, handlers.tooltip_mouseleave); - } - - generate_tails(); - - internal.tooltip_content = $('
'); - internal.tooltip.append(internal.tooltip_content); - - if(o.use_mousepos){ - $(document).bind('mousemove.'+internal.guid,function(e,d){ - if(d && d.mousepos){ - internal.mousepos = d.mousepos; - } else { - internal.mousepos = { - x:e.pageX, - y:e.pageY - }; - } - }); - } - } - - function generate_tails(){ - var i, my_tail; - - var css_fn = { - top:function(container){ - var h = container.children('.tooltip-tail').css('height'); - return { - //border: '1px solid red', - width:'100%', - height: h, - bottom: '-' + h, - left: '0px' - }; - }, - right:function(container){ - var w = container.children(".tooltip-tail").css("width"); - return { - //border: '1px solid green', - width: w, - height: '100%', - top: '0px', - left: '-' + w - }; - }, - bottom:function(container){ - var h = container.children('.tooltip-tail').css('height'); - return { - //border: '1px solid yellow', - width: '100%', - height: h, - top: '-' + h, - left: '0px' - }; - }, - left:function(container){ - var w = container.children(".tooltip-tail").css("width"); - return { - //border: '1px solid blue', - width: w, - height: '100%', - top: '0px', - right: '-' + w - }; - } - }; - - for (i = 0; i < o.positions.length; i += 1) { - my_tail = $('
'); - internal.tooltip.append(my_tail); - if ($.isFunction(css_fn[o.positions[i]])) { - my_tail.css($.extend(css_fn[o.positions[i]](my_tail),{ - position: 'absolute', - zIndex: 100 - })); - } - } - - internal.tails = internal.tooltip.find('.tooltip-tail-container'); - } - - // the default markup generator - // (if none is provided by the user) - function markup_generator(markup) { - var output; - if (markup instanceof $) { - output = markup; - } else if (typeof markup === "string") { - output = $(markup); - } else { - output = $("

No Data.

"); - } - return output; - } - - function show(data) { - internal.tooltip_content.empty().append( - ($.isFunction(o.markup_generator) ? o.markup_generator(data) : markup_generator(data)) - ); - move_to_target( calculate_target_position() ); - } - - function reposition() { - if (!internal.animating) { - move_to_target( calculate_target_position() ); - } - } - - function get_source_position(){ - var offset; - if(o.use_mousepos){ - return { - left: internal.mousepos.x, - top: internal.mousepos.y - }; - } else { - offset = internal.current_trigger.offset(); - return { - left: offset.left + o.container.scrollLeft(), - top: offset.top + o.container.scrollTop() - }; - } - } - - function get_trigger_size(){ - if(o.use_mousepos){ - return { - width:0, - height:0 - }; - } else { - // current_trigger must be rendered - return { - width: internal.current_trigger.outerWidth(), - height: internal.current_trigger.outerHeight() - }; - } - } - - function get_tooltip_size(){ - return { - width:internal.tooltip.outerWidth(), - height:internal.tooltip.outerHeight() - }; - } - - calculate_position = { - // sp -- source_position - // trs -- trigger_size - // tts -- tooltip_size - - top:function(sp,trs,tts){ - var tail = get_tail("top"); - return { - className:'top', - top:(sp.top - (tts.height) - o.tail_offset_top - (tail ? trimPX(tail.css("height")) : 0)) + o.offset_top, - left:((sp.left + (trs.width/2)) - (tts.width/2) + o.tail_offset_left) + o.offset_left - }; - }, - bottom:function(sp,trs,tts){ - var tail = get_tail("bottom"); - return { - className:'bottom', - top:(sp.top + trs.height + o.tail_offset_top + (tail ? trimPX(tail.css("height")) : 0) ) - o.offset_top, - left:((sp.left + (trs.width/2)) - (tts.width/2) + o.tail_offset_left) + o.offset_left - }; - }, - right:function(sp,trs,tts){ - var tail = get_tail("right"); - return { - className:'right', - top: (sp.top + (trs.height/2) - (tts.height/2)) + o.offset_top, - left: (sp.left + (trs.width) + o.tail_offset_top + (tail ? trimPX(tail.css("width")) : 0)) + o.offset_left - }; - }, - left:function(sp,trs,tts){ - var tail = get_tail("left"); - return { - className:'left', - top: (sp.top + (trs.height/2) - (tts.height/2)) + o.offset_top, - left: (sp.left - (tts.width) - o.tail_offset_top - (tail ? trimPX(tail.css("width")) : 0)) - o.offset_left - }; - } - }; - - function get_tail(position){ - var tail = internal.tails.filter('.'+position).children('.tooltip-tail'); - return tail.length ? tail : null; - } - - function get_edge_collisions(tp, tts){ - // tp -- target_position - // tts -- tooltip_size - - var collisions = []; - - //check top - if((tp.top - internal.window.scrollTop()) < 0){ - collisions.push('top'); - } - - //check bottom - if((tp.top + tts.height) > internal.window.height()){ - collisions.push('bottom'); - } - - //check left - if((tp.left - internal.window.scrollLeft()) < 0){ - collisions.push('left'); - } - - //check right - if((tp.left + tts.width) > internal.window.width()){ - collisions.push('right'); - } - - return collisions; - } - - function calculate_target_position(){ - var source_position, trigger_size, tooltip_size, target_position, i; - - source_position = get_source_position(); - trigger_size = get_trigger_size(); - tooltip_size = get_tooltip_size(); - - for (i = 0; i < o.positions.length; i += 1) { - if($.isFunction(calculate_position[o.positions[i]])){ - target_position = calculate_position[o.positions[i]](source_position, trigger_size, tooltip_size); - } - if (!get_edge_collisions(target_position, tooltip_size).length) { - return target_position; - } - } - - return null; - } - - function move_to_target(target_pos){ - var me = this, css_change, animate_change, tail, tail_css_change, tail_animate_change; - - if (!target_pos) { - return; - } - - internal.tooltip.removeClass('position-top position-right position-bottom position-left').addClass('position-' + target_pos.className); - internal.tails.css('visibility','hidden').filter('.' + target_pos.className).css('visibility','visible'); - - css_change = {}; - animate_change = {}; - - tail = get_tail(target_pos.className); - tail_css_change = {}; - tail_animate_change = {}; - - if(o.animate_slide){ - animate_change.top = target_pos.top; - animate_change.left = target_pos.left; - switch(target_pos.className){ - case 'top': - case 'bottom': - tail_animate_change.left = (internal.tooltip.width()/2) - o.tail_offset_left - (trimPX(tail.css("width"))/2); - break; - case 'left': - case 'right': - tail_animate_change.top = (internal.tooltip.height()/2) + o.tail_offset_top - (trimPX(tail.css("height"))/2); - break; - } - } else { - css_change.top = target_pos.top; - css_change.left = target_pos.left; - - switch(target_pos.className){ - case 'top': - case 'bottom': - tail_css_change.left = (internal.tooltip.width()/2) - o.tail_offset_left - (trimPX(tail.css("width"))/2); - break; - case 'left': - case 'right': - tail_css_change.top = (internal.tooltip.height()/2) + o.tail_offset_top - (trimPX(tail.css("height"))/2); - break; - } - } - - if(o.animate_opacity){ - if(!internal.has_been_shown){ - css_change.opacity = '0.0'; - } - animate_change.opacity = '1.0'; - } else { - css_change.opacity = '1.0'; - } - - internal.animating = true; - - tail.css(tail_css_change).stop(true).show().animate(tail_animate_change,500,'easeOutCubic',function(){}); - - internal.tooltip.stop().show().css(css_change).animate(animate_change,500,'easeOutCubic',function(){ - internal.animating = false; - internal.visible = true; - }); - - $(window).bind("resize."+ internal.guid, handlers.window_resize); - if (o.modal_tooltip) { - $(document).bind("click."+ internal.guid, handlers.doc_click); - } - - internal.has_been_shown = true; - } - - function hide(){ - internal.animating = true; - internal.visible = false; - internal.tooltip.stop().animate({ - 'opacity':0.0 - },200,'easeOutCirc',function(){ - internal.tooltip.hide(); - internal.animating = false; - internal.current_trigger = null; - }); - $(window).unbind('resize.'+internal.guid); - if (o.modal_tooltip) { - $(document).unbind("click."+ internal.guid); - } - } - - handlers = { - trigger_mouseenter:function(e){ - if(internal.visibility_timer){ - clearTimeout(internal.visibility_timer); - internal.visibility_timer = null; - } - internal.current_trigger = $(this); - show(); - }, - trigger_mouseleave:function(e){ - if(internal.visibility_timer){ - clearTimeout(internal.visibility_timer); - internal.visibility_timer = null; - } - internal.visibility_timer = setTimeout(hide,o.hide_delay); - }, - trigger_click: function(e) { - if (internal.visible) { - hide(); - } else { - internal.current_trigger = $(this); - show(); - } - }, - tooltip_mouseenter:function(e){ - if(internal.visibility_timer){ - clearTimeout(internal.visibility_timer); - internal.visibility_timer = null; - } - if(!o.use_mousepos && internal.current_trigger && !internal.visible){ - show(); - } - }, - tooltip_mouseleave:function(e,d){ - if(internal.animating){ - return; - } - if(internal.visibility_timer){ - clearTimeout(internal.visibility_timer); - internal.visibility_timer = null; - } - internal.visibility_timer = setTimeout(hide,o.hide_delay); - }, - window_resize: function(e) { - if (internal.resize_timer) { - clearTimeout(internal.resize_timer); - internal.resize_timer = null; - } - internal.resize_timer = setTimeout(reposition, o.resize_response_delay); - }, - doc_click: function(e) { - if (internal.tooltip[0] === e.target || $.contains(internal.tooltip[0], e.target)) { - return; - } - if (internal.current_trigger && - (internal.current_trigger[0] === e.target || $.contains(internal.current_trigger[0], e.target))) { - return; - } - // if the click didn't occur on the tooltip or the current trigger --> hide - hide(); - } - }; - - this.add_trigger = function(trigger){ - var event_data = {me: this}; - - if (o.modal_tooltip) { - trigger.bind('click.'+internal.guid, event_data, handlers.trigger_click); - } else { - trigger.bind('mouseenter.'+internal.guid, event_data, this.handlers.trigger_mouseenter); - trigger.bind('mouseleave.'+internal.guid, event_data, this.handlers.trigger_mouseleave); - } - - if(!internal.triggers.length){ - internal.triggers = trigger; - } else { - internal.triggers.add(trigger); - } - }; - - this.clear_triggers = function() { - internal.triggers.each(function(i,j){ - $(j).unbind('mouseenter.'+internal.guid).unbind('mouseleave.'+internal.guid).unbind('click.'+internal.guid); - }); - internal.triggers = $({}); - }; - - this.show_tooltip = function(_options){ - var _o = $.extend({ - trigger:null, - data:null - },_options); - - if(!_o.trigger){ - return false; - } - - if(internal.visibility_timer){ - clearTimeout(internal.visibility_timer); - internal.visibility_timer = null; - } - - internal.current_trigger = _o.trigger; - internal.tooltip.stop(true); - - show(_o.data); - }; - - this.hide_tooltip = function(delay){ - if(internal.visibility_timer){ - clearTimeout(internal.visibility_timer); - internal.visibility_timer = null; - } - internal.visibility_timer = setTimeout(hide,(delay ? delay : o.hide_delay)); - }; - - this.get_tooltip = function(){ - return internal.tooltip; - }; - - this.destroy = function() { - if(internal.visibility_timer){ - clearTimeout(internal.visibility_timer); - internal.visibility_timer = null; - } - internal.tooltip.remove(); - this.clear_triggers(); - if (o.use_mousepos) { - $(document).unbind('mousemove.'+internal.guid); - } - $(window).unbind('resize.'+internal.guid); - if (o.modal_tooltip) { - $(document).unbind("click."+ internal.guid); - } - }; - - init(); - } - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - NI.Tooltip = Tooltip; - -}(this, this.jQuery)); \ No newline at end of file diff --git a/lib/tc.validation.js b/lib/tc.validation.js deleted file mode 100644 index cab9555..0000000 --- a/lib/tc.validation.js +++ /dev/null @@ -1,505 +0,0 @@ -/* ============================================================================ - - >4SESz., _, ,gSEE2zx.,_ .azx ,w. -@Sh. "QEE3. JEE3. &ss `*4EEEEE2x.,_ "EEV ,aS5^;dEEEE2x., VEEF _ -\E2`_,gF4EEEx.?jF EE5L `*4EEEEE2zpn..ZEEF ;sz. `*EEESzw.w* '|EE. - ,dEEF `"?j] _,_ ,_ _, _,. L.EEEF !EEF _,, `"`` EE7 ,,_ - :EEE7 ,ws,`|EEL`JEEL`JEE)`JEEL zE5` E3. / [EE3 ,w. zE2` Ek .zE5^JZE3.,6EF [3 - {EEE. VEE7.EE2 AE3. EEV ZEEL{EEL ws. ; [EE1 EEEt{E3. JEELEE3. JE5LJEEF ,w, - \EEk,,>^ JEEL,@EEF ZE5L,ZE5^ "Q3. V2`. \EEk,,J' "Q[ yE2^ VE[_zEE[,"QEL V5F - ,ss :EE7 ;EEF L,szzw.. ,., `` - \E5.,E5F EE1. /; ``*4EEEZhw._ EEEL - ```` `` JEEE. `"45EEEhw.,,,] - -From 2010 till ∞ -typecode-js v 0.1 -*/ - -(function(window, $) { - - var NI = window.NI, - console = NI.app.getConsole(true); - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -// regular expressions - - var regex = { - //email: /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i, - email: /^[a-zA-Z0-9\+._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/, - - url: /^((ht|f)tps?:\/\/)?[a-zA-Z0-9-\.]+\.[a-zA-Z]{2,4}\/?([^\s<>\%"\,\{\}\\|\\\^\[\]`]+)?$/, - - alphanumeric: /^\s*[a-z\d\.]+([a-z\d\.]*\.|\s*\-\s*[a-z\d\.]+)?(\s+[a-z\d\.]+(\.|\s*\-\s*[a-z\d\.]+)?)*\s*$/i, - - number: /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/, - - hex_color: /^(#)?([0-9a-fA-F]{3})([0-9a-fA-F]{3})?$/ - }; - - function regTest(s, key) { - return regex[key].test(s); - } - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -// tests - - var is = { - - empty: function(s) { - return NI.ex.isEmpty(s); - }, - - alphaNumeric: function(s) { - return regTest(s, "alphanumeric"); - }, - - email: function(s) { - return regTest(s, "email"); - }, - - url: function(s) { - return regTest(s, "url"); - }, - - num: function(s) { - return regTest(s, "number"); - }, - - hex_color: function(s) { - return regTest(s, "hex_color"); - }, - - numNonNegative: function(s) { - return isNum(s) && Number(s) >= 0; - }, - - numPositive: function(s) { - return isNum(s) && Number(s) > 0; - }, - - date: function(s) { - var day, month, year, buf, date; - if (s) { - buf = s.split("/"); - if (buf.length == 3) { - month = buf[0].replace(/^0+/,''); - day = buf[1].replace(/^0+/,''); - year = buf[2].replace(/^0+/,''); - if (!(year.length == 2 || year.length == 4)) { - return false; - } - try { - date = new Date(); - month = (month*1) - 1; - date.setFullYear(year, month, day); - if (date.getMonth() == month && - date.getDate() == day && - date.getFullYear() == year) { - return true; - } - } catch(err) { - // ignore - } - } - return false; - } - return false; - } - }; - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -// built-in validators - - var error_messages = { - - required: "This is a required field", - - alphanumeric: "This is not a valid alpha-numeric value", - - email: "This is not a valid Email address", - - url: "This is not a valid URL", - - number: "This is not a valid number", - - date: "This is not a valid date", - - hex_color: "This is not a valid hex value" - }; - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -// field validation - - - //begin ValidationToken - function ValidationToken() { - this.clean(); - } - - ValidationToken.prototype = { - errors: function() { - return this.errs.length ? - this.errs : false; - }, - addError: function(str) { - this.errs.push(str); - return this; - }, - clean: function() { - this.errs = []; - return this; - } - }; - //end ValidationToken - - - //begin validate - function validate(field, validators) { - var value, - validators, - token, - errors, - type, - master; - - master = field.data("master"); - - if (master && $.isFunction(master.get_val)) { - // the field is an instance of NI.Field - value = master.get_val(); - if (master._name) { - type = master._name; - } - } else { - switch (field[0].nodeName.toLowerCase()) { - case "input": - value = "false"; - switch (field.attr("type")) { - case "radio": - case "checkbox": - type = "bool"; - if (field.prop("checked")) { - value = "true"; - } - break; - default: - value = field.val(); - break; - } - break; - case "textarea": - value = field.val(); - break; - case "select": - type = "select"; - value = field.find("option:selected").attr("value"); - break; - default: - value = false; - break; - } - } - - //NI.ex.checkStr(value); - - if (!validators) { - validators = field.data("validators"); - } - token = field.data("vtoken"); - - if (!validators || !token) { - throw new Error("Field not prepared for validation"); - } - token.clean(); - - $.each(validators, function(j, v) { - var t, validation; - t = typeof v; - if (t === "string") { - v = v.toLowerCase(); - if ($.isFunction(ValidationManager.validators[v])) { - validation = ValidationManager.validators[v](value); - if (validation && validation.errors && validation.errors.length) { - $.each(validation.errors, function(k, err) { - token.addError(err); - }); - } - } else if (v.indexOf("maxlen") === 0) { - (function(max) { - if (value.length > max) { - token.addError("This cannot exceed "+ max +" characters"); - } - }(v.split("=")[1])); - } else if (v.indexOf("minlen") === 0) { - (function(min) { - if (value.length < min) { - token.addError("This must be at least "+ min +" characters"); - } - }(v.split("=")[1])); - } else { - switch (v) { - case "required": - (function() { - var err; - err = error_messages["required"]; - if (type === "bool" || type == "Checkbox") { - if (value === "false") { - token.addError(err); - } - } else if (type === "select" || type == "Dropdown" || type == "RadioSet") { - if (value === "-1") { - token.addError(err); - } - } else if (type == "CheckboxSet") { - if (!value.length) { - token.addError(err); - } - } else { - if (NI.ex.isEmpty(value)) { - token.addError(err); - } - } - }()); - break; - case "alphanumeric": - if (value && !is.alphaNumeric(value)) { - token.addError(error_messages["alphanumeric"]); - } - break; - case "email": - if (value && !is.email(value)) { - token.addError(error_messages["email"]); - } - break; - case "url": - if (value && !is.url(value)) { - token.addError(error_messages["url"]); - } - break; - case "number": - if (value && !is.num(value)) { - token.addError(error_messages["number"]); - } - break; - case "date": - if (value && !is.date(value)) { - token.addError(error_messages["date"]); - } - break; - case "hex_color": - if (value && !is.hex_color(value)){ - token.addError(error_messages["hex_color"]); - } - break; - default: - break; - } - } - } else if (t === "function") { - validation = v(value); - if (validation.errors && validation.errors.length) { - $.each(validation.errors, function(k, err) { - token.addError(err); - }); - } - } - }); - - errors = token.errors(); - if (errors) { - field.trigger("validationFail", { errors: errors }); - return { valid: false, errors: errors }; - } - field.trigger("validationPass"); - return { valid: true }; - } - //end validate - - - //begin reset - function reset(field) { - var token; - - token = field.data("vtoken"); - - if (!token) { - throw new Error("Field not prepared for validation"); - } - - token.clean(); - - field.trigger("validationReset"); - return { }; - } - //end reset - - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -// manager - - var events = { - fieldValidationPass: function(e, d) { - e.data.master.removeClass("state-invalid").addClass("state-valid"); - e.data.manager.internal.eventTarget.trigger("fieldValidationPass", d); - e.data.manager.isValid(); - return false; - }, - fieldValidationFail: function(e, d) { - e.data.master.removeClass("state-valid").addClass("state-invalid"); - e.data.manager.internal.eventTarget.trigger("fieldValidationFail", d); - e.data.manager.isValid(); - return false; - }, - fieldValidationReset: function(e, d) { - e.data.master.removeClass("state-valid state-invalid"); - return false; - }, - watchEventHandler: function(e, d){ - validate($(this)); - }, - managerValidationPass: function(e, d){ - e.data.manager.internal.eventTarget.removeClass("state-invalid").addClass("state-valid"); - }, - managerValidationFail: function(e, d){ - e.stopPropagation(); - e.data.manager.internal.eventTarget.removeClass("state-valid").addClass("state-invalid"); - } - }; - - function ValidationManager(options) { - var me = this; - - this.o = $.extend({ - $mother: null, - spec: [], - watchEvents:['keyup', 'change'] - }, options); - - this.internal = { - eventTarget: this.o.$mother || $({}) - }; - - this.fields = []; - - $.each(this.o.spec, function(i, item) { - me.addField(item); - }); - - this.internal.eventTarget.bind("managerValidationFail", { manager:this }, events.managerValidationFail) - .bind("managerValidationPass", { manager:this }, events.managerValidationPass); - } - - ValidationManager.prototype = { - addField: function(item) { - var field, i; - field = typeof item.element === "string" ? $(item.element) : item.element; - if (!field.length) { - return false; - } - - field.data("validators", item.validators); - field.data("vtoken", new ValidationToken()); - - if (item.master) { - field.data("master", item.master); - } - - field.bind("validationPass", { manager:this, master:(item.master ? item.master.$e : field) }, events.fieldValidationPass) - .bind("validationFail", { manager:this, master:(item.master ? item.master.$e : field) }, events.fieldValidationFail) - .bind("validationReset", { manager:this, master:(item.master ? item.master.$e : field) }, events.fieldValidationReset) - .bind("validate", { manager:this, field:field }, function(e,d){ - validate(e.data.field); - }); - - for (i in this.o.watchEvents) { - field.bind(this.o.watchEvents[i], { manager:this }, events.watchEventHandler); - } - - this.fields.push(field); - return field; - //validate(field); - }, - validate: function() { - var errorCount = 0; - - $.each(this.fields, function(i, field) { - var validation = validate(field); - if (!validation.valid) { - errorCount += validation.errors.length; - } - }); - - return errorCount === 0; - }, - isValid: function() { - var i, errors; - errors = []; - for (i = 0; i < this.fields.length; i += 1) { - if (this.fields[i].data("vtoken").errors()) { - errors.push({ - field:this.fields[i], - token:this.fields[i].data("vtoken") - }); - } - } - if(errors.length){ - this.internal.eventTarget.trigger('managerValidationFail', {errors:errors}); - return false; - } - this.internal.eventTarget.trigger('managerValidationPass', {errors:errors}); - return true; - }, - reset: function() { - $.each(this.fields, function(i, field) { - field.data("vtoken").clean(); - field.trigger("validationReset"); - }); - if (this.o.$mother instanceof $) { - this.$e.removeClass("state-valid state-invalid"); - } - this.invalidFieldCount = 0; - return this; - } - }; - - ValidationManager.validators = {}; - - ValidationManager.registerValidator = function(key, fn) { - NI.ex.checkStr(key); - NI.ex.checkFn(fn); - key = key.toLowerCase(); - if (error_messages[key]) { - console.warn("Warning: you are overriding the built-in validator: "+ key); - //console.warn("Cannot override the built-in validator: "+ key); - //return; - } - ValidationManager.validators[key] = fn; - }; - - ValidationManager.registerErrorMessage = function(key, note) { - NI.ex.checkStr(key); - NI.ex.checkStr(note); - if (error_messages[key]) { - error_messages[key] = note; - } else { - - } - }; - - ValidationManager.makeRangeValidator = function(low, high, note) { - note = note || "This must be between "+ low +" and "+ high; - return function(value) { - value = Number(value); - if (value < low || value > high) { - return { valid: false, errors: [note] }; - } - return { valid: true }; - }; - }; - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - - NI.ValidationManager = ValidationManager; - NI.is = $.extend(NI.is || {}, is); - -}(this, this.jQuery)); \ No newline at end of file