Skip to content

Instantly share code, notes, and snippets.

@sebastien-p
Created September 11, 2011 21:09

Revisions

  1. Sebastien P. revised this gist Sep 14, 2011. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions production.js
    Original file line number Diff line number Diff line change
    @@ -3,12 +3,12 @@
    * http://twitter.com/_sebastienp
    * Licensed under the MIT license
    *
    * Tue Sep 13 2011 13:55:25 GMT+0200 (CEST)
    * 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,e,f,g,i,k){
    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=(e={
    b=(methods={

    /*** Public methods ***/

    @@ -50,7 +50,7 @@

    /**********************/

    })[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},{
    })[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 ***/

  2. Sebastien P. revised this gist Sep 13, 2011. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions production.js
    Original file line number Diff line number Diff line change
    @@ -24,25 +24,25 @@

    /*** Public methods ***/

    create: function (settings) {
    create: function (data) {



    },

    option: function (settings) {
    option: function (data) {



    },

    refresh: function (settings) {
    refresh: function (data) {



    },

    destroy:function (settings) {
    destroy:function (data) {



  3. Sebastien P. revised this gist Sep 13, 2011. 2 changed files with 110 additions and 25 deletions.
    67 changes: 67 additions & 0 deletions production.js
    Original 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);
    68 changes: 43 additions & 25 deletions jquery.cord.plugin-boilerplate.js → source.js
    Original 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) {
    ;!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 = $.extend)(

    $.fn[PLUGIN_NAME] = function (method, options, value, _methods, _i, _that, _data) {
    $.fn[PLUGIN_NAME] = function (method, options, value, methods, _i, _that, _data, _settings) {

    /*** Private methods ***/

    @@ -25,11 +27,11 @@

    /*** Public methods ***/

    method = (_methods = {
    method = (methods = {

    // $(element).myPlugin(["create",][options]) -> chainable jQuery object

    create: function (settings) {
    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 (settings) {
    option: function (data) {

    // 'this' refers to $(element) ...

    },

    // $(element).myPlugin("refresh") -> chainable jQuery object

    refresh: function (settings) {
    refresh: function (data) {

    // 'this' refers to $(element) ...

    },

    // $(element).myPlugin("destroy") -> chainable jQuery object

    destroy: function (settings) {
    destroy: function (data) {

    // 'this' refers to $(element) ...

    }

    })[method] || (options = options || method, _methods.create);
    })[method] || (

    options = /ct]$/.test({}.toString.call(options = options || method)) && options,

    methods.create

    );

    /*** Methods logic ***/

    for (_i = 0; (_that = this.eq(_i++))[0];)

    if (!(_data = _that.data(PLUGIN_NAME)) == (method == _methods.create)) {
    if (!(_data =

    if (method == _methods.option) {
    // Maybe kind of a workaround for the Zepto '$.fn.data' bug ? See above.
    //JSON.parse(

    if (!(1 in arguments)) return _data;
    _that.data(PLUGIN_NAME)

    if (typeof options == "string") {
    //)

    if (!(2 in arguments)) return _data[options];
    ) != (method != methods.create || !(_data || _that.data(PLUGIN_NAME,

    _data[options] = value
    // 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) }

    }
    //)

    method.call(_that, method != _methods.destroy ? $.extend(
    )))) {

    //TRUE, // Uncomment if needed but deep copy is not currently a part of Zepto's API
    if (method == methods.option) {

    _settings = _data.settings;

    if (!(1 in arguments)) return _settings;

    if (typeof options == "string") {

    _data || _that.data(PLUGIN_NAME, _data = {}) && _data, $.fn[PLUGIN_NAME].defaults,
    if (!(2 in arguments)) return _settings[options];

    ($.isPlainObject || $.isObject || function (object) {
    _settings[options] = value

    return /ct]$/.test({}.toString.call(object))
    } else extend(_settings, options)

    })(options) && 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, "");

    ) : _that.data(PLUGIN_NAME, "") && _data)
    method.call(_that, _data)

    }

    @@ -106,7 +124,7 @@

    /*** Public properties ***/

    defaults: $.extend({}, PLUGIN_DEFAULTS = {
    defaults: extend({}, PLUGIN_DEFAULTS = {

    // key: value ...

  4. Sebastien P. revised this gist Sep 12, 2011. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions jquery.cord.plugin-boilerplate.js
    Original 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) {
    ;!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));
    }("myPlugin", window, document, !0, !1, null);
  5. Sebastien P. created this gist Sep 11, 2011.
    121 changes: 121 additions & 0 deletions jquery.cord.plugin-boilerplate.js
    Original 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));