From bd4d247a4b5a5f1a33a43e2b51b1b4c510311eec Mon Sep 17 00:00:00 2001 From: Massimiliano Marcon Date: Sun, 10 Feb 2013 11:50:51 +0100 Subject: [PATCH] Support for Tire.js --- .jshintrc | 3 +- Makefile | 5 +- dist/tire.adapter.min.js | 1 + src/examples/example.tire.html | 295 +++++++++++++++++++++++++++++++++ src/tire.adapter.js | 133 +++++++++++++++ 5 files changed, 435 insertions(+), 2 deletions(-) create mode 100644 dist/tire.adapter.min.js create mode 100644 src/examples/example.tire.html create mode 100644 src/tire.adapter.js diff --git a/.jshintrc b/.jshintrc index 9be1fff..bc50461 100644 --- a/.jshintrc +++ b/.jshintrc @@ -3,7 +3,8 @@ "globals": { "jQuery": true, "nokia": true, - "Zepto": true + "Zepto": true, + "tire": true }, "browser": true, diff --git a/Makefile b/Makefile index 380a91a..57b2ec5 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ PLUGIN = jhere deps: npm install -dist: hint plugin zepto extensions summary +dist: hint plugin zepto tire extensions summary plugin: @./node_modules/.bin/uglifyjs -nc -o dist/$(PLUGIN).min.js src/$(PLUGIN).js @@ -13,6 +13,9 @@ plugin: zepto: @./node_modules/.bin/uglifyjs -nc -o dist/zepto.adapter.min.js src/zepto.adapter.js +tire: + @./node_modules/.bin/uglifyjs -nc -o dist/tire.adapter.min.js src/tire.adapter.js + extensions: @./build-scripts/build-extensions.sh diff --git a/dist/tire.adapter.min.js b/dist/tire.adapter.min.js new file mode 100644 index 0000000..aa9bf90 --- /dev/null +++ b/dist/tire.adapter.min.js @@ -0,0 +1 @@ +(function(e){function t(){e.each(this.queue,function(e,t){typeof t=="function"&&t.call(null)})}function u(e){return e._zid||(e._zid=o++)}e.error=function(e){throw new Error(e)},e.Deferred=function(){if(!(this instanceof e.Deferred))return new e.Deferred;this.queue=[],this._state="pending"};var n=e.Deferred.prototype,r,i,s;n.resolve=function(){this._state="resolved",t.call(this)},n.state=function(){return this._state},n.done=function(e){if(this._state==="pending"){this.queue.push(e);return}e.call(null)},r=function(){this.store={},this.counter=0},i=r.prototype,i.data=function(e,t,n){if(!n)return this.store[e.__data]&&this.store[e.__data][t];e.__data||(e.__data="cache"+this.counter++),this.store[e.__data]=this.store[e.__data]||{},this.store[e.__data][t]=n},i.removeData=function(e,t){if(t){this.store[e.__data][t]=null;return}this.store[e.__data]=null},s=new r,e.data=function(){return s.data.apply(s,arguments)},e.removeData=function(){return s.removeData.apply(s,arguments)};var o=1;e.proxy=function(t,n){if(e.isFunction(t)){var r=function(){return t.apply(n,arguments)};return r._zid=u(t),r}if(typeof n=="string")return e.proxy(t[n],t);throw new TypeError("expected function")},e.inArray=function(e,t,n){return[].indexOf.call(t,e,n)},e.Event=function(t,n){typeof t!="string"&&(n=t,t=n.type);var r=document.createEvent((t.match(/click|mouse/)?"Mouse":"")+"Events"),i=!0;return n&&(e.each(n,function(e,t,n,s){s=e==="bubbles"?i=!!t:r[e]=t}),r.initEvent(t,i,!0,null,null,null,null,null,null,null,null,null,null,null,null),r.isDefaultPrevented=function(){return this.defaultPrevented}),r},window.jQuery=e})(tire); \ No newline at end of file diff --git a/src/examples/example.tire.html b/src/examples/example.tire.html new file mode 100644 index 0000000..aa1b5ac --- /dev/null +++ b/src/examples/example.tire.html @@ -0,0 +1,295 @@ + + + + + HTML5 boilerplate—all you really need… + + + + +
+ + + + + + + + \ No newline at end of file diff --git a/src/tire.adapter.js b/src/tire.adapter.js new file mode 100644 index 0000000..fe672fd --- /dev/null +++ b/src/tire.adapter.js @@ -0,0 +1,133 @@ +/* +Copyright (c) 2013 Massimiliano Marcon, http://marcon.me + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +;(function($){ + $.error = function(msg){ + throw new Error(msg); + }; + /*MINIMAL implementation of $.Deferred*/ + /*This only implements the method required by jHERE*/ + /*So do not use it for real "promises" purpose*/ + $.Deferred = function(){ + if(!(this instanceof $.Deferred)) { + return new $.Deferred(); + } + this.queue = []; + this._state = 'pending'; + }; + + function callCallbacks(){ + $.each(this.queue, function(i, fn){ + if(typeof fn === 'function') { + fn.call(null); + } + }); + } + + var D = $.Deferred.prototype, Data, P, d; + D.resolve = function(){ + this._state = 'resolved'; + callCallbacks.call(this); + }; + D.state = function(){ + return this._state; + }; + D.done = function(callback){ + if(this._state === 'pending') { + this.queue.push(callback); + return; + } + callback.call(null); + }; + + Data = function(){ + this.store = {}; + this.counter = 0; + }; + P = Data.prototype; + P.data = function(element, key, object){ + if(!object) { + //getter + return this.store[element.__data] && this.store[element.__data][key]; + } + if(!element.__data) { + element.__data = 'cache' + this.counter++; + } + this.store[element.__data] = this.store[element.__data] || {}; + this.store[element.__data][key] = object; + }; + P.removeData = function(element, key){ + if(key) { + this.store[element.__data][key] = null; + return; + } + this.store[element.__data] = null; + }; + + d = new Data(); + $.data = function(){ + return d.data.apply(d, arguments); + }; + $.removeData = function(){ + return d.removeData.apply(d, arguments); + }; + + //Export Zepto as jQuery so there is no need + //to check for it in the plugin. + + //$.proxy implementation from Zepto source code + var _zid = 1; + function zid(element) { + return element._zid || (element._zid = _zid++); + } + $.proxy = function(fn, context) { + if ($.isFunction(fn)) { + var proxyFn = function(){ return fn.apply(context, arguments); }; + proxyFn._zid = zid(fn); + return proxyFn; + } else if (typeof context === 'string') { + return $.proxy(fn[context], fn); + } else { + throw new TypeError("expected function"); + } + }; + //$.inArray implementation from Zepto source code + $.inArray = function(elem, array, i){ + return [].indexOf.call(array, elem, i); + }; + $.Event = function(type, props) { + if (typeof type !== 'string') { + props = type; + type = props.type; + } + var event = document.createEvent((type.match(/click|mouse/) ? 'Mouse' : '') + 'Events'), bubbles = true; + if (props) { + $.each(props, function(name, value, a, x){ + x = (name === 'bubbles') ? (bubbles = !!value) : (event[name] = value); + }); + event.initEvent(type, bubbles, true, null, null, null, null, null, null, null, null, null, null, null, null); + event.isDefaultPrevented = function(){ return this.defaultPrevented; }; + } + return event; + }; + window.jQuery = $; +}(tire)); \ No newline at end of file