Created
September 11, 2011 21:09
Revisions
-
Sebastien P. revised this gist
Sep 14, 2011 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,12 +3,12 @@ * http://twitter.com/_sebastienp * Licensed under the MIT license * * Wed Sep 14 2011 11:53:40 GMT+0200 (CEST) */ ;!function (PLUGIN_NAME, WINDOW, DOCUMENT, TRUE, FALSE, NULL, UNDEFINED, $, PLUGIN_DEFAULTS, j) { if($=WINDOW.Zepto||WINDOW.jQuery)(j=$.extend)($.fn[PLUGIN_NAME]=function(b,c,d,methods,f,g,i,k){ /*** Private methods ***/ @@ -20,7 +20,7 @@ /***********************/ b=(methods={ /*** Public methods ***/ @@ -50,7 +50,7 @@ /**********************/ })[b]||(c=/ct]$/.test({}.toString.call(c=c||b))&&c,methods.create);for(f=0;(g=this.eq(f++))[0];)if(!(i=g.data(PLUGIN_NAME))!=(b!=methods.create||!i&&!g.data(PLUGIN_NAME,i={settings:j({},$.fn[PLUGIN_NAME].defaults,c)}))){if(b==methods.option){k=i.settings;if(!(1 in arguments))return k;if(typeof c=="string")if(2 in arguments)k[c]=d;else return k[c];else j(k,c)}else b==methods.destroy&&g.data(PLUGIN_NAME,"");b.call(g,i)}return this},{ /*** Public properties ***/ -
Sebastien P. revised this gist
Sep 13, 2011 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,25 +24,25 @@ /*** Public methods ***/ create: function (data) { }, option: function (data) { }, refresh: function (data) { }, destroy:function (data) { -
Sebastien P. revised this gist
Sep 13, 2011 . 2 changed files with 110 additions and 25 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,67 @@ /*! * Copyright (c) 2011 Sebastien P. * http://twitter.com/_sebastienp * Licensed under the MIT license * * Tue Sep 13 2011 13:55:25 GMT+0200 (CEST) */ ;!function (PLUGIN_NAME, WINDOW, DOCUMENT, TRUE, FALSE, NULL, UNDEFINED, $, PLUGIN_DEFAULTS, j) { if($=WINDOW.Zepto||WINDOW.jQuery)(j=$.extend)($.fn[PLUGIN_NAME]=function(b,c,d,e,f,g,i,k){ /*** Private methods ***/ function myPrivateMethod() { } /***********************/ b=(e={ /*** Public methods ***/ create: function (settings) { }, option: function (settings) { }, refresh: function (settings) { }, destroy:function (settings) { } /**********************/ })[b]||(c=/ct]$/.test({}.toString.call(c=c||b))&&c,e.create);for(f=0;(g=this.eq(f++))[0];)if(!(i=g.data(PLUGIN_NAME))!=(b!=e.create||!i&&!g.data(PLUGIN_NAME,i={settings:j({},$.fn[PLUGIN_NAME].defaults,c)}))){if(b==e.option){k=i.settings;if(!(1 in arguments))return k;if(typeof c=="string")if(2 in arguments)k[c]=d;else return k[c];else j(k,c)}else b==e.destroy&&g.data(PLUGIN_NAME,"");b.call(g,i)}return this},{ /*** Public properties ***/ defaults: j({},PLUGIN_DEFAULTS={ }), version: "1.0.0" /*************************/ })}("myPlugin", window, document, !0, !1, null); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,18 +2,20 @@ * Copyright (c) 2011 Sebastien P. * http://twitter.com/_sebastienp * Licensed under the MIT license * * Tue Sep 13 2011 13:55:25 GMT+0200 (CEST) */ ;!function (PLUGIN_NAME, WINDOW, DOCUMENT, TRUE, FALSE, NULL, UNDEFINED, $, PLUGIN_DEFAULTS, extend) { // Zepto is not currently fully supported because of a weird implementation of '$.fn.data' // which causes '$(element).data("namespace", {}).data("namespace")' to return '[object Object]' if ($ = WINDOW.Zepto || WINDOW.jQuery) (extend = $.extend)( $.fn[PLUGIN_NAME] = function (method, options, value, methods, _i, _that, _data, _settings) { /*** Private methods ***/ @@ -25,11 +27,11 @@ /*** Public methods ***/ method = (methods = { // $(element).myPlugin(["create",][options]) -> chainable jQuery object create: function (data) { // 'this' refers to $(element) ... @@ -40,63 +42,79 @@ // $(element).myPlugin("option", "optionName") -> value // $(element).myPlugin("option", "optionName", value) - > chainable jQuery object option: function (data) { // 'this' refers to $(element) ... }, // $(element).myPlugin("refresh") -> chainable jQuery object refresh: function (data) { // 'this' refers to $(element) ... }, // $(element).myPlugin("destroy") -> chainable jQuery object destroy: function (data) { // 'this' refers to $(element) ... } })[method] || ( options = /ct]$/.test({}.toString.call(options = options || method)) && options, methods.create ); /*** Methods logic ***/ for (_i = 0; (_that = this.eq(_i++))[0];) if (!(_data = // Maybe kind of a workaround for the Zepto '$.fn.data' bug ? See above. //JSON.parse( _that.data(PLUGIN_NAME) //) ) != (method != methods.create || !(_data || _that.data(PLUGIN_NAME, // Maybe kind of a workaround for the Zepto '$.fn.data' bug ? See above. //JSON.stringify( // Uncomment below if needed but deep copy isn't currently a part of Zepto's API _data = { settings: extend(/*TRUE, */{}, $.fn[PLUGIN_NAME].defaults, options) } //) )))) { if (method == methods.option) { _settings = _data.settings; if (!(1 in arguments)) return _settings; if (typeof options == "string") { if (!(2 in arguments)) return _settings[options]; _settings[options] = value } else extend(_settings, options) // '$.fn.removeData' would have been better but isn't currently a part of Zepto's API } else method == methods.destroy && _that.data(PLUGIN_NAME, ""); method.call(_that, _data) } @@ -106,7 +124,7 @@ /*** Public properties ***/ defaults: extend({}, PLUGIN_DEFAULTS = { // key: value ... -
Sebastien P. revised this gist
Sep 12, 2011 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ * Licensed under the MIT license */ ;!function (PLUGIN_NAME, WINDOW, DOCUMENT, TRUE, FALSE, NULL, UNDEFINED, $, PLUGIN_DEFAULTS) { // Zepto is not currently fully supported because of a weird implementation of '$.fn.data' // which causes '$(element).data("namespace", {}).data("namespace")' to return '[object Object]' @@ -118,4 +118,4 @@ ) }("myPlugin", window, document, !0, !1, null); -
Sebastien P. created this gist
Sep 11, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,121 @@ /*! * Copyright (c) 2011 Sebastien P. * http://twitter.com/_sebastienp * Licensed under the MIT license */ ;(function (PLUGIN_NAME, WINDOW, DOCUMENT, TRUE, FALSE, NULL, UNDEFINED, $, PLUGIN_DEFAULTS) { // Zepto is not currently fully supported because of a weird implementation of '$.fn.data' // which causes '$(element).data("namespace", {}).data("namespace")' to return '[object Object]' if ($ = WINDOW.Zepto || WINDOW.jQuery) $.extend( $.fn[PLUGIN_NAME] = function (method, options, value, _methods, _i, _that, _data) { /*** Private methods ***/ function privateMethod () { // ... } /*** Public methods ***/ method = (_methods = { // $(element).myPlugin(["create",][options]) -> chainable jQuery object create: function (settings) { // 'this' refers to $(element) ... }, // $(element).myPlugin("option") -> object // $(element).myPlugin("option", options) -> chainable jQuery object // $(element).myPlugin("option", "optionName") -> value // $(element).myPlugin("option", "optionName", value) - > chainable jQuery object option: function (settings) { // 'this' refers to $(element) ... }, // $(element).myPlugin("refresh") -> chainable jQuery object refresh: function (settings) { // 'this' refers to $(element) ... }, // $(element).myPlugin("destroy") -> chainable jQuery object destroy: function (settings) { // 'this' refers to $(element) ... } })[method] || (options = options || method, _methods.create); /*** Methods logic ***/ for (_i = 0; (_that = this.eq(_i++))[0];) if (!(_data = _that.data(PLUGIN_NAME)) == (method == _methods.create)) { if (method == _methods.option) { if (!(1 in arguments)) return _data; if (typeof options == "string") { if (!(2 in arguments)) return _data[options]; _data[options] = value } } method.call(_that, method != _methods.destroy ? $.extend( //TRUE, // Uncomment if needed but deep copy is not currently a part of Zepto's API _data || _that.data(PLUGIN_NAME, _data = {}) && _data, $.fn[PLUGIN_NAME].defaults, ($.isPlainObject || $.isObject || function (object) { return /ct]$/.test({}.toString.call(object)) })(options) && options ) : _that.data(PLUGIN_NAME, "") && _data) } return this }, { /*** Public properties ***/ defaults: $.extend({}, PLUGIN_DEFAULTS = { // key: value ... }), version: "1.0.0" } ) }("myPlugin", window, document, !0, !1, null));