Category: jquery-plugins

  • WordPress源代码——jquery-plugins(jquery.ui.touch-punch.js)

    WordPress源代码——jquery-plugins(jquery.ui.touch-punch.js)

    1	/*!
    2	 * jQuery UI Touch Punch 0.2.2
    3	 *
    4	 * Copyright 2011, Dave Furfero
    5	 * Dual licensed under the MIT or GPL Version 2 licenses.
    6	 *
    7	 * Depends:
    8	 *  jquery.ui.widget.js
    9	 *  jquery.ui.mouse.js
    10	 */
    11	(function ($) {
    12	
    13	  // Detect touch support
    14	  $.support.touch = 'ontouchend' in document;
    15	
    16	  // Ignore browsers without touch support
    17	  if (!$.support.touch) {
    18	    return;
    19	  }
    20	
    21	  var mouseProto = $.ui.mouse.prototype,
    22	      _mouseInit = mouseProto._mouseInit,
    23	      touchHandled;
    24	
    25	  /**
    26	   * Simulate a mouse event based on a corresponding touch event
    27	   * @param {Object} event A touch event
    28	   * @param {String} simulatedType The corresponding mouse event
    29	   */
    30	  function simulateMouseEvent (event, simulatedType) {
    31	
    32	    // Ignore multi-touch events
    33	    if (event.originalEvent.touches.length > 1) {
    34	      return;
    35	    }
    36	
    37	    event.preventDefault();
    38	
    39	    var touch = event.originalEvent.changedTouches[0],
    40	        simulatedEvent = document.createEvent('MouseEvents');
    41	   
    42	    // Initialize the simulated mouse event using the touch event's coordinates
    43	    simulatedEvent.initMouseEvent(
    44	      simulatedType,    // type
    45	      true,             // bubbles                   
    46	      true,             // cancelable                 
    47	      window,           // view                       
    48	      1,                // detail                     
    49	      touch.screenX,    // screenX                   
    50	      touch.screenY,    // screenY                   
    51	      touch.clientX,    // clientX                   
    52	      touch.clientY,    // clientY                   
    53	      false,            // ctrlKey                   
    54	      false,            // altKey                     
    55	      false,            // shiftKey                   
    56	      false,            // metaKey                   
    57	      0,                // button                     
    58	      null              // relatedTarget             
    59	    );
    60	
    61	    // Dispatch the simulated event to the target element
    62	    event.target.dispatchEvent(simulatedEvent);
    63	  }
    64	
    65	  /**
    66	   * Handle the jQuery UI widget's touchstart events
    67	   * @param {Object} event The widget element's touchstart event
    68	   */
    69	  mouseProto._touchStart = function (event) {
    70	
    71	    var self = this;
    72	
    73	    // Ignore the event if another widget is already being handled
    74	    if (touchHandled || !self._mouseCapture(event.originalEvent.changedTouches[0])) {
    75	      return;
    76	    }
    77	
    78	    // Set the flag to prevent other widgets from inheriting the touch event
    79	    touchHandled = true;
    80	
    81	    // Track movement to determine if interaction was a click
    82	    self._touchMoved = false;
    83	
    84	    // Simulate the mouseover event
    85	    simulateMouseEvent(event, 'mouseover');
    86	
    87	    // Simulate the mousemove event
    88	    simulateMouseEvent(event, 'mousemove');
    89	
    90	    // Simulate the mousedown event
    91	    simulateMouseEvent(event, 'mousedown');
    92	  };
    93	
    94	  /**
    95	   * Handle the jQuery UI widget's touchmove events
    96	   * @param {Object} event The document's touchmove event
    97	   */
    98	  mouseProto._touchMove = function (event) {
    99	
    100	    // Ignore event if not handled
    101	    if (!touchHandled) {
    102	      return;
    103	    }
    104	
    105	    // Interaction was not a click
    106	    this._touchMoved = true;
    107	
    108	    // Simulate the mousemove event
    109	    simulateMouseEvent(event, 'mousemove');
    110	  };
    111	
    112	  /**
    113	   * Handle the jQuery UI widget's touchend events
    114	   * @param {Object} event The document's touchend event
    115	   */
    116	  mouseProto._touchEnd = function (event) {
    117	
    118	    // Ignore event if not handled
    119	    if (!touchHandled) {
    120	      return;
    121	    }
    122	
    123	    // Simulate the mouseup event
    124	    simulateMouseEvent(event, 'mouseup');
    125	
    126	    // Simulate the mouseout event
    127	    simulateMouseEvent(event, 'mouseout');
    128	
    129	    // If the touch interaction did not move, it should trigger a click
    130	    if (!this._touchMoved) {
    131	
    132	      // Simulate the click event
    133	      simulateMouseEvent(event, 'click');
    134	    }
    135	
    136	    // Unset the flag to allow other widgets to inherit the touch event
    137	    touchHandled = false;
    138	  };
    139	
    140	  /**
    141	   * A duck punch of the $.ui.mouse _mouseInit method to support touch events.
    142	   * This method extends the widget with bound touch event handlers that
    143	   * translate touch events to mouse events and pass them to the widget's
    144	   * original mouse event handling methods.
    145	   */
    146	  mouseProto._mouseInit = function () {
    147	   
    148	    var self = this;
    149	
    150	    // Delegate the touch handlers to the widget's element
    151	    self.element
    152	      .bind('touchstart', $.proxy(self, '_touchStart'))
    153	      .bind('touchmove', $.proxy(self, '_touchMove'))
    154	      .bind('touchend', $.proxy(self, '_touchEnd'));
    155	
    156	    // Call the original $.ui.mouse init method
    157	    _mouseInit.call(self);
    158	  };
    159	
    160	})(jQuery);
  • WordPress源代码——jquery-plugins(jquery.schedule.js)

    WordPress源代码——jquery-plugins(jquery.schedule.js)

    1	/*
    2	**  jquery.schedule.js -- jQuery plugin for scheduled/deferred actions
    3	**  Copyright (c) 2007 Ralf S. Engelschall <rse@engelschall.com>
    4	**  Licensed under GPL <http://www.gnu.org/licenses/gpl.txt>
    5	**
    6	**  $LastChangedDate$
    7	**  $LastChangedRevision$
    8	*/
    9	
    10	/*
    11	 *  <div id="button">TEST BUTTON</div>
    12	 *  <div id="test"></div>
    13	 *
    14	 *  <script type="text/javascript">
    15	 *     $(document).ready(
    16	 *     function(){
    17	 *         $('#button').click(function () {
    18	 *             $(this).css("color", "blue").schedule(2000, function (x) {
    19	 *                 $(this).css("color", "red");
    20	 *                 $("#test").html("test: x = " + x);
    21	 *             }, 42);
    22	 *         });
    23	 *     });
    24	 *  </script>
    25	 */
    26	
    27	(function($) {
    28	
    29	    /*  object constructor  */
    30	    $.scheduler = function () {
    31	        this.bucket = {};
    32	        return;
    33	    };
    34	
    35	    /*  object methods  */
    36	    $.scheduler.prototype = {
    37	        /*  schedule a task  */
    38	        schedule: function () {
    39	            /*  schedule context with default parameters */
    40	            var ctx = {
    41	                "id":         null,         /* unique identifier of high-level schedule */
    42	                "time":       1000,         /* time in milliseconds after which the task is run */
    43	                "repeat":     false,        /* whether schedule should be automatically repeated */
    44	                "protect":    false,        /* whether schedule should be protected from double scheduling */
    45	                "obj":        null,         /* function context object ("this") */
    46	                "func":       function(){}, /* function to call */
    47	                "args":       []            /* function arguments to pass */
    48	            };
    49	
    50	            /*  helper function: portable checking whether something is a function  */
    51	            function _isfn (fn) {
    52	                return (
    53	                       !!fn
    54	                    && typeof fn != "string"
    55	                    && typeof fn[0] == "undefined"
    56	                    && RegExp("function", "i").test(fn + "")
    57	                );
    58	            };
    59	           
    60	            /*  parse arguments into context parameters (part 1/4):
    61	                detect an override object (special case to support jQuery method) */
    62	            var i = 0;
    63	            var override = false;
    64	            if (typeof arguments[i] == "object" && arguments.length > 1) {
    65	                override = true;
    66	                i++;
    67	            }
    68	
    69	            /*  parse arguments into context parameters (part 2/4):
    70	                support the flexible way of an associated array */
    71	            if (typeof arguments[i] == "object") {
    72	                for (var option in arguments[i])
    73	                    if (typeof ctx[option] != "undefined")
    74	                        ctx[option] = arguments[i][option];
    75	                i++;
    76	            }
    77	
    78	            /*  parse arguments into context parameters (part 3/4):
    79	                support: schedule([time [, repeat], ]{{obj, methodname} | func}[, arg, ...]); */
    80	            if (   typeof arguments[i] == "number"
    81	                || (   typeof arguments[i] == "string" 
    82	                    && arguments[i].match(RegExp("^[0-9]+[smhdw]$"))))
    83	                ctx["time"] = arguments[i++];
    84	            if (typeof arguments[i] == "boolean")
    85	                ctx["repeat"] = arguments[i++];
    86	            if (typeof arguments[i] == "boolean")
    87	                ctx["protect"] = arguments[i++];
    88	            if (   typeof arguments[i] == "object"
    89	                && typeof arguments[i+1] == "string"
    90	                && _isfn(arguments[i][arguments[i+1]])) {
    91	                ctx["obj"] = arguments[i++];
    92	                ctx["func"] = arguments[i++];
    93	            }
    94	            else if (   typeof arguments[i] != "undefined"
    95	                     && (   _isfn(arguments[i]) 
    96	                         || typeof arguments[i] == "string"))
    97	                ctx["func"] = arguments[i++];
    98	            while (typeof arguments[i] != "undefined")
    99	                ctx["args"].push(arguments[i++]);
    100	
    101	            /*  parse arguments into context parameters (part 4/4):
    102	                apply parameters from override object */
    103	            if (override) {
    104	                if (typeof arguments[1] == "object") {
    105	                    for (var option in arguments[0])
    106	                        if (   typeof ctx[option] != "undefined"
    107	                            && typeof arguments[1][option] == "undefined")
    108	                            ctx[option] = arguments[0][option];
    109	                }
    110	                else {
    111	                    for (var option in arguments[0])
    112	                        if (typeof ctx[option] != "undefined")
    113	                            ctx[option] = arguments[0][option];
    114	                }
    115	                i++;
    116	            }
    117	
    118	            /*  annotate context with internals */
    119	            ctx["_scheduler"] = this; /* internal: back-reference to scheduler object */
    120	            ctx["_handle"]    = null; /* internal: unique handle of low-level task */
    121	
    122	            /*  determine time value in milliseconds */
    123	            var match = String(ctx["time"]).match(RegExp("^([0-9]+)([smhdw])$"));
    124	            if (match && match[0] != "undefined" && match[1] != "undefined")
    125	                ctx["time"] = String(parseInt(match[1]) *
    126	                    { s: 1000, m: 1000*60, h: 1000*60*60,
    127	                      d: 1000*60*60*24, w: 1000*60*60*24*7 }[match[2]]);
    128	
    129	            /*  determine unique identifier of task  */
    130	            if (ctx["id"] == null)
    131	                ctx["id"] = (  String(ctx["repeat"])  + ":"
    132	                             + String(ctx["protect"]) + ":"
    133	                             + String(ctx["time"])    + ":"
    134	                             + String(ctx["obj"])     + ":"
    135	                             + String(ctx["func"])    + ":"
    136	                             + String(ctx["args"])         );
    137	
    138	            /*  optionally protect from duplicate calls  */
    139	            if (ctx["protect"])
    140	                if (typeof this.bucket[ctx["id"]] != "undefined")
    141	                    return this.bucket[ctx["id"]];
    142	
    143	            /*  support execution of methods by name and arbitrary scripts  */
    144	            if (!_isfn(ctx["func"])) {
    145	                if (   ctx["obj"] != null
    146	                    && typeof ctx["obj"] == "object"
    147	                    && typeof ctx["func"] == "string"
    148	                    && _isfn(ctx["obj"][ctx["func"]]))
    149	                    /*  method by name  */
    150	                    ctx["func"] = ctx["obj"][ctx["func"]];
    151	                else
    152	                    /*  arbitrary script  */
    153	                    ctx["func"] = eval("function () { " + ctx["func"] + " }");
    154	            }
    155	
    156	            /*  pass-through to internal scheduling operation  */
    157	            ctx["_handle"] = this._schedule(ctx);
    158	
    159	            /*  store context into bucket of scheduler object  */
    160	            this.bucket[ctx["id"]] = ctx;
    161	
    162	            /*  return context  */
    163	            return ctx;
    164	        },
    165	
    166	        /*  re-schedule a task  */
    167	        reschedule: function (ctx) {
    168	            if (typeof ctx == "string")
    169	                ctx = this.bucket[ctx];
    170	
    171	            /*  pass-through to internal scheduling operation  */
    172	            ctx["_handle"] = this._schedule(ctx);
    173	
    174	            /*  return context  */
    175	            return ctx;
    176	        },
    177	
    178	        /*  internal scheduling operation  */
    179	        _schedule: function (ctx) {
    180	            /*  closure to act as the call trampoline function  */
    181	            var trampoline = function () {
    182	                /*  jump into function  */
    183	                var obj = (ctx["obj"] != null ? ctx["obj"] : ctx);
    184	                (ctx["func"]).apply(obj, ctx["args"]);
    185	
    186	                /*  either repeat scheduling and keep in bucket or
    187	                    just stop scheduling and delete from scheduler bucket  */
    188	                if (   /* not cancelled from inside... */
    189	                       typeof (ctx["_scheduler"]).bucket[ctx["id"]] != "undefined"
    190	                    && /* ...and repeating requested */
    191	                       ctx["repeat"])
    192	                    (ctx["_scheduler"])._schedule(ctx);
    193	                else
    194	                    delete (ctx["_scheduler"]).bucket[ctx["id"]];
    195	            };
    196	
    197	            /*  schedule task and return handle  */
    198	            return setTimeout(trampoline, ctx["time"]);
    199	        },
    200	
    201	        /*  cancel a scheduled task  */
    202	        cancel: function (ctx) {
    203	            if (typeof ctx == "string")
    204	                ctx = this.bucket[ctx];
    205	
    206	            /*  cancel scheduled task  */
    207	            if (typeof ctx == "object") {
    208	                clearTimeout(ctx["_handle"]);
    209	                delete this.bucket[ctx["id"]];
    210	            }
    211	        }
    212	    };
    213	
    214	    /* integrate a global instance of the scheduler into the global jQuery object */
    215	    $.extend({
    216	        scheduler$: new $.scheduler(),
    217	        schedule:   function () { return $.scheduler$.schedule.apply  ($.scheduler$, arguments) },
    218	        reschedule: function () { return $.scheduler$.reschedule.apply($.scheduler$, arguments) },
    219	        cancel:     function () { return $.scheduler$.cancel.apply    ($.scheduler$, arguments) }
    220	    });
    221	
    222	    /* integrate scheduling convinience method into all jQuery objects */
    223	    $.fn.extend({
    224	        schedule: function () {
    225	            var a = [ {} ];
    226	            for (var i = 0; i < arguments.length; i++)
    227	                a.push(arguments[i]);
    228	            return this.each(function () {
    229	                a[0] = { "id": this, "obj": this };
    230	                return $.schedule.apply($, a);
    231	            });
    232	        }
    233	    });
    234	
    235	})(jQuery);
    236	
    237	/*
    238	**  jquery.schedule.js -- jQuery plugin for scheduled/deferred actions
    239	**  Copyright (c) 2007 Ralf S. Engelschall <rse@engelschall.com>
    240	**  Licensed under GPL <http://www.gnu.org/licenses/gpl.txt>
    241	**
    242	**  $LastChangedDate$
    243	**  $LastChangedRevision$
    244	*/
    245	
    246	/*
    247	 *  <div id="button">TEST BUTTON</div>
    248	 *  <div id="test"></div>
    249	 *
    250	 *  <script type="text/javascript">
    251	 *     $(document).ready(
    252	 *     function(){
    253	 *         $('#button').click(function () {
    254	 *             $(this).css("color", "blue").schedule(2000, function (x) {
    255	 *                 $(this).css("color", "red");
    256	 *                 $("#test").html("test: x = " + x);
    257	 *             }, 42);
    258	 *         });
    259	 *     });
    260	 *  </script>
    261	 */
    262	
    263	(function($) {
    264	
    265	    /*  object constructor  */
    266	    $.scheduler = function () {
    267	        this.bucket = {};
    268	        return;
    269	    };
    270	
    271	    /*  object methods  */
    272	    $.scheduler.prototype = {
    273	        /*  schedule a task  */
    274	        schedule: function () {
    275	            /*  schedule context with default parameters */
    276	            var ctx = {
    277	                "id":         null,         /* unique identifier of high-level schedule */
    278	                "time":       1000,         /* time in milliseconds after which the task is run */
    279	                "repeat":     false,        /* whether schedule should be automatically repeated */
    280	                "protect":    false,        /* whether schedule should be protected from double scheduling */
    281	                "obj":        null,         /* function context object ("this") */
    282	                "func":       function(){}, /* function to call */
    283	                "args":       []            /* function arguments to pass */
    284	            };
    285	
    286	            /*  helper function: portable checking whether something is a function  */
    287	            function _isfn (fn) {
    288	                return (
    289	                       !!fn
    290	                    && typeof fn != "string"
    291	                    && typeof fn[0] == "undefined"
    292	                    && RegExp("function", "i").test(fn + "")
    293	                );
    294	            };
    295	           
    296	            /*  parse arguments into context parameters (part 1/4):
    297	                detect an override object (special case to support jQuery method) */
    298	            var i = 0;
    299	            var override = false;
    300	            if (typeof arguments[i] == "object" && arguments.length > 1) {
    301	                override = true;
    302	                i++;
    303	            }
    304	
    305	            /*  parse arguments into context parameters (part 2/4):
    306	                support the flexible way of an associated array */
    307	            if (typeof arguments[i] == "object") {
    308	                for (var option in arguments[i])
    309	                    if (typeof ctx[option] != "undefined")
    310	                        ctx[option] = arguments[i][option];
    311	                i++;
    312	            }
    313	
    314	            /*  parse arguments into context parameters (part 3/4):
    315	                support: schedule([time [, repeat], ]{{obj, methodname} | func}[, arg, ...]); */
    316	            if (   typeof arguments[i] == "number"
    317	                || (   typeof arguments[i] == "string" 
    318	                    && arguments[i].match(RegExp("^[0-9]+[smhdw]$"))))
    319	                ctx["time"] = arguments[i++];
    320	            if (typeof arguments[i] == "boolean")
    321	                ctx["repeat"] = arguments[i++];
    322	            if (typeof arguments[i] == "boolean")
    323	                ctx["protect"] = arguments[i++];
    324	            if (   typeof arguments[i] == "object"
    325	                && typeof arguments[i+1] == "string"
    326	                && _isfn(arguments[i][arguments[i+1]])) {
    327	                ctx["obj"] = arguments[i++];
    328	                ctx["func"] = arguments[i++];
    329	            }
    330	            else if (   typeof arguments[i] != "undefined"
    331	                     && (   _isfn(arguments[i]) 
    332	                         || typeof arguments[i] == "string"))
    333	                ctx["func"] = arguments[i++];
    334	            while (typeof arguments[i] != "undefined")
    335	                ctx["args"].push(arguments[i++]);
    336	
    337	            /*  parse arguments into context parameters (part 4/4):
    338	                apply parameters from override object */
    339	            if (override) {
    340	                if (typeof arguments[1] == "object") {
    341	                    for (var option in arguments[0])
    342	                        if (   typeof ctx[option] != "undefined"
    343	                            && typeof arguments[1][option] == "undefined")
    344	                            ctx[option] = arguments[0][option];
    345	                }
    346	                else {
    347	                    for (var option in arguments[0])
    348	                        if (typeof ctx[option] != "undefined")
    349	                            ctx[option] = arguments[0][option];
    350	                }
    351	                i++;
    352	            }
    353	
    354	            /*  annotate context with internals */
    355	            ctx["_scheduler"] = this; /* internal: back-reference to scheduler object */
    356	            ctx["_handle"]    = null; /* internal: unique handle of low-level task */
    357	
    358	            /*  determine time value in milliseconds */
    359	            var match = String(ctx["time"]).match(RegExp("^([0-9]+)([smhdw])$"));
    360	            if (match && match[0] != "undefined" && match[1] != "undefined")
    361	                ctx["time"] = String(parseInt(match[1]) *
    362	                    { s: 1000, m: 1000*60, h: 1000*60*60,
    363	                      d: 1000*60*60*24, w: 1000*60*60*24*7 }[match[2]]);
    364	
    365	            /*  determine unique identifier of task  */
    366	            if (ctx["id"] == null)
    367	                ctx["id"] = (  String(ctx["repeat"])  + ":"
    368	                             + String(ctx["protect"]) + ":"
    369	                             + String(ctx["time"])    + ":"
    370	                             + String(ctx["obj"])     + ":"
    371	                             + String(ctx["func"])    + ":"
    372	                             + String(ctx["args"])         );
    373	
    374	            /*  optionally protect from duplicate calls  */
    375	            if (ctx["protect"])
    376	                if (typeof this.bucket[ctx["id"]] != "undefined")
    377	                    return this.bucket[ctx["id"]];
    378	
    379	            /*  support execution of methods by name and arbitrary scripts  */
    380	            if (!_isfn(ctx["func"])) {
    381	                if (   ctx["obj"] != null
    382	                    && typeof ctx["obj"] == "object"
    383	                    && typeof ctx["func"] == "string"
    384	                    && _isfn(ctx["obj"][ctx["func"]]))
    385	                    /*  method by name  */
    386	                    ctx["func"] = ctx["obj"][ctx["func"]];
    387	                else
    388	                    /*  arbitrary script  */
    389	                    ctx["func"] = eval("function () { " + ctx["func"] + " }");
    390	            }
    391	
    392	            /*  pass-through to internal scheduling operation  */
    393	            ctx["_handle"] = this._schedule(ctx);
    394	
    395	            /*  store context into bucket of scheduler object  */
    396	            this.bucket[ctx["id"]] = ctx;
    397	
    398	            /*  return context  */
    399	            return ctx;
    400	        },
    401	
    402	        /*  re-schedule a task  */
    403	        reschedule: function (ctx) {
    404	            if (typeof ctx == "string")
    405	                ctx = this.bucket[ctx];
    406	
    407	            /*  pass-through to internal scheduling operation  */
    408	            ctx["_handle"] = this._schedule(ctx);
    409	
    410	            /*  return context  */
    411	            return ctx;
    412	        },
    413	
    414	        /*  internal scheduling operation  */
    415	        _schedule: function (ctx) {
    416	            /*  closure to act as the call trampoline function  */
    417	            var trampoline = function () {
    418	                /*  jump into function  */
    419	                var obj = (ctx["obj"] != null ? ctx["obj"] : ctx);
    420	                (ctx["func"]).apply(obj, ctx["args"]);
    421	
    422	                /*  either repeat scheduling and keep in bucket or
    423	                    just stop scheduling and delete from scheduler bucket  */
    424	                if (   /* not cancelled from inside... */
    425	                       typeof (ctx["_scheduler"]).bucket[ctx["id"]] != "undefined"
    426	                    && /* ...and repeating requested */
    427	                       ctx["repeat"])
    428	                    (ctx["_scheduler"])._schedule(ctx);
    429	                else
    430	                    delete (ctx["_scheduler"]).bucket[ctx["id"]];
    431	            };
    432	
    433	            /*  schedule task and return handle  */
    434	            return setTimeout(trampoline, ctx["time"]);
    435	        },
    436	
    437	        /*  cancel a scheduled task  */
    438	        cancel: function (ctx) {
    439	            if (typeof ctx == "string")
    440	                ctx = this.bucket[ctx];
    441	
    442	            /*  cancel scheduled task  */
    443	            if (typeof ctx == "object") {
    444	                clearTimeout(ctx["_handle"]);
    445	                delete this.bucket[ctx["id"]];
    446	            }
    447	        }
    448	    };
    449	
    450	    /* integrate a global instance of the scheduler into the global jQuery object */
    451	    $.extend({
    452	        scheduler$: new $.scheduler(),
    453	        schedule:   function () { return $.scheduler$.schedule.apply  ($.scheduler$, arguments) },
    454	        reschedule: function () { return $.scheduler$.reschedule.apply($.scheduler$, arguments) },
    455	        cancel:     function () { return $.scheduler$.cancel.apply    ($.scheduler$, arguments) }
    456	    });
    457	
    458	    /* integrate scheduling convinience method into all jQuery objects */
    459	    $.fn.extend({
    460	        schedule: function () {
    461	            var a = [ {} ];
    462	            for (var i = 0; i < arguments.length; i++)
    463	                a.push(arguments[i]);
    464	            return this.each(function () {
    465	                a[0] = { "id": this, "obj": this };
    466	                return $.schedule.apply($, a);
    467	            });
    468	        }
    469	    });
    470	
    471	})(jQuery);
    472	
    473	/*
    474	**  jquery.schedule.js -- jQuery plugin for scheduled/deferred actions
    475	**  Copyright (c) 2007 Ralf S. Engelschall <rse@engelschall.com>
    476	**  Licensed under GPL <http://www.gnu.org/licenses/gpl.txt>
    477	**
    478	**  $LastChangedDate$
    479	**  $LastChangedRevision$
    480	*/
    481	
    482	/*
    483	 *  <div id="button">TEST BUTTON</div>
    484	 *  <div id="test"></div>
    485	 *
    486	 *  <script type="text/javascript">
    487	 *     $(document).ready(
    488	 *     function(){
    489	 *         $('#button').click(function () {
    490	 *             $(this).css("color", "blue").schedule(2000, function (x) {
    491	 *                 $(this).css("color", "red");
    492	 *                 $("#test").html("test: x = " + x);
    493	 *             }, 42);
    494	 *         });
    495	 *     });
    496	 *  </script>
    497	 */
    498	
    499	(function($) {
    500	
    501	    /*  object constructor  */
    502	    $.scheduler = function () {
    503	        this.bucket = {};
    504	        return;
    505	    };
    506	
    507	    /*  object methods  */
    508	    $.scheduler.prototype = {
    509	        /*  schedule a task  */
    510	        schedule: function () {
    511	            /*  schedule context with default parameters */
    512	            var ctx = {
    513	                "id":         null,         /* unique identifier of high-level schedule */
    514	                "time":       1000,         /* time in milliseconds after which the task is run */
    515	                "repeat":     false,        /* whether schedule should be automatically repeated */
    516	                "protect":    false,        /* whether schedule should be protected from double scheduling */
    517	                "obj":        null,         /* function context object ("this") */
    518	                "func":       function(){}, /* function to call */
    519	                "args":       []            /* function arguments to pass */
    520	            };
    521	
    522	            /*  helper function: portable checking whether something is a function  */
    523	            function _isfn (fn) {
    524	                return (
    525	                       !!fn
    526	                    && typeof fn != "string"
    527	                    && typeof fn[0] == "undefined"
    528	                    && RegExp("function", "i").test(fn + "")
    529	                );
    530	            };
    531	           
    532	            /*  parse arguments into context parameters (part 1/4):
    533	                detect an override object (special case to support jQuery method) */
    534	            var i = 0;
    535	            var override = false;
    536	            if (typeof arguments[i] == "object" && arguments.length > 1) {
    537	                override = true;
    538	                i++;
    539	            }
    540	
    541	            /*  parse arguments into context parameters (part 2/4):
    542	                support the flexible way of an associated array */
    543	            if (typeof arguments[i] == "object") {
    544	                for (var option in arguments[i])
    545	                    if (typeof ctx[option] != "undefined")
    546	                        ctx[option] = arguments[i][option];
    547	                i++;
    548	            }
    549	
    550	            /*  parse arguments into context parameters (part 3/4):
    551	                support: schedule([time [, repeat], ]{{obj, methodname} | func}[, arg, ...]); */
    552	            if (   typeof arguments[i] == "number"
    553	                || (   typeof arguments[i] == "string" 
    554	                    && arguments[i].match(RegExp("^[0-9]+[smhdw]$"))))
    555	                ctx["time"] = arguments[i++];
    556	            if (typeof arguments[i] == "boolean")
    557	                ctx["repeat"] = arguments[i++];
    558	            if (typeof arguments[i] == "boolean")
    559	                ctx["protect"] = arguments[i++];
    560	            if (   typeof arguments[i] == "object"
    561	                && typeof arguments[i+1] == "string"
    562	                && _isfn(arguments[i][arguments[i+1]])) {
    563	                ctx["obj"] = arguments[i++];
    564	                ctx["func"] = arguments[i++];
    565	            }
    566	            else if (   typeof arguments[i] != "undefined"
    567	                     && (   _isfn(arguments[i]) 
    568	                         || typeof arguments[i] == "string"))
    569	                ctx["func"] = arguments[i++];
    570	            while (typeof arguments[i] != "undefined")
    571	                ctx["args"].push(arguments[i++]);
    572	
    573	            /*  parse arguments into context parameters (part 4/4):
    574	                apply parameters from override object */
    575	            if (override) {
    576	                if (typeof arguments[1] == "object") {
    577	                    for (var option in arguments[0])
    578	                        if (   typeof ctx[option] != "undefined"
    579	                            && typeof arguments[1][option] == "undefined")
    580	                            ctx[option] = arguments[0][option];
    581	                }
    582	                else {
    583	                    for (var option in arguments[0])
    584	                        if (typeof ctx[option] != "undefined")
    585	                            ctx[option] = arguments[0][option];
    586	                }
    587	                i++;
    588	            }
    589	
    590	            /*  annotate context with internals */
    591	            ctx["_scheduler"] = this; /* internal: back-reference to scheduler object */
    592	            ctx["_handle"]    = null; /* internal: unique handle of low-level task */
    593	
    594	            /*  determine time value in milliseconds */
    595	            var match = String(ctx["time"]).match(RegExp("^([0-9]+)([smhdw])$"));
    596	            if (match && match[0] != "undefined" && match[1] != "undefined")
    597	                ctx["time"] = String(parseInt(match[1]) *
    598	                    { s: 1000, m: 1000*60, h: 1000*60*60,
    599	                      d: 1000*60*60*24, w: 1000*60*60*24*7 }[match[2]]);
    600	
    601	            /*  determine unique identifier of task  */
    602	            if (ctx["id"] == null)
    603	                ctx["id"] = (  String(ctx["repeat"])  + ":"
    604	                             + String(ctx["protect"]) + ":"
    605	                             + String(ctx["time"])    + ":"
    606	                             + String(ctx["obj"])     + ":"
    607	                             + String(ctx["func"])    + ":"
    608	                             + String(ctx["args"])         );
    609	
    610	            /*  optionally protect from duplicate calls  */
    611	            if (ctx["protect"])
    612	                if (typeof this.bucket[ctx["id"]] != "undefined")
    613	                    return this.bucket[ctx["id"]];
    614	
    615	            /*  support execution of methods by name and arbitrary scripts  */
    616	            if (!_isfn(ctx["func"])) {
    617	                if (   ctx["obj"] != null
    618	                    && typeof ctx["obj"] == "object"
    619	                    && typeof ctx["func"] == "string"
    620	                    && _isfn(ctx["obj"][ctx["func"]]))
    621	                    /*  method by name  */
    622	                    ctx["func"] = ctx["obj"][ctx["func"]];
    623	                else
    624	                    /*  arbitrary script  */
    625	                    ctx["func"] = eval("function () { " + ctx["func"] + " }");
    626	            }
    627	
    628	            /*  pass-through to internal scheduling operation  */
    629	            ctx["_handle"] = this._schedule(ctx);
    630	
    631	            /*  store context into bucket of scheduler object  */
    632	            this.bucket[ctx["id"]] = ctx;
    633	
    634	            /*  return context  */
    635	            return ctx;
    636	        },
    637	
    638	        /*  re-schedule a task  */
    639	        reschedule: function (ctx) {
    640	            if (typeof ctx == "string")
    641	                ctx = this.bucket[ctx];
    642	
    643	            /*  pass-through to internal scheduling operation  */
    644	            ctx["_handle"] = this._schedule(ctx);
    645	
    646	            /*  return context  */
    647	            return ctx;
    648	        },
    649	
    650	        /*  internal scheduling operation  */
    651	        _schedule: function (ctx) {
    652	            /*  closure to act as the call trampoline function  */
    653	            var trampoline = function () {
    654	                /*  jump into function  */
    655	                var obj = (ctx["obj"] != null ? ctx["obj"] : ctx);
    656	                (ctx["func"]).apply(obj, ctx["args"]);
    657	
    658	                /*  either repeat scheduling and keep in bucket or
    659	                    just stop scheduling and delete from scheduler bucket  */
    660	                if (   /* not cancelled from inside... */
    661	                       typeof (ctx["_scheduler"]).bucket[ctx["id"]] != "undefined"
    662	                    && /* ...and repeating requested */
    663	                       ctx["repeat"])
    664	                    (ctx["_scheduler"])._schedule(ctx);
    665	                else
    666	                    delete (ctx["_scheduler"]).bucket[ctx["id"]];
    667	            };
    668	
    669	            /*  schedule task and return handle  */
    670	            return setTimeout(trampoline, ctx["time"]);
    671	        },
    672	
    673	        /*  cancel a scheduled task  */
    674	        cancel: function (ctx) {
    675	            if (typeof ctx == "string")
    676	                ctx = this.bucket[ctx];
    677	
    678	            /*  cancel scheduled task  */
    679	            if (typeof ctx == "object") {
    680	                clearTimeout(ctx["_handle"]);
    681	                delete this.bucket[ctx["id"]];
    682	            }
    683	        }
    684	    };
    685	
    686	    /* integrate a global instance of the scheduler into the global jQuery object */
    687	    $.extend({
    688	        scheduler$: new $.scheduler(),
    689	        schedule:   function () { return $.scheduler$.schedule.apply  ($.scheduler$, arguments) },
    690	        reschedule: function () { return $.scheduler$.reschedule.apply($.scheduler$, arguments) },
    691	        cancel:     function () { return $.scheduler$.cancel.apply    ($.scheduler$, arguments) }
    692	    });
    693	
    694	    /* integrate scheduling convinience method into all jQuery objects */
    695	    $.fn.extend({
    696	        schedule: function () {
    697	            var a = [ {} ];
    698	            for (var i = 0; i < arguments.length; i++)
    699	                a.push(arguments[i]);
    700	            return this.each(function () {
    701	                a[0] = { "id": this, "obj": this };
    702	                return $.schedule.apply($, a);
    703	            });
    704	        }
    705	    });
    706	
    707	})(jQuery);
    708	
  • WordPress源代码——jquery-plugins(jquery.query.js)

    WordPress源代码——jquery-plugins(jquery.query.js)

    1	/**
    2	 * jQuery.query - Query String Modification and Creation for jQuery
    3	 * Written by Blair Mitchelmore (blair DOT mitchelmore AT gmail DOT com)
    4	 * Licensed under the WTFPL (http://sam.zoy.org/wtfpl/).
    5	 * Date: 2009/8/13
    6	 *
    7	 * @author Blair Mitchelmore
    8	 * @version 2.1.7
    9	 *
    10	 **/
    11	new function(settings) { 
    12	  // Various Settings
    13	  var $separator = settings.separator || '&';
    14	  var $spaces = settings.spaces === false ? false : true;
    15	  var $suffix = settings.suffix === false ? '' : '[]';
    16	  var $prefix = settings.prefix === false ? false : true;
    17	  var $hash = $prefix ? settings.hash === true ? "#" : "?" : "";
    18	  var $numbers = settings.numbers === false ? false : true;
    19	 
    20	  jQuery.query = new function() {
    21	    var is = function(o, t) {
    22	      return o != undefined && o !== null && (!!t ? o.constructor == t : true);
    23	    };
    24	    var parse = function(path) {
    25	      var m, rx = /\[([^[]*)\]/g, match = /^([^[]+)(\[.*\])?$/.exec(path), base = match[1], tokens = [];
    26	      while (m = rx.exec(match[2])) tokens.push(m[1]);
    27	      return [base, tokens];
    28	    };
    29	    var set = function(target, tokens, value) {
    30	      var o, token = tokens.shift();
    31	      if (typeof target != 'object') target = null;
    32	      if (token === "") {
    33	        if (!target) target = [];
    34	        if (is(target, Array)) {
    35	          target.push(tokens.length == 0 ? value : set(null, tokens.slice(0), value));
    36	        } else if (is(target, Object)) {
    37	          var i = 0;
    38	          while (target[i++] != null);
    39	          target[--i] = tokens.length == 0 ? value : set(target[i], tokens.slice(0), value);
    40	        } else {
    41	          target = [];
    42	          target.push(tokens.length == 0 ? value : set(null, tokens.slice(0), value));
    43	        }
    44	      } else if (token && token.match(/^\s*[0-9]+\s*$/)) {
    45	        var index = parseInt(token, 10);
    46	        if (!target) target = [];
    47	        target[index] = tokens.length == 0 ? value : set(target[index], tokens.slice(0), value);
    48	      } else if (token) {
    49	        var index = token.replace(/^\s*|\s*$/g, "");
    50	        if (!target) target = {};
    51	        if (is(target, Array)) {
    52	          var temp = {};
    53	          for (var i = 0; i < target.length; ++i) {
    54	            temp[i] = target[i];
    55	          }
    56	          target = temp;
    57	        }
    58	        target[index] = tokens.length == 0 ? value : set(target[index], tokens.slice(0), value);
    59	      } else {
    60	        return value;
    61	      }
    62	      return target;
    63	    };
    64	   
    65	    var queryObject = function(a) {
    66	      var self = this;
    67	      self.keys = {};
    68	     
    69	      if (a.queryObject) {
    70	        jQuery.each(a.get(), function(key, val) {
    71	          self.SET(key, val);
    72	        });
    73	      } else {
    74	        jQuery.each(arguments, function() {
    75	          var q = "" + this;
    76	          q = q.replace(/^[?#]/,''); // remove any leading ? || #
    77	          q = q.replace(/[;&]$/,''); // remove any trailing & || ;
    78	          if ($spaces) q = q.replace(/[+]/g,' '); // replace +'s with spaces
    79	         
    80	          jQuery.each(q.split(/[&;]/), function(){
    81	            var key = decodeURIComponent(this.split('=')[0] || "");
    82	            var val = decodeURIComponent(this.split('=')[1] || "");
    83	           
    84	            if (!key) return;
    85	           
    86	            if ($numbers) {
    87	              if (/^[+-]?[0-9]+\.[0-9]*$/.test(val)) // simple float regex
    88	                val = parseFloat(val);
    89	              else if (/^[+-]?[0-9]+$/.test(val)) // simple int regex
    90	                val = parseInt(val, 10);
    91	            }
    92	           
    93	            val = (!val && val !== 0) ? true : val;
    94	           
    95	            if (val !== false && val !== true && typeof val != 'number')
    96	              val = val;
    97	           
    98	            self.SET(key, val);
    99	          });
    100	        });
    101	      }
    102	      return self;
    103	    };
    104	   
    105	    queryObject.prototype = {
    106	      queryObject: true,
    107	      has: function(key, type) {
    108	        var value = this.get(key);
    109	        return is(value, type);
    110	      },
    111	      GET: function(key) {
    112	        if (!is(key)) return this.keys;
    113	        var parsed = parse(key), base = parsed[0], tokens = parsed[1];
    114	        var target = this.keys[base];
    115	        while (target != null && tokens.length != 0) {
    116	          target = target[tokens.shift()];
    117	        }
    118	        return typeof target == 'number' ? target : target || "";
    119	      },
    120	      get: function(key) {
    121	        var target = this.GET(key);
    122	        if (is(target, Object))
    123	          return jQuery.extend(true, {}, target);
    124	        else if (is(target, Array))
    125	          return target.slice(0);
    126	        return target;
    127	      },
    128	      SET: function(key, val) {
    129	        var value = !is(val) ? null : val;
    130	        var parsed = parse(key), base = parsed[0], tokens = parsed[1];
    131	        var target = this.keys[base];
    132	        this.keys[base] = set(target, tokens.slice(0), value);
    133	        return this;
    134	      },
    135	      set: function(key, val) {
    136	        return this.copy().SET(key, val);
    137	      },
    138	      REMOVE: function(key) {
    139	        return this.SET(key, null).COMPACT();
    140	      },
    141	      remove: function(key) {
    142	        return this.copy().REMOVE(key);
    143	      },
    144	      EMPTY: function() {
    145	        var self = this;
    146	        jQuery.each(self.keys, function(key, value) {
    147	          delete self.keys[key];
    148	        });
    149	        return self;
    150	      },
    151	      load: function(url) {
    152	        var hash = url.replace(/^.*?[#](.+?)(?:\?.+)?$/, "$1");
    153	        var search = url.replace(/^.*?[?](.+?)(?:#.+)?$/, "$1");
    154	        return new queryObject(url.length == search.length ? '' : search, url.length == hash.length ? '' : hash);
    155	      },
    156	      empty: function() {
    157	        return this.copy().EMPTY();
    158	      },
    159	      copy: function() {
    160	        return new queryObject(this);
    161	      },
    162	      COMPACT: function() {
    163	        function build(orig) {
    164	          var obj = typeof orig == "object" ? is(orig, Array) ? [] : {} : orig;
    165	          if (typeof orig == 'object') {
    166	            function add(o, key, value) {
    167	              if (is(o, Array))
    168	                o.push(value);
    169	              else
    170	                o[key] = value;
    171	            }
    172	            jQuery.each(orig, function(key, value) {
    173	              if (!is(value)) return true;
    174	              add(obj, key, build(value));
    175	            });
    176	          }
    177	          return obj;
    178	        }
    179	        this.keys = build(this.keys);
    180	        return this;
    181	      },
    182	      compact: function() {
    183	        return this.copy().COMPACT();
    184	      },
    185	      toString: function() {
    186	        var i = 0, queryString = [], chunks = [], self = this;
    187	        var encode = function(str) {
    188	          str = str + "";
    189	          if ($spaces) str = str.replace(/ /g, "+");
    190	          return encodeURIComponent(str);
    191	        };
    192	        var addFields = function(arr, key, value) {
    193	          if (!is(value) || value === false) return;
    194	          var o = [encode(key)];
    195	          if (value !== true) {
    196	            o.push("=");
    197	            o.push(encode(value));
    198	          }
    199	          arr.push(o.join(""));
    200	        };
    201	        var build = function(obj, base) {
    202	          var newKey = function(key) {
    203	            return !base || base == "" ? [key].join("") : [base, "[", key, "]"].join("");
    204	          };
    205	          jQuery.each(obj, function(key, value) {
    206	            if (typeof value == 'object') 
    207	              build(value, newKey(key));
    208	            else
    209	              addFields(chunks, newKey(key), value);
    210	          });
    211	        };
    212	       
    213	        build(this.keys);
    214	       
    215	        if (chunks.length > 0) queryString.push($hash);
    216	        queryString.push(chunks.join($separator));
    217	       
    218	        return queryString.join("");
    219	      }
    220	    };
    221	   
    222	    return new queryObject(location.search, location.hash);
    223	  };
    224	}(jQuery.query || {}); // Pass in jQuery.query as settings object
  • WordPress源代码——jquery-plugins(jquery.masonry-2.1.05.js)

    WordPress源代码——jquery-plugins(jquery.masonry-2.1.05.js)

    1	/**
    2	 * jQuery Masonry v2.1.05
    3	 * A dynamic layout plugin for jQuery
    4	 * The flip-side of CSS Floats
    5	 * http://masonry.desandro.com
    6	 *
    7	 * Licensed under the MIT license.
    8	 * Copyright 2012 David DeSandro
    9	 */
    10	
    11	/*jshint browser: true, curly: true, eqeqeq: true, forin: false, immed: false, newcap: true, noempty: true, strict: true, undef: true */
    12	/*global jQuery: false */
    13	
    14	(function( window, $, undefined ){
    15	
    16	  'use strict';
    17	
    18	  /*
    19	   * smartresize: debounced resize event for jQuery
    20	   *
    21	   * latest version and complete README available on Github:
    22	   * https://github.com/louisremi/jquery.smartresize.js
    23	   *
    24	   * Copyright 2011 @louis_remi
    25	   * Licensed under the MIT license.
    26	   */
    27	
    28	  var $event = $.event,
    29	      resizeTimeout;
    30	
    31	  $event.special.smartresize = {
    32	    setup: function() {
    33	      $(this).bind( "resize", $event.special.smartresize.handler );
    34	    },
    35	    teardown: function() {
    36	      $(this).unbind( "resize", $event.special.smartresize.handler );
    37	    },
    38	    handler: function( event, execAsap ) {
    39	      // Save the context
    40	      var context = this,
    41	          args = arguments;
    42	
    43	      // set correct event type
    44	      event.type = "smartresize";
    45	
    46	      if ( resizeTimeout ) { clearTimeout( resizeTimeout ); }
    47	      resizeTimeout = setTimeout(function() {
    48	        $.event.handle.apply( context, args );
    49	      }, execAsap === "execAsap"? 0 : 100 );
    50	    }
    51	  };
    52	
    53	  $.fn.smartresize = function( fn ) {
    54	    return fn ? this.bind( "smartresize", fn ) : this.trigger( "smartresize", ["execAsap"] );
    55	  };
    56	
    57	
    58	
    59	// ========================= Masonry ===============================
    60	
    61	
    62	  // our "Widget" object constructor
    63	  $.Mason = function( options, element ){
    64	    this.element = $( element );
    65	
    66	    this._create( options );
    67	    this._init();
    68	  };
    69	
    70	  $.Mason.settings = {
    71	    isResizable: true,
    72	    isAnimated: false,
    73	    animationOptions: {
    74	      queue: false,
    75	      duration: 500
    76	    },
    77	    gutterWidth: 0,
    78	    isRTL: false,
    79	    isFitWidth: false,
    80	    containerStyle: {
    81	      position: 'relative'
    82	    }
    83	  };
    84	
    85	  $.Mason.prototype = {
    86	
    87	    _filterFindBricks: function( $elems ) {
    88	      var selector = this.options.itemSelector;
    89	      // if there is a selector
    90	      // filter/find appropriate item elements
    91	      return !selector ? $elems : $elems.filter( selector ).add( $elems.find( selector ) );
    92	    },
    93	
    94	    _getBricks: function( $elems ) {
    95	      var $bricks = this._filterFindBricks( $elems )
    96	        .css({ position: 'absolute' })
    97	        .addClass('masonry-brick');
    98	      return $bricks;
    99	    },
    100	   
    101	    // sets up widget
    102	    _create : function( options ) {
    103	     
    104	      this.options = $.extend( true, {}, $.Mason.settings, options );
    105	      this.styleQueue = [];
    106	
    107	      // get original styles in case we re-apply them in .destroy()
    108	      var elemStyle = this.element[0].style;
    109	      this.originalStyle = {
    110	        // get height
    111	        height: elemStyle.height || ''
    112	      };
    113	      // get other styles that will be overwritten
    114	      var containerStyle = this.options.containerStyle;
    115	      for ( var prop in containerStyle ) {
    116	        this.originalStyle[ prop ] = elemStyle[ prop ] || '';
    117	      }
    118	
    119	      this.element.css( containerStyle );
    120	
    121	      this.horizontalDirection = this.options.isRTL ? 'right' : 'left';
    122	
    123	      this.offset = {
    124	        x: parseInt( this.element.css( 'padding-' + this.horizontalDirection ), 10 ),
    125	        y: parseInt( this.element.css( 'padding-top' ), 10 )
    126	      };
    127	     
    128	      this.isFluid = this.options.columnWidth && typeof this.options.columnWidth === 'function';
    129	
    130	      // add masonry class first time around
    131	      var instance = this;
    132	      setTimeout( function() {
    133	        instance.element.addClass('masonry');
    134	      }, 0 );
    135	     
    136	      // bind resize method
    137	      if ( this.options.isResizable ) {
    138	        $(window).bind( 'smartresize.masonry', function() { 
    139	          instance.resize();
    140	        });
    141	      }
    142	
    143	
    144	      // need to get bricks
    145	      this.reloadItems();
    146	
    147	    },
    148	 
    149	    // _init fires when instance is first created
    150	    // and when instance is triggered again -> $el.masonry();
    151	    _init : function( callback ) {
    152	      this._getColumns();
    153	      this._reLayout( callback );
    154	    },
    155	
    156	    option: function( key, value ){
    157	      // set options AFTER initialization:
    158	      // signature: $('#foo').bar({ cool:false });
    159	      if ( $.isPlainObject( key ) ){
    160	        this.options = $.extend(true, this.options, key);
    161	      } 
    162	    },
    163	   
    164	    // ====================== General Layout ======================
    165	
    166	    // used on collection of atoms (should be filtered, and sorted before )
    167	    // accepts atoms-to-be-laid-out to start with
    168	    layout : function( $bricks, callback ) {
    169	
    170	      // place each brick
    171	      for (var i=0, len = $bricks.length; i < len; i++) {
    172	        this._placeBrick( $bricks[i] );
    173	      }
    174	     
    175	      // set the size of the container
    176	      var containerSize = {};
    177	      containerSize.height = Math.max.apply( Math, this.colYs );
    178	      if ( this.options.isFitWidth ) {
    179	        var unusedCols = 0;
    180	        i = this.cols;
    181	        // count unused columns
    182	        while ( --i ) {
    183	          if ( this.colYs[i] !== 0 ) {
    184	            break;
    185	          }
    186	          unusedCols++;
    187	        }
    188	        // fit container to columns that have been used;
    189	        containerSize.width = (this.cols - unusedCols) * this.columnWidth - this.options.gutterWidth;
    190	      }
    191	      this.styleQueue.push({ $el: this.element, style: containerSize });
    192	
    193	      // are we animating the layout arrangement?
    194	      // use plugin-ish syntax for css or animate
    195	      var styleFn = !this.isLaidOut ? 'css' : (
    196	            this.options.isAnimated ? 'animate' : 'css'
    197	          ),
    198	          animOpts = this.options.animationOptions;
    199	
    200	      // process styleQueue
    201	      var obj;
    202	      for (i=0, len = this.styleQueue.length; i < len; i++) {
    203	        obj = this.styleQueue[i];
    204	        obj.$el[ styleFn ]( obj.style, animOpts );
    205	      }
    206	
    207	      // clear out queue for next time
    208	      this.styleQueue = [];
    209	
    210	      // provide $elems as context for the callback
    211	      if ( callback ) {
    212	        callback.call( $bricks );
    213	      }
    214	     
    215	      this.isLaidOut = true;
    216	    },
    217	   
    218	    // calculates number of columns
    219	    // i.e. this.columnWidth = 200
    220	    _getColumns : function() {
    221	      var container = this.options.isFitWidth ? this.element.parent() : this.element,
    222	          containerWidth = container.width();
    223	
    224	                         // use fluid columnWidth function if there
    225	      this.columnWidth = this.isFluid ? this.options.columnWidth( containerWidth ) :
    226	                    // if not, how about the explicitly set option?
    227	                    this.options.columnWidth ||
    228	                    // or use the size of the first item
    229	                    this.$bricks.outerWidth(true) ||
    230	                    // if there's no items, use size of container
    231	                    containerWidth;
    232	
    233	      this.columnWidth += this.options.gutterWidth;
    234	
    235	      this.cols = Math.floor( ( containerWidth + this.options.gutterWidth ) / this.columnWidth );
    236	      this.cols = Math.max( this.cols, 1 );
    237	
    238	    },
    239	
    240	    // layout logic
    241	    _placeBrick: function( brick ) {
    242	      var $brick = $(brick),
    243	          colSpan, groupCount, groupY, groupColY, j;
    244	
    245	      //how many columns does this brick span
    246	      colSpan = Math.ceil( $brick.outerWidth(true) / this.columnWidth );
    247	      colSpan = Math.min( colSpan, this.cols );
    248	
    249	      if ( colSpan === 1 ) {
    250	        // if brick spans only one column, just like singleMode
    251	        groupY = this.colYs;
    252	      } else {
    253	        // brick spans more than one column
    254	        // how many different places could this brick fit horizontally
    255	        groupCount = this.cols + 1 - colSpan;
    256	        groupY = [];
    257	
    258	        // for each group potential horizontal position
    259	        for ( j=0; j < groupCount; j++ ) {
    260	          // make an array of colY values for that one group
    261	          groupColY = this.colYs.slice( j, j+colSpan );
    262	          // and get the max value of the array
    263	          groupY[j] = Math.max.apply( Math, groupColY );
    264	        }
    265	
    266	      }
    267	
    268	      // get the minimum Y value from the columns
    269	      var minimumY = Math.min.apply( Math, groupY ),
    270	          shortCol = 0;
    271	     
    272	      // Find index of short column, the first from the left
    273	      for (var i=0, len = groupY.length; i < len; i++) {
    274	        if ( groupY[i] === minimumY ) {
    275	          shortCol = i;
    276	          break;
    277	        }
    278	      }
    279	
    280	      // position the brick
    281	      var position = {
    282	        top: minimumY + this.offset.y
    283	      };
    284	      // position.left or position.right
    285	      position[ this.horizontalDirection ] = this.columnWidth * shortCol + this.offset.x;
    286	      this.styleQueue.push({ $el: $brick, style: position });
    287	
    288	      // apply setHeight to necessary columns
    289	      var setHeight = minimumY + $brick.outerHeight(true),
    290	          setSpan = this.cols + 1 - len;
    291	      for ( i=0; i < setSpan; i++ ) {
    292	        this.colYs[ shortCol + i ] = setHeight;
    293	      }
    294	
    295	    },
    296	   
    297	   
    298	    resize: function() {
    299	      var prevColCount = this.cols;
    300	      // get updated colCount
    301	      this._getColumns();
    302	      if ( this.isFluid || this.cols !== prevColCount ) {
    303	        // if column count has changed, trigger new layout
    304	        this._reLayout();
    305	      }
    306	    },
    307	   
    308	   
    309	    _reLayout : function( callback ) {
    310	      // reset columns
    311	      var i = this.cols;
    312	      this.colYs = [];
    313	      while (i--) {
    314	        this.colYs.push( 0 );
    315	      }
    316	      // apply layout logic to all bricks
    317	      this.layout( this.$bricks, callback );
    318	    },
    319	   
    320	    // ====================== Convenience methods ======================
    321	   
    322	    // goes through all children again and gets bricks in proper order
    323	    reloadItems : function() {
    324	      this.$bricks = this._getBricks( this.element.children() );
    325	    },
    326	   
    327	   
    328	    reload : function( callback ) {
    329	      this.reloadItems();
    330	      this._init( callback );
    331	    },
    332	   
    333	
    334	    // convienence method for working with Infinite Scroll
    335	    appended : function( $content, isAnimatedFromBottom, callback ) {
    336	      if ( isAnimatedFromBottom ) {
    337	        // set new stuff to the bottom
    338	        this._filterFindBricks( $content ).css({ top: this.element.height() });
    339	        var instance = this;
    340	        setTimeout( function(){
    341	          instance._appended( $content, callback );
    342	        }, 1 );
    343	      } else {
    344	        this._appended( $content, callback );
    345	      }
    346	    },
    347	   
    348	    _appended : function( $content, callback ) {
    349	      var $newBricks = this._getBricks( $content );
    350	      // add new bricks to brick pool
    351	      this.$bricks = this.$bricks.add( $newBricks );
    352	      this.layout( $newBricks, callback );
    353	    },
    354	   
    355	    // removes elements from Masonry widget
    356	    remove : function( $content ) {
    357	      this.$bricks = this.$bricks.not( $content );
    358	      $content.remove();
    359	    },
    360	   
    361	    // destroys widget, returns elements and container back (close) to original style
    362	    destroy : function() {
    363	
    364	      this.$bricks
    365	        .removeClass('masonry-brick')
    366	        .each(function(){
    367	          this.style.position = '';
    368	          this.style.top = '';
    369	          this.style.left = '';
    370	        });
    371	     
    372	      // re-apply saved container styles
    373	      var elemStyle = this.element[0].style;
    374	      for ( var prop in this.originalStyle ) {
    375	        elemStyle[ prop ] = this.originalStyle[ prop ];
    376	      }
    377	
    378	      this.element
    379	        .unbind('.masonry')
    380	        .removeClass('masonry')
    381	        .removeData('masonry');
    382	     
    383	      $(window).unbind('.masonry');
    384	
    385	    }
    386	   
    387	  };
    388	 
    389	 
    390	  // ======================= imagesLoaded Plugin ===============================
    391	  /*!
    392	   * jQuery imagesLoaded plugin v1.1.0
    393	   * http://github.com/desandro/imagesloaded
    394	   *
    395	   * MIT License. by Paul Irish et al.
    396	   */
    397	
    398	
    399	  // $('#my-container').imagesLoaded(myFunction)
    400	  // or
    401	  // $('img').imagesLoaded(myFunction)
    402	
    403	  // execute a callback when all images have loaded.
    404	  // needed because .load() doesn't work on cached images
    405	
    406	  // callback function gets image collection as argument
    407	  //  `this` is the container
    408	
    409	  $.fn.imagesLoaded = function( callback ) {
    410	    var $this = this,
    411	        $images = $this.find('img').add( $this.filter('img') ),
    412	        len = $images.length,
    413	        blank = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==',
    414	        loaded = [];
    415	
    416	    function triggerCallback() {
    417	      callback.call( $this, $images );
    418	    }
    419	
    420	    function imgLoaded( event ) {
    421	      var img = event.target;
    422	      if ( img.src !== blank && $.inArray( img, loaded ) === -1 ){
    423	        loaded.push( img );
    424	        if ( --len <= 0 ){
    425	          setTimeout( triggerCallback );
    426	          $images.unbind( '.imagesLoaded', imgLoaded );
    427	        }
    428	      }
    429	    }
    430	
    431	    // if no images, trigger immediately
    432	    if ( !len ) {
    433	      triggerCallback();
    434	    }
    435	
    436	    $images.bind( 'load.imagesLoaded error.imagesLoaded',  imgLoaded ).each( function() {
    437	      // cached images don't fire load sometimes, so we reset src.
    438	      var src = this.src;
    439	      // webkit hack from http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f
    440	      // data uri bypasses webkit log warning (thx doug jones)
    441	      this.src = blank;
    442	      this.src = src;
    443	    });
    444	
    445	    return $this;
    446	  };
    447	
    448	
    449	  // helper function for logging errors
    450	  // $.error breaks jQuery chaining
    451	  var logError = function( message ) {
    452	    if ( window.console ) {
    453	      window.console.error( message );
    454	    }
    455	  };
    456	 
    457	  // =======================  Plugin bridge  ===============================
    458	  // leverages data method to either create or return $.Mason constructor
    459	  // A bit from jQuery UI
    460	  //   https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.widget.js
    461	  // A bit from jcarousel
    462	  //   https://github.com/jsor/jcarousel/blob/master/lib/jquery.jcarousel.js
    463	
    464	  $.fn.masonry = function( options ) {
    465	    if ( typeof options === 'string' ) {
    466	      // call method
    467	      var args = Array.prototype.slice.call( arguments, 1 );
    468	
    469	      this.each(function(){
    470	        var instance = $.data( this, 'masonry' );
    471	        if ( !instance ) {
    472	          logError( "cannot call methods on masonry prior to initialization; " +
    473	            "attempted to call method '" + options + "'" );
    474	          return;
    475	        }
    476	        if ( !$.isFunction( instance[options] ) || options.charAt(0) === "_" ) {
    477	          logError( "no such method '" + options + "' for masonry instance" );
    478	          return;
    479	        }
    480	        // apply method
    481	        instance[ options ].apply( instance, args );
    482	      });
    483	    } else {
    484	      this.each(function() {
    485	        var instance = $.data( this, 'masonry' );
    486	        if ( instance ) {
    487	          // apply options & init
    488	          instance.option( options || {} );
    489	          instance._init();
    490	        } else {
    491	          // initialize new instance
    492	          $.data( this, 'masonry', new $.Mason( options, this ) );
    493	        }
    494	      });
    495	    }
    496	    return this;
    497	  };
    498	
    499	})( window, jQuery );
    
  • WordPress源代码——jquery-plugins(jquery.color-2.1.1.js)

    WordPress源代码——jquery-plugins(jquery.color-2.1.1.js)

    1	/*!
    2	 * jQuery Color Animations v2.1.1
    3	 * https://github.com/jquery/jquery-color
    4	 *
    5	 * Copyright 2012 jQuery Foundation and other contributors
    6	 * Released under the MIT license.
    7	 * http://jquery.org/license
    8	 *
    9	 * Date: Sun Oct 28 15:08:06 2012 -0400
    10	 */
    11	(function( jQuery, undefined ) {
    12	
    13	        var stepHooks = "backgroundColor borderBottomColor borderLeftColor borderRightColor borderTopColor color columnRuleColor outlineColor textDecorationColor textEmphasisColor",
    14	
    15	        // plusequals test for += 100 -= 100
    16	        rplusequals = /^([\-+])=\s*(\d+\.?\d*)/,
    17	        // a set of RE's that can match strings and generate color tuples.
    18	        stringParsers = [{
    19	                        re: /rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
    20	                        parse: function( execResult ) {
    21	                                return [
    22	                                        execResult[ 1 ],
    23	                                        execResult[ 2 ],
    24	                                        execResult[ 3 ],
    25	                                        execResult[ 4 ]
    26	                                ];
    27	                        }
    28	                }, {
    29	                        re: /rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
    30	                        parse: function( execResult ) {
    31	                                return [
    32	                                        execResult[ 1 ] * 2.55,
    33	                                        execResult[ 2 ] * 2.55,
    34	                                        execResult[ 3 ] * 2.55,
    35	                                        execResult[ 4 ]
    36	                                ];
    37	                        }
    38	                }, {
    39	                        // this regex ignores A-F because it's compared against an already lowercased string
    40	                        re: /#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})/,
    41	                        parse: function( execResult ) {
    42	                                return [
    43	                                        parseInt( execResult[ 1 ], 16 ),
    44	                                        parseInt( execResult[ 2 ], 16 ),
    45	                                        parseInt( execResult[ 3 ], 16 )
    46	                                ];
    47	                        }
    48	                }, {
    49	                        // this regex ignores A-F because it's compared against an already lowercased string
    50	                        re: /#([a-f0-9])([a-f0-9])([a-f0-9])/,
    51	                        parse: function( execResult ) {
    52	                                return [
    53	                                        parseInt( execResult[ 1 ] + execResult[ 1 ], 16 ),
    54	                                        parseInt( execResult[ 2 ] + execResult[ 2 ], 16 ),
    55	                                        parseInt( execResult[ 3 ] + execResult[ 3 ], 16 )
    56	                                ];
    57	                        }
    58	                }, {
    59	                        re: /hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
    60	                        space: "hsla",
    61	                        parse: function( execResult ) {
    62	                                return [
    63	                                        execResult[ 1 ],
    64	                                        execResult[ 2 ] / 100,
    65	                                        execResult[ 3 ] / 100,
    66	                                        execResult[ 4 ]
    67	                                ];
    68	                        }
    69	                }],
    70	
    71	        // jQuery.Color( )
    72	        color = jQuery.Color = function( color, green, blue, alpha ) {
    73	                return new jQuery.Color.fn.parse( color, green, blue, alpha );
    74	        },
    75	        spaces = {
    76	                rgba: {
    77	                        props: {
    78	                                red: {
    79	                                        idx: 0,
    80	                                        type: "byte"
    81	                                },
    82	                                green: {
    83	                                        idx: 1,
    84	                                        type: "byte"
    85	                                },
    86	                                blue: {
    87	                                        idx: 2,
    88	                                        type: "byte"
    89	                                }
    90	                        }
    91	                },
    92	
    93	                hsla: {
    94	                        props: {
    95	                                hue: {
    96	                                        idx: 0,
    97	                                        type: "degrees"
    98	                                },
    99	                                saturation: {
    100	                                        idx: 1,
    101	                                        type: "percent"
    102	                                },
    103	                                lightness: {
    104	                                        idx: 2,
    105	                                        type: "percent"
    106	                                }
    107	                        }
    108	                }
    109	        },
    110	        propTypes = {
    111	                "byte": {
    112	                        floor: true,
    113	                        max: 255
    114	                },
    115	                "percent": {
    116	                        max: 1
    117	                },
    118	                "degrees": {
    119	                        mod: 360,
    120	                        floor: true
    121	                }
    122	        },
    123	        support = color.support = {},
    124	
    125	        // element for support tests
    126	        supportElem = jQuery( "<p>" )[ 0 ],
    127	
    128	        // colors = jQuery.Color.names
    129	        colors,
    130	
    131	        // local aliases of functions called often
    132	        each = jQuery.each;
    133	
    134	// determine rgba support immediately
    135	supportElem.style.cssText = "background-color:rgba(1,1,1,.5)";
    136	support.rgba = supportElem.style.backgroundColor.indexOf( "rgba" ) > -1;
    137	
    138	// define cache name and alpha properties
    139	// for rgba and hsla spaces
    140	each( spaces, function( spaceName, space ) {
    141	        space.cache = "_" + spaceName;
    142	        space.props.alpha = {
    143	                idx: 3,
    144	                type: "percent",
    145	                def: 1
    146	        };
    147	});
    148	
    149	function clamp( value, prop, allowEmpty ) {
    150	        var type = propTypes[ prop.type ] || {};
    151	
    152	        if ( value == null ) {
    153	                return (allowEmpty || !prop.def) ? null : prop.def;
    154	        }
    155	
    156	        // ~~ is an short way of doing floor for positive numbers
    157	        value = type.floor ? ~~value : parseFloat( value );
    158	
    159	        // IE will pass in empty strings as value for alpha,
    160	        // which will hit this case
    161	        if ( isNaN( value ) ) {
    162	                return prop.def;
    163	        }
    164	
    165	        if ( type.mod ) {
    166	                // we add mod before modding to make sure that negatives values
    167	                // get converted properly: -10 -> 350
    168	                return (value + type.mod) % type.mod;
    169	        }
    170	
    171	        // for now all property types without mod have min and max
    172	        return 0 > value ? 0 : type.max < value ? type.max : value;
    173	}
    174	
    175	function stringParse( string ) {
    176	        var inst = color(),
    177	                rgba = inst._rgba = [];
    178	
    179	        string = string.toLowerCase();
    180	
    181	        each( stringParsers, function( i, parser ) {
    182	                var parsed,
    183	                        match = parser.re.exec( string ),
    184	                        values = match && parser.parse( match ),
    185	                        spaceName = parser.space || "rgba";
    186	
    187	                if ( values ) {
    188	                        parsed = inst[ spaceName ]( values );
    189	
    190	                        // if this was an rgba parse the assignment might happen twice
    191	                        // oh well....
    192	                        inst[ spaces[ spaceName ].cache ] = parsed[ spaces[ spaceName ].cache ];
    193	                        rgba = inst._rgba = parsed._rgba;
    194	
    195	                        // exit each( stringParsers ) here because we matched
    196	                        return false;
    197	                }
    198	        });
    199	
    200	        // Found a stringParser that handled it
    201	        if ( rgba.length ) {
    202	
    203	                // if this came from a parsed string, force "transparent" when alpha is 0
    204	                // chrome, (and maybe others) return "transparent" as rgba(0,0,0,0)
    205	                if ( rgba.join() === "0,0,0,0" ) {
    206	                        jQuery.extend( rgba, colors.transparent );
    207	                }
    208	                return inst;
    209	        }
    210	
    211	        // named colors
    212	        return colors[ string ];
    213	}
    214	
    215	color.fn = jQuery.extend( color.prototype, {
    216	        parse: function( red, green, blue, alpha ) {
    217	                if ( red === undefined ) {
    218	                        this._rgba = [ null, null, null, null ];
    219	                        return this;
    220	                }
    221	                if ( red.jquery || red.nodeType ) {
    222	                        red = jQuery( red ).css( green );
    223	                        green = undefined;
    224	                }
    225	
    226	                var inst = this,
    227	                        type = jQuery.type( red ),
    228	                        rgba = this._rgba = [];
    229	
    230	                // more than 1 argument specified - assume ( red, green, blue, alpha )
    231	                if ( green !== undefined ) {
    232	                        red = [ red, green, blue, alpha ];
    233	                        type = "array";
    234	                }
    235	
    236	                if ( type === "string" ) {
    237	                        return this.parse( stringParse( red ) || colors._default );
    238	                }
    239	
    240	                if ( type === "array" ) {
    241	                        each( spaces.rgba.props, function( key, prop ) {
    242	                                rgba[ prop.idx ] = clamp( red[ prop.idx ], prop );
    243	                        });
    244	                        return this;
    245	                }
    246	
    247	                if ( type === "object" ) {
    248	                        if ( red instanceof color ) {
    249	                                each( spaces, function( spaceName, space ) {
    250	                                        if ( red[ space.cache ] ) {
    251	                                                inst[ space.cache ] = red[ space.cache ].slice();
    252	                                        }
    253	                                });
    254	                        } else {
    255	                                each( spaces, function( spaceName, space ) {
    256	                                        var cache = space.cache;
    257	                                        each( space.props, function( key, prop ) {
    258	
    259	                                                // if the cache doesn't exist, and we know how to convert
    260	                                                if ( !inst[ cache ] && space.to ) {
    261	
    262	                                                        // if the value was null, we don't need to copy it
    263	                                                        // if the key was alpha, we don't need to copy it either
    264	                                                        if ( key === "alpha" || red[ key ] == null ) {
    265	                                                                return;
    266	                                                        }
    267	                                                        inst[ cache ] = space.to( inst._rgba );
    268	                                                }
    269	
    270	                                                // this is the only case where we allow nulls for ALL properties.
    271	                                                // call clamp with alwaysAllowEmpty
    272	                                                inst[ cache ][ prop.idx ] = clamp( red[ key ], prop, true );
    273	                                        });
    274	
    275	                                        // everything defined but alpha?
    276	                                        if ( inst[ cache ] && jQuery.inArray( null, inst[ cache ].slice( 0, 3 ) ) < 0 ) {
    277	                                                // use the default of 1
    278	                                                inst[ cache ][ 3 ] = 1;
    279	                                                if ( space.from ) {
    280	                                                        inst._rgba = space.from( inst[ cache ] );
    281	                                                }
    282	                                        }
    283	                                });
    284	                        }
    285	                        return this;
    286	                }
    287	        },
    288	        is: function( compare ) {
    289	                var is = color( compare ),
    290	                        same = true,
    291	                        inst = this;
    292	
    293	                each( spaces, function( _, space ) {
    294	                        var localCache,
    295	                                isCache = is[ space.cache ];
    296	                        if (isCache) {
    297	                                localCache = inst[ space.cache ] || space.to && space.to( inst._rgba ) || [];
    298	                                each( space.props, function( _, prop ) {
    299	                                        if ( isCache[ prop.idx ] != null ) {
    300	                                                same = ( isCache[ prop.idx ] === localCache[ prop.idx ] );
    301	                                                return same;
    302	                                        }
    303	                                });
    304	                        }
    305	                        return same;
    306	                });
    307	                return same;
    308	        },
    309	        _space: function() {
    310	                var used = [],
    311	                        inst = this;
    312	                each( spaces, function( spaceName, space ) {
    313	                        if ( inst[ space.cache ] ) {
    314	                                used.push( spaceName );
    315	                        }
    316	                });
    317	                return used.pop();
    318	        },
    319	        transition: function( other, distance ) {
    320	                var end = color( other ),
    321	                        spaceName = end._space(),
    322	                        space = spaces[ spaceName ],
    323	                        startColor = this.alpha() === 0 ? color( "transparent" ) : this,
    324	                        start = startColor[ space.cache ] || space.to( startColor._rgba ),
    325	                        result = start.slice();
    326	
    327	                end = end[ space.cache ];
    328	                each( space.props, function( key, prop ) {
    329	                        var index = prop.idx,
    330	                                startValue = start[ index ],
    331	                                endValue = end[ index ],
    332	                                type = propTypes[ prop.type ] || {};
    333	
    334	                        // if null, don't override start value
    335	                        if ( endValue === null ) {
    336	                                return;
    337	                        }
    338	                        // if null - use end
    339	                        if ( startValue === null ) {
    340	                                result[ index ] = endValue;
    341	                        } else {
    342	                                if ( type.mod ) {
    343	                                        if ( endValue - startValue > type.mod / 2 ) {
    344	                                                startValue += type.mod;
    345	                                        } else if ( startValue - endValue > type.mod / 2 ) {
    346	                                                startValue -= type.mod;
    347	                                        }
    348	                                }
    349	                                result[ index ] = clamp( ( endValue - startValue ) * distance + startValue, prop );
    350	                        }
    351	                });
    352	                return this[ spaceName ]( result );
    353	        },
    354	        blend: function( opaque ) {
    355	                // if we are already opaque - return ourself
    356	                if ( this._rgba[ 3 ] === 1 ) {
    357	                        return this;
    358	                }
    359	
    360	                var rgb = this._rgba.slice(),
    361	                        a = rgb.pop(),
    362	                        blend = color( opaque )._rgba;
    363	
    364	                return color( jQuery.map( rgb, function( v, i ) {
    365	                        return ( 1 - a ) * blend[ i ] + a * v;
    366	                }));
    367	        },
    368	        toRgbaString: function() {
    369	                var prefix = "rgba(",
    370	                        rgba = jQuery.map( this._rgba, function( v, i ) {
    371	                                return v == null ? ( i > 2 ? 1 : 0 ) : v;
    372	                        });
    373	
    374	                if ( rgba[ 3 ] === 1 ) {
    375	                        rgba.pop();
    376	                        prefix = "rgb(";
    377	                }
    378	
    379	                return prefix + rgba.join() + ")";
    380	        },
    381	        toHslaString: function() {
    382	                var prefix = "hsla(",
    383	                        hsla = jQuery.map( this.hsla(), function( v, i ) {
    384	                                if ( v == null ) {
    385	                                        v = i > 2 ? 1 : 0;
    386	                                }
    387	
    388	                                // catch 1 and 2
    389	                                if ( i && i < 3 ) {
    390	                                        v = Math.round( v * 100 ) + "%";
    391	                                }
    392	                                return v;
    393	                        });
    394	
    395	                if ( hsla[ 3 ] === 1 ) {
    396	                        hsla.pop();
    397	                        prefix = "hsl(";
    398	                }
    399	                return prefix + hsla.join() + ")";
    400	        },
    401	        toHexString: function( includeAlpha ) {
    402	                var rgba = this._rgba.slice(),
    403	                        alpha = rgba.pop();
    404	
    405	                if ( includeAlpha ) {
    406	                        rgba.push( ~~( alpha * 255 ) );
    407	                }
    408	
    409	                return "#" + jQuery.map( rgba, function( v ) {
    410	
    411	                        // default to 0 when nulls exist
    412	                        v = ( v || 0 ).toString( 16 );
    413	                        return v.length === 1 ? "0" + v : v;
    414	                }).join("");
    415	        },
    416	        toString: function() {
    417	                return this._rgba[ 3 ] === 0 ? "transparent" : this.toRgbaString();
    418	        }
    419	});
    420	color.fn.parse.prototype = color.fn;
    421	
    422	// hsla conversions adapted from:
    423	// https://code.google.com/p/maashaack/source/browse/packages/graphics/trunk/src/graphics/colors/HUE2RGB.as?r=5021
    424	
    425	function hue2rgb( p, q, h ) {
    426	        h = ( h + 1 ) % 1;
    427	        if ( h * 6 < 1 ) {
    428	                return p + (q - p) * h * 6;
    429	        }
    430	        if ( h * 2 < 1) {
    431	                return q;
    432	        }
    433	        if ( h * 3 < 2 ) {
    434	                return p + (q - p) * ((2/3) - h) * 6;
    435	        }
    436	        return p;
    437	}
    438	
    439	spaces.hsla.to = function ( rgba ) {
    440	        if ( rgba[ 0 ] == null || rgba[ 1 ] == null || rgba[ 2 ] == null ) {
    441	                return [ null, null, null, rgba[ 3 ] ];
    442	        }
    443	        var r = rgba[ 0 ] / 255,
    444	                g = rgba[ 1 ] / 255,
    445	                b = rgba[ 2 ] / 255,
    446	                a = rgba[ 3 ],
    447	                max = Math.max( r, g, b ),
    448	                min = Math.min( r, g, b ),
    449	                diff = max - min,
    450	                add = max + min,
    451	                l = add * 0.5,
    452	                h, s;
    453	
    454	        if ( min === max ) {
    455	                h = 0;
    456	        } else if ( r === max ) {
    457	                h = ( 60 * ( g - b ) / diff ) + 360;
    458	        } else if ( g === max ) {
    459	                h = ( 60 * ( b - r ) / diff ) + 120;
    460	        } else {
    461	                h = ( 60 * ( r - g ) / diff ) + 240;
    462	        }
    463	
    464	        // chroma (diff) == 0 means greyscale which, by definition, saturation = 0%
    465	        // otherwise, saturation is based on the ratio of chroma (diff) to lightness (add)
    466	        if ( diff === 0 ) {
    467	                s = 0;
    468	        } else if ( l <= 0.5 ) {
    469	                s = diff / add;
    470	        } else {
    471	                s = diff / ( 2 - add );
    472	        }
    473	        return [ Math.round(h) % 360, s, l, a == null ? 1 : a ];
    474	};
    475	
    476	spaces.hsla.from = function ( hsla ) {
    477	        if ( hsla[ 0 ] == null || hsla[ 1 ] == null || hsla[ 2 ] == null ) {
    478	                return [ null, null, null, hsla[ 3 ] ];
    479	        }
    480	        var h = hsla[ 0 ] / 360,
    481	                s = hsla[ 1 ],
    482	                l = hsla[ 2 ],
    483	                a = hsla[ 3 ],
    484	                q = l <= 0.5 ? l * ( 1 + s ) : l + s - l * s,
    485	                p = 2 * l - q;
    486	
    487	        return [
    488	                Math.round( hue2rgb( p, q, h + ( 1 / 3 ) ) * 255 ),
    489	                Math.round( hue2rgb( p, q, h ) * 255 ),
    490	                Math.round( hue2rgb( p, q, h - ( 1 / 3 ) ) * 255 ),
    491	                a
    492	        ];
    493	};
    494	
    495	
    496	each( spaces, function( spaceName, space ) {
    497	        var props = space.props,
    498	                cache = space.cache,
    499	                to = space.to,
    500	                from = space.from;
    501	
    502	        // makes rgba() and hsla()
    503	        color.fn[ spaceName ] = function( value ) {
    504	
    505	                // generate a cache for this space if it doesn't exist
    506	                if ( to && !this[ cache ] ) {
    507	                        this[ cache ] = to( this._rgba );
    508	                }
    509	                if ( value === undefined ) {
    510	                        return this[ cache ].slice();
    511	                }
    512	
    513	                var ret,
    514	                        type = jQuery.type( value ),
    515	                        arr = ( type === "array" || type === "object" ) ? value : arguments,
    516	                        local = this[ cache ].slice();
    517	
    518	                each( props, function( key, prop ) {
    519	                        var val = arr[ type === "object" ? key : prop.idx ];
    520	                        if ( val == null ) {
    521	                                val = local[ prop.idx ];
    522	                        }
    523	                        local[ prop.idx ] = clamp( val, prop );
    524	                });
    525	
    526	                if ( from ) {
    527	                        ret = color( from( local ) );
    528	                        ret[ cache ] = local;
    529	                        return ret;
    530	                } else {
    531	                        return color( local );
    532	                }
    533	        };
    534	
    535	        // makes red() green() blue() alpha() hue() saturation() lightness()
    536	        each( props, function( key, prop ) {
    537	                // alpha is included in more than one space
    538	                if ( color.fn[ key ] ) {
    539	                        return;
    540	                }
    541	                color.fn[ key ] = function( value ) {
    542	                        var vtype = jQuery.type( value ),
    543	                                fn = ( key === "alpha" ? ( this._hsla ? "hsla" : "rgba" ) : spaceName ),
    544	                                local = this[ fn ](),
    545	                                cur = local[ prop.idx ],
    546	                                match;
    547	
    548	                        if ( vtype === "undefined" ) {
    549	                                return cur;
    550	                        }
    551	
    552	                        if ( vtype === "function" ) {
    553	                                value = value.call( this, cur );
    554	                                vtype = jQuery.type( value );
    555	                        }
    556	                        if ( value == null && prop.empty ) {
    557	                                return this;
    558	                        }
    559	                        if ( vtype === "string" ) {
    560	                                match = rplusequals.exec( value );
    561	                                if ( match ) {
    562	                                        value = cur + parseFloat( match[ 2 ] ) * ( match[ 1 ] === "+" ? 1 : -1 );
    563	                                }
    564	                        }
    565	                        local[ prop.idx ] = value;
    566	                        return this[ fn ]( local );
    567	                };
    568	        });
    569	});
    570	
    571	// add cssHook and .fx.step function for each named hook.
    572	// accept a space separated string of properties
    573	color.hook = function( hook ) {
    574	        var hooks = hook.split( " " );
    575	        each( hooks, function( i, hook ) {
    576	                jQuery.cssHooks[ hook ] = {
    577	                        set: function( elem, value ) {
    578	                                var parsed, curElem,
    579	                                        backgroundColor = "";
    580	
    581	                                if ( jQuery.type( value ) !== "string" || ( parsed = stringParse( value ) ) ) {
    582	                                        value = color( parsed || value );
    583	                                        if ( !support.rgba && value._rgba[ 3 ] !== 1 ) {
    584	                                                curElem = hook === "backgroundColor" ? elem.parentNode : elem;
    585	                                                while (
    586	                                                        (backgroundColor === "" || backgroundColor === "transparent") &&
    587	                                                        curElem && curElem.style
    588	                                                ) {
    589	                                                        try {
    590	                                                                backgroundColor = jQuery.css( curElem, "backgroundColor" );
    591	                                                                curElem = curElem.parentNode;
    592	                                                        } catch ( e ) {
    593	                                                        }
    594	                                                }
    595	
    596	                                                value = value.blend( backgroundColor && backgroundColor !== "transparent" ?
    597	                                                        backgroundColor :
    598	                                                        "_default" );
    599	                                        }
    600	
    601	                                        value = value.toRgbaString();
    602	                                }
    603	                                try {
    604	                                        elem.style[ hook ] = value;
    605	                                } catch( e ) {
    606	                                        // wrapped to prevent IE from throwing errors on "invalid" values like 'auto' or 'inherit'
    607	                                }
    608	                        }
    609	                };
    610	                jQuery.fx.step[ hook ] = function( fx ) {
    611	                        if ( !fx.colorInit ) {
    612	                                fx.start = color( fx.elem, hook );
    613	                                fx.end = color( fx.end );
    614	                                fx.colorInit = true;
    615	                        }
    616	                        jQuery.cssHooks[ hook ].set( fx.elem, fx.start.transition( fx.end, fx.pos ) );
    617	                };
    618	        });
    619	
    620	};
    621	
    622	color.hook( stepHooks );
    623	
    624	jQuery.cssHooks.borderColor = {
    625	        expand: function( value ) {
    626	                var expanded = {};
    627	
    628	                each( [ "Top", "Right", "Bottom", "Left" ], function( i, part ) {
    629	                        expanded[ "border" + part + "Color" ] = value;
    630	                });
    631	                return expanded;
    632	        }
    633	};
    634	
    635	// Basic color names only.
    636	// Usage of any of the other color names requires adding yourself or including
    637	// jquery.color.svg-names.js.
    638	colors = jQuery.Color.names = {
    639	        // 4.1. Basic color keywords
    640	        aqua: "#00ffff",
    641	        black: "#000000",
    642	        blue: "#0000ff",
    643	        fuchsia: "#ff00ff",
    644	        gray: "#808080",
    645	        green: "#008000",
    646	        lime: "#00ff00",
    647	        maroon: "#800000",
    648	        navy: "#000080",
    649	        olive: "#808000",
    650	        purple: "#800080",
    651	        red: "#ff0000",
    652	        silver: "#c0c0c0",
    653	        teal: "#008080",
    654	        white: "#ffffff",
    655	        yellow: "#ffff00",
    656	
    657	        // 4.2.3. ‘transparent’ color keyword
    658	        transparent: [ null, null, null, 0 ],
    659	
    660	        _default: "#ffffff"
    661	};
    662	
    663	})( jQuery );
  • WordPress源代码——jquery-plugins(jquery.color-2.1.0.js)

    WordPress源代码——jquery-plugins(jquery.color-2.1.0.js)

    1	/*!
    2	 * jQuery Color Animations v2.1.0
    3	 * http://jquery.com/
    4	 *
    5	 * Copyright 2012 jQuery Foundation and other contributors
    6	 * Released under the MIT license.
    7	 * http://jquery.org/license
    8	 *
    9	 * Date: Fri Aug 24 12:02:24 2012 -0500
    10	 */
    11	(function( jQuery, undefined ) {
    12	
    13	        var stepHooks = "backgroundColor borderBottomColor borderLeftColor borderRightColor borderTopColor color columnRuleColor outlineColor textDecorationColor textEmphasisColor",
    14	
    15	        // plusequals test for += 100 -= 100
    16	        rplusequals = /^([\-+])=\s*(\d+\.?\d*)/,
    17	        // a set of RE's that can match strings and generate color tuples.
    18	        stringParsers = [{
    19	                        re: /rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
    20	                        parse: function( execResult ) {
    21	                                return [
    22	                                        execResult[ 1 ],
    23	                                        execResult[ 2 ],
    24	                                        execResult[ 3 ],
    25	                                        execResult[ 4 ]
    26	                                ];
    27	                        }
    28	                }, {
    29	                        re: /rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
    30	                        parse: function( execResult ) {
    31	                                return [
    32	                                        execResult[ 1 ] * 2.55,
    33	                                        execResult[ 2 ] * 2.55,
    34	                                        execResult[ 3 ] * 2.55,
    35	                                        execResult[ 4 ]
    36	                                ];
    37	                        }
    38	                }, {
    39	                        // this regex ignores A-F because it's compared against an already lowercased string
    40	                        re: /#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})/,
    41	                        parse: function( execResult ) {
    42	                                return [
    43	                                        parseInt( execResult[ 1 ], 16 ),
    44	                                        parseInt( execResult[ 2 ], 16 ),
    45	                                        parseInt( execResult[ 3 ], 16 )
    46	                                ];
    47	                        }
    48	                }, {
    49	                        // this regex ignores A-F because it's compared against an already lowercased string
    50	                        re: /#([a-f0-9])([a-f0-9])([a-f0-9])/,
    51	                        parse: function( execResult ) {
    52	                                return [
    53	                                        parseInt( execResult[ 1 ] + execResult[ 1 ], 16 ),
    54	                                        parseInt( execResult[ 2 ] + execResult[ 2 ], 16 ),
    55	                                        parseInt( execResult[ 3 ] + execResult[ 3 ], 16 )
    56	                                ];
    57	                        }
    58	                }, {
    59	                        re: /hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
    60	                        space: "hsla",
    61	                        parse: function( execResult ) {
    62	                                return [
    63	                                        execResult[ 1 ],
    64	                                        execResult[ 2 ] / 100,
    65	                                        execResult[ 3 ] / 100,
    66	                                        execResult[ 4 ]
    67	                                ];
    68	                        }
    69	                }],
    70	
    71	        // jQuery.Color( )
    72	        color = jQuery.Color = function( color, green, blue, alpha ) {
    73	                return new jQuery.Color.fn.parse( color, green, blue, alpha );
    74	        },
    75	        spaces = {
    76	                rgba: {
    77	                        props: {
    78	                                red: {
    79	                                        idx: 0,
    80	                                        type: "byte"
    81	                                },
    82	                                green: {
    83	                                        idx: 1,
    84	                                        type: "byte"
    85	                                },
    86	                                blue: {
    87	                                        idx: 2,
    88	                                        type: "byte"
    89	                                }
    90	                        }
    91	                },
    92	
    93	                hsla: {
    94	                        props: {
    95	                                hue: {
    96	                                        idx: 0,
    97	                                        type: "degrees"
    98	                                },
    99	                                saturation: {
    100	                                        idx: 1,
    101	                                        type: "percent"
    102	                                },
    103	                                lightness: {
    104	                                        idx: 2,
    105	                                        type: "percent"
    106	                                }
    107	                        }
    108	                }
    109	        },
    110	        propTypes = {
    111	                "byte": {
    112	                        floor: true,
    113	                        max: 255
    114	                },
    115	                "percent": {
    116	                        max: 1
    117	                },
    118	                "degrees": {
    119	                        mod: 360,
    120	                        floor: true
    121	                }
    122	        },
    123	        support = color.support = {},
    124	
    125	        // element for support tests
    126	        supportElem = jQuery( "<p>" )[ 0 ],
    127	
    128	        // colors = jQuery.Color.names
    129	        colors,
    130	
    131	        // local aliases of functions called often
    132	        each = jQuery.each;
    133	
    134	// determine rgba support immediately
    135	supportElem.style.cssText = "background-color:rgba(1,1,1,.5)";
    136	support.rgba = supportElem.style.backgroundColor.indexOf( "rgba" ) > -1;
    137	
    138	// define cache name and alpha properties
    139	// for rgba and hsla spaces
    140	each( spaces, function( spaceName, space ) {
    141	        space.cache = "_" + spaceName;
    142	        space.props.alpha = {
    143	                idx: 3,
    144	                type: "percent",
    145	                def: 1
    146	        };
    147	});
    148	
    149	function clamp( value, prop, allowEmpty ) {
    150	        var type = propTypes[ prop.type ] || {};
    151	
    152	        if ( value == null ) {
    153	                return (allowEmpty || !prop.def) ? null : prop.def;
    154	        }
    155	
    156	        // ~~ is an short way of doing floor for positive numbers
    157	        value = type.floor ? ~~value : parseFloat( value );
    158	
    159	        // IE will pass in empty strings as value for alpha,
    160	        // which will hit this case
    161	        if ( isNaN( value ) ) {
    162	                return prop.def;
    163	        }
    164	
    165	        if ( type.mod ) {
    166	                // we add mod before modding to make sure that negatives values
    167	                // get converted properly: -10 -> 350
    168	                return (value + type.mod) % type.mod;
    169	        }
    170	
    171	        // for now all property types without mod have min and max
    172	        return 0 > value ? 0 : type.max < value ? type.max : value;
    173	}
    174	
    175	function stringParse( string ) {
    176	        var inst = color(),
    177	                rgba = inst._rgba = [];
    178	
    179	        string = string.toLowerCase();
    180	
    181	        each( stringParsers, function( i, parser ) {
    182	                var parsed,
    183	                        match = parser.re.exec( string ),
    184	                        values = match && parser.parse( match ),
    185	                        spaceName = parser.space || "rgba";
    186	
    187	                if ( values ) {
    188	                        parsed = inst[ spaceName ]( values );
    189	
    190	                        // if this was an rgba parse the assignment might happen twice
    191	                        // oh well....
    192	                        inst[ spaces[ spaceName ].cache ] = parsed[ spaces[ spaceName ].cache ];
    193	                        rgba = inst._rgba = parsed._rgba;
    194	
    195	                        // exit each( stringParsers ) here because we matched
    196	                        return false;
    197	                }
    198	        });
    199	
    200	        // Found a stringParser that handled it
    201	        if ( rgba.length ) {
    202	
    203	                // if this came from a parsed string, force "transparent" when alpha is 0
    204	                // chrome, (and maybe others) return "transparent" as rgba(0,0,0,0)
    205	                if ( rgba.join() === "0,0,0,0" ) {
    206	                        jQuery.extend( rgba, colors.transparent );
    207	                }
    208	                return inst;
    209	        }
    210	
    211	        // named colors
    212	        return colors[ string ];
    213	}
    214	
    215	color.fn = jQuery.extend( color.prototype, {
    216	        parse: function( red, green, blue, alpha ) {
    217	                if ( red === undefined ) {
    218	                        this._rgba = [ null, null, null, null ];
    219	                        return this;
    220	                }
    221	                if ( red.jquery || red.nodeType ) {
    222	                        red = jQuery( red ).css( green );
    223	                        green = undefined;
    224	                }
    225	
    226	                var inst = this,
    227	                        type = jQuery.type( red ),
    228	                        rgba = this._rgba = [],
    229	                        source;
    230	
    231	                // more than 1 argument specified - assume ( red, green, blue, alpha )
    232	                if ( green !== undefined ) {
    233	                        red = [ red, green, blue, alpha ];
    234	                        type = "array";
    235	                }
    236	
    237	                if ( type === "string" ) {
    238	                        return this.parse( stringParse( red ) || colors._default );
    239	                }
    240	
    241	                if ( type === "array" ) {
    242	                        each( spaces.rgba.props, function( key, prop ) {
    243	                                rgba[ prop.idx ] = clamp( red[ prop.idx ], prop );
    244	                        });
    245	                        return this;
    246	                }
    247	
    248	                if ( type === "object" ) {
    249	                        if ( red instanceof color ) {
    250	                                each( spaces, function( spaceName, space ) {
    251	                                        if ( red[ space.cache ] ) {
    252	                                                inst[ space.cache ] = red[ space.cache ].slice();
    253	                                        }
    254	                                });
    255	                        } else {
    256	                                each( spaces, function( spaceName, space ) {
    257	                                        var cache = space.cache;
    258	                                        each( space.props, function( key, prop ) {
    259	
    260	                                                // if the cache doesn't exist, and we know how to convert
    261	                                                if ( !inst[ cache ] && space.to ) {
    262	
    263	                                                        // if the value was null, we don't need to copy it
    264	                                                        // if the key was alpha, we don't need to copy it either
    265	                                                        if ( key === "alpha" || red[ key ] == null ) {
    266	                                                                return;
    267	                                                        }
    268	                                                        inst[ cache ] = space.to( inst._rgba );
    269	                                                }
    270	
    271	                                                // this is the only case where we allow nulls for ALL properties.
    272	                                                // call clamp with alwaysAllowEmpty
    273	                                                inst[ cache ][ prop.idx ] = clamp( red[ key ], prop, true );
    274	                                        });
    275	
    276	                                        // everything defined but alpha?
    277	                                        if ( inst[ cache ] && jQuery.inArray( null, inst[ cache ].slice( 0, 3 ) ) < 0 ) {
    278	                                                // use the default of 1
    279	                                                inst[ cache ][ 3 ] = 1;
    280	                                                if ( space.from ) {
    281	                                                        inst._rgba = space.from( inst[ cache ] );
    282	                                                }
    283	                                        }
    284	                                });
    285	                        }
    286	                        return this;
    287	                }
    288	        },
    289	        is: function( compare ) {
    290	                var is = color( compare ),
    291	                        same = true,
    292	                        inst = this;
    293	
    294	                each( spaces, function( _, space ) {
    295	                        var localCache,
    296	                                isCache = is[ space.cache ];
    297	                        if (isCache) {
    298	                                localCache = inst[ space.cache ] || space.to && space.to( inst._rgba ) || [];
    299	                                each( space.props, function( _, prop ) {
    300	                                        if ( isCache[ prop.idx ] != null ) {
    301	                                                same = ( isCache[ prop.idx ] === localCache[ prop.idx ] );
    302	                                                return same;
    303	                                        }
    304	                                });
    305	                        }
    306	                        return same;
    307	                });
    308	                return same;
    309	        },
    310	        _space: function() {
    311	                var used = [],
    312	                        inst = this;
    313	                each( spaces, function( spaceName, space ) {
    314	                        if ( inst[ space.cache ] ) {
    315	                                used.push( spaceName );
    316	                        }
    317	                });
    318	                return used.pop();
    319	        },
    320	        transition: function( other, distance ) {
    321	                var end = color( other ),
    322	                        spaceName = end._space(),
    323	                        space = spaces[ spaceName ],
    324	                        startColor = this.alpha() === 0 ? color( "transparent" ) : this,
    325	                        start = startColor[ space.cache ] || space.to( startColor._rgba ),
    326	                        result = start.slice();
    327	
    328	                end = end[ space.cache ];
    329	                each( space.props, function( key, prop ) {
    330	                        var index = prop.idx,
    331	                                startValue = start[ index ],
    332	                                endValue = end[ index ],
    333	                                type = propTypes[ prop.type ] || {};
    334	
    335	                        // if null, don't override start value
    336	                        if ( endValue === null ) {
    337	                                return;
    338	                        }
    339	                        // if null - use end
    340	                        if ( startValue === null ) {
    341	                                result[ index ] = endValue;
    342	                        } else {
    343	                                if ( type.mod ) {
    344	                                        if ( endValue - startValue > type.mod / 2 ) {
    345	                                                startValue += type.mod;
    346	                                        } else if ( startValue - endValue > type.mod / 2 ) {
    347	                                                startValue -= type.mod;
    348	                                        }
    349	                                }
    350	                                result[ index ] = clamp( ( endValue - startValue ) * distance + startValue, prop );
    351	                        }
    352	                });
    353	                return this[ spaceName ]( result );
    354	        },
    355	        blend: function( opaque ) {
    356	                // if we are already opaque - return ourself
    357	                if ( this._rgba[ 3 ] === 1 ) {
    358	                        return this;
    359	                }
    360	
    361	                var rgb = this._rgba.slice(),
    362	                        a = rgb.pop(),
    363	                        blend = color( opaque )._rgba;
    364	
    365	                return color( jQuery.map( rgb, function( v, i ) {
    366	                        return ( 1 - a ) * blend[ i ] + a * v;
    367	                }));
    368	        },
    369	        toRgbaString: function() {
    370	                var prefix = "rgba(",
    371	                        rgba = jQuery.map( this._rgba, function( v, i ) {
    372	                                return v == null ? ( i > 2 ? 1 : 0 ) : v;
    373	                        });
    374	
    375	                if ( rgba[ 3 ] === 1 ) {
    376	                        rgba.pop();
    377	                        prefix = "rgb(";
    378	                }
    379	
    380	                return prefix + rgba.join() + ")";
    381	        },
    382	        toHslaString: function() {
    383	                var prefix = "hsla(",
    384	                        hsla = jQuery.map( this.hsla(), function( v, i ) {
    385	                                if ( v == null ) {
    386	                                        v = i > 2 ? 1 : 0;
    387	                                }
    388	
    389	                                // catch 1 and 2
    390	                                if ( i && i < 3 ) {
    391	                                        v = Math.round( v * 100 ) + "%";
    392	                                }
    393	                                return v;
    394	                        });
    395	
    396	                if ( hsla[ 3 ] === 1 ) {
    397	                        hsla.pop();
    398	                        prefix = "hsl(";
    399	                }
    400	                return prefix + hsla.join() + ")";
    401	        },
    402	        toHexString: function( includeAlpha ) {
    403	                var rgba = this._rgba.slice(),
    404	                        alpha = rgba.pop();
    405	
    406	                if ( includeAlpha ) {
    407	                        rgba.push( ~~( alpha * 255 ) );
    408	                }
    409	
    410	                return "#" + jQuery.map( rgba, function( v, i ) {
    411	
    412	                        // default to 0 when nulls exist
    413	                        v = ( v || 0 ).toString( 16 );
    414	                        return v.length === 1 ? "0" + v : v;
    415	                }).join("");
    416	        },
    417	        toString: function() {
    418	                return this._rgba[ 3 ] === 0 ? "transparent" : this.toRgbaString();
    419	        }
    420	});
    421	color.fn.parse.prototype = color.fn;
    422	
    423	// hsla conversions adapted from:
    424	// https://code.google.com/p/maashaack/source/browse/packages/graphics/trunk/src/graphics/colors/HUE2RGB.as?r=5021
    425	
    426	function hue2rgb( p, q, h ) {
    427	        h = ( h + 1 ) % 1;
    428	        if ( h * 6 < 1 ) {
    429	                return p + (q - p) * h * 6;
    430	        }
    431	        if ( h * 2 < 1) {
    432	                return q;
    433	        }
    434	        if ( h * 3 < 2 ) {
    435	                return p + (q - p) * ((2/3) - h) * 6;
    436	        }
    437	        return p;
    438	}
    439	
    440	spaces.hsla.to = function ( rgba ) {
    441	        if ( rgba[ 0 ] == null || rgba[ 1 ] == null || rgba[ 2 ] == null ) {
    442	                return [ null, null, null, rgba[ 3 ] ];
    443	        }
    444	        var r = rgba[ 0 ] / 255,
    445	                g = rgba[ 1 ] / 255,
    446	                b = rgba[ 2 ] / 255,
    447	                a = rgba[ 3 ],
    448	                max = Math.max( r, g, b ),
    449	                min = Math.min( r, g, b ),
    450	                diff = max - min,
    451	                add = max + min,
    452	                l = add * 0.5,
    453	                h, s;
    454	
    455	        if ( min === max ) {
    456	                h = 0;
    457	        } else if ( r === max ) {
    458	                h = ( 60 * ( g - b ) / diff ) + 360;
    459	        } else if ( g === max ) {
    460	                h = ( 60 * ( b - r ) / diff ) + 120;
    461	        } else {
    462	                h = ( 60 * ( r - g ) / diff ) + 240;
    463	        }
    464	
    465	        if ( l === 0 || l === 1 ) {
    466	                s = l;
    467	        } else if ( l <= 0.5 ) {
    468	                s = diff / add;
    469	        } else {
    470	                s = diff / ( 2 - add );
    471	        }
    472	        return [ Math.round(h) % 360, s, l, a == null ? 1 : a ];
    473	};
    474	
    475	spaces.hsla.from = function ( hsla ) {
    476	        if ( hsla[ 0 ] == null || hsla[ 1 ] == null || hsla[ 2 ] == null ) {
    477	                return [ null, null, null, hsla[ 3 ] ];
    478	        }
    479	        var h = hsla[ 0 ] / 360,
    480	                s = hsla[ 1 ],
    481	                l = hsla[ 2 ],
    482	                a = hsla[ 3 ],
    483	                q = l <= 0.5 ? l * ( 1 + s ) : l + s - l * s,
    484	                p = 2 * l - q,
    485	                r, g, b;
    486	
    487	        return [
    488	                Math.round( hue2rgb( p, q, h + ( 1 / 3 ) ) * 255 ),
    489	                Math.round( hue2rgb( p, q, h ) * 255 ),
    490	                Math.round( hue2rgb( p, q, h - ( 1 / 3 ) ) * 255 ),
    491	                a
    492	        ];
    493	};
    494	
    495	
    496	each( spaces, function( spaceName, space ) {
    497	        var props = space.props,
    498	                cache = space.cache,
    499	                to = space.to,
    500	                from = space.from;
    501	
    502	        // makes rgba() and hsla()
    503	        color.fn[ spaceName ] = function( value ) {
    504	
    505	                // generate a cache for this space if it doesn't exist
    506	                if ( to && !this[ cache ] ) {
    507	                        this[ cache ] = to( this._rgba );
    508	                }
    509	                if ( value === undefined ) {
    510	                        return this[ cache ].slice();
    511	                }
    512	
    513	                var ret,
    514	                        type = jQuery.type( value ),
    515	                        arr = ( type === "array" || type === "object" ) ? value : arguments,
    516	                        local = this[ cache ].slice();
    517	
    518	                each( props, function( key, prop ) {
    519	                        var val = arr[ type === "object" ? key : prop.idx ];
    520	                        if ( val == null ) {
    521	                                val = local[ prop.idx ];
    522	                        }
    523	                        local[ prop.idx ] = clamp( val, prop );
    524	                });
    525	
    526	                if ( from ) {
    527	                        ret = color( from( local ) );
    528	                        ret[ cache ] = local;
    529	                        return ret;
    530	                } else {
    531	                        return color( local );
    532	                }
    533	        };
    534	
    535	        // makes red() green() blue() alpha() hue() saturation() lightness()
    536	        each( props, function( key, prop ) {
    537	                // alpha is included in more than one space
    538	                if ( color.fn[ key ] ) {
    539	                        return;
    540	                }
    541	                color.fn[ key ] = function( value ) {
    542	                        var vtype = jQuery.type( value ),
    543	                                fn = ( key === "alpha" ? ( this._hsla ? "hsla" : "rgba" ) : spaceName ),
    544	                                local = this[ fn ](),
    545	                                cur = local[ prop.idx ],
    546	                                match;
    547	
    548	                        if ( vtype === "undefined" ) {
    549	                                return cur;
    550	                        }
    551	
    552	                        if ( vtype === "function" ) {
    553	                                value = value.call( this, cur );
    554	                                vtype = jQuery.type( value );
    555	                        }
    556	                        if ( value == null && prop.empty ) {
    557	                                return this;
    558	                        }
    559	                        if ( vtype === "string" ) {
    560	                                match = rplusequals.exec( value );
    561	                                if ( match ) {
    562	                                        value = cur + parseFloat( match[ 2 ] ) * ( match[ 1 ] === "+" ? 1 : -1 );
    563	                                }
    564	                        }
    565	                        local[ prop.idx ] = value;
    566	                        return this[ fn ]( local );
    567	                };
    568	        });
    569	});
    570	
    571	// add cssHook and .fx.step function for each named hook.
    572	// accept a space separated string of properties
    573	color.hook = function( hook ) {
    574	        var hooks = hook.split( " " );
    575	        each( hooks, function( i, hook ) {
    576	                jQuery.cssHooks[ hook ] = {
    577	                        set: function( elem, value ) {
    578	                                var parsed, curElem,
    579	                                        backgroundColor = "";
    580	
    581	                                if ( jQuery.type( value ) !== "string" || ( parsed = stringParse( value ) ) ) {
    582	                                        value = color( parsed || value );
    583	                                        if ( !support.rgba && value._rgba[ 3 ] !== 1 ) {
    584	                                                curElem = hook === "backgroundColor" ? elem.parentNode : elem;
    585	                                                while (
    586	                                                        (backgroundColor === "" || backgroundColor === "transparent") &&
    587	                                                        curElem && curElem.style
    588	                                                ) {
    589	                                                        try {
    590	                                                                backgroundColor = jQuery.css( curElem, "backgroundColor" );
    591	                                                                curElem = curElem.parentNode;
    592	                                                        } catch ( e ) {
    593	                                                        }
    594	                                                }
    595	
    596	                                                value = value.blend( backgroundColor && backgroundColor !== "transparent" ?
    597	                                                        backgroundColor :
    598	                                                        "_default" );
    599	                                        }
    600	
    601	                                        value = value.toRgbaString();
    602	                                }
    603	                                try {
    604	                                        elem.style[ hook ] = value;
    605	                                } catch( value ) {
    606	                                        // wrapped to prevent IE from throwing errors on "invalid" values like 'auto' or 'inherit'
    607	                                }
    608	                        }
    609	                };
    610	                jQuery.fx.step[ hook ] = function( fx ) {
    611	                        if ( !fx.colorInit ) {
    612	                                fx.start = color( fx.elem, hook );
    613	                                fx.end = color( fx.end );
    614	                                fx.colorInit = true;
    615	                        }
    616	                        jQuery.cssHooks[ hook ].set( fx.elem, fx.start.transition( fx.end, fx.pos ) );
    617	                };
    618	        });
    619	
    620	};
    621	
    622	color.hook( stepHooks );
    623	
    624	jQuery.cssHooks.borderColor = {
    625	        expand: function( value ) {
    626	                var expanded = {};
    627	
    628	                each( [ "Top", "Right", "Bottom", "Left" ], function( i, part ) {
    629	                        expanded[ "border" + part + "Color" ] = value;
    630	                });
    631	                return expanded;
    632	        }
    633	};
    634	
    635	// Basic color names only.
    636	// Usage of any of the other color names requires adding yourself or including
    637	// jquery.color.svg-names.js.
    638	colors = jQuery.Color.names = {
    639	        // 4.1. Basic color keywords
    640	        aqua: "#00ffff",
    641	        black: "#000000",
    642	        blue: "#0000ff",
    643	        fuchsia: "#ff00ff",
    644	        gray: "#808080",
    645	        green: "#008000",
    646	        lime: "#00ff00",
    647	        maroon: "#800000",
    648	        navy: "#000080",
    649	        olive: "#808000",
    650	        purple: "#800080",
    651	        red: "#ff0000",
    652	        silver: "#c0c0c0",
    653	        teal: "#008080",
    654	        white: "#ffffff",
    655	        yellow: "#ffff00",
    656	
    657	        // 4.2.3. ‘transparent’ color keyword
    658	        transparent: [ null, null, null, 0 ],
    659	
    660	        _default: "#ffffff"
    661	};
    662	
    663	})( jQuery );
    664	
    665	/*!
    666	 * jQuery Color Animations v2.1.0 - SVG Color Names
    667	 * http://jquery.org/
    668	 *
    669	 * Remaining HTML/CSS color names per W3C's CSS Color Module Level 3.
    670	 * http://www.w3.org/TR/css3-color/#svg-color
    671	 *
    672	 * Copyright 2012 jQuery Foundation and other contributors
    673	 * Released under the MIT license.
    674	 * http://jquery.org/license
    675	 *
    676	 * Date: Fri Aug 24 12:02:24 2012 -0500
    677	 */
    678	jQuery.extend( jQuery.Color.names, {
    679	        // 4.3. Extended color keywords (minus the basic ones in core color plugin)
    680	        aliceblue: "#f0f8ff",
    681	        antiquewhite: "#faebd7",
    682	        aquamarine: "#7fffd4",
    683	        azure: "#f0ffff",
    684	        beige: "#f5f5dc",
    685	        bisque: "#ffe4c4",
    686	        blanchedalmond: "#ffebcd",
    687	        blueviolet: "#8a2be2",
    688	        brown: "#a52a2a",
    689	        burlywood: "#deb887",
    690	        cadetblue: "#5f9ea0",
    691	        chartreuse: "#7fff00",
    692	        chocolate: "#d2691e",
    693	        coral: "#ff7f50",
    694	        cornflowerblue: "#6495ed",
    695	        cornsilk: "#fff8dc",
    696	        crimson: "#dc143c",
    697	        cyan: "#00ffff",
    698	        darkblue: "#00008b",
    699	        darkcyan: "#008b8b",
    700	        darkgoldenrod: "#b8860b",
    701	        darkgray: "#a9a9a9",
    702	        darkgreen: "#006400",
    703	        darkgrey: "#a9a9a9",
    704	        darkkhaki: "#bdb76b",
    705	        darkmagenta: "#8b008b",
    706	        darkolivegreen: "#556b2f",
    707	        darkorange: "#ff8c00",
    708	        darkorchid: "#9932cc",
    709	        darkred: "#8b0000",
    710	        darksalmon: "#e9967a",
    711	        darkseagreen: "#8fbc8f",
    712	        darkslateblue: "#483d8b",
    713	        darkslategray: "#2f4f4f",
    714	        darkslategrey: "#2f4f4f",
    715	        darkturquoise: "#00ced1",
    716	        darkviolet: "#9400d3",
    717	        deeppink: "#ff1493",
    718	        deepskyblue: "#00bfff",
    719	        dimgray: "#696969",
    720	        dimgrey: "#696969",
    721	        dodgerblue: "#1e90ff",
    722	        firebrick: "#b22222",
    723	        floralwhite: "#fffaf0",
    724	        forestgreen: "#228b22",
    725	        gainsboro: "#dcdcdc",
    726	        ghostwhite: "#f8f8ff",
    727	        gold: "#ffd700",
    728	        goldenrod: "#daa520",
    729	        greenyellow: "#adff2f",
    730	        grey: "#808080",
    731	        honeydew: "#f0fff0",
    732	        hotpink: "#ff69b4",
    733	        indianred: "#cd5c5c",
    734	        indigo: "#4b0082",
    735	        ivory: "#fffff0",
    736	        khaki: "#f0e68c",
    737	        lavender: "#e6e6fa",
    738	        lavenderblush: "#fff0f5",
    739	        lawngreen: "#7cfc00",
    740	        lemonchiffon: "#fffacd",
    741	        lightblue: "#add8e6",
    742	        lightcoral: "#f08080",
    743	        lightcyan: "#e0ffff",
    744	        lightgoldenrodyellow: "#fafad2",
    745	        lightgray: "#d3d3d3",
    746	        lightgreen: "#90ee90",
    747	        lightgrey: "#d3d3d3",
    748	        lightpink: "#ffb6c1",
    749	        lightsalmon: "#ffa07a",
    750	        lightseagreen: "#20b2aa",
    751	        lightskyblue: "#87cefa",
    752	        lightslategray: "#778899",
    753	        lightslategrey: "#778899",
    754	        lightsteelblue: "#b0c4de",
    755	        lightyellow: "#ffffe0",
    756	        limegreen: "#32cd32",
    757	        linen: "#faf0e6",
    758	        mediumaquamarine: "#66cdaa",
    759	        mediumblue: "#0000cd",
    760	        mediumorchid: "#ba55d3",
    761	        mediumpurple: "#9370db",
    762	        mediumseagreen: "#3cb371",
    763	        mediumslateblue: "#7b68ee",
    764	        mediumspringgreen: "#00fa9a",
    765	        mediumturquoise: "#48d1cc",
    766	        mediumvioletred: "#c71585",
    767	        midnightblue: "#191970",
    768	        mintcream: "#f5fffa",
    769	        mistyrose: "#ffe4e1",
    770	        moccasin: "#ffe4b5",
    771	        navajowhite: "#ffdead",
    772	        oldlace: "#fdf5e6",
    773	        olivedrab: "#6b8e23",
    774	        orange: "#ffa500",
    775	        orangered: "#ff4500",
    776	        orchid: "#da70d6",
    777	        palegoldenrod: "#eee8aa",
    778	        palegreen: "#98fb98",
    779	        paleturquoise: "#afeeee",
    780	        palevioletred: "#db7093",
    781	        papayawhip: "#ffefd5",
    782	        peachpuff: "#ffdab9",
    783	        peru: "#cd853f",
    784	        pink: "#ffc0cb",
    785	        plum: "#dda0dd",
    786	        powderblue: "#b0e0e6",
    787	        rosybrown: "#bc8f8f",
    788	        royalblue: "#4169e1",
    789	        saddlebrown: "#8b4513",
    790	        salmon: "#fa8072",
    791	        sandybrown: "#f4a460",
    792	        seagreen: "#2e8b57",
    793	        seashell: "#fff5ee",
    794	        sienna: "#a0522d",
    795	        skyblue: "#87ceeb",
    796	        slateblue: "#6a5acd",
    797	        slategray: "#708090",
    798	        slategrey: "#708090",
    799	        snow: "#fffafa",
    800	        springgreen: "#00ff7f",
    801	        steelblue: "#4682b4",
    802	        tan: "#d2b48c",
    803	        thistle: "#d8bfd8",
    804	        tomato: "#ff6347",
    805	        turquoise: "#40e0d0",
    806	        violet: "#ee82ee",
    807	        wheat: "#f5deb3",
    808	        whitesmoke: "#f5f5f5",
    809	        yellowgreen: "#9acd32",
    810	});