flapjack 0.7.35 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -1
- data/Gemfile +3 -4
- data/Guardfile +1 -1
- data/README.md +38 -19
- data/Rakefile +1 -3
- data/etc/flapjack_config.yaml.example +11 -1
- data/features/steps/cli_steps.rb +3 -3
- data/features/steps/events_steps.rb +7 -6
- data/features/steps/flapjack-netsaint-parser_steps.rb +8 -8
- data/features/steps/notifications_steps.rb +10 -10
- data/features/steps/packaging-lintian_steps.rb +5 -9
- data/features/steps/time_travel_steps.rb +1 -1
- data/flapjack.gemspec +4 -3
- data/lib/flapjack/data/contact.rb +78 -6
- data/lib/flapjack/data/entity.rb +11 -2
- data/lib/flapjack/data/notification_rule.rb +67 -59
- data/lib/flapjack/data/semaphore.rb +44 -0
- data/lib/flapjack/gateways/api.rb +24 -28
- data/lib/flapjack/gateways/api/contact_methods.rb +1 -2
- data/lib/flapjack/gateways/api/entity_methods.rb +3 -3
- data/lib/flapjack/gateways/jsonapi.rb +249 -0
- data/lib/flapjack/gateways/jsonapi/contact_methods.rb +544 -0
- data/lib/flapjack/gateways/jsonapi/entity_check_presenter.rb +217 -0
- data/lib/flapjack/gateways/jsonapi/entity_methods.rb +350 -0
- data/lib/flapjack/gateways/jsonapi/entity_presenter.rb +75 -0
- data/lib/flapjack/gateways/jsonapi/rack/json_params_parser.rb +32 -0
- data/lib/flapjack/gateways/web.rb +78 -12
- data/lib/flapjack/gateways/web/public/css/bootstrap-theme.css +397 -0
- data/lib/flapjack/gateways/web/public/css/bootstrap-theme.min.css +7 -0
- data/lib/flapjack/gateways/web/public/css/bootstrap.css +7118 -0
- data/lib/flapjack/gateways/web/public/css/bootstrap.min.css +6 -8
- data/lib/flapjack/gateways/web/public/css/font-awesome.css +1338 -0
- data/lib/flapjack/gateways/web/public/css/font-awesome.min.css +4 -0
- data/lib/flapjack/gateways/web/public/css/screen.css +80 -0
- data/lib/flapjack/gateways/web/public/css/select2-bootstrap.css +87 -0
- data/lib/flapjack/gateways/web/public/css/select2.css +615 -0
- data/lib/flapjack/gateways/web/public/fonts/FontAwesome.otf +0 -0
- data/lib/flapjack/gateways/web/public/fonts/fontawesome-webfont.eot +0 -0
- data/lib/flapjack/gateways/web/public/fonts/fontawesome-webfont.svg +414 -0
- data/lib/flapjack/gateways/web/public/fonts/fontawesome-webfont.ttf +0 -0
- data/lib/flapjack/gateways/web/public/fonts/fontawesome-webfont.woff +0 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.eot +0 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.svg +229 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.woff +0 -0
- data/lib/flapjack/gateways/web/public/img/flapjack-2013-notext-transparent-300-300.png +0 -0
- data/lib/flapjack/gateways/web/public/img/select2.png +0 -0
- data/lib/flapjack/gateways/web/public/img/select2x2.png +0 -0
- data/lib/flapjack/gateways/web/public/js/backbone-min.js +2 -0
- data/lib/flapjack/gateways/web/public/js/backbone.js +1581 -0
- data/lib/flapjack/gateways/web/public/js/backbone.jsonapi.js +75 -0
- data/lib/flapjack/gateways/web/public/js/bootstrap.js +2276 -0
- data/lib/flapjack/gateways/web/public/js/contacts.js +225 -0
- data/lib/flapjack/gateways/web/public/js/jquery-1.10.2.js +9789 -0
- data/lib/flapjack/gateways/web/public/js/jquery-1.10.2.min.js +6 -0
- data/lib/flapjack/gateways/web/public/js/select2.js +3255 -0
- data/lib/flapjack/gateways/web/public/js/select2.min.js +22 -0
- data/lib/flapjack/gateways/web/public/js/underscore-min.js +6 -0
- data/lib/flapjack/gateways/web/public/js/underscore.js +1276 -0
- data/lib/flapjack/gateways/web/views/check.html.erb +423 -193
- data/lib/flapjack/gateways/web/views/checks.html.erb +51 -71
- data/lib/flapjack/gateways/web/views/contact.html.erb +142 -164
- data/lib/flapjack/gateways/web/views/contacts.html.erb +20 -40
- data/lib/flapjack/gateways/web/views/edit_contacts.html.erb +83 -0
- data/lib/flapjack/gateways/web/views/entities.html.erb +18 -37
- data/lib/flapjack/gateways/web/views/entity.html.erb +46 -65
- data/lib/flapjack/gateways/web/views/index.html.erb +6 -27
- data/lib/flapjack/gateways/web/views/layout.erb +95 -0
- data/lib/flapjack/gateways/web/views/self_stats.html.erb +100 -114
- data/lib/flapjack/pikelet.rb +4 -2
- data/lib/flapjack/version.rb +1 -1
- data/spec/lib/flapjack/coordinator_spec.rb +120 -120
- data/spec/lib/flapjack/data/contact_spec.rb +66 -58
- data/spec/lib/flapjack/data/entity_check_spec.rb +179 -179
- data/spec/lib/flapjack/data/entity_spec.rb +71 -71
- data/spec/lib/flapjack/data/event_spec.rb +34 -30
- data/spec/lib/flapjack/data/message_spec.rb +6 -6
- data/spec/lib/flapjack/data/notification_rule_spec.rb +24 -24
- data/spec/lib/flapjack/data/notification_spec.rb +19 -19
- data/spec/lib/flapjack/data/semaphore_spec.rb +24 -0
- data/spec/lib/flapjack/data/tag_spec.rb +11 -10
- data/spec/lib/flapjack/gateways/api/contact_methods_spec.rb +201 -201
- data/spec/lib/flapjack/gateways/api/entity_check_presenter_spec.rb +55 -55
- data/spec/lib/flapjack/gateways/api/entity_methods_spec.rb +257 -257
- data/spec/lib/flapjack/gateways/api/entity_presenter_spec.rb +26 -26
- data/spec/lib/flapjack/gateways/api_spec.rb +1 -1
- data/spec/lib/flapjack/gateways/email_spec.rb +4 -4
- data/spec/lib/flapjack/gateways/jabber_spec.rb +77 -77
- data/spec/lib/flapjack/gateways/jsonapi/contact_methods_spec.rb +830 -0
- data/spec/lib/flapjack/gateways/jsonapi/entity_check_presenter_spec.rb +211 -0
- data/spec/lib/flapjack/gateways/jsonapi/entity_methods_spec.rb +863 -0
- data/spec/lib/flapjack/gateways/jsonapi/entity_presenter_spec.rb +108 -0
- data/spec/lib/flapjack/gateways/jsonapi_spec.rb +8 -0
- data/spec/lib/flapjack/gateways/oobetet_spec.rb +35 -35
- data/spec/lib/flapjack/gateways/pagerduty_spec.rb +40 -40
- data/spec/lib/flapjack/gateways/sms_messagenet_spec.rb +3 -3
- data/spec/lib/flapjack/gateways/web/views/check.html.erb_spec.rb +1 -1
- data/spec/lib/flapjack/gateways/web/views/contact.html.erb_spec.rb +5 -5
- data/spec/lib/flapjack/gateways/web/views/index.html.erb_spec.rb +1 -1
- data/spec/lib/flapjack/gateways/web_spec.rb +73 -74
- data/spec/lib/flapjack/logger_spec.rb +13 -13
- data/spec/lib/flapjack/pikelet_spec.rb +33 -33
- data/spec/lib/flapjack/processor_spec.rb +22 -22
- data/spec/lib/flapjack/redis_pool_spec.rb +1 -1
- data/spec/lib/flapjack/utility_spec.rb +12 -12
- data/spec/spec_helper.rb +9 -9
- data/spec/support/erb_view_helper.rb +4 -0
- metadata +107 -96
- data/lib/flapjack/gateways/web/public/css/flapjack.css +0 -49
- data/lib/flapjack/gateways/web/views/_css.html.erb +0 -42
- data/lib/flapjack/gateways/web/views/_foot.html.erb +0 -3
- data/lib/flapjack/gateways/web/views/_head.html.erb +0 -5
- data/lib/flapjack/gateways/web/views/_nav.html.erb +0 -10
@@ -0,0 +1,22 @@
|
|
1
|
+
/*
|
2
|
+
Copyright 2012 Igor Vaynberg
|
3
|
+
|
4
|
+
Version: 3.4.5 Timestamp: Mon Nov 4 08:22:42 PST 2013
|
5
|
+
|
6
|
+
This software is licensed under the Apache License, Version 2.0 (the "Apache License") or the GNU
|
7
|
+
General Public License version 2 (the "GPL License"). You may choose either license to govern your
|
8
|
+
use of this software only upon the condition that you accept all of the terms of either the Apache
|
9
|
+
License or the GPL License.
|
10
|
+
|
11
|
+
You may obtain a copy of the Apache License and the GPL License at:
|
12
|
+
|
13
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
http://www.gnu.org/licenses/gpl-2.0.html
|
15
|
+
|
16
|
+
Unless required by applicable law or agreed to in writing, software distributed under the Apache License
|
17
|
+
or the GPL Licesnse is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
18
|
+
either express or implied. See the Apache License and the GPL License for the specific language governing
|
19
|
+
permissions and limitations under the Apache License and the GPL License.
|
20
|
+
*/
|
21
|
+
!function(a){"undefined"==typeof a.fn.each2&&a.extend(a.fn,{each2:function(b){for(var c=a([0]),d=-1,e=this.length;++d<e&&(c.context=c[0]=this[d])&&b.call(c[0],d,c)!==!1;);return this}})}(jQuery),function(a,b){"use strict";function n(a){var b,c,d,e;if(!a||a.length<1)return a;for(b="",c=0,d=a.length;d>c;c++)e=a.charAt(c),b+=m[e]||e;return b}function o(a,b){for(var c=0,d=b.length;d>c;c+=1)if(q(a,b[c]))return c;return-1}function p(){var b=a(l);b.appendTo("body");var c={width:b.width()-b[0].clientWidth,height:b.height()-b[0].clientHeight};return b.remove(),c}function q(a,c){return a===c?!0:a===b||c===b?!1:null===a||null===c?!1:a.constructor===String?a+""==c+"":c.constructor===String?c+""==a+"":!1}function r(b,c){var d,e,f;if(null===b||b.length<1)return[];for(d=b.split(c),e=0,f=d.length;f>e;e+=1)d[e]=a.trim(d[e]);return d}function s(a){return a.outerWidth(!1)-a.width()}function t(c){var d="keyup-change-value";c.on("keydown",function(){a.data(c,d)===b&&a.data(c,d,c.val())}),c.on("keyup",function(){var e=a.data(c,d);e!==b&&c.val()!==e&&(a.removeData(c,d),c.trigger("keyup-change"))})}function u(c){c.on("mousemove",function(c){var d=i;(d===b||d.x!==c.pageX||d.y!==c.pageY)&&a(c.target).trigger("mousemove-filtered",c)})}function v(a,c,d){d=d||b;var e;return function(){var b=arguments;window.clearTimeout(e),e=window.setTimeout(function(){c.apply(d,b)},a)}}function w(a){var c,b=!1;return function(){return b===!1&&(c=a(),b=!0),c}}function x(a,b){var c=v(a,function(a){b.trigger("scroll-debounced",a)});b.on("scroll",function(a){o(a.target,b.get())>=0&&c(a)})}function y(a){a[0]!==document.activeElement&&window.setTimeout(function(){var d,b=a[0],c=a.val().length;a.focus(),a.is(":visible")&&b===document.activeElement&&(b.setSelectionRange?b.setSelectionRange(c,c):b.createTextRange&&(d=b.createTextRange(),d.collapse(!1),d.select()))},0)}function z(b){b=a(b)[0];var c=0,d=0;if("selectionStart"in b)c=b.selectionStart,d=b.selectionEnd-c;else if("selection"in document){b.focus();var e=document.selection.createRange();d=document.selection.createRange().text.length,e.moveStart("character",-b.value.length),c=e.text.length-d}return{offset:c,length:d}}function A(a){a.preventDefault(),a.stopPropagation()}function B(a){a.preventDefault(),a.stopImmediatePropagation()}function C(b){if(!h){var c=b[0].currentStyle||window.getComputedStyle(b[0],null);h=a(document.createElement("div")).css({position:"absolute",left:"-10000px",top:"-10000px",display:"none",fontSize:c.fontSize,fontFamily:c.fontFamily,fontStyle:c.fontStyle,fontWeight:c.fontWeight,letterSpacing:c.letterSpacing,textTransform:c.textTransform,whiteSpace:"nowrap"}),h.attr("class","select2-sizer"),a("body").append(h)}return h.text(b.val()),h.width()}function D(b,c,d){var e,g,f=[];e=b.attr("class"),e&&(e=""+e,a(e.split(" ")).each2(function(){0===this.indexOf("select2-")&&f.push(this)})),e=c.attr("class"),e&&(e=""+e,a(e.split(" ")).each2(function(){0!==this.indexOf("select2-")&&(g=d(this),g&&f.push(g))})),b.attr("class",f.join(" "))}function E(a,b,c,d){var e=n(a.toUpperCase()).indexOf(n(b.toUpperCase())),f=b.length;return 0>e?(c.push(d(a)),void 0):(c.push(d(a.substring(0,e))),c.push("<span class='select2-match'>"),c.push(d(a.substring(e,e+f))),c.push("</span>"),c.push(d(a.substring(e+f,a.length))),void 0)}function F(a){var b={"\\":"\","&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};return String(a).replace(/[&<>"'\/\\]/g,function(a){return b[a]})}function G(c){var d,e=null,f=c.quietMillis||100,g=c.url,h=this;return function(i){window.clearTimeout(d),d=window.setTimeout(function(){var d=c.data,f=g,j=c.transport||a.fn.select2.ajaxDefaults.transport,k={type:c.type||"GET",cache:c.cache||!1,jsonpCallback:c.jsonpCallback||b,dataType:c.dataType||"json"},l=a.extend({},a.fn.select2.ajaxDefaults.params,k);d=d?d.call(h,i.term,i.page,i.context):null,f="function"==typeof f?f.call(h,i.term,i.page,i.context):f,e&&e.abort(),c.params&&(a.isFunction(c.params)?a.extend(l,c.params.call(h)):a.extend(l,c.params)),a.extend(l,{url:f,dataType:c.dataType,data:d,success:function(a){var b=c.results(a,i.page);i.callback(b)}}),e=j.call(h,l)},f)}}function H(b){var d,e,c=b,f=function(a){return""+a.text};a.isArray(c)&&(e=c,c={results:e}),a.isFunction(c)===!1&&(e=c,c=function(){return e});var g=c();return g.text&&(f=g.text,a.isFunction(f)||(d=g.text,f=function(a){return a[d]})),function(b){var g,d=b.term,e={results:[]};return""===d?(b.callback(c()),void 0):(g=function(c,e){var h,i;if(c=c[0],c.children){h={};for(i in c)c.hasOwnProperty(i)&&(h[i]=c[i]);h.children=[],a(c.children).each2(function(a,b){g(b,h.children)}),(h.children.length||b.matcher(d,f(h),c))&&e.push(h)}else b.matcher(d,f(c),c)&&e.push(c)},a(c().results).each2(function(a,b){g(b,e.results)}),b.callback(e),void 0)}}function I(c){var d=a.isFunction(c);return function(e){var f=e.term,g={results:[]};a(d?c():c).each(function(){var a=this.text!==b,c=a?this.text:this;(""===f||e.matcher(f,c))&&g.results.push(a?this:{id:this,text:this})}),e.callback(g)}}function J(b,c){if(a.isFunction(b))return!0;if(!b)return!1;throw new Error(c+" must be a function or a falsy value")}function K(b){return a.isFunction(b)?b():b}function L(b){var c=0;return a.each(b,function(a,b){b.children?c+=L(b.children):c++}),c}function M(a,c,d,e){var h,i,j,k,l,f=a,g=!1;if(!e.createSearchChoice||!e.tokenSeparators||e.tokenSeparators.length<1)return b;for(;;){for(i=-1,j=0,k=e.tokenSeparators.length;k>j&&(l=e.tokenSeparators[j],i=a.indexOf(l),!(i>=0));j++);if(0>i)break;if(h=a.substring(0,i),a=a.substring(i+l.length),h.length>0&&(h=e.createSearchChoice.call(this,h,c),h!==b&&null!==h&&e.id(h)!==b&&null!==e.id(h))){for(g=!1,j=0,k=c.length;k>j;j++)if(q(e.id(h),e.id(c[j]))){g=!0;break}g||d(h)}}return f!==a?a:void 0}function N(b,c){var d=function(){};return d.prototype=new b,d.prototype.constructor=d,d.prototype.parent=b.prototype,d.prototype=a.extend(d.prototype,c),d}if(window.Select2===b){var c,d,e,f,g,h,j,k,i={x:0,y:0},c={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,isArrow:function(a){switch(a=a.which?a.which:a){case c.LEFT:case c.RIGHT:case c.UP:case c.DOWN:return!0}return!1},isControl:function(a){var b=a.which;switch(b){case c.SHIFT:case c.CTRL:case c.ALT:return!0}return a.metaKey?!0:!1},isFunctionKey:function(a){return a=a.which?a.which:a,a>=112&&123>=a}},l="<div class='select2-measure-scrollbar'></div>",m={"\u24b6":"A","\uff21":"A","\xc0":"A","\xc1":"A","\xc2":"A","\u1ea6":"A","\u1ea4":"A","\u1eaa":"A","\u1ea8":"A","\xc3":"A","\u0100":"A","\u0102":"A","\u1eb0":"A","\u1eae":"A","\u1eb4":"A","\u1eb2":"A","\u0226":"A","\u01e0":"A","\xc4":"A","\u01de":"A","\u1ea2":"A","\xc5":"A","\u01fa":"A","\u01cd":"A","\u0200":"A","\u0202":"A","\u1ea0":"A","\u1eac":"A","\u1eb6":"A","\u1e00":"A","\u0104":"A","\u023a":"A","\u2c6f":"A","\ua732":"AA","\xc6":"AE","\u01fc":"AE","\u01e2":"AE","\ua734":"AO","\ua736":"AU","\ua738":"AV","\ua73a":"AV","\ua73c":"AY","\u24b7":"B","\uff22":"B","\u1e02":"B","\u1e04":"B","\u1e06":"B","\u0243":"B","\u0182":"B","\u0181":"B","\u24b8":"C","\uff23":"C","\u0106":"C","\u0108":"C","\u010a":"C","\u010c":"C","\xc7":"C","\u1e08":"C","\u0187":"C","\u023b":"C","\ua73e":"C","\u24b9":"D","\uff24":"D","\u1e0a":"D","\u010e":"D","\u1e0c":"D","\u1e10":"D","\u1e12":"D","\u1e0e":"D","\u0110":"D","\u018b":"D","\u018a":"D","\u0189":"D","\ua779":"D","\u01f1":"DZ","\u01c4":"DZ","\u01f2":"Dz","\u01c5":"Dz","\u24ba":"E","\uff25":"E","\xc8":"E","\xc9":"E","\xca":"E","\u1ec0":"E","\u1ebe":"E","\u1ec4":"E","\u1ec2":"E","\u1ebc":"E","\u0112":"E","\u1e14":"E","\u1e16":"E","\u0114":"E","\u0116":"E","\xcb":"E","\u1eba":"E","\u011a":"E","\u0204":"E","\u0206":"E","\u1eb8":"E","\u1ec6":"E","\u0228":"E","\u1e1c":"E","\u0118":"E","\u1e18":"E","\u1e1a":"E","\u0190":"E","\u018e":"E","\u24bb":"F","\uff26":"F","\u1e1e":"F","\u0191":"F","\ua77b":"F","\u24bc":"G","\uff27":"G","\u01f4":"G","\u011c":"G","\u1e20":"G","\u011e":"G","\u0120":"G","\u01e6":"G","\u0122":"G","\u01e4":"G","\u0193":"G","\ua7a0":"G","\ua77d":"G","\ua77e":"G","\u24bd":"H","\uff28":"H","\u0124":"H","\u1e22":"H","\u1e26":"H","\u021e":"H","\u1e24":"H","\u1e28":"H","\u1e2a":"H","\u0126":"H","\u2c67":"H","\u2c75":"H","\ua78d":"H","\u24be":"I","\uff29":"I","\xcc":"I","\xcd":"I","\xce":"I","\u0128":"I","\u012a":"I","\u012c":"I","\u0130":"I","\xcf":"I","\u1e2e":"I","\u1ec8":"I","\u01cf":"I","\u0208":"I","\u020a":"I","\u1eca":"I","\u012e":"I","\u1e2c":"I","\u0197":"I","\u24bf":"J","\uff2a":"J","\u0134":"J","\u0248":"J","\u24c0":"K","\uff2b":"K","\u1e30":"K","\u01e8":"K","\u1e32":"K","\u0136":"K","\u1e34":"K","\u0198":"K","\u2c69":"K","\ua740":"K","\ua742":"K","\ua744":"K","\ua7a2":"K","\u24c1":"L","\uff2c":"L","\u013f":"L","\u0139":"L","\u013d":"L","\u1e36":"L","\u1e38":"L","\u013b":"L","\u1e3c":"L","\u1e3a":"L","\u0141":"L","\u023d":"L","\u2c62":"L","\u2c60":"L","\ua748":"L","\ua746":"L","\ua780":"L","\u01c7":"LJ","\u01c8":"Lj","\u24c2":"M","\uff2d":"M","\u1e3e":"M","\u1e40":"M","\u1e42":"M","\u2c6e":"M","\u019c":"M","\u24c3":"N","\uff2e":"N","\u01f8":"N","\u0143":"N","\xd1":"N","\u1e44":"N","\u0147":"N","\u1e46":"N","\u0145":"N","\u1e4a":"N","\u1e48":"N","\u0220":"N","\u019d":"N","\ua790":"N","\ua7a4":"N","\u01ca":"NJ","\u01cb":"Nj","\u24c4":"O","\uff2f":"O","\xd2":"O","\xd3":"O","\xd4":"O","\u1ed2":"O","\u1ed0":"O","\u1ed6":"O","\u1ed4":"O","\xd5":"O","\u1e4c":"O","\u022c":"O","\u1e4e":"O","\u014c":"O","\u1e50":"O","\u1e52":"O","\u014e":"O","\u022e":"O","\u0230":"O","\xd6":"O","\u022a":"O","\u1ece":"O","\u0150":"O","\u01d1":"O","\u020c":"O","\u020e":"O","\u01a0":"O","\u1edc":"O","\u1eda":"O","\u1ee0":"O","\u1ede":"O","\u1ee2":"O","\u1ecc":"O","\u1ed8":"O","\u01ea":"O","\u01ec":"O","\xd8":"O","\u01fe":"O","\u0186":"O","\u019f":"O","\ua74a":"O","\ua74c":"O","\u01a2":"OI","\ua74e":"OO","\u0222":"OU","\u24c5":"P","\uff30":"P","\u1e54":"P","\u1e56":"P","\u01a4":"P","\u2c63":"P","\ua750":"P","\ua752":"P","\ua754":"P","\u24c6":"Q","\uff31":"Q","\ua756":"Q","\ua758":"Q","\u024a":"Q","\u24c7":"R","\uff32":"R","\u0154":"R","\u1e58":"R","\u0158":"R","\u0210":"R","\u0212":"R","\u1e5a":"R","\u1e5c":"R","\u0156":"R","\u1e5e":"R","\u024c":"R","\u2c64":"R","\ua75a":"R","\ua7a6":"R","\ua782":"R","\u24c8":"S","\uff33":"S","\u1e9e":"S","\u015a":"S","\u1e64":"S","\u015c":"S","\u1e60":"S","\u0160":"S","\u1e66":"S","\u1e62":"S","\u1e68":"S","\u0218":"S","\u015e":"S","\u2c7e":"S","\ua7a8":"S","\ua784":"S","\u24c9":"T","\uff34":"T","\u1e6a":"T","\u0164":"T","\u1e6c":"T","\u021a":"T","\u0162":"T","\u1e70":"T","\u1e6e":"T","\u0166":"T","\u01ac":"T","\u01ae":"T","\u023e":"T","\ua786":"T","\ua728":"TZ","\u24ca":"U","\uff35":"U","\xd9":"U","\xda":"U","\xdb":"U","\u0168":"U","\u1e78":"U","\u016a":"U","\u1e7a":"U","\u016c":"U","\xdc":"U","\u01db":"U","\u01d7":"U","\u01d5":"U","\u01d9":"U","\u1ee6":"U","\u016e":"U","\u0170":"U","\u01d3":"U","\u0214":"U","\u0216":"U","\u01af":"U","\u1eea":"U","\u1ee8":"U","\u1eee":"U","\u1eec":"U","\u1ef0":"U","\u1ee4":"U","\u1e72":"U","\u0172":"U","\u1e76":"U","\u1e74":"U","\u0244":"U","\u24cb":"V","\uff36":"V","\u1e7c":"V","\u1e7e":"V","\u01b2":"V","\ua75e":"V","\u0245":"V","\ua760":"VY","\u24cc":"W","\uff37":"W","\u1e80":"W","\u1e82":"W","\u0174":"W","\u1e86":"W","\u1e84":"W","\u1e88":"W","\u2c72":"W","\u24cd":"X","\uff38":"X","\u1e8a":"X","\u1e8c":"X","\u24ce":"Y","\uff39":"Y","\u1ef2":"Y","\xdd":"Y","\u0176":"Y","\u1ef8":"Y","\u0232":"Y","\u1e8e":"Y","\u0178":"Y","\u1ef6":"Y","\u1ef4":"Y","\u01b3":"Y","\u024e":"Y","\u1efe":"Y","\u24cf":"Z","\uff3a":"Z","\u0179":"Z","\u1e90":"Z","\u017b":"Z","\u017d":"Z","\u1e92":"Z","\u1e94":"Z","\u01b5":"Z","\u0224":"Z","\u2c7f":"Z","\u2c6b":"Z","\ua762":"Z","\u24d0":"a","\uff41":"a","\u1e9a":"a","\xe0":"a","\xe1":"a","\xe2":"a","\u1ea7":"a","\u1ea5":"a","\u1eab":"a","\u1ea9":"a","\xe3":"a","\u0101":"a","\u0103":"a","\u1eb1":"a","\u1eaf":"a","\u1eb5":"a","\u1eb3":"a","\u0227":"a","\u01e1":"a","\xe4":"a","\u01df":"a","\u1ea3":"a","\xe5":"a","\u01fb":"a","\u01ce":"a","\u0201":"a","\u0203":"a","\u1ea1":"a","\u1ead":"a","\u1eb7":"a","\u1e01":"a","\u0105":"a","\u2c65":"a","\u0250":"a","\ua733":"aa","\xe6":"ae","\u01fd":"ae","\u01e3":"ae","\ua735":"ao","\ua737":"au","\ua739":"av","\ua73b":"av","\ua73d":"ay","\u24d1":"b","\uff42":"b","\u1e03":"b","\u1e05":"b","\u1e07":"b","\u0180":"b","\u0183":"b","\u0253":"b","\u24d2":"c","\uff43":"c","\u0107":"c","\u0109":"c","\u010b":"c","\u010d":"c","\xe7":"c","\u1e09":"c","\u0188":"c","\u023c":"c","\ua73f":"c","\u2184":"c","\u24d3":"d","\uff44":"d","\u1e0b":"d","\u010f":"d","\u1e0d":"d","\u1e11":"d","\u1e13":"d","\u1e0f":"d","\u0111":"d","\u018c":"d","\u0256":"d","\u0257":"d","\ua77a":"d","\u01f3":"dz","\u01c6":"dz","\u24d4":"e","\uff45":"e","\xe8":"e","\xe9":"e","\xea":"e","\u1ec1":"e","\u1ebf":"e","\u1ec5":"e","\u1ec3":"e","\u1ebd":"e","\u0113":"e","\u1e15":"e","\u1e17":"e","\u0115":"e","\u0117":"e","\xeb":"e","\u1ebb":"e","\u011b":"e","\u0205":"e","\u0207":"e","\u1eb9":"e","\u1ec7":"e","\u0229":"e","\u1e1d":"e","\u0119":"e","\u1e19":"e","\u1e1b":"e","\u0247":"e","\u025b":"e","\u01dd":"e","\u24d5":"f","\uff46":"f","\u1e1f":"f","\u0192":"f","\ua77c":"f","\u24d6":"g","\uff47":"g","\u01f5":"g","\u011d":"g","\u1e21":"g","\u011f":"g","\u0121":"g","\u01e7":"g","\u0123":"g","\u01e5":"g","\u0260":"g","\ua7a1":"g","\u1d79":"g","\ua77f":"g","\u24d7":"h","\uff48":"h","\u0125":"h","\u1e23":"h","\u1e27":"h","\u021f":"h","\u1e25":"h","\u1e29":"h","\u1e2b":"h","\u1e96":"h","\u0127":"h","\u2c68":"h","\u2c76":"h","\u0265":"h","\u0195":"hv","\u24d8":"i","\uff49":"i","\xec":"i","\xed":"i","\xee":"i","\u0129":"i","\u012b":"i","\u012d":"i","\xef":"i","\u1e2f":"i","\u1ec9":"i","\u01d0":"i","\u0209":"i","\u020b":"i","\u1ecb":"i","\u012f":"i","\u1e2d":"i","\u0268":"i","\u0131":"i","\u24d9":"j","\uff4a":"j","\u0135":"j","\u01f0":"j","\u0249":"j","\u24da":"k","\uff4b":"k","\u1e31":"k","\u01e9":"k","\u1e33":"k","\u0137":"k","\u1e35":"k","\u0199":"k","\u2c6a":"k","\ua741":"k","\ua743":"k","\ua745":"k","\ua7a3":"k","\u24db":"l","\uff4c":"l","\u0140":"l","\u013a":"l","\u013e":"l","\u1e37":"l","\u1e39":"l","\u013c":"l","\u1e3d":"l","\u1e3b":"l","\u017f":"l","\u0142":"l","\u019a":"l","\u026b":"l","\u2c61":"l","\ua749":"l","\ua781":"l","\ua747":"l","\u01c9":"lj","\u24dc":"m","\uff4d":"m","\u1e3f":"m","\u1e41":"m","\u1e43":"m","\u0271":"m","\u026f":"m","\u24dd":"n","\uff4e":"n","\u01f9":"n","\u0144":"n","\xf1":"n","\u1e45":"n","\u0148":"n","\u1e47":"n","\u0146":"n","\u1e4b":"n","\u1e49":"n","\u019e":"n","\u0272":"n","\u0149":"n","\ua791":"n","\ua7a5":"n","\u01cc":"nj","\u24de":"o","\uff4f":"o","\xf2":"o","\xf3":"o","\xf4":"o","\u1ed3":"o","\u1ed1":"o","\u1ed7":"o","\u1ed5":"o","\xf5":"o","\u1e4d":"o","\u022d":"o","\u1e4f":"o","\u014d":"o","\u1e51":"o","\u1e53":"o","\u014f":"o","\u022f":"o","\u0231":"o","\xf6":"o","\u022b":"o","\u1ecf":"o","\u0151":"o","\u01d2":"o","\u020d":"o","\u020f":"o","\u01a1":"o","\u1edd":"o","\u1edb":"o","\u1ee1":"o","\u1edf":"o","\u1ee3":"o","\u1ecd":"o","\u1ed9":"o","\u01eb":"o","\u01ed":"o","\xf8":"o","\u01ff":"o","\u0254":"o","\ua74b":"o","\ua74d":"o","\u0275":"o","\u01a3":"oi","\u0223":"ou","\ua74f":"oo","\u24df":"p","\uff50":"p","\u1e55":"p","\u1e57":"p","\u01a5":"p","\u1d7d":"p","\ua751":"p","\ua753":"p","\ua755":"p","\u24e0":"q","\uff51":"q","\u024b":"q","\ua757":"q","\ua759":"q","\u24e1":"r","\uff52":"r","\u0155":"r","\u1e59":"r","\u0159":"r","\u0211":"r","\u0213":"r","\u1e5b":"r","\u1e5d":"r","\u0157":"r","\u1e5f":"r","\u024d":"r","\u027d":"r","\ua75b":"r","\ua7a7":"r","\ua783":"r","\u24e2":"s","\uff53":"s","\xdf":"s","\u015b":"s","\u1e65":"s","\u015d":"s","\u1e61":"s","\u0161":"s","\u1e67":"s","\u1e63":"s","\u1e69":"s","\u0219":"s","\u015f":"s","\u023f":"s","\ua7a9":"s","\ua785":"s","\u1e9b":"s","\u24e3":"t","\uff54":"t","\u1e6b":"t","\u1e97":"t","\u0165":"t","\u1e6d":"t","\u021b":"t","\u0163":"t","\u1e71":"t","\u1e6f":"t","\u0167":"t","\u01ad":"t","\u0288":"t","\u2c66":"t","\ua787":"t","\ua729":"tz","\u24e4":"u","\uff55":"u","\xf9":"u","\xfa":"u","\xfb":"u","\u0169":"u","\u1e79":"u","\u016b":"u","\u1e7b":"u","\u016d":"u","\xfc":"u","\u01dc":"u","\u01d8":"u","\u01d6":"u","\u01da":"u","\u1ee7":"u","\u016f":"u","\u0171":"u","\u01d4":"u","\u0215":"u","\u0217":"u","\u01b0":"u","\u1eeb":"u","\u1ee9":"u","\u1eef":"u","\u1eed":"u","\u1ef1":"u","\u1ee5":"u","\u1e73":"u","\u0173":"u","\u1e77":"u","\u1e75":"u","\u0289":"u","\u24e5":"v","\uff56":"v","\u1e7d":"v","\u1e7f":"v","\u028b":"v","\ua75f":"v","\u028c":"v","\ua761":"vy","\u24e6":"w","\uff57":"w","\u1e81":"w","\u1e83":"w","\u0175":"w","\u1e87":"w","\u1e85":"w","\u1e98":"w","\u1e89":"w","\u2c73":"w","\u24e7":"x","\uff58":"x","\u1e8b":"x","\u1e8d":"x","\u24e8":"y","\uff59":"y","\u1ef3":"y","\xfd":"y","\u0177":"y","\u1ef9":"y","\u0233":"y","\u1e8f":"y","\xff":"y","\u1ef7":"y","\u1e99":"y","\u1ef5":"y","\u01b4":"y","\u024f":"y","\u1eff":"y","\u24e9":"z","\uff5a":"z","\u017a":"z","\u1e91":"z","\u017c":"z","\u017e":"z","\u1e93":"z","\u1e95":"z","\u01b6":"z","\u0225":"z","\u0240":"z","\u2c6c":"z","\ua763":"z"};j=a(document),g=function(){var a=1;return function(){return a++}}(),j.on("mousemove",function(a){i.x=a.pageX,i.y=a.pageY}),d=N(Object,{bind:function(a){var b=this;return function(){a.apply(b,arguments)}},init:function(c){var d,e,f=".select2-results";this.opts=c=this.prepareOpts(c),this.id=c.id,c.element.data("select2")!==b&&null!==c.element.data("select2")&&c.element.data("select2").destroy(),this.container=this.createContainer(),this.containerId="s2id_"+(c.element.attr("id")||"autogen"+g()),this.containerSelector="#"+this.containerId.replace(/([;&,\.\+\*\~':"\!\^#$%@\[\]\(\)=>\|])/g,"\\$1"),this.container.attr("id",this.containerId),this.body=w(function(){return c.element.closest("body")}),D(this.container,this.opts.element,this.opts.adaptContainerCssClass),this.container.attr("style",c.element.attr("style")),this.container.css(K(c.containerCss)),this.container.addClass(K(c.containerCssClass)),this.elementTabIndex=this.opts.element.attr("tabindex"),this.opts.element.data("select2",this).attr("tabindex","-1").before(this.container).on("click.select2",A),this.container.data("select2",this),this.dropdown=this.container.find(".select2-drop"),D(this.dropdown,this.opts.element,this.opts.adaptDropdownCssClass),this.dropdown.addClass(K(c.dropdownCssClass)),this.dropdown.data("select2",this),this.dropdown.on("click",A),this.results=d=this.container.find(f),this.search=e=this.container.find("input.select2-input"),this.queryCount=0,this.resultsPage=0,this.context=null,this.initContainer(),this.container.on("click",A),u(this.results),this.dropdown.on("mousemove-filtered touchstart touchmove touchend",f,this.bind(this.highlightUnderEvent)),x(80,this.results),this.dropdown.on("scroll-debounced",f,this.bind(this.loadMoreIfNeeded)),a(this.container).on("change",".select2-input",function(a){a.stopPropagation()}),a(this.dropdown).on("change",".select2-input",function(a){a.stopPropagation()}),a.fn.mousewheel&&d.mousewheel(function(a,b,c,e){var f=d.scrollTop();e>0&&0>=f-e?(d.scrollTop(0),A(a)):0>e&&d.get(0).scrollHeight-d.scrollTop()+e<=d.height()&&(d.scrollTop(d.get(0).scrollHeight-d.height()),A(a))}),t(e),e.on("keyup-change input paste",this.bind(this.updateResults)),e.on("focus",function(){e.addClass("select2-focused")}),e.on("blur",function(){e.removeClass("select2-focused")}),this.dropdown.on("mouseup",f,this.bind(function(b){a(b.target).closest(".select2-result-selectable").length>0&&(this.highlightUnderEvent(b),this.selectHighlighted(b))})),this.dropdown.on("click mouseup mousedown",function(a){a.stopPropagation()}),a.isFunction(this.opts.initSelection)&&(this.initSelection(),this.monitorSource()),null!==c.maximumInputLength&&this.search.attr("maxlength",c.maximumInputLength);var h=c.element.prop("disabled");h===b&&(h=!1),this.enable(!h);var i=c.element.prop("readonly");i===b&&(i=!1),this.readonly(i),k=k||p(),this.autofocus=c.element.prop("autofocus"),c.element.prop("autofocus",!1),this.autofocus&&this.focus(),this.nextSearchTerm=b},destroy:function(){var a=this.opts.element,c=a.data("select2");this.close(),this.propertyObserver&&(delete this.propertyObserver,this.propertyObserver=null),c!==b&&(c.container.remove(),c.dropdown.remove(),a.removeClass("select2-offscreen").removeData("select2").off(".select2").prop("autofocus",this.autofocus||!1),this.elementTabIndex?a.attr({tabindex:this.elementTabIndex}):a.removeAttr("tabindex"),a.show())},optionToData:function(a){return a.is("option")?{id:a.prop("value"),text:a.text(),element:a.get(),css:a.attr("class"),disabled:a.prop("disabled"),locked:q(a.attr("locked"),"locked")||q(a.data("locked"),!0)}:a.is("optgroup")?{text:a.attr("label"),children:[],element:a.get(),css:a.attr("class")}:void 0},prepareOpts:function(c){var d,e,f,g,h=this;if(d=c.element,"select"===d.get(0).tagName.toLowerCase()&&(this.select=e=c.element),e&&a.each(["id","multiple","ajax","query","createSearchChoice","initSelection","data","tags"],function(){if(this in c)throw new Error("Option '"+this+"' is not allowed for Select2 when attached to a <select> element.")}),c=a.extend({},{populateResults:function(d,e,f){var g,i=this.opts.id;g=function(d,e,j){var k,l,m,n,o,p,q,r,s,t;for(d=c.sortResults(d,e,f),k=0,l=d.length;l>k;k+=1)m=d[k],o=m.disabled===!0,n=!o&&i(m)!==b,p=m.children&&m.children.length>0,q=a("<li></li>"),q.addClass("select2-results-dept-"+j),q.addClass("select2-result"),q.addClass(n?"select2-result-selectable":"select2-result-unselectable"),o&&q.addClass("select2-disabled"),p&&q.addClass("select2-result-with-children"),q.addClass(h.opts.formatResultCssClass(m)),r=a(document.createElement("div")),r.addClass("select2-result-label"),t=c.formatResult(m,r,f,h.opts.escapeMarkup),t!==b&&r.html(t),q.append(r),p&&(s=a("<ul></ul>"),s.addClass("select2-result-sub"),g(m.children,s,j+1),q.append(s)),q.data("select2-data",m),e.append(q)},g(e,d,0)}},a.fn.select2.defaults,c),"function"!=typeof c.id&&(f=c.id,c.id=function(a){return a[f]}),a.isArray(c.element.data("select2Tags"))){if("tags"in c)throw"tags specified as both an attribute 'data-select2-tags' and in options of Select2 "+c.element.attr("id");c.tags=c.element.data("select2Tags")}if(e?(c.query=this.bind(function(a){var f,g,i,c={results:[],more:!1},e=a.term;i=function(b,c){var d;b.is("option")?a.matcher(e,b.text(),b)&&c.push(h.optionToData(b)):b.is("optgroup")&&(d=h.optionToData(b),b.children().each2(function(a,b){i(b,d.children)}),d.children.length>0&&c.push(d))},f=d.children(),this.getPlaceholder()!==b&&f.length>0&&(g=this.getPlaceholderOption(),g&&(f=f.not(g))),f.each2(function(a,b){i(b,c.results)}),a.callback(c)}),c.id=function(a){return a.id},c.formatResultCssClass=function(a){return a.css}):"query"in c||("ajax"in c?(g=c.element.data("ajax-url"),g&&g.length>0&&(c.ajax.url=g),c.query=G.call(c.element,c.ajax)):"data"in c?c.query=H(c.data):"tags"in c&&(c.query=I(c.tags),c.createSearchChoice===b&&(c.createSearchChoice=function(b){return{id:a.trim(b),text:a.trim(b)}}),c.initSelection===b&&(c.initSelection=function(b,d){var e=[];a(r(b.val(),c.separator)).each(function(){var b={id:this,text:this},d=c.tags;a.isFunction(d)&&(d=d()),a(d).each(function(){return q(this.id,b.id)?(b=this,!1):void 0}),e.push(b)}),d(e)}))),"function"!=typeof c.query)throw"query function not defined for Select2 "+c.element.attr("id");return c},monitorSource:function(){var c,d,a=this.opts.element;a.on("change.select2",this.bind(function(){this.opts.element.data("select2-change-triggered")!==!0&&this.initSelection()})),c=this.bind(function(){var c=a.prop("disabled");c===b&&(c=!1),this.enable(!c);var d=a.prop("readonly");d===b&&(d=!1),this.readonly(d),D(this.container,this.opts.element,this.opts.adaptContainerCssClass),this.container.addClass(K(this.opts.containerCssClass)),D(this.dropdown,this.opts.element,this.opts.adaptDropdownCssClass),this.dropdown.addClass(K(this.opts.dropdownCssClass))}),a.on("propertychange.select2",c),this.mutationCallback===b&&(this.mutationCallback=function(a){a.forEach(c)}),d=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver,d!==b&&(this.propertyObserver&&(delete this.propertyObserver,this.propertyObserver=null),this.propertyObserver=new d(this.mutationCallback),this.propertyObserver.observe(a.get(0),{attributes:!0,subtree:!1}))},triggerSelect:function(b){var c=a.Event("select2-selecting",{val:this.id(b),object:b});return this.opts.element.trigger(c),!c.isDefaultPrevented()},triggerChange:function(b){b=b||{},b=a.extend({},b,{type:"change",val:this.val()}),this.opts.element.data("select2-change-triggered",!0),this.opts.element.trigger(b),this.opts.element.data("select2-change-triggered",!1),this.opts.element.click(),this.opts.blurOnChange&&this.opts.element.blur()},isInterfaceEnabled:function(){return this.enabledInterface===!0},enableInterface:function(){var a=this._enabled&&!this._readonly,b=!a;return a===this.enabledInterface?!1:(this.container.toggleClass("select2-container-disabled",b),this.close(),this.enabledInterface=a,!0)},enable:function(a){a===b&&(a=!0),this._enabled!==a&&(this._enabled=a,this.opts.element.prop("disabled",!a),this.enableInterface())},disable:function(){this.enable(!1)},readonly:function(a){return a===b&&(a=!1),this._readonly===a?!1:(this._readonly=a,this.opts.element.prop("readonly",a),this.enableInterface(),!0)},opened:function(){return this.container.hasClass("select2-dropdown-open")},positionDropdown:function(){var t,u,v,w,x,b=this.dropdown,c=this.container.offset(),d=this.container.outerHeight(!1),e=this.container.outerWidth(!1),f=b.outerHeight(!1),g=a(window),h=g.width(),i=g.height(),j=g.scrollLeft()+h,l=g.scrollTop()+i,m=c.top+d,n=c.left,o=l>=m+f,p=c.top-f>=this.body().scrollTop(),q=b.outerWidth(!1),r=j>=n+q,s=b.hasClass("select2-drop-above");s?(u=!0,!p&&o&&(v=!0,u=!1)):(u=!1,!o&&p&&(v=!0,u=!0)),v&&(b.hide(),c=this.container.offset(),d=this.container.outerHeight(!1),e=this.container.outerWidth(!1),f=b.outerHeight(!1),j=g.scrollLeft()+h,l=g.scrollTop()+i,m=c.top+d,n=c.left,q=b.outerWidth(!1),r=j>=n+q,b.show()),this.opts.dropdownAutoWidth?(x=a(".select2-results",b)[0],b.addClass("select2-drop-auto-width"),b.css("width",""),q=b.outerWidth(!1)+(x.scrollHeight===x.clientHeight?0:k.width),q>e?e=q:q=e,r=j>=n+q):this.container.removeClass("select2-drop-auto-width"),"static"!==this.body().css("position")&&(t=this.body().offset(),m-=t.top,n-=t.left),r||(n=c.left+e-q),w={left:n,width:e},u?(w.bottom=i-c.top,w.top="auto",this.container.addClass("select2-drop-above"),b.addClass("select2-drop-above")):(w.top=m,w.bottom="auto",this.container.removeClass("select2-drop-above"),b.removeClass("select2-drop-above")),w=a.extend(w,K(this.opts.dropdownCss)),b.css(w)},shouldOpen:function(){var b;return this.opened()?!1:this._enabled===!1||this._readonly===!0?!1:(b=a.Event("select2-opening"),this.opts.element.trigger(b),!b.isDefaultPrevented())},clearDropdownAlignmentPreference:function(){this.container.removeClass("select2-drop-above"),this.dropdown.removeClass("select2-drop-above")},open:function(){return this.shouldOpen()?(this.opening(),!0):!1},opening:function(){var f,b=this.containerId,c="scroll."+b,d="resize."+b,e="orientationchange."+b;this.container.addClass("select2-dropdown-open").addClass("select2-container-active"),this.clearDropdownAlignmentPreference(),this.dropdown[0]!==this.body().children().last()[0]&&this.dropdown.detach().appendTo(this.body()),f=a("#select2-drop-mask"),0==f.length&&(f=a(document.createElement("div")),f.attr("id","select2-drop-mask").attr("class","select2-drop-mask"),f.hide(),f.appendTo(this.body()),f.on("mousedown touchstart click",function(b){var d,c=a("#select2-drop");c.length>0&&(d=c.data("select2"),d.opts.selectOnBlur&&d.selectHighlighted({noFocus:!0}),d.close({focus:!0}),b.preventDefault(),b.stopPropagation())})),this.dropdown.prev()[0]!==f[0]&&this.dropdown.before(f),a("#select2-drop").removeAttr("id"),this.dropdown.attr("id","select2-drop"),f.show(),this.positionDropdown(),this.dropdown.show(),this.positionDropdown(),this.dropdown.addClass("select2-drop-active");var g=this;this.container.parents().add(window).each(function(){a(this).on(d+" "+c+" "+e,function(){g.positionDropdown()})})},close:function(){if(this.opened()){var b=this.containerId,c="scroll."+b,d="resize."+b,e="orientationchange."+b;this.container.parents().add(window).each(function(){a(this).off(c).off(d).off(e)}),this.clearDropdownAlignmentPreference(),a("#select2-drop-mask").hide(),this.dropdown.removeAttr("id"),this.dropdown.hide(),this.container.removeClass("select2-dropdown-open").removeClass("select2-container-active"),this.results.empty(),this.clearSearch(),this.search.removeClass("select2-active"),this.opts.element.trigger(a.Event("select2-close"))}},externalSearch:function(a){this.open(),this.search.val(a),this.updateResults(!1)},clearSearch:function(){},getMaximumSelectionSize:function(){return K(this.opts.maximumSelectionSize)},ensureHighlightVisible:function(){var c,d,e,f,g,h,i,b=this.results;if(d=this.highlight(),!(0>d)){if(0==d)return b.scrollTop(0),void 0;c=this.findHighlightableChoices().find(".select2-result-label"),e=a(c[d]),f=e.offset().top+e.outerHeight(!0),d===c.length-1&&(i=b.find("li.select2-more-results"),i.length>0&&(f=i.offset().top+i.outerHeight(!0))),g=b.offset().top+b.outerHeight(!0),f>g&&b.scrollTop(b.scrollTop()+(f-g)),h=e.offset().top-b.offset().top,0>h&&"none"!=e.css("display")&&b.scrollTop(b.scrollTop()+h)}},findHighlightableChoices:function(){return this.results.find(".select2-result-selectable:not(.select2-disabled, .select2-selected)")},moveHighlight:function(b){for(var c=this.findHighlightableChoices(),d=this.highlight();d>-1&&d<c.length;){d+=b;var e=a(c[d]);if(e.hasClass("select2-result-selectable")&&!e.hasClass("select2-disabled")&&!e.hasClass("select2-selected")){this.highlight(d);break}}},highlight:function(b){var d,e,c=this.findHighlightableChoices();return 0===arguments.length?o(c.filter(".select2-highlighted")[0],c.get()):(b>=c.length&&(b=c.length-1),0>b&&(b=0),this.removeHighlight(),d=a(c[b]),d.addClass("select2-highlighted"),this.ensureHighlightVisible(),e=d.data("select2-data"),e&&this.opts.element.trigger({type:"select2-highlight",val:this.id(e),choice:e}),void 0)},removeHighlight:function(){this.results.find(".select2-highlighted").removeClass("select2-highlighted")},countSelectableResults:function(){return this.findHighlightableChoices().length},highlightUnderEvent:function(b){var c=a(b.target).closest(".select2-result-selectable");if(c.length>0&&!c.is(".select2-highlighted")){var d=this.findHighlightableChoices();this.highlight(d.index(c))}else 0==c.length&&this.removeHighlight()},loadMoreIfNeeded:function(){var c,a=this.results,b=a.find("li.select2-more-results"),d=this.resultsPage+1,e=this,f=this.search.val(),g=this.context;0!==b.length&&(c=b.offset().top-a.offset().top-a.height(),c<=this.opts.loadMorePadding&&(b.addClass("select2-active"),this.opts.query({element:this.opts.element,term:f,page:d,context:g,matcher:this.opts.matcher,callback:this.bind(function(c){e.opened()&&(e.opts.populateResults.call(this,a,c.results,{term:f,page:d,context:g}),e.postprocessResults(c,!1,!1),c.more===!0?(b.detach().appendTo(a).text(e.opts.formatLoadMore(d+1)),window.setTimeout(function(){e.loadMoreIfNeeded()},10)):b.remove(),e.positionDropdown(),e.resultsPage=d,e.context=c.context,this.opts.element.trigger({type:"select2-loaded",items:c}))})})))},tokenize:function(){},updateResults:function(c){function m(){d.removeClass("select2-active"),h.positionDropdown()}function n(a){e.html(a),m()}var g,i,l,d=this.search,e=this.results,f=this.opts,h=this,j=d.val(),k=a.data(this.container,"select2-last-term");if((c===!0||!k||!q(j,k))&&(a.data(this.container,"select2-last-term",j),c===!0||this.showSearchInput!==!1&&this.opened())){l=++this.queryCount;var o=this.getMaximumSelectionSize();if(o>=1&&(g=this.data(),a.isArray(g)&&g.length>=o&&J(f.formatSelectionTooBig,"formatSelectionTooBig")))return n("<li class='select2-selection-limit'>"+f.formatSelectionTooBig(o)+"</li>"),void 0;if(d.val().length<f.minimumInputLength)return J(f.formatInputTooShort,"formatInputTooShort")?n("<li class='select2-no-results'>"+f.formatInputTooShort(d.val(),f.minimumInputLength)+"</li>"):n(""),c&&this.showSearch&&this.showSearch(!0),void 0;
|
22
|
+
if(f.maximumInputLength&&d.val().length>f.maximumInputLength)return J(f.formatInputTooLong,"formatInputTooLong")?n("<li class='select2-no-results'>"+f.formatInputTooLong(d.val(),f.maximumInputLength)+"</li>"):n(""),void 0;f.formatSearching&&0===this.findHighlightableChoices().length&&n("<li class='select2-searching'>"+f.formatSearching()+"</li>"),d.addClass("select2-active"),this.removeHighlight(),i=this.tokenize(),i!=b&&null!=i&&d.val(i),this.resultsPage=1,f.query({element:f.element,term:d.val(),page:this.resultsPage,context:null,matcher:f.matcher,callback:this.bind(function(g){var i;if(l==this.queryCount){if(!this.opened())return this.search.removeClass("select2-active"),void 0;if(this.context=g.context===b?null:g.context,this.opts.createSearchChoice&&""!==d.val()&&(i=this.opts.createSearchChoice.call(h,d.val(),g.results),i!==b&&null!==i&&h.id(i)!==b&&null!==h.id(i)&&0===a(g.results).filter(function(){return q(h.id(this),h.id(i))}).length&&g.results.unshift(i)),0===g.results.length&&J(f.formatNoMatches,"formatNoMatches"))return n("<li class='select2-no-results'>"+f.formatNoMatches(d.val())+"</li>"),void 0;e.empty(),h.opts.populateResults.call(this,e,g.results,{term:d.val(),page:this.resultsPage,context:null}),g.more===!0&&J(f.formatLoadMore,"formatLoadMore")&&(e.append("<li class='select2-more-results'>"+h.opts.escapeMarkup(f.formatLoadMore(this.resultsPage))+"</li>"),window.setTimeout(function(){h.loadMoreIfNeeded()},10)),this.postprocessResults(g,c),m(),this.opts.element.trigger({type:"select2-loaded",items:g})}})})}},cancel:function(){this.close()},blur:function(){this.opts.selectOnBlur&&this.selectHighlighted({noFocus:!0}),this.close(),this.container.removeClass("select2-container-active"),this.search[0]===document.activeElement&&this.search.blur(),this.clearSearch(),this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus")},focusSearch:function(){y(this.search)},selectHighlighted:function(a){var b=this.highlight(),c=this.results.find(".select2-highlighted"),d=c.closest(".select2-result").data("select2-data");d?(this.highlight(b),this.onSelect(d,a)):a&&a.noFocus&&this.close()},getPlaceholder:function(){var a;return this.opts.element.attr("placeholder")||this.opts.element.attr("data-placeholder")||this.opts.element.data("placeholder")||this.opts.placeholder||((a=this.getPlaceholderOption())!==b?a.text():b)},getPlaceholderOption:function(){if(this.select){var a=this.select.children("option").first();if(this.opts.placeholderOption!==b)return"first"===this.opts.placeholderOption&&a||"function"==typeof this.opts.placeholderOption&&this.opts.placeholderOption(this.select);if(""===a.text()&&""===a.val())return a}},initContainerWidth:function(){function c(){var c,d,e,f,g,h;if("off"===this.opts.width)return null;if("element"===this.opts.width)return 0===this.opts.element.outerWidth(!1)?"auto":this.opts.element.outerWidth(!1)+"px";if("copy"===this.opts.width||"resolve"===this.opts.width){if(c=this.opts.element.attr("style"),c!==b)for(d=c.split(";"),f=0,g=d.length;g>f;f+=1)if(h=d[f].replace(/\s/g,""),e=h.match(/^width:(([-+]?([0-9]*\.)?[0-9]+)(px|em|ex|%|in|cm|mm|pt|pc))/i),null!==e&&e.length>=1)return e[1];return"resolve"===this.opts.width?(c=this.opts.element.css("width"),c.indexOf("%")>0?c:0===this.opts.element.outerWidth(!1)?"auto":this.opts.element.outerWidth(!1)+"px"):null}return a.isFunction(this.opts.width)?this.opts.width():this.opts.width}var d=c.call(this);null!==d&&this.container.css("width",d)}}),e=N(d,{createContainer:function(){var b=a(document.createElement("div")).attr({"class":"select2-container"}).html(["<a href='javascript:void(0)' onclick='return false;' class='select2-choice' tabindex='-1'>"," <span class='select2-chosen'> </span><abbr class='select2-search-choice-close'></abbr>"," <span class='select2-arrow'><b></b></span>","</a>","<input class='select2-focusser select2-offscreen' type='text'/>","<div class='select2-drop select2-display-none'>"," <div class='select2-search'>"," <input type='text' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' class='select2-input'/>"," </div>"," <ul class='select2-results'>"," </ul>","</div>"].join(""));return b},enableInterface:function(){this.parent.enableInterface.apply(this,arguments)&&this.focusser.prop("disabled",!this.isInterfaceEnabled())},opening:function(){var c,d,e;this.opts.minimumResultsForSearch>=0&&this.showSearch(!0),this.parent.opening.apply(this,arguments),this.showSearchInput!==!1&&this.search.val(this.focusser.val()),this.search.focus(),c=this.search.get(0),c.createTextRange?(d=c.createTextRange(),d.collapse(!1),d.select()):c.setSelectionRange&&(e=this.search.val().length,c.setSelectionRange(e,e)),""===this.search.val()&&this.nextSearchTerm!=b&&(this.search.val(this.nextSearchTerm),this.search.select()),this.focusser.prop("disabled",!0).val(""),this.updateResults(!0),this.opts.element.trigger(a.Event("select2-open"))},close:function(a){this.opened()&&(this.parent.close.apply(this,arguments),a=a||{focus:!0},this.focusser.removeAttr("disabled"),a.focus&&this.focusser.focus())},focus:function(){this.opened()?this.close():(this.focusser.removeAttr("disabled"),this.focusser.focus())},isFocused:function(){return this.container.hasClass("select2-container-active")},cancel:function(){this.parent.cancel.apply(this,arguments),this.focusser.removeAttr("disabled"),this.focusser.focus()},destroy:function(){a("label[for='"+this.focusser.attr("id")+"']").attr("for",this.opts.element.attr("id")),this.parent.destroy.apply(this,arguments)},initContainer:function(){var b,d=this.container,e=this.dropdown;this.opts.minimumResultsForSearch<0?this.showSearch(!1):this.showSearch(!0),this.selection=b=d.find(".select2-choice"),this.focusser=d.find(".select2-focusser"),this.focusser.attr("id","s2id_autogen"+g()),a("label[for='"+this.opts.element.attr("id")+"']").attr("for",this.focusser.attr("id")),this.focusser.attr("tabindex",this.elementTabIndex),this.search.on("keydown",this.bind(function(a){if(this.isInterfaceEnabled()){if(a.which===c.PAGE_UP||a.which===c.PAGE_DOWN)return A(a),void 0;switch(a.which){case c.UP:case c.DOWN:return this.moveHighlight(a.which===c.UP?-1:1),A(a),void 0;case c.ENTER:return this.selectHighlighted(),A(a),void 0;case c.TAB:return this.selectHighlighted({noFocus:!0}),void 0;case c.ESC:return this.cancel(a),A(a),void 0}}})),this.search.on("blur",this.bind(function(){document.activeElement===this.body().get(0)&&window.setTimeout(this.bind(function(){this.search.focus()}),0)})),this.focusser.on("keydown",this.bind(function(a){if(this.isInterfaceEnabled()&&a.which!==c.TAB&&!c.isControl(a)&&!c.isFunctionKey(a)&&a.which!==c.ESC){if(this.opts.openOnEnter===!1&&a.which===c.ENTER)return A(a),void 0;if(a.which==c.DOWN||a.which==c.UP||a.which==c.ENTER&&this.opts.openOnEnter){if(a.altKey||a.ctrlKey||a.shiftKey||a.metaKey)return;return this.open(),A(a),void 0}return a.which==c.DELETE||a.which==c.BACKSPACE?(this.opts.allowClear&&this.clear(),A(a),void 0):void 0}})),t(this.focusser),this.focusser.on("keyup-change input",this.bind(function(a){if(this.opts.minimumResultsForSearch>=0){if(a.stopPropagation(),this.opened())return;this.open()}})),b.on("mousedown","abbr",this.bind(function(a){this.isInterfaceEnabled()&&(this.clear(),B(a),this.close(),this.selection.focus())})),b.on("mousedown",this.bind(function(b){this.container.hasClass("select2-container-active")||this.opts.element.trigger(a.Event("select2-focus")),this.opened()?this.close():this.isInterfaceEnabled()&&this.open(),A(b)})),e.on("mousedown",this.bind(function(){this.search.focus()})),b.on("focus",this.bind(function(a){A(a)})),this.focusser.on("focus",this.bind(function(){this.container.hasClass("select2-container-active")||this.opts.element.trigger(a.Event("select2-focus")),this.container.addClass("select2-container-active")})).on("blur",this.bind(function(){this.opened()||(this.container.removeClass("select2-container-active"),this.opts.element.trigger(a.Event("select2-blur")))})),this.search.on("focus",this.bind(function(){this.container.hasClass("select2-container-active")||this.opts.element.trigger(a.Event("select2-focus")),this.container.addClass("select2-container-active")})),this.initContainerWidth(),this.opts.element.addClass("select2-offscreen"),this.setPlaceholder()},clear:function(b){var c=this.selection.data("select2-data");if(c){var d=a.Event("select2-clearing");if(this.opts.element.trigger(d),d.isDefaultPrevented())return;var e=this.getPlaceholderOption();this.opts.element.val(e?e.val():""),this.selection.find(".select2-chosen").empty(),this.selection.removeData("select2-data"),this.setPlaceholder(),b!==!1&&(this.opts.element.trigger({type:"select2-removed",val:this.id(c),choice:c}),this.triggerChange({removed:c}))}},initSelection:function(){if(this.isPlaceholderOptionSelected())this.updateSelection(null),this.close(),this.setPlaceholder();else{var c=this;this.opts.initSelection.call(null,this.opts.element,function(a){a!==b&&null!==a&&(c.updateSelection(a),c.close(),c.setPlaceholder())})}},isPlaceholderOptionSelected:function(){var a;return this.getPlaceholder()?(a=this.getPlaceholderOption())!==b&&a.prop("selected")||""===this.opts.element.val()||this.opts.element.val()===b||null===this.opts.element.val():!1},prepareOpts:function(){var b=this.parent.prepareOpts.apply(this,arguments),c=this;return"select"===b.element.get(0).tagName.toLowerCase()?b.initSelection=function(a,b){var d=a.find("option").filter(function(){return this.selected});b(c.optionToData(d))}:"data"in b&&(b.initSelection=b.initSelection||function(c,d){var e=c.val(),f=null;b.query({matcher:function(a,c,d){var g=q(e,b.id(d));return g&&(f=d),g},callback:a.isFunction(d)?function(){d(f)}:a.noop})}),b},getPlaceholder:function(){return this.select&&this.getPlaceholderOption()===b?b:this.parent.getPlaceholder.apply(this,arguments)},setPlaceholder:function(){var a=this.getPlaceholder();if(this.isPlaceholderOptionSelected()&&a!==b){if(this.select&&this.getPlaceholderOption()===b)return;this.selection.find(".select2-chosen").html(this.opts.escapeMarkup(a)),this.selection.addClass("select2-default"),this.container.removeClass("select2-allowclear")}},postprocessResults:function(a,b,c){var d=0,e=this;if(this.findHighlightableChoices().each2(function(a,b){return q(e.id(b.data("select2-data")),e.opts.element.val())?(d=a,!1):void 0}),c!==!1&&(b===!0&&d>=0?this.highlight(d):this.highlight(0)),b===!0){var g=this.opts.minimumResultsForSearch;g>=0&&this.showSearch(L(a.results)>=g)}},showSearch:function(b){this.showSearchInput!==b&&(this.showSearchInput=b,this.dropdown.find(".select2-search").toggleClass("select2-search-hidden",!b),this.dropdown.find(".select2-search").toggleClass("select2-offscreen",!b),a(this.dropdown,this.container).toggleClass("select2-with-searchbox",b))},onSelect:function(a,b){if(this.triggerSelect(a)){var c=this.opts.element.val(),d=this.data();this.opts.element.val(this.id(a)),this.updateSelection(a),this.opts.element.trigger({type:"select2-selected",val:this.id(a),choice:a}),this.nextSearchTerm=this.opts.nextSearchTerm(a,this.search.val()),this.close(),b&&b.noFocus||this.focusser.focus(),q(c,this.id(a))||this.triggerChange({added:a,removed:d})}},updateSelection:function(a){var d,e,c=this.selection.find(".select2-chosen");this.selection.data("select2-data",a),c.empty(),null!==a&&(d=this.opts.formatSelection(a,c,this.opts.escapeMarkup)),d!==b&&c.append(d),e=this.opts.formatSelectionCssClass(a,c),e!==b&&c.addClass(e),this.selection.removeClass("select2-default"),this.opts.allowClear&&this.getPlaceholder()!==b&&this.container.addClass("select2-allowclear")},val:function(){var a,c=!1,d=null,e=this,f=this.data();if(0===arguments.length)return this.opts.element.val();if(a=arguments[0],arguments.length>1&&(c=arguments[1]),this.select)this.select.val(a).find("option").filter(function(){return this.selected}).each2(function(a,b){return d=e.optionToData(b),!1}),this.updateSelection(d),this.setPlaceholder(),c&&this.triggerChange({added:d,removed:f});else{if(!a&&0!==a)return this.clear(c),void 0;if(this.opts.initSelection===b)throw new Error("cannot call val() if initSelection() is not defined");this.opts.element.val(a),this.opts.initSelection(this.opts.element,function(a){e.opts.element.val(a?e.id(a):""),e.updateSelection(a),e.setPlaceholder(),c&&e.triggerChange({added:a,removed:f})})}},clearSearch:function(){this.search.val(""),this.focusser.val("")},data:function(a){var c,d=!1;return 0===arguments.length?(c=this.selection.data("select2-data"),c==b&&(c=null),c):(arguments.length>1&&(d=arguments[1]),a?(c=this.data(),this.opts.element.val(a?this.id(a):""),this.updateSelection(a),d&&this.triggerChange({added:a,removed:c})):this.clear(d),void 0)}}),f=N(d,{createContainer:function(){var b=a(document.createElement("div")).attr({"class":"select2-container select2-container-multi"}).html(["<ul class='select2-choices'>"," <li class='select2-search-field'>"," <input type='text' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' class='select2-input'>"," </li>","</ul>","<div class='select2-drop select2-drop-multi select2-display-none'>"," <ul class='select2-results'>"," </ul>","</div>"].join(""));return b},prepareOpts:function(){var b=this.parent.prepareOpts.apply(this,arguments),c=this;return"select"===b.element.get(0).tagName.toLowerCase()?b.initSelection=function(a,b){var d=[];a.find("option").filter(function(){return this.selected}).each2(function(a,b){d.push(c.optionToData(b))}),b(d)}:"data"in b&&(b.initSelection=b.initSelection||function(c,d){var e=r(c.val(),b.separator),f=[];b.query({matcher:function(c,d,g){var h=a.grep(e,function(a){return q(a,b.id(g))}).length;return h&&f.push(g),h},callback:a.isFunction(d)?function(){for(var a=[],c=0;c<e.length;c++)for(var g=e[c],h=0;h<f.length;h++){var i=f[h];if(q(g,b.id(i))){a.push(i),f.splice(h,1);break}}d(a)}:a.noop})}),b},selectChoice:function(a){var b=this.container.find(".select2-search-choice-focus");b.length&&a&&a[0]==b[0]||(b.length&&this.opts.element.trigger("choice-deselected",b),b.removeClass("select2-search-choice-focus"),a&&a.length&&(this.close(),a.addClass("select2-search-choice-focus"),this.opts.element.trigger("choice-selected",a)))},destroy:function(){a("label[for='"+this.search.attr("id")+"']").attr("for",this.opts.element.attr("id")),this.parent.destroy.apply(this,arguments)},initContainer:function(){var d,b=".select2-choices";this.searchContainer=this.container.find(".select2-search-field"),this.selection=d=this.container.find(b);var e=this;this.selection.on("click",".select2-search-choice:not(.select2-locked)",function(){e.search[0].focus(),e.selectChoice(a(this))}),this.search.attr("id","s2id_autogen"+g()),a("label[for='"+this.opts.element.attr("id")+"']").attr("for",this.search.attr("id")),this.search.on("input paste",this.bind(function(){this.isInterfaceEnabled()&&(this.opened()||this.open())})),this.search.attr("tabindex",this.elementTabIndex),this.keydowns=0,this.search.on("keydown",this.bind(function(a){if(this.isInterfaceEnabled()){++this.keydowns;var b=d.find(".select2-search-choice-focus"),e=b.prev(".select2-search-choice:not(.select2-locked)"),f=b.next(".select2-search-choice:not(.select2-locked)"),g=z(this.search);if(b.length&&(a.which==c.LEFT||a.which==c.RIGHT||a.which==c.BACKSPACE||a.which==c.DELETE||a.which==c.ENTER)){var h=b;return a.which==c.LEFT&&e.length?h=e:a.which==c.RIGHT?h=f.length?f:null:a.which===c.BACKSPACE?(this.unselect(b.first()),this.search.width(10),h=e.length?e:f):a.which==c.DELETE?(this.unselect(b.first()),this.search.width(10),h=f.length?f:null):a.which==c.ENTER&&(h=null),this.selectChoice(h),A(a),h&&h.length||this.open(),void 0}if((a.which===c.BACKSPACE&&1==this.keydowns||a.which==c.LEFT)&&0==g.offset&&!g.length)return this.selectChoice(d.find(".select2-search-choice:not(.select2-locked)").last()),A(a),void 0;if(this.selectChoice(null),this.opened())switch(a.which){case c.UP:case c.DOWN:return this.moveHighlight(a.which===c.UP?-1:1),A(a),void 0;case c.ENTER:return this.selectHighlighted(),A(a),void 0;case c.TAB:return this.selectHighlighted({noFocus:!0}),this.close(),void 0;case c.ESC:return this.cancel(a),A(a),void 0}if(a.which!==c.TAB&&!c.isControl(a)&&!c.isFunctionKey(a)&&a.which!==c.BACKSPACE&&a.which!==c.ESC){if(a.which===c.ENTER){if(this.opts.openOnEnter===!1)return;if(a.altKey||a.ctrlKey||a.shiftKey||a.metaKey)return}this.open(),(a.which===c.PAGE_UP||a.which===c.PAGE_DOWN)&&A(a),a.which===c.ENTER&&A(a)}}})),this.search.on("keyup",this.bind(function(){this.keydowns=0,this.resizeSearch()})),this.search.on("blur",this.bind(function(b){this.container.removeClass("select2-container-active"),this.search.removeClass("select2-focused"),this.selectChoice(null),this.opened()||this.clearSearch(),b.stopImmediatePropagation(),this.opts.element.trigger(a.Event("select2-blur"))})),this.container.on("click",b,this.bind(function(b){this.isInterfaceEnabled()&&(a(b.target).closest(".select2-search-choice").length>0||(this.selectChoice(null),this.clearPlaceholder(),this.container.hasClass("select2-container-active")||this.opts.element.trigger(a.Event("select2-focus")),this.open(),this.focusSearch(),b.preventDefault()))})),this.container.on("focus",b,this.bind(function(){this.isInterfaceEnabled()&&(this.container.hasClass("select2-container-active")||this.opts.element.trigger(a.Event("select2-focus")),this.container.addClass("select2-container-active"),this.dropdown.addClass("select2-drop-active"),this.clearPlaceholder())})),this.initContainerWidth(),this.opts.element.addClass("select2-offscreen"),this.clearSearch()},enableInterface:function(){this.parent.enableInterface.apply(this,arguments)&&this.search.prop("disabled",!this.isInterfaceEnabled())},initSelection:function(){if(""===this.opts.element.val()&&""===this.opts.element.text()&&(this.updateSelection([]),this.close(),this.clearSearch()),this.select||""!==this.opts.element.val()){var c=this;this.opts.initSelection.call(null,this.opts.element,function(a){a!==b&&null!==a&&(c.updateSelection(a),c.close(),c.clearSearch())})}},clearSearch:function(){var a=this.getPlaceholder(),c=this.getMaxSearchWidth();a!==b&&0===this.getVal().length&&this.search.hasClass("select2-focused")===!1?(this.search.val(a).addClass("select2-default"),this.search.width(c>0?c:this.container.css("width"))):this.search.val("").width(10)},clearPlaceholder:function(){this.search.hasClass("select2-default")&&this.search.val("").removeClass("select2-default")},opening:function(){this.clearPlaceholder(),this.resizeSearch(),this.parent.opening.apply(this,arguments),this.focusSearch(),this.updateResults(!0),this.search.focus(),this.opts.element.trigger(a.Event("select2-open"))},close:function(){this.opened()&&this.parent.close.apply(this,arguments)},focus:function(){this.close(),this.search.focus()},isFocused:function(){return this.search.hasClass("select2-focused")},updateSelection:function(b){var c=[],d=[],e=this;a(b).each(function(){o(e.id(this),c)<0&&(c.push(e.id(this)),d.push(this))}),b=d,this.selection.find(".select2-search-choice").remove(),a(b).each(function(){e.addSelectedChoice(this)}),e.postprocessResults()},tokenize:function(){var a=this.search.val();a=this.opts.tokenizer.call(this,a,this.data(),this.bind(this.onSelect),this.opts),null!=a&&a!=b&&(this.search.val(a),a.length>0&&this.open())},onSelect:function(a,b){this.triggerSelect(a)&&(this.addSelectedChoice(a),this.opts.element.trigger({type:"selected",val:this.id(a),choice:a}),(this.select||!this.opts.closeOnSelect)&&this.postprocessResults(a,!1,this.opts.closeOnSelect===!0),this.opts.closeOnSelect?(this.close(),this.search.width(10)):this.countSelectableResults()>0?(this.search.width(10),this.resizeSearch(),this.getMaximumSelectionSize()>0&&this.val().length>=this.getMaximumSelectionSize()&&this.updateResults(!0),this.positionDropdown()):(this.close(),this.search.width(10)),this.triggerChange({added:a}),b&&b.noFocus||this.focusSearch())},cancel:function(){this.close(),this.focusSearch()},addSelectedChoice:function(c){var j,k,d=!c.locked,e=a("<li class='select2-search-choice'> <div></div> <a href='#' onclick='return false;' class='select2-search-choice-close' tabindex='-1'></a></li>"),f=a("<li class='select2-search-choice select2-locked'><div></div></li>"),g=d?e:f,h=this.id(c),i=this.getVal();j=this.opts.formatSelection(c,g.find("div"),this.opts.escapeMarkup),j!=b&&g.find("div").replaceWith("<div>"+j+"</div>"),k=this.opts.formatSelectionCssClass(c,g.find("div")),k!=b&&g.addClass(k),d&&g.find(".select2-search-choice-close").on("mousedown",A).on("click dblclick",this.bind(function(b){this.isInterfaceEnabled()&&(a(b.target).closest(".select2-search-choice").fadeOut("fast",this.bind(function(){this.unselect(a(b.target)),this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus"),this.close(),this.focusSearch()})).dequeue(),A(b))})).on("focus",this.bind(function(){this.isInterfaceEnabled()&&(this.container.addClass("select2-container-active"),this.dropdown.addClass("select2-drop-active"))})),g.data("select2-data",c),g.insertBefore(this.searchContainer),i.push(h),this.setVal(i)},unselect:function(b){var d,e,c=this.getVal();if(b=b.closest(".select2-search-choice"),0===b.length)throw"Invalid argument: "+b+". Must be .select2-search-choice";if(d=b.data("select2-data")){for(;(e=o(this.id(d),c))>=0;)c.splice(e,1),this.setVal(c),this.select&&this.postprocessResults();var f=a.Event("select2-removing");f.val=this.id(d),f.choice=d,this.opts.element.trigger(f),f.isDefaultPrevented()||(b.remove(),this.opts.element.trigger({type:"select2-removed",val:this.id(d),choice:d}),this.triggerChange({removed:d}))}},postprocessResults:function(a,b,c){var d=this.getVal(),e=this.results.find(".select2-result"),f=this.results.find(".select2-result-with-children"),g=this;e.each2(function(a,b){var c=g.id(b.data("select2-data"));o(c,d)>=0&&(b.addClass("select2-selected"),b.find(".select2-result-selectable").addClass("select2-selected"))}),f.each2(function(a,b){b.is(".select2-result-selectable")||0!==b.find(".select2-result-selectable:not(.select2-selected)").length||b.addClass("select2-selected")}),-1==this.highlight()&&c!==!1&&g.highlight(0),!this.opts.createSearchChoice&&!e.filter(".select2-result:not(.select2-selected)").length>0&&(!a||a&&!a.more&&0===this.results.find(".select2-no-results").length)&&J(g.opts.formatNoMatches,"formatNoMatches")&&this.results.append("<li class='select2-no-results'>"+g.opts.formatNoMatches(g.search.val())+"</li>")},getMaxSearchWidth:function(){return this.selection.width()-s(this.search)},resizeSearch:function(){var a,b,c,d,e,f=s(this.search);a=C(this.search)+10,b=this.search.offset().left,c=this.selection.width(),d=this.selection.offset().left,e=c-(b-d)-f,a>e&&(e=c-f),40>e&&(e=c-f),0>=e&&(e=a),this.search.width(Math.floor(e))},getVal:function(){var a;return this.select?(a=this.select.val(),null===a?[]:a):(a=this.opts.element.val(),r(a,this.opts.separator))},setVal:function(b){var c;this.select?this.select.val(b):(c=[],a(b).each(function(){o(this,c)<0&&c.push(this)}),this.opts.element.val(0===c.length?"":c.join(this.opts.separator)))},buildChangeDetails:function(a,b){for(var b=b.slice(0),a=a.slice(0),c=0;c<b.length;c++)for(var d=0;d<a.length;d++)q(this.opts.id(b[c]),this.opts.id(a[d]))&&(b.splice(c,1),c>0&&c--,a.splice(d,1),d--);return{added:b,removed:a}},val:function(c,d){var e,f=this;if(0===arguments.length)return this.getVal();if(e=this.data(),e.length||(e=[]),!c&&0!==c)return this.opts.element.val(""),this.updateSelection([]),this.clearSearch(),d&&this.triggerChange({added:this.data(),removed:e}),void 0;if(this.setVal(c),this.select)this.opts.initSelection(this.select,this.bind(this.updateSelection)),d&&this.triggerChange(this.buildChangeDetails(e,this.data()));else{if(this.opts.initSelection===b)throw new Error("val() cannot be called if initSelection() is not defined");this.opts.initSelection(this.opts.element,function(b){var c=a.map(b,f.id);f.setVal(c),f.updateSelection(b),f.clearSearch(),d&&f.triggerChange(f.buildChangeDetails(e,f.data()))})}this.clearSearch()},onSortStart:function(){if(this.select)throw new Error("Sorting of elements is not supported when attached to <select>. Attach to <input type='hidden'/> instead.");this.search.width(0),this.searchContainer.hide()},onSortEnd:function(){var b=[],c=this;this.searchContainer.show(),this.searchContainer.appendTo(this.searchContainer.parent()),this.resizeSearch(),this.selection.find(".select2-search-choice").each(function(){b.push(c.opts.id(a(this).data("select2-data")))}),this.setVal(b),this.triggerChange()},data:function(b,c){var e,f,d=this;return 0===arguments.length?this.selection.find(".select2-search-choice").map(function(){return a(this).data("select2-data")}).get():(f=this.data(),b||(b=[]),e=a.map(b,function(a){return d.opts.id(a)}),this.setVal(e),this.updateSelection(b),this.clearSearch(),c&&this.triggerChange(this.buildChangeDetails(f,this.data())),void 0)}}),a.fn.select2=function(){var d,g,h,i,j,c=Array.prototype.slice.call(arguments,0),k=["val","destroy","opened","open","close","focus","isFocused","container","dropdown","onSortStart","onSortEnd","enable","disable","readonly","positionDropdown","data","search"],l=["opened","isFocused","container","dropdown"],m=["val","data"],n={search:"externalSearch"};return this.each(function(){if(0===c.length||"object"==typeof c[0])d=0===c.length?{}:a.extend({},c[0]),d.element=a(this),"select"===d.element.get(0).tagName.toLowerCase()?j=d.element.prop("multiple"):(j=d.multiple||!1,"tags"in d&&(d.multiple=j=!0)),g=j?new f:new e,g.init(d);else{if("string"!=typeof c[0])throw"Invalid arguments to select2 plugin: "+c;if(o(c[0],k)<0)throw"Unknown method: "+c[0];if(i=b,g=a(this).data("select2"),g===b)return;if(h=c[0],"container"===h?i=g.container:"dropdown"===h?i=g.dropdown:(n[h]&&(h=n[h]),i=g[h].apply(g,c.slice(1))),o(c[0],l)>=0||o(c[0],m)&&1==c.length)return!1}}),i===b?this:i},a.fn.select2.defaults={width:"copy",loadMorePadding:0,closeOnSelect:!0,openOnEnter:!0,containerCss:{},dropdownCss:{},containerCssClass:"",dropdownCssClass:"",formatResult:function(a,b,c,d){var e=[];return E(a.text,c.term,e,d),e.join("")},formatSelection:function(a,c,d){return a?d(a.text):b},sortResults:function(a){return a},formatResultCssClass:function(){return b},formatSelectionCssClass:function(){return b},formatNoMatches:function(){return"No matches found"},formatInputTooShort:function(a,b){var c=b-a.length;return"Please enter "+c+" more character"+(1==c?"":"s")},formatInputTooLong:function(a,b){var c=a.length-b;return"Please delete "+c+" character"+(1==c?"":"s")},formatSelectionTooBig:function(a){return"You can only select "+a+" item"+(1==a?"":"s")},formatLoadMore:function(){return"Loading more results..."},formatSearching:function(){return"Searching..."},minimumResultsForSearch:0,minimumInputLength:0,maximumInputLength:null,maximumSelectionSize:0,id:function(a){return a.id},matcher:function(a,b){return n(""+b).toUpperCase().indexOf(n(""+a).toUpperCase())>=0},separator:",",tokenSeparators:[],tokenizer:M,escapeMarkup:F,blurOnChange:!1,selectOnBlur:!1,adaptContainerCssClass:function(a){return a},adaptDropdownCssClass:function(){return null},nextSearchTerm:function(){return b}},a.fn.select2.ajaxDefaults={transport:a.ajax,params:{type:"GET",cache:!1,dataType:"json"}},window.Select2={query:{ajax:G,local:H,tags:I},util:{debounce:v,markMatch:E,escapeMarkup:F,stripDiacritics:n},"class":{"abstract":d,single:e,multi:f}}}}(jQuery);
|
@@ -0,0 +1,6 @@
|
|
1
|
+
// Underscore.js 1.5.2
|
2
|
+
// http://underscorejs.org
|
3
|
+
// (c) 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
4
|
+
// Underscore may be freely distributed under the MIT license.
|
5
|
+
(function(){var n=this,t=n._,r={},e=Array.prototype,u=Object.prototype,i=Function.prototype,a=e.push,o=e.slice,c=e.concat,l=u.toString,f=u.hasOwnProperty,s=e.forEach,p=e.map,h=e.reduce,v=e.reduceRight,g=e.filter,d=e.every,m=e.some,y=e.indexOf,b=e.lastIndexOf,x=Array.isArray,w=Object.keys,_=i.bind,j=function(n){return n instanceof j?n:this instanceof j?(this._wrapped=n,void 0):new j(n)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=j),exports._=j):n._=j,j.VERSION="1.5.2";var A=j.each=j.forEach=function(n,t,e){if(null!=n)if(s&&n.forEach===s)n.forEach(t,e);else if(n.length===+n.length){for(var u=0,i=n.length;i>u;u++)if(t.call(e,n[u],u,n)===r)return}else for(var a=j.keys(n),u=0,i=a.length;i>u;u++)if(t.call(e,n[a[u]],a[u],n)===r)return};j.map=j.collect=function(n,t,r){var e=[];return null==n?e:p&&n.map===p?n.map(t,r):(A(n,function(n,u,i){e.push(t.call(r,n,u,i))}),e)};var E="Reduce of empty array with no initial value";j.reduce=j.foldl=j.inject=function(n,t,r,e){var u=arguments.length>2;if(null==n&&(n=[]),h&&n.reduce===h)return e&&(t=j.bind(t,e)),u?n.reduce(t,r):n.reduce(t);if(A(n,function(n,i,a){u?r=t.call(e,r,n,i,a):(r=n,u=!0)}),!u)throw new TypeError(E);return r},j.reduceRight=j.foldr=function(n,t,r,e){var u=arguments.length>2;if(null==n&&(n=[]),v&&n.reduceRight===v)return e&&(t=j.bind(t,e)),u?n.reduceRight(t,r):n.reduceRight(t);var i=n.length;if(i!==+i){var a=j.keys(n);i=a.length}if(A(n,function(o,c,l){c=a?a[--i]:--i,u?r=t.call(e,r,n[c],c,l):(r=n[c],u=!0)}),!u)throw new TypeError(E);return r},j.find=j.detect=function(n,t,r){var e;return O(n,function(n,u,i){return t.call(r,n,u,i)?(e=n,!0):void 0}),e},j.filter=j.select=function(n,t,r){var e=[];return null==n?e:g&&n.filter===g?n.filter(t,r):(A(n,function(n,u,i){t.call(r,n,u,i)&&e.push(n)}),e)},j.reject=function(n,t,r){return j.filter(n,function(n,e,u){return!t.call(r,n,e,u)},r)},j.every=j.all=function(n,t,e){t||(t=j.identity);var u=!0;return null==n?u:d&&n.every===d?n.every(t,e):(A(n,function(n,i,a){return(u=u&&t.call(e,n,i,a))?void 0:r}),!!u)};var O=j.some=j.any=function(n,t,e){t||(t=j.identity);var u=!1;return null==n?u:m&&n.some===m?n.some(t,e):(A(n,function(n,i,a){return u||(u=t.call(e,n,i,a))?r:void 0}),!!u)};j.contains=j.include=function(n,t){return null==n?!1:y&&n.indexOf===y?n.indexOf(t)!=-1:O(n,function(n){return n===t})},j.invoke=function(n,t){var r=o.call(arguments,2),e=j.isFunction(t);return j.map(n,function(n){return(e?t:n[t]).apply(n,r)})},j.pluck=function(n,t){return j.map(n,function(n){return n[t]})},j.where=function(n,t,r){return j.isEmpty(t)?r?void 0:[]:j[r?"find":"filter"](n,function(n){for(var r in t)if(t[r]!==n[r])return!1;return!0})},j.findWhere=function(n,t){return j.where(n,t,!0)},j.max=function(n,t,r){if(!t&&j.isArray(n)&&n[0]===+n[0]&&n.length<65535)return Math.max.apply(Math,n);if(!t&&j.isEmpty(n))return-1/0;var e={computed:-1/0,value:-1/0};return A(n,function(n,u,i){var a=t?t.call(r,n,u,i):n;a>e.computed&&(e={value:n,computed:a})}),e.value},j.min=function(n,t,r){if(!t&&j.isArray(n)&&n[0]===+n[0]&&n.length<65535)return Math.min.apply(Math,n);if(!t&&j.isEmpty(n))return 1/0;var e={computed:1/0,value:1/0};return A(n,function(n,u,i){var a=t?t.call(r,n,u,i):n;a<e.computed&&(e={value:n,computed:a})}),e.value},j.shuffle=function(n){var t,r=0,e=[];return A(n,function(n){t=j.random(r++),e[r-1]=e[t],e[t]=n}),e},j.sample=function(n,t,r){return arguments.length<2||r?n[j.random(n.length-1)]:j.shuffle(n).slice(0,Math.max(0,t))};var k=function(n){return j.isFunction(n)?n:function(t){return t[n]}};j.sortBy=function(n,t,r){var e=k(t);return j.pluck(j.map(n,function(n,t,u){return{value:n,index:t,criteria:e.call(r,n,t,u)}}).sort(function(n,t){var r=n.criteria,e=t.criteria;if(r!==e){if(r>e||r===void 0)return 1;if(e>r||e===void 0)return-1}return n.index-t.index}),"value")};var F=function(n){return function(t,r,e){var u={},i=null==r?j.identity:k(r);return A(t,function(r,a){var o=i.call(e,r,a,t);n(u,o,r)}),u}};j.groupBy=F(function(n,t,r){(j.has(n,t)?n[t]:n[t]=[]).push(r)}),j.indexBy=F(function(n,t,r){n[t]=r}),j.countBy=F(function(n,t){j.has(n,t)?n[t]++:n[t]=1}),j.sortedIndex=function(n,t,r,e){r=null==r?j.identity:k(r);for(var u=r.call(e,t),i=0,a=n.length;a>i;){var o=i+a>>>1;r.call(e,n[o])<u?i=o+1:a=o}return i},j.toArray=function(n){return n?j.isArray(n)?o.call(n):n.length===+n.length?j.map(n,j.identity):j.values(n):[]},j.size=function(n){return null==n?0:n.length===+n.length?n.length:j.keys(n).length},j.first=j.head=j.take=function(n,t,r){return null==n?void 0:null==t||r?n[0]:o.call(n,0,t)},j.initial=function(n,t,r){return o.call(n,0,n.length-(null==t||r?1:t))},j.last=function(n,t,r){return null==n?void 0:null==t||r?n[n.length-1]:o.call(n,Math.max(n.length-t,0))},j.rest=j.tail=j.drop=function(n,t,r){return o.call(n,null==t||r?1:t)},j.compact=function(n){return j.filter(n,j.identity)};var M=function(n,t,r){return t&&j.every(n,j.isArray)?c.apply(r,n):(A(n,function(n){j.isArray(n)||j.isArguments(n)?t?a.apply(r,n):M(n,t,r):r.push(n)}),r)};j.flatten=function(n,t){return M(n,t,[])},j.without=function(n){return j.difference(n,o.call(arguments,1))},j.uniq=j.unique=function(n,t,r,e){j.isFunction(t)&&(e=r,r=t,t=!1);var u=r?j.map(n,r,e):n,i=[],a=[];return A(u,function(r,e){(t?e&&a[a.length-1]===r:j.contains(a,r))||(a.push(r),i.push(n[e]))}),i},j.union=function(){return j.uniq(j.flatten(arguments,!0))},j.intersection=function(n){var t=o.call(arguments,1);return j.filter(j.uniq(n),function(n){return j.every(t,function(t){return j.indexOf(t,n)>=0})})},j.difference=function(n){var t=c.apply(e,o.call(arguments,1));return j.filter(n,function(n){return!j.contains(t,n)})},j.zip=function(){for(var n=j.max(j.pluck(arguments,"length").concat(0)),t=new Array(n),r=0;n>r;r++)t[r]=j.pluck(arguments,""+r);return t},j.object=function(n,t){if(null==n)return{};for(var r={},e=0,u=n.length;u>e;e++)t?r[n[e]]=t[e]:r[n[e][0]]=n[e][1];return r},j.indexOf=function(n,t,r){if(null==n)return-1;var e=0,u=n.length;if(r){if("number"!=typeof r)return e=j.sortedIndex(n,t),n[e]===t?e:-1;e=0>r?Math.max(0,u+r):r}if(y&&n.indexOf===y)return n.indexOf(t,r);for(;u>e;e++)if(n[e]===t)return e;return-1},j.lastIndexOf=function(n,t,r){if(null==n)return-1;var e=null!=r;if(b&&n.lastIndexOf===b)return e?n.lastIndexOf(t,r):n.lastIndexOf(t);for(var u=e?r:n.length;u--;)if(n[u]===t)return u;return-1},j.range=function(n,t,r){arguments.length<=1&&(t=n||0,n=0),r=arguments[2]||1;for(var e=Math.max(Math.ceil((t-n)/r),0),u=0,i=new Array(e);e>u;)i[u++]=n,n+=r;return i};var R=function(){};j.bind=function(n,t){var r,e;if(_&&n.bind===_)return _.apply(n,o.call(arguments,1));if(!j.isFunction(n))throw new TypeError;return r=o.call(arguments,2),e=function(){if(!(this instanceof e))return n.apply(t,r.concat(o.call(arguments)));R.prototype=n.prototype;var u=new R;R.prototype=null;var i=n.apply(u,r.concat(o.call(arguments)));return Object(i)===i?i:u}},j.partial=function(n){var t=o.call(arguments,1);return function(){return n.apply(this,t.concat(o.call(arguments)))}},j.bindAll=function(n){var t=o.call(arguments,1);if(0===t.length)throw new Error("bindAll must be passed function names");return A(t,function(t){n[t]=j.bind(n[t],n)}),n},j.memoize=function(n,t){var r={};return t||(t=j.identity),function(){var e=t.apply(this,arguments);return j.has(r,e)?r[e]:r[e]=n.apply(this,arguments)}},j.delay=function(n,t){var r=o.call(arguments,2);return setTimeout(function(){return n.apply(null,r)},t)},j.defer=function(n){return j.delay.apply(j,[n,1].concat(o.call(arguments,1)))},j.throttle=function(n,t,r){var e,u,i,a=null,o=0;r||(r={});var c=function(){o=r.leading===!1?0:new Date,a=null,i=n.apply(e,u)};return function(){var l=new Date;o||r.leading!==!1||(o=l);var f=t-(l-o);return e=this,u=arguments,0>=f?(clearTimeout(a),a=null,o=l,i=n.apply(e,u)):a||r.trailing===!1||(a=setTimeout(c,f)),i}},j.debounce=function(n,t,r){var e,u,i,a,o;return function(){i=this,u=arguments,a=new Date;var c=function(){var l=new Date-a;t>l?e=setTimeout(c,t-l):(e=null,r||(o=n.apply(i,u)))},l=r&&!e;return e||(e=setTimeout(c,t)),l&&(o=n.apply(i,u)),o}},j.once=function(n){var t,r=!1;return function(){return r?t:(r=!0,t=n.apply(this,arguments),n=null,t)}},j.wrap=function(n,t){return function(){var r=[n];return a.apply(r,arguments),t.apply(this,r)}},j.compose=function(){var n=arguments;return function(){for(var t=arguments,r=n.length-1;r>=0;r--)t=[n[r].apply(this,t)];return t[0]}},j.after=function(n,t){return function(){return--n<1?t.apply(this,arguments):void 0}},j.keys=w||function(n){if(n!==Object(n))throw new TypeError("Invalid object");var t=[];for(var r in n)j.has(n,r)&&t.push(r);return t},j.values=function(n){for(var t=j.keys(n),r=t.length,e=new Array(r),u=0;r>u;u++)e[u]=n[t[u]];return e},j.pairs=function(n){for(var t=j.keys(n),r=t.length,e=new Array(r),u=0;r>u;u++)e[u]=[t[u],n[t[u]]];return e},j.invert=function(n){for(var t={},r=j.keys(n),e=0,u=r.length;u>e;e++)t[n[r[e]]]=r[e];return t},j.functions=j.methods=function(n){var t=[];for(var r in n)j.isFunction(n[r])&&t.push(r);return t.sort()},j.extend=function(n){return A(o.call(arguments,1),function(t){if(t)for(var r in t)n[r]=t[r]}),n},j.pick=function(n){var t={},r=c.apply(e,o.call(arguments,1));return A(r,function(r){r in n&&(t[r]=n[r])}),t},j.omit=function(n){var t={},r=c.apply(e,o.call(arguments,1));for(var u in n)j.contains(r,u)||(t[u]=n[u]);return t},j.defaults=function(n){return A(o.call(arguments,1),function(t){if(t)for(var r in t)n[r]===void 0&&(n[r]=t[r])}),n},j.clone=function(n){return j.isObject(n)?j.isArray(n)?n.slice():j.extend({},n):n},j.tap=function(n,t){return t(n),n};var S=function(n,t,r,e){if(n===t)return 0!==n||1/n==1/t;if(null==n||null==t)return n===t;n instanceof j&&(n=n._wrapped),t instanceof j&&(t=t._wrapped);var u=l.call(n);if(u!=l.call(t))return!1;switch(u){case"[object String]":return n==String(t);case"[object Number]":return n!=+n?t!=+t:0==n?1/n==1/t:n==+t;case"[object Date]":case"[object Boolean]":return+n==+t;case"[object RegExp]":return n.source==t.source&&n.global==t.global&&n.multiline==t.multiline&&n.ignoreCase==t.ignoreCase}if("object"!=typeof n||"object"!=typeof t)return!1;for(var i=r.length;i--;)if(r[i]==n)return e[i]==t;var a=n.constructor,o=t.constructor;if(a!==o&&!(j.isFunction(a)&&a instanceof a&&j.isFunction(o)&&o instanceof o))return!1;r.push(n),e.push(t);var c=0,f=!0;if("[object Array]"==u){if(c=n.length,f=c==t.length)for(;c--&&(f=S(n[c],t[c],r,e)););}else{for(var s in n)if(j.has(n,s)&&(c++,!(f=j.has(t,s)&&S(n[s],t[s],r,e))))break;if(f){for(s in t)if(j.has(t,s)&&!c--)break;f=!c}}return r.pop(),e.pop(),f};j.isEqual=function(n,t){return S(n,t,[],[])},j.isEmpty=function(n){if(null==n)return!0;if(j.isArray(n)||j.isString(n))return 0===n.length;for(var t in n)if(j.has(n,t))return!1;return!0},j.isElement=function(n){return!(!n||1!==n.nodeType)},j.isArray=x||function(n){return"[object Array]"==l.call(n)},j.isObject=function(n){return n===Object(n)},A(["Arguments","Function","String","Number","Date","RegExp"],function(n){j["is"+n]=function(t){return l.call(t)=="[object "+n+"]"}}),j.isArguments(arguments)||(j.isArguments=function(n){return!(!n||!j.has(n,"callee"))}),"function"!=typeof/./&&(j.isFunction=function(n){return"function"==typeof n}),j.isFinite=function(n){return isFinite(n)&&!isNaN(parseFloat(n))},j.isNaN=function(n){return j.isNumber(n)&&n!=+n},j.isBoolean=function(n){return n===!0||n===!1||"[object Boolean]"==l.call(n)},j.isNull=function(n){return null===n},j.isUndefined=function(n){return n===void 0},j.has=function(n,t){return f.call(n,t)},j.noConflict=function(){return n._=t,this},j.identity=function(n){return n},j.times=function(n,t,r){for(var e=Array(Math.max(0,n)),u=0;n>u;u++)e[u]=t.call(r,u);return e},j.random=function(n,t){return null==t&&(t=n,n=0),n+Math.floor(Math.random()*(t-n+1))};var I={escape:{"&":"&","<":"<",">":">",'"':""","'":"'"}};I.unescape=j.invert(I.escape);var T={escape:new RegExp("["+j.keys(I.escape).join("")+"]","g"),unescape:new RegExp("("+j.keys(I.unescape).join("|")+")","g")};j.each(["escape","unescape"],function(n){j[n]=function(t){return null==t?"":(""+t).replace(T[n],function(t){return I[n][t]})}}),j.result=function(n,t){if(null==n)return void 0;var r=n[t];return j.isFunction(r)?r.call(n):r},j.mixin=function(n){A(j.functions(n),function(t){var r=j[t]=n[t];j.prototype[t]=function(){var n=[this._wrapped];return a.apply(n,arguments),z.call(this,r.apply(j,n))}})};var N=0;j.uniqueId=function(n){var t=++N+"";return n?n+t:t},j.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var q=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},D=/\\|'|\r|\n|\t|\u2028|\u2029/g;j.template=function(n,t,r){var e;r=j.defaults({},r,j.templateSettings);var u=new RegExp([(r.escape||q).source,(r.interpolate||q).source,(r.evaluate||q).source].join("|")+"|$","g"),i=0,a="__p+='";n.replace(u,function(t,r,e,u,o){return a+=n.slice(i,o).replace(D,function(n){return"\\"+B[n]}),r&&(a+="'+\n((__t=("+r+"))==null?'':_.escape(__t))+\n'"),e&&(a+="'+\n((__t=("+e+"))==null?'':__t)+\n'"),u&&(a+="';\n"+u+"\n__p+='"),i=o+t.length,t}),a+="';\n",r.variable||(a="with(obj||{}){\n"+a+"}\n"),a="var __t,__p='',__j=Array.prototype.join,"+"print=function(){__p+=__j.call(arguments,'');};\n"+a+"return __p;\n";try{e=new Function(r.variable||"obj","_",a)}catch(o){throw o.source=a,o}if(t)return e(t,j);var c=function(n){return e.call(this,n,j)};return c.source="function("+(r.variable||"obj")+"){\n"+a+"}",c},j.chain=function(n){return j(n).chain()};var z=function(n){return this._chain?j(n).chain():n};j.mixin(j),A(["pop","push","reverse","shift","sort","splice","unshift"],function(n){var t=e[n];j.prototype[n]=function(){var r=this._wrapped;return t.apply(r,arguments),"shift"!=n&&"splice"!=n||0!==r.length||delete r[0],z.call(this,r)}}),A(["concat","join","slice"],function(n){var t=e[n];j.prototype[n]=function(){return z.call(this,t.apply(this._wrapped,arguments))}}),j.extend(j.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this);
|
6
|
+
//# sourceMappingURL=underscore-min.map
|
@@ -0,0 +1,1276 @@
|
|
1
|
+
// Underscore.js 1.5.2
|
2
|
+
// http://underscorejs.org
|
3
|
+
// (c) 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
4
|
+
// Underscore may be freely distributed under the MIT license.
|
5
|
+
|
6
|
+
(function() {
|
7
|
+
|
8
|
+
// Baseline setup
|
9
|
+
// --------------
|
10
|
+
|
11
|
+
// Establish the root object, `window` in the browser, or `exports` on the server.
|
12
|
+
var root = this;
|
13
|
+
|
14
|
+
// Save the previous value of the `_` variable.
|
15
|
+
var previousUnderscore = root._;
|
16
|
+
|
17
|
+
// Establish the object that gets returned to break out of a loop iteration.
|
18
|
+
var breaker = {};
|
19
|
+
|
20
|
+
// Save bytes in the minified (but not gzipped) version:
|
21
|
+
var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
|
22
|
+
|
23
|
+
// Create quick reference variables for speed access to core prototypes.
|
24
|
+
var
|
25
|
+
push = ArrayProto.push,
|
26
|
+
slice = ArrayProto.slice,
|
27
|
+
concat = ArrayProto.concat,
|
28
|
+
toString = ObjProto.toString,
|
29
|
+
hasOwnProperty = ObjProto.hasOwnProperty;
|
30
|
+
|
31
|
+
// All **ECMAScript 5** native function implementations that we hope to use
|
32
|
+
// are declared here.
|
33
|
+
var
|
34
|
+
nativeForEach = ArrayProto.forEach,
|
35
|
+
nativeMap = ArrayProto.map,
|
36
|
+
nativeReduce = ArrayProto.reduce,
|
37
|
+
nativeReduceRight = ArrayProto.reduceRight,
|
38
|
+
nativeFilter = ArrayProto.filter,
|
39
|
+
nativeEvery = ArrayProto.every,
|
40
|
+
nativeSome = ArrayProto.some,
|
41
|
+
nativeIndexOf = ArrayProto.indexOf,
|
42
|
+
nativeLastIndexOf = ArrayProto.lastIndexOf,
|
43
|
+
nativeIsArray = Array.isArray,
|
44
|
+
nativeKeys = Object.keys,
|
45
|
+
nativeBind = FuncProto.bind;
|
46
|
+
|
47
|
+
// Create a safe reference to the Underscore object for use below.
|
48
|
+
var _ = function(obj) {
|
49
|
+
if (obj instanceof _) return obj;
|
50
|
+
if (!(this instanceof _)) return new _(obj);
|
51
|
+
this._wrapped = obj;
|
52
|
+
};
|
53
|
+
|
54
|
+
// Export the Underscore object for **Node.js**, with
|
55
|
+
// backwards-compatibility for the old `require()` API. If we're in
|
56
|
+
// the browser, add `_` as a global object via a string identifier,
|
57
|
+
// for Closure Compiler "advanced" mode.
|
58
|
+
if (typeof exports !== 'undefined') {
|
59
|
+
if (typeof module !== 'undefined' && module.exports) {
|
60
|
+
exports = module.exports = _;
|
61
|
+
}
|
62
|
+
exports._ = _;
|
63
|
+
} else {
|
64
|
+
root._ = _;
|
65
|
+
}
|
66
|
+
|
67
|
+
// Current version.
|
68
|
+
_.VERSION = '1.5.2';
|
69
|
+
|
70
|
+
// Collection Functions
|
71
|
+
// --------------------
|
72
|
+
|
73
|
+
// The cornerstone, an `each` implementation, aka `forEach`.
|
74
|
+
// Handles objects with the built-in `forEach`, arrays, and raw objects.
|
75
|
+
// Delegates to **ECMAScript 5**'s native `forEach` if available.
|
76
|
+
var each = _.each = _.forEach = function(obj, iterator, context) {
|
77
|
+
if (obj == null) return;
|
78
|
+
if (nativeForEach && obj.forEach === nativeForEach) {
|
79
|
+
obj.forEach(iterator, context);
|
80
|
+
} else if (obj.length === +obj.length) {
|
81
|
+
for (var i = 0, length = obj.length; i < length; i++) {
|
82
|
+
if (iterator.call(context, obj[i], i, obj) === breaker) return;
|
83
|
+
}
|
84
|
+
} else {
|
85
|
+
var keys = _.keys(obj);
|
86
|
+
for (var i = 0, length = keys.length; i < length; i++) {
|
87
|
+
if (iterator.call(context, obj[keys[i]], keys[i], obj) === breaker) return;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
};
|
91
|
+
|
92
|
+
// Return the results of applying the iterator to each element.
|
93
|
+
// Delegates to **ECMAScript 5**'s native `map` if available.
|
94
|
+
_.map = _.collect = function(obj, iterator, context) {
|
95
|
+
var results = [];
|
96
|
+
if (obj == null) return results;
|
97
|
+
if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
|
98
|
+
each(obj, function(value, index, list) {
|
99
|
+
results.push(iterator.call(context, value, index, list));
|
100
|
+
});
|
101
|
+
return results;
|
102
|
+
};
|
103
|
+
|
104
|
+
var reduceError = 'Reduce of empty array with no initial value';
|
105
|
+
|
106
|
+
// **Reduce** builds up a single result from a list of values, aka `inject`,
|
107
|
+
// or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available.
|
108
|
+
_.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) {
|
109
|
+
var initial = arguments.length > 2;
|
110
|
+
if (obj == null) obj = [];
|
111
|
+
if (nativeReduce && obj.reduce === nativeReduce) {
|
112
|
+
if (context) iterator = _.bind(iterator, context);
|
113
|
+
return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
|
114
|
+
}
|
115
|
+
each(obj, function(value, index, list) {
|
116
|
+
if (!initial) {
|
117
|
+
memo = value;
|
118
|
+
initial = true;
|
119
|
+
} else {
|
120
|
+
memo = iterator.call(context, memo, value, index, list);
|
121
|
+
}
|
122
|
+
});
|
123
|
+
if (!initial) throw new TypeError(reduceError);
|
124
|
+
return memo;
|
125
|
+
};
|
126
|
+
|
127
|
+
// The right-associative version of reduce, also known as `foldr`.
|
128
|
+
// Delegates to **ECMAScript 5**'s native `reduceRight` if available.
|
129
|
+
_.reduceRight = _.foldr = function(obj, iterator, memo, context) {
|
130
|
+
var initial = arguments.length > 2;
|
131
|
+
if (obj == null) obj = [];
|
132
|
+
if (nativeReduceRight && obj.reduceRight === nativeReduceRight) {
|
133
|
+
if (context) iterator = _.bind(iterator, context);
|
134
|
+
return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator);
|
135
|
+
}
|
136
|
+
var length = obj.length;
|
137
|
+
if (length !== +length) {
|
138
|
+
var keys = _.keys(obj);
|
139
|
+
length = keys.length;
|
140
|
+
}
|
141
|
+
each(obj, function(value, index, list) {
|
142
|
+
index = keys ? keys[--length] : --length;
|
143
|
+
if (!initial) {
|
144
|
+
memo = obj[index];
|
145
|
+
initial = true;
|
146
|
+
} else {
|
147
|
+
memo = iterator.call(context, memo, obj[index], index, list);
|
148
|
+
}
|
149
|
+
});
|
150
|
+
if (!initial) throw new TypeError(reduceError);
|
151
|
+
return memo;
|
152
|
+
};
|
153
|
+
|
154
|
+
// Return the first value which passes a truth test. Aliased as `detect`.
|
155
|
+
_.find = _.detect = function(obj, iterator, context) {
|
156
|
+
var result;
|
157
|
+
any(obj, function(value, index, list) {
|
158
|
+
if (iterator.call(context, value, index, list)) {
|
159
|
+
result = value;
|
160
|
+
return true;
|
161
|
+
}
|
162
|
+
});
|
163
|
+
return result;
|
164
|
+
};
|
165
|
+
|
166
|
+
// Return all the elements that pass a truth test.
|
167
|
+
// Delegates to **ECMAScript 5**'s native `filter` if available.
|
168
|
+
// Aliased as `select`.
|
169
|
+
_.filter = _.select = function(obj, iterator, context) {
|
170
|
+
var results = [];
|
171
|
+
if (obj == null) return results;
|
172
|
+
if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context);
|
173
|
+
each(obj, function(value, index, list) {
|
174
|
+
if (iterator.call(context, value, index, list)) results.push(value);
|
175
|
+
});
|
176
|
+
return results;
|
177
|
+
};
|
178
|
+
|
179
|
+
// Return all the elements for which a truth test fails.
|
180
|
+
_.reject = function(obj, iterator, context) {
|
181
|
+
return _.filter(obj, function(value, index, list) {
|
182
|
+
return !iterator.call(context, value, index, list);
|
183
|
+
}, context);
|
184
|
+
};
|
185
|
+
|
186
|
+
// Determine whether all of the elements match a truth test.
|
187
|
+
// Delegates to **ECMAScript 5**'s native `every` if available.
|
188
|
+
// Aliased as `all`.
|
189
|
+
_.every = _.all = function(obj, iterator, context) {
|
190
|
+
iterator || (iterator = _.identity);
|
191
|
+
var result = true;
|
192
|
+
if (obj == null) return result;
|
193
|
+
if (nativeEvery && obj.every === nativeEvery) return obj.every(iterator, context);
|
194
|
+
each(obj, function(value, index, list) {
|
195
|
+
if (!(result = result && iterator.call(context, value, index, list))) return breaker;
|
196
|
+
});
|
197
|
+
return !!result;
|
198
|
+
};
|
199
|
+
|
200
|
+
// Determine if at least one element in the object matches a truth test.
|
201
|
+
// Delegates to **ECMAScript 5**'s native `some` if available.
|
202
|
+
// Aliased as `any`.
|
203
|
+
var any = _.some = _.any = function(obj, iterator, context) {
|
204
|
+
iterator || (iterator = _.identity);
|
205
|
+
var result = false;
|
206
|
+
if (obj == null) return result;
|
207
|
+
if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
|
208
|
+
each(obj, function(value, index, list) {
|
209
|
+
if (result || (result = iterator.call(context, value, index, list))) return breaker;
|
210
|
+
});
|
211
|
+
return !!result;
|
212
|
+
};
|
213
|
+
|
214
|
+
// Determine if the array or object contains a given value (using `===`).
|
215
|
+
// Aliased as `include`.
|
216
|
+
_.contains = _.include = function(obj, target) {
|
217
|
+
if (obj == null) return false;
|
218
|
+
if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1;
|
219
|
+
return any(obj, function(value) {
|
220
|
+
return value === target;
|
221
|
+
});
|
222
|
+
};
|
223
|
+
|
224
|
+
// Invoke a method (with arguments) on every item in a collection.
|
225
|
+
_.invoke = function(obj, method) {
|
226
|
+
var args = slice.call(arguments, 2);
|
227
|
+
var isFunc = _.isFunction(method);
|
228
|
+
return _.map(obj, function(value) {
|
229
|
+
return (isFunc ? method : value[method]).apply(value, args);
|
230
|
+
});
|
231
|
+
};
|
232
|
+
|
233
|
+
// Convenience version of a common use case of `map`: fetching a property.
|
234
|
+
_.pluck = function(obj, key) {
|
235
|
+
return _.map(obj, function(value){ return value[key]; });
|
236
|
+
};
|
237
|
+
|
238
|
+
// Convenience version of a common use case of `filter`: selecting only objects
|
239
|
+
// containing specific `key:value` pairs.
|
240
|
+
_.where = function(obj, attrs, first) {
|
241
|
+
if (_.isEmpty(attrs)) return first ? void 0 : [];
|
242
|
+
return _[first ? 'find' : 'filter'](obj, function(value) {
|
243
|
+
for (var key in attrs) {
|
244
|
+
if (attrs[key] !== value[key]) return false;
|
245
|
+
}
|
246
|
+
return true;
|
247
|
+
});
|
248
|
+
};
|
249
|
+
|
250
|
+
// Convenience version of a common use case of `find`: getting the first object
|
251
|
+
// containing specific `key:value` pairs.
|
252
|
+
_.findWhere = function(obj, attrs) {
|
253
|
+
return _.where(obj, attrs, true);
|
254
|
+
};
|
255
|
+
|
256
|
+
// Return the maximum element or (element-based computation).
|
257
|
+
// Can't optimize arrays of integers longer than 65,535 elements.
|
258
|
+
// See [WebKit Bug 80797](https://bugs.webkit.org/show_bug.cgi?id=80797)
|
259
|
+
_.max = function(obj, iterator, context) {
|
260
|
+
if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
|
261
|
+
return Math.max.apply(Math, obj);
|
262
|
+
}
|
263
|
+
if (!iterator && _.isEmpty(obj)) return -Infinity;
|
264
|
+
var result = {computed : -Infinity, value: -Infinity};
|
265
|
+
each(obj, function(value, index, list) {
|
266
|
+
var computed = iterator ? iterator.call(context, value, index, list) : value;
|
267
|
+
computed > result.computed && (result = {value : value, computed : computed});
|
268
|
+
});
|
269
|
+
return result.value;
|
270
|
+
};
|
271
|
+
|
272
|
+
// Return the minimum element (or element-based computation).
|
273
|
+
_.min = function(obj, iterator, context) {
|
274
|
+
if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
|
275
|
+
return Math.min.apply(Math, obj);
|
276
|
+
}
|
277
|
+
if (!iterator && _.isEmpty(obj)) return Infinity;
|
278
|
+
var result = {computed : Infinity, value: Infinity};
|
279
|
+
each(obj, function(value, index, list) {
|
280
|
+
var computed = iterator ? iterator.call(context, value, index, list) : value;
|
281
|
+
computed < result.computed && (result = {value : value, computed : computed});
|
282
|
+
});
|
283
|
+
return result.value;
|
284
|
+
};
|
285
|
+
|
286
|
+
// Shuffle an array, using the modern version of the
|
287
|
+
// [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisher–Yates_shuffle).
|
288
|
+
_.shuffle = function(obj) {
|
289
|
+
var rand;
|
290
|
+
var index = 0;
|
291
|
+
var shuffled = [];
|
292
|
+
each(obj, function(value) {
|
293
|
+
rand = _.random(index++);
|
294
|
+
shuffled[index - 1] = shuffled[rand];
|
295
|
+
shuffled[rand] = value;
|
296
|
+
});
|
297
|
+
return shuffled;
|
298
|
+
};
|
299
|
+
|
300
|
+
// Sample **n** random values from an array.
|
301
|
+
// If **n** is not specified, returns a single random element from the array.
|
302
|
+
// The internal `guard` argument allows it to work with `map`.
|
303
|
+
_.sample = function(obj, n, guard) {
|
304
|
+
if (arguments.length < 2 || guard) {
|
305
|
+
return obj[_.random(obj.length - 1)];
|
306
|
+
}
|
307
|
+
return _.shuffle(obj).slice(0, Math.max(0, n));
|
308
|
+
};
|
309
|
+
|
310
|
+
// An internal function to generate lookup iterators.
|
311
|
+
var lookupIterator = function(value) {
|
312
|
+
return _.isFunction(value) ? value : function(obj){ return obj[value]; };
|
313
|
+
};
|
314
|
+
|
315
|
+
// Sort the object's values by a criterion produced by an iterator.
|
316
|
+
_.sortBy = function(obj, value, context) {
|
317
|
+
var iterator = lookupIterator(value);
|
318
|
+
return _.pluck(_.map(obj, function(value, index, list) {
|
319
|
+
return {
|
320
|
+
value: value,
|
321
|
+
index: index,
|
322
|
+
criteria: iterator.call(context, value, index, list)
|
323
|
+
};
|
324
|
+
}).sort(function(left, right) {
|
325
|
+
var a = left.criteria;
|
326
|
+
var b = right.criteria;
|
327
|
+
if (a !== b) {
|
328
|
+
if (a > b || a === void 0) return 1;
|
329
|
+
if (a < b || b === void 0) return -1;
|
330
|
+
}
|
331
|
+
return left.index - right.index;
|
332
|
+
}), 'value');
|
333
|
+
};
|
334
|
+
|
335
|
+
// An internal function used for aggregate "group by" operations.
|
336
|
+
var group = function(behavior) {
|
337
|
+
return function(obj, value, context) {
|
338
|
+
var result = {};
|
339
|
+
var iterator = value == null ? _.identity : lookupIterator(value);
|
340
|
+
each(obj, function(value, index) {
|
341
|
+
var key = iterator.call(context, value, index, obj);
|
342
|
+
behavior(result, key, value);
|
343
|
+
});
|
344
|
+
return result;
|
345
|
+
};
|
346
|
+
};
|
347
|
+
|
348
|
+
// Groups the object's values by a criterion. Pass either a string attribute
|
349
|
+
// to group by, or a function that returns the criterion.
|
350
|
+
_.groupBy = group(function(result, key, value) {
|
351
|
+
(_.has(result, key) ? result[key] : (result[key] = [])).push(value);
|
352
|
+
});
|
353
|
+
|
354
|
+
// Indexes the object's values by a criterion, similar to `groupBy`, but for
|
355
|
+
// when you know that your index values will be unique.
|
356
|
+
_.indexBy = group(function(result, key, value) {
|
357
|
+
result[key] = value;
|
358
|
+
});
|
359
|
+
|
360
|
+
// Counts instances of an object that group by a certain criterion. Pass
|
361
|
+
// either a string attribute to count by, or a function that returns the
|
362
|
+
// criterion.
|
363
|
+
_.countBy = group(function(result, key) {
|
364
|
+
_.has(result, key) ? result[key]++ : result[key] = 1;
|
365
|
+
});
|
366
|
+
|
367
|
+
// Use a comparator function to figure out the smallest index at which
|
368
|
+
// an object should be inserted so as to maintain order. Uses binary search.
|
369
|
+
_.sortedIndex = function(array, obj, iterator, context) {
|
370
|
+
iterator = iterator == null ? _.identity : lookupIterator(iterator);
|
371
|
+
var value = iterator.call(context, obj);
|
372
|
+
var low = 0, high = array.length;
|
373
|
+
while (low < high) {
|
374
|
+
var mid = (low + high) >>> 1;
|
375
|
+
iterator.call(context, array[mid]) < value ? low = mid + 1 : high = mid;
|
376
|
+
}
|
377
|
+
return low;
|
378
|
+
};
|
379
|
+
|
380
|
+
// Safely create a real, live array from anything iterable.
|
381
|
+
_.toArray = function(obj) {
|
382
|
+
if (!obj) return [];
|
383
|
+
if (_.isArray(obj)) return slice.call(obj);
|
384
|
+
if (obj.length === +obj.length) return _.map(obj, _.identity);
|
385
|
+
return _.values(obj);
|
386
|
+
};
|
387
|
+
|
388
|
+
// Return the number of elements in an object.
|
389
|
+
_.size = function(obj) {
|
390
|
+
if (obj == null) return 0;
|
391
|
+
return (obj.length === +obj.length) ? obj.length : _.keys(obj).length;
|
392
|
+
};
|
393
|
+
|
394
|
+
// Array Functions
|
395
|
+
// ---------------
|
396
|
+
|
397
|
+
// Get the first element of an array. Passing **n** will return the first N
|
398
|
+
// values in the array. Aliased as `head` and `take`. The **guard** check
|
399
|
+
// allows it to work with `_.map`.
|
400
|
+
_.first = _.head = _.take = function(array, n, guard) {
|
401
|
+
if (array == null) return void 0;
|
402
|
+
return (n == null) || guard ? array[0] : slice.call(array, 0, n);
|
403
|
+
};
|
404
|
+
|
405
|
+
// Returns everything but the last entry of the array. Especially useful on
|
406
|
+
// the arguments object. Passing **n** will return all the values in
|
407
|
+
// the array, excluding the last N. The **guard** check allows it to work with
|
408
|
+
// `_.map`.
|
409
|
+
_.initial = function(array, n, guard) {
|
410
|
+
return slice.call(array, 0, array.length - ((n == null) || guard ? 1 : n));
|
411
|
+
};
|
412
|
+
|
413
|
+
// Get the last element of an array. Passing **n** will return the last N
|
414
|
+
// values in the array. The **guard** check allows it to work with `_.map`.
|
415
|
+
_.last = function(array, n, guard) {
|
416
|
+
if (array == null) return void 0;
|
417
|
+
if ((n == null) || guard) {
|
418
|
+
return array[array.length - 1];
|
419
|
+
} else {
|
420
|
+
return slice.call(array, Math.max(array.length - n, 0));
|
421
|
+
}
|
422
|
+
};
|
423
|
+
|
424
|
+
// Returns everything but the first entry of the array. Aliased as `tail` and `drop`.
|
425
|
+
// Especially useful on the arguments object. Passing an **n** will return
|
426
|
+
// the rest N values in the array. The **guard**
|
427
|
+
// check allows it to work with `_.map`.
|
428
|
+
_.rest = _.tail = _.drop = function(array, n, guard) {
|
429
|
+
return slice.call(array, (n == null) || guard ? 1 : n);
|
430
|
+
};
|
431
|
+
|
432
|
+
// Trim out all falsy values from an array.
|
433
|
+
_.compact = function(array) {
|
434
|
+
return _.filter(array, _.identity);
|
435
|
+
};
|
436
|
+
|
437
|
+
// Internal implementation of a recursive `flatten` function.
|
438
|
+
var flatten = function(input, shallow, output) {
|
439
|
+
if (shallow && _.every(input, _.isArray)) {
|
440
|
+
return concat.apply(output, input);
|
441
|
+
}
|
442
|
+
each(input, function(value) {
|
443
|
+
if (_.isArray(value) || _.isArguments(value)) {
|
444
|
+
shallow ? push.apply(output, value) : flatten(value, shallow, output);
|
445
|
+
} else {
|
446
|
+
output.push(value);
|
447
|
+
}
|
448
|
+
});
|
449
|
+
return output;
|
450
|
+
};
|
451
|
+
|
452
|
+
// Flatten out an array, either recursively (by default), or just one level.
|
453
|
+
_.flatten = function(array, shallow) {
|
454
|
+
return flatten(array, shallow, []);
|
455
|
+
};
|
456
|
+
|
457
|
+
// Return a version of the array that does not contain the specified value(s).
|
458
|
+
_.without = function(array) {
|
459
|
+
return _.difference(array, slice.call(arguments, 1));
|
460
|
+
};
|
461
|
+
|
462
|
+
// Produce a duplicate-free version of the array. If the array has already
|
463
|
+
// been sorted, you have the option of using a faster algorithm.
|
464
|
+
// Aliased as `unique`.
|
465
|
+
_.uniq = _.unique = function(array, isSorted, iterator, context) {
|
466
|
+
if (_.isFunction(isSorted)) {
|
467
|
+
context = iterator;
|
468
|
+
iterator = isSorted;
|
469
|
+
isSorted = false;
|
470
|
+
}
|
471
|
+
var initial = iterator ? _.map(array, iterator, context) : array;
|
472
|
+
var results = [];
|
473
|
+
var seen = [];
|
474
|
+
each(initial, function(value, index) {
|
475
|
+
if (isSorted ? (!index || seen[seen.length - 1] !== value) : !_.contains(seen, value)) {
|
476
|
+
seen.push(value);
|
477
|
+
results.push(array[index]);
|
478
|
+
}
|
479
|
+
});
|
480
|
+
return results;
|
481
|
+
};
|
482
|
+
|
483
|
+
// Produce an array that contains the union: each distinct element from all of
|
484
|
+
// the passed-in arrays.
|
485
|
+
_.union = function() {
|
486
|
+
return _.uniq(_.flatten(arguments, true));
|
487
|
+
};
|
488
|
+
|
489
|
+
// Produce an array that contains every item shared between all the
|
490
|
+
// passed-in arrays.
|
491
|
+
_.intersection = function(array) {
|
492
|
+
var rest = slice.call(arguments, 1);
|
493
|
+
return _.filter(_.uniq(array), function(item) {
|
494
|
+
return _.every(rest, function(other) {
|
495
|
+
return _.indexOf(other, item) >= 0;
|
496
|
+
});
|
497
|
+
});
|
498
|
+
};
|
499
|
+
|
500
|
+
// Take the difference between one array and a number of other arrays.
|
501
|
+
// Only the elements present in just the first array will remain.
|
502
|
+
_.difference = function(array) {
|
503
|
+
var rest = concat.apply(ArrayProto, slice.call(arguments, 1));
|
504
|
+
return _.filter(array, function(value){ return !_.contains(rest, value); });
|
505
|
+
};
|
506
|
+
|
507
|
+
// Zip together multiple lists into a single array -- elements that share
|
508
|
+
// an index go together.
|
509
|
+
_.zip = function() {
|
510
|
+
var length = _.max(_.pluck(arguments, "length").concat(0));
|
511
|
+
var results = new Array(length);
|
512
|
+
for (var i = 0; i < length; i++) {
|
513
|
+
results[i] = _.pluck(arguments, '' + i);
|
514
|
+
}
|
515
|
+
return results;
|
516
|
+
};
|
517
|
+
|
518
|
+
// Converts lists into objects. Pass either a single array of `[key, value]`
|
519
|
+
// pairs, or two parallel arrays of the same length -- one of keys, and one of
|
520
|
+
// the corresponding values.
|
521
|
+
_.object = function(list, values) {
|
522
|
+
if (list == null) return {};
|
523
|
+
var result = {};
|
524
|
+
for (var i = 0, length = list.length; i < length; i++) {
|
525
|
+
if (values) {
|
526
|
+
result[list[i]] = values[i];
|
527
|
+
} else {
|
528
|
+
result[list[i][0]] = list[i][1];
|
529
|
+
}
|
530
|
+
}
|
531
|
+
return result;
|
532
|
+
};
|
533
|
+
|
534
|
+
// If the browser doesn't supply us with indexOf (I'm looking at you, **MSIE**),
|
535
|
+
// we need this function. Return the position of the first occurrence of an
|
536
|
+
// item in an array, or -1 if the item is not included in the array.
|
537
|
+
// Delegates to **ECMAScript 5**'s native `indexOf` if available.
|
538
|
+
// If the array is large and already in sort order, pass `true`
|
539
|
+
// for **isSorted** to use binary search.
|
540
|
+
_.indexOf = function(array, item, isSorted) {
|
541
|
+
if (array == null) return -1;
|
542
|
+
var i = 0, length = array.length;
|
543
|
+
if (isSorted) {
|
544
|
+
if (typeof isSorted == 'number') {
|
545
|
+
i = (isSorted < 0 ? Math.max(0, length + isSorted) : isSorted);
|
546
|
+
} else {
|
547
|
+
i = _.sortedIndex(array, item);
|
548
|
+
return array[i] === item ? i : -1;
|
549
|
+
}
|
550
|
+
}
|
551
|
+
if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted);
|
552
|
+
for (; i < length; i++) if (array[i] === item) return i;
|
553
|
+
return -1;
|
554
|
+
};
|
555
|
+
|
556
|
+
// Delegates to **ECMAScript 5**'s native `lastIndexOf` if available.
|
557
|
+
_.lastIndexOf = function(array, item, from) {
|
558
|
+
if (array == null) return -1;
|
559
|
+
var hasIndex = from != null;
|
560
|
+
if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) {
|
561
|
+
return hasIndex ? array.lastIndexOf(item, from) : array.lastIndexOf(item);
|
562
|
+
}
|
563
|
+
var i = (hasIndex ? from : array.length);
|
564
|
+
while (i--) if (array[i] === item) return i;
|
565
|
+
return -1;
|
566
|
+
};
|
567
|
+
|
568
|
+
// Generate an integer Array containing an arithmetic progression. A port of
|
569
|
+
// the native Python `range()` function. See
|
570
|
+
// [the Python documentation](http://docs.python.org/library/functions.html#range).
|
571
|
+
_.range = function(start, stop, step) {
|
572
|
+
if (arguments.length <= 1) {
|
573
|
+
stop = start || 0;
|
574
|
+
start = 0;
|
575
|
+
}
|
576
|
+
step = arguments[2] || 1;
|
577
|
+
|
578
|
+
var length = Math.max(Math.ceil((stop - start) / step), 0);
|
579
|
+
var idx = 0;
|
580
|
+
var range = new Array(length);
|
581
|
+
|
582
|
+
while(idx < length) {
|
583
|
+
range[idx++] = start;
|
584
|
+
start += step;
|
585
|
+
}
|
586
|
+
|
587
|
+
return range;
|
588
|
+
};
|
589
|
+
|
590
|
+
// Function (ahem) Functions
|
591
|
+
// ------------------
|
592
|
+
|
593
|
+
// Reusable constructor function for prototype setting.
|
594
|
+
var ctor = function(){};
|
595
|
+
|
596
|
+
// Create a function bound to a given object (assigning `this`, and arguments,
|
597
|
+
// optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
|
598
|
+
// available.
|
599
|
+
_.bind = function(func, context) {
|
600
|
+
var args, bound;
|
601
|
+
if (nativeBind && func.bind === nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
|
602
|
+
if (!_.isFunction(func)) throw new TypeError;
|
603
|
+
args = slice.call(arguments, 2);
|
604
|
+
return bound = function() {
|
605
|
+
if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments)));
|
606
|
+
ctor.prototype = func.prototype;
|
607
|
+
var self = new ctor;
|
608
|
+
ctor.prototype = null;
|
609
|
+
var result = func.apply(self, args.concat(slice.call(arguments)));
|
610
|
+
if (Object(result) === result) return result;
|
611
|
+
return self;
|
612
|
+
};
|
613
|
+
};
|
614
|
+
|
615
|
+
// Partially apply a function by creating a version that has had some of its
|
616
|
+
// arguments pre-filled, without changing its dynamic `this` context.
|
617
|
+
_.partial = function(func) {
|
618
|
+
var args = slice.call(arguments, 1);
|
619
|
+
return function() {
|
620
|
+
return func.apply(this, args.concat(slice.call(arguments)));
|
621
|
+
};
|
622
|
+
};
|
623
|
+
|
624
|
+
// Bind all of an object's methods to that object. Useful for ensuring that
|
625
|
+
// all callbacks defined on an object belong to it.
|
626
|
+
_.bindAll = function(obj) {
|
627
|
+
var funcs = slice.call(arguments, 1);
|
628
|
+
if (funcs.length === 0) throw new Error("bindAll must be passed function names");
|
629
|
+
each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); });
|
630
|
+
return obj;
|
631
|
+
};
|
632
|
+
|
633
|
+
// Memoize an expensive function by storing its results.
|
634
|
+
_.memoize = function(func, hasher) {
|
635
|
+
var memo = {};
|
636
|
+
hasher || (hasher = _.identity);
|
637
|
+
return function() {
|
638
|
+
var key = hasher.apply(this, arguments);
|
639
|
+
return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments));
|
640
|
+
};
|
641
|
+
};
|
642
|
+
|
643
|
+
// Delays a function for the given number of milliseconds, and then calls
|
644
|
+
// it with the arguments supplied.
|
645
|
+
_.delay = function(func, wait) {
|
646
|
+
var args = slice.call(arguments, 2);
|
647
|
+
return setTimeout(function(){ return func.apply(null, args); }, wait);
|
648
|
+
};
|
649
|
+
|
650
|
+
// Defers a function, scheduling it to run after the current call stack has
|
651
|
+
// cleared.
|
652
|
+
_.defer = function(func) {
|
653
|
+
return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1)));
|
654
|
+
};
|
655
|
+
|
656
|
+
// Returns a function, that, when invoked, will only be triggered at most once
|
657
|
+
// during a given window of time. Normally, the throttled function will run
|
658
|
+
// as much as it can, without ever going more than once per `wait` duration;
|
659
|
+
// but if you'd like to disable the execution on the leading edge, pass
|
660
|
+
// `{leading: false}`. To disable execution on the trailing edge, ditto.
|
661
|
+
_.throttle = function(func, wait, options) {
|
662
|
+
var context, args, result;
|
663
|
+
var timeout = null;
|
664
|
+
var previous = 0;
|
665
|
+
options || (options = {});
|
666
|
+
var later = function() {
|
667
|
+
previous = options.leading === false ? 0 : new Date;
|
668
|
+
timeout = null;
|
669
|
+
result = func.apply(context, args);
|
670
|
+
};
|
671
|
+
return function() {
|
672
|
+
var now = new Date;
|
673
|
+
if (!previous && options.leading === false) previous = now;
|
674
|
+
var remaining = wait - (now - previous);
|
675
|
+
context = this;
|
676
|
+
args = arguments;
|
677
|
+
if (remaining <= 0) {
|
678
|
+
clearTimeout(timeout);
|
679
|
+
timeout = null;
|
680
|
+
previous = now;
|
681
|
+
result = func.apply(context, args);
|
682
|
+
} else if (!timeout && options.trailing !== false) {
|
683
|
+
timeout = setTimeout(later, remaining);
|
684
|
+
}
|
685
|
+
return result;
|
686
|
+
};
|
687
|
+
};
|
688
|
+
|
689
|
+
// Returns a function, that, as long as it continues to be invoked, will not
|
690
|
+
// be triggered. The function will be called after it stops being called for
|
691
|
+
// N milliseconds. If `immediate` is passed, trigger the function on the
|
692
|
+
// leading edge, instead of the trailing.
|
693
|
+
_.debounce = function(func, wait, immediate) {
|
694
|
+
var timeout, args, context, timestamp, result;
|
695
|
+
return function() {
|
696
|
+
context = this;
|
697
|
+
args = arguments;
|
698
|
+
timestamp = new Date();
|
699
|
+
var later = function() {
|
700
|
+
var last = (new Date()) - timestamp;
|
701
|
+
if (last < wait) {
|
702
|
+
timeout = setTimeout(later, wait - last);
|
703
|
+
} else {
|
704
|
+
timeout = null;
|
705
|
+
if (!immediate) result = func.apply(context, args);
|
706
|
+
}
|
707
|
+
};
|
708
|
+
var callNow = immediate && !timeout;
|
709
|
+
if (!timeout) {
|
710
|
+
timeout = setTimeout(later, wait);
|
711
|
+
}
|
712
|
+
if (callNow) result = func.apply(context, args);
|
713
|
+
return result;
|
714
|
+
};
|
715
|
+
};
|
716
|
+
|
717
|
+
// Returns a function that will be executed at most one time, no matter how
|
718
|
+
// often you call it. Useful for lazy initialization.
|
719
|
+
_.once = function(func) {
|
720
|
+
var ran = false, memo;
|
721
|
+
return function() {
|
722
|
+
if (ran) return memo;
|
723
|
+
ran = true;
|
724
|
+
memo = func.apply(this, arguments);
|
725
|
+
func = null;
|
726
|
+
return memo;
|
727
|
+
};
|
728
|
+
};
|
729
|
+
|
730
|
+
// Returns the first function passed as an argument to the second,
|
731
|
+
// allowing you to adjust arguments, run code before and after, and
|
732
|
+
// conditionally execute the original function.
|
733
|
+
_.wrap = function(func, wrapper) {
|
734
|
+
return function() {
|
735
|
+
var args = [func];
|
736
|
+
push.apply(args, arguments);
|
737
|
+
return wrapper.apply(this, args);
|
738
|
+
};
|
739
|
+
};
|
740
|
+
|
741
|
+
// Returns a function that is the composition of a list of functions, each
|
742
|
+
// consuming the return value of the function that follows.
|
743
|
+
_.compose = function() {
|
744
|
+
var funcs = arguments;
|
745
|
+
return function() {
|
746
|
+
var args = arguments;
|
747
|
+
for (var i = funcs.length - 1; i >= 0; i--) {
|
748
|
+
args = [funcs[i].apply(this, args)];
|
749
|
+
}
|
750
|
+
return args[0];
|
751
|
+
};
|
752
|
+
};
|
753
|
+
|
754
|
+
// Returns a function that will only be executed after being called N times.
|
755
|
+
_.after = function(times, func) {
|
756
|
+
return function() {
|
757
|
+
if (--times < 1) {
|
758
|
+
return func.apply(this, arguments);
|
759
|
+
}
|
760
|
+
};
|
761
|
+
};
|
762
|
+
|
763
|
+
// Object Functions
|
764
|
+
// ----------------
|
765
|
+
|
766
|
+
// Retrieve the names of an object's properties.
|
767
|
+
// Delegates to **ECMAScript 5**'s native `Object.keys`
|
768
|
+
_.keys = nativeKeys || function(obj) {
|
769
|
+
if (obj !== Object(obj)) throw new TypeError('Invalid object');
|
770
|
+
var keys = [];
|
771
|
+
for (var key in obj) if (_.has(obj, key)) keys.push(key);
|
772
|
+
return keys;
|
773
|
+
};
|
774
|
+
|
775
|
+
// Retrieve the values of an object's properties.
|
776
|
+
_.values = function(obj) {
|
777
|
+
var keys = _.keys(obj);
|
778
|
+
var length = keys.length;
|
779
|
+
var values = new Array(length);
|
780
|
+
for (var i = 0; i < length; i++) {
|
781
|
+
values[i] = obj[keys[i]];
|
782
|
+
}
|
783
|
+
return values;
|
784
|
+
};
|
785
|
+
|
786
|
+
// Convert an object into a list of `[key, value]` pairs.
|
787
|
+
_.pairs = function(obj) {
|
788
|
+
var keys = _.keys(obj);
|
789
|
+
var length = keys.length;
|
790
|
+
var pairs = new Array(length);
|
791
|
+
for (var i = 0; i < length; i++) {
|
792
|
+
pairs[i] = [keys[i], obj[keys[i]]];
|
793
|
+
}
|
794
|
+
return pairs;
|
795
|
+
};
|
796
|
+
|
797
|
+
// Invert the keys and values of an object. The values must be serializable.
|
798
|
+
_.invert = function(obj) {
|
799
|
+
var result = {};
|
800
|
+
var keys = _.keys(obj);
|
801
|
+
for (var i = 0, length = keys.length; i < length; i++) {
|
802
|
+
result[obj[keys[i]]] = keys[i];
|
803
|
+
}
|
804
|
+
return result;
|
805
|
+
};
|
806
|
+
|
807
|
+
// Return a sorted list of the function names available on the object.
|
808
|
+
// Aliased as `methods`
|
809
|
+
_.functions = _.methods = function(obj) {
|
810
|
+
var names = [];
|
811
|
+
for (var key in obj) {
|
812
|
+
if (_.isFunction(obj[key])) names.push(key);
|
813
|
+
}
|
814
|
+
return names.sort();
|
815
|
+
};
|
816
|
+
|
817
|
+
// Extend a given object with all the properties in passed-in object(s).
|
818
|
+
_.extend = function(obj) {
|
819
|
+
each(slice.call(arguments, 1), function(source) {
|
820
|
+
if (source) {
|
821
|
+
for (var prop in source) {
|
822
|
+
obj[prop] = source[prop];
|
823
|
+
}
|
824
|
+
}
|
825
|
+
});
|
826
|
+
return obj;
|
827
|
+
};
|
828
|
+
|
829
|
+
// Return a copy of the object only containing the whitelisted properties.
|
830
|
+
_.pick = function(obj) {
|
831
|
+
var copy = {};
|
832
|
+
var keys = concat.apply(ArrayProto, slice.call(arguments, 1));
|
833
|
+
each(keys, function(key) {
|
834
|
+
if (key in obj) copy[key] = obj[key];
|
835
|
+
});
|
836
|
+
return copy;
|
837
|
+
};
|
838
|
+
|
839
|
+
// Return a copy of the object without the blacklisted properties.
|
840
|
+
_.omit = function(obj) {
|
841
|
+
var copy = {};
|
842
|
+
var keys = concat.apply(ArrayProto, slice.call(arguments, 1));
|
843
|
+
for (var key in obj) {
|
844
|
+
if (!_.contains(keys, key)) copy[key] = obj[key];
|
845
|
+
}
|
846
|
+
return copy;
|
847
|
+
};
|
848
|
+
|
849
|
+
// Fill in a given object with default properties.
|
850
|
+
_.defaults = function(obj) {
|
851
|
+
each(slice.call(arguments, 1), function(source) {
|
852
|
+
if (source) {
|
853
|
+
for (var prop in source) {
|
854
|
+
if (obj[prop] === void 0) obj[prop] = source[prop];
|
855
|
+
}
|
856
|
+
}
|
857
|
+
});
|
858
|
+
return obj;
|
859
|
+
};
|
860
|
+
|
861
|
+
// Create a (shallow-cloned) duplicate of an object.
|
862
|
+
_.clone = function(obj) {
|
863
|
+
if (!_.isObject(obj)) return obj;
|
864
|
+
return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
|
865
|
+
};
|
866
|
+
|
867
|
+
// Invokes interceptor with the obj, and then returns obj.
|
868
|
+
// The primary purpose of this method is to "tap into" a method chain, in
|
869
|
+
// order to perform operations on intermediate results within the chain.
|
870
|
+
_.tap = function(obj, interceptor) {
|
871
|
+
interceptor(obj);
|
872
|
+
return obj;
|
873
|
+
};
|
874
|
+
|
875
|
+
// Internal recursive comparison function for `isEqual`.
|
876
|
+
var eq = function(a, b, aStack, bStack) {
|
877
|
+
// Identical objects are equal. `0 === -0`, but they aren't identical.
|
878
|
+
// See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
|
879
|
+
if (a === b) return a !== 0 || 1 / a == 1 / b;
|
880
|
+
// A strict comparison is necessary because `null == undefined`.
|
881
|
+
if (a == null || b == null) return a === b;
|
882
|
+
// Unwrap any wrapped objects.
|
883
|
+
if (a instanceof _) a = a._wrapped;
|
884
|
+
if (b instanceof _) b = b._wrapped;
|
885
|
+
// Compare `[[Class]]` names.
|
886
|
+
var className = toString.call(a);
|
887
|
+
if (className != toString.call(b)) return false;
|
888
|
+
switch (className) {
|
889
|
+
// Strings, numbers, dates, and booleans are compared by value.
|
890
|
+
case '[object String]':
|
891
|
+
// Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
|
892
|
+
// equivalent to `new String("5")`.
|
893
|
+
return a == String(b);
|
894
|
+
case '[object Number]':
|
895
|
+
// `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for
|
896
|
+
// other numeric values.
|
897
|
+
return a != +a ? b != +b : (a == 0 ? 1 / a == 1 / b : a == +b);
|
898
|
+
case '[object Date]':
|
899
|
+
case '[object Boolean]':
|
900
|
+
// Coerce dates and booleans to numeric primitive values. Dates are compared by their
|
901
|
+
// millisecond representations. Note that invalid dates with millisecond representations
|
902
|
+
// of `NaN` are not equivalent.
|
903
|
+
return +a == +b;
|
904
|
+
// RegExps are compared by their source patterns and flags.
|
905
|
+
case '[object RegExp]':
|
906
|
+
return a.source == b.source &&
|
907
|
+
a.global == b.global &&
|
908
|
+
a.multiline == b.multiline &&
|
909
|
+
a.ignoreCase == b.ignoreCase;
|
910
|
+
}
|
911
|
+
if (typeof a != 'object' || typeof b != 'object') return false;
|
912
|
+
// Assume equality for cyclic structures. The algorithm for detecting cyclic
|
913
|
+
// structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
|
914
|
+
var length = aStack.length;
|
915
|
+
while (length--) {
|
916
|
+
// Linear search. Performance is inversely proportional to the number of
|
917
|
+
// unique nested structures.
|
918
|
+
if (aStack[length] == a) return bStack[length] == b;
|
919
|
+
}
|
920
|
+
// Objects with different constructors are not equivalent, but `Object`s
|
921
|
+
// from different frames are.
|
922
|
+
var aCtor = a.constructor, bCtor = b.constructor;
|
923
|
+
if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) &&
|
924
|
+
_.isFunction(bCtor) && (bCtor instanceof bCtor))) {
|
925
|
+
return false;
|
926
|
+
}
|
927
|
+
// Add the first object to the stack of traversed objects.
|
928
|
+
aStack.push(a);
|
929
|
+
bStack.push(b);
|
930
|
+
var size = 0, result = true;
|
931
|
+
// Recursively compare objects and arrays.
|
932
|
+
if (className == '[object Array]') {
|
933
|
+
// Compare array lengths to determine if a deep comparison is necessary.
|
934
|
+
size = a.length;
|
935
|
+
result = size == b.length;
|
936
|
+
if (result) {
|
937
|
+
// Deep compare the contents, ignoring non-numeric properties.
|
938
|
+
while (size--) {
|
939
|
+
if (!(result = eq(a[size], b[size], aStack, bStack))) break;
|
940
|
+
}
|
941
|
+
}
|
942
|
+
} else {
|
943
|
+
// Deep compare objects.
|
944
|
+
for (var key in a) {
|
945
|
+
if (_.has(a, key)) {
|
946
|
+
// Count the expected number of properties.
|
947
|
+
size++;
|
948
|
+
// Deep compare each member.
|
949
|
+
if (!(result = _.has(b, key) && eq(a[key], b[key], aStack, bStack))) break;
|
950
|
+
}
|
951
|
+
}
|
952
|
+
// Ensure that both objects contain the same number of properties.
|
953
|
+
if (result) {
|
954
|
+
for (key in b) {
|
955
|
+
if (_.has(b, key) && !(size--)) break;
|
956
|
+
}
|
957
|
+
result = !size;
|
958
|
+
}
|
959
|
+
}
|
960
|
+
// Remove the first object from the stack of traversed objects.
|
961
|
+
aStack.pop();
|
962
|
+
bStack.pop();
|
963
|
+
return result;
|
964
|
+
};
|
965
|
+
|
966
|
+
// Perform a deep comparison to check if two objects are equal.
|
967
|
+
_.isEqual = function(a, b) {
|
968
|
+
return eq(a, b, [], []);
|
969
|
+
};
|
970
|
+
|
971
|
+
// Is a given array, string, or object empty?
|
972
|
+
// An "empty" object has no enumerable own-properties.
|
973
|
+
_.isEmpty = function(obj) {
|
974
|
+
if (obj == null) return true;
|
975
|
+
if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
|
976
|
+
for (var key in obj) if (_.has(obj, key)) return false;
|
977
|
+
return true;
|
978
|
+
};
|
979
|
+
|
980
|
+
// Is a given value a DOM element?
|
981
|
+
_.isElement = function(obj) {
|
982
|
+
return !!(obj && obj.nodeType === 1);
|
983
|
+
};
|
984
|
+
|
985
|
+
// Is a given value an array?
|
986
|
+
// Delegates to ECMA5's native Array.isArray
|
987
|
+
_.isArray = nativeIsArray || function(obj) {
|
988
|
+
return toString.call(obj) == '[object Array]';
|
989
|
+
};
|
990
|
+
|
991
|
+
// Is a given variable an object?
|
992
|
+
_.isObject = function(obj) {
|
993
|
+
return obj === Object(obj);
|
994
|
+
};
|
995
|
+
|
996
|
+
// Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp.
|
997
|
+
each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) {
|
998
|
+
_['is' + name] = function(obj) {
|
999
|
+
return toString.call(obj) == '[object ' + name + ']';
|
1000
|
+
};
|
1001
|
+
});
|
1002
|
+
|
1003
|
+
// Define a fallback version of the method in browsers (ahem, IE), where
|
1004
|
+
// there isn't any inspectable "Arguments" type.
|
1005
|
+
if (!_.isArguments(arguments)) {
|
1006
|
+
_.isArguments = function(obj) {
|
1007
|
+
return !!(obj && _.has(obj, 'callee'));
|
1008
|
+
};
|
1009
|
+
}
|
1010
|
+
|
1011
|
+
// Optimize `isFunction` if appropriate.
|
1012
|
+
if (typeof (/./) !== 'function') {
|
1013
|
+
_.isFunction = function(obj) {
|
1014
|
+
return typeof obj === 'function';
|
1015
|
+
};
|
1016
|
+
}
|
1017
|
+
|
1018
|
+
// Is a given object a finite number?
|
1019
|
+
_.isFinite = function(obj) {
|
1020
|
+
return isFinite(obj) && !isNaN(parseFloat(obj));
|
1021
|
+
};
|
1022
|
+
|
1023
|
+
// Is the given value `NaN`? (NaN is the only number which does not equal itself).
|
1024
|
+
_.isNaN = function(obj) {
|
1025
|
+
return _.isNumber(obj) && obj != +obj;
|
1026
|
+
};
|
1027
|
+
|
1028
|
+
// Is a given value a boolean?
|
1029
|
+
_.isBoolean = function(obj) {
|
1030
|
+
return obj === true || obj === false || toString.call(obj) == '[object Boolean]';
|
1031
|
+
};
|
1032
|
+
|
1033
|
+
// Is a given value equal to null?
|
1034
|
+
_.isNull = function(obj) {
|
1035
|
+
return obj === null;
|
1036
|
+
};
|
1037
|
+
|
1038
|
+
// Is a given variable undefined?
|
1039
|
+
_.isUndefined = function(obj) {
|
1040
|
+
return obj === void 0;
|
1041
|
+
};
|
1042
|
+
|
1043
|
+
// Shortcut function for checking if an object has a given property directly
|
1044
|
+
// on itself (in other words, not on a prototype).
|
1045
|
+
_.has = function(obj, key) {
|
1046
|
+
return hasOwnProperty.call(obj, key);
|
1047
|
+
};
|
1048
|
+
|
1049
|
+
// Utility Functions
|
1050
|
+
// -----------------
|
1051
|
+
|
1052
|
+
// Run Underscore.js in *noConflict* mode, returning the `_` variable to its
|
1053
|
+
// previous owner. Returns a reference to the Underscore object.
|
1054
|
+
_.noConflict = function() {
|
1055
|
+
root._ = previousUnderscore;
|
1056
|
+
return this;
|
1057
|
+
};
|
1058
|
+
|
1059
|
+
// Keep the identity function around for default iterators.
|
1060
|
+
_.identity = function(value) {
|
1061
|
+
return value;
|
1062
|
+
};
|
1063
|
+
|
1064
|
+
// Run a function **n** times.
|
1065
|
+
_.times = function(n, iterator, context) {
|
1066
|
+
var accum = Array(Math.max(0, n));
|
1067
|
+
for (var i = 0; i < n; i++) accum[i] = iterator.call(context, i);
|
1068
|
+
return accum;
|
1069
|
+
};
|
1070
|
+
|
1071
|
+
// Return a random integer between min and max (inclusive).
|
1072
|
+
_.random = function(min, max) {
|
1073
|
+
if (max == null) {
|
1074
|
+
max = min;
|
1075
|
+
min = 0;
|
1076
|
+
}
|
1077
|
+
return min + Math.floor(Math.random() * (max - min + 1));
|
1078
|
+
};
|
1079
|
+
|
1080
|
+
// List of HTML entities for escaping.
|
1081
|
+
var entityMap = {
|
1082
|
+
escape: {
|
1083
|
+
'&': '&',
|
1084
|
+
'<': '<',
|
1085
|
+
'>': '>',
|
1086
|
+
'"': '"',
|
1087
|
+
"'": '''
|
1088
|
+
}
|
1089
|
+
};
|
1090
|
+
entityMap.unescape = _.invert(entityMap.escape);
|
1091
|
+
|
1092
|
+
// Regexes containing the keys and values listed immediately above.
|
1093
|
+
var entityRegexes = {
|
1094
|
+
escape: new RegExp('[' + _.keys(entityMap.escape).join('') + ']', 'g'),
|
1095
|
+
unescape: new RegExp('(' + _.keys(entityMap.unescape).join('|') + ')', 'g')
|
1096
|
+
};
|
1097
|
+
|
1098
|
+
// Functions for escaping and unescaping strings to/from HTML interpolation.
|
1099
|
+
_.each(['escape', 'unescape'], function(method) {
|
1100
|
+
_[method] = function(string) {
|
1101
|
+
if (string == null) return '';
|
1102
|
+
return ('' + string).replace(entityRegexes[method], function(match) {
|
1103
|
+
return entityMap[method][match];
|
1104
|
+
});
|
1105
|
+
};
|
1106
|
+
});
|
1107
|
+
|
1108
|
+
// If the value of the named `property` is a function then invoke it with the
|
1109
|
+
// `object` as context; otherwise, return it.
|
1110
|
+
_.result = function(object, property) {
|
1111
|
+
if (object == null) return void 0;
|
1112
|
+
var value = object[property];
|
1113
|
+
return _.isFunction(value) ? value.call(object) : value;
|
1114
|
+
};
|
1115
|
+
|
1116
|
+
// Add your own custom functions to the Underscore object.
|
1117
|
+
_.mixin = function(obj) {
|
1118
|
+
each(_.functions(obj), function(name) {
|
1119
|
+
var func = _[name] = obj[name];
|
1120
|
+
_.prototype[name] = function() {
|
1121
|
+
var args = [this._wrapped];
|
1122
|
+
push.apply(args, arguments);
|
1123
|
+
return result.call(this, func.apply(_, args));
|
1124
|
+
};
|
1125
|
+
});
|
1126
|
+
};
|
1127
|
+
|
1128
|
+
// Generate a unique integer id (unique within the entire client session).
|
1129
|
+
// Useful for temporary DOM ids.
|
1130
|
+
var idCounter = 0;
|
1131
|
+
_.uniqueId = function(prefix) {
|
1132
|
+
var id = ++idCounter + '';
|
1133
|
+
return prefix ? prefix + id : id;
|
1134
|
+
};
|
1135
|
+
|
1136
|
+
// By default, Underscore uses ERB-style template delimiters, change the
|
1137
|
+
// following template settings to use alternative delimiters.
|
1138
|
+
_.templateSettings = {
|
1139
|
+
evaluate : /<%([\s\S]+?)%>/g,
|
1140
|
+
interpolate : /<%=([\s\S]+?)%>/g,
|
1141
|
+
escape : /<%-([\s\S]+?)%>/g
|
1142
|
+
};
|
1143
|
+
|
1144
|
+
// When customizing `templateSettings`, if you don't want to define an
|
1145
|
+
// interpolation, evaluation or escaping regex, we need one that is
|
1146
|
+
// guaranteed not to match.
|
1147
|
+
var noMatch = /(.)^/;
|
1148
|
+
|
1149
|
+
// Certain characters need to be escaped so that they can be put into a
|
1150
|
+
// string literal.
|
1151
|
+
var escapes = {
|
1152
|
+
"'": "'",
|
1153
|
+
'\\': '\\',
|
1154
|
+
'\r': 'r',
|
1155
|
+
'\n': 'n',
|
1156
|
+
'\t': 't',
|
1157
|
+
'\u2028': 'u2028',
|
1158
|
+
'\u2029': 'u2029'
|
1159
|
+
};
|
1160
|
+
|
1161
|
+
var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g;
|
1162
|
+
|
1163
|
+
// JavaScript micro-templating, similar to John Resig's implementation.
|
1164
|
+
// Underscore templating handles arbitrary delimiters, preserves whitespace,
|
1165
|
+
// and correctly escapes quotes within interpolated code.
|
1166
|
+
_.template = function(text, data, settings) {
|
1167
|
+
var render;
|
1168
|
+
settings = _.defaults({}, settings, _.templateSettings);
|
1169
|
+
|
1170
|
+
// Combine delimiters into one regular expression via alternation.
|
1171
|
+
var matcher = new RegExp([
|
1172
|
+
(settings.escape || noMatch).source,
|
1173
|
+
(settings.interpolate || noMatch).source,
|
1174
|
+
(settings.evaluate || noMatch).source
|
1175
|
+
].join('|') + '|$', 'g');
|
1176
|
+
|
1177
|
+
// Compile the template source, escaping string literals appropriately.
|
1178
|
+
var index = 0;
|
1179
|
+
var source = "__p+='";
|
1180
|
+
text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
|
1181
|
+
source += text.slice(index, offset)
|
1182
|
+
.replace(escaper, function(match) { return '\\' + escapes[match]; });
|
1183
|
+
|
1184
|
+
if (escape) {
|
1185
|
+
source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
|
1186
|
+
}
|
1187
|
+
if (interpolate) {
|
1188
|
+
source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
|
1189
|
+
}
|
1190
|
+
if (evaluate) {
|
1191
|
+
source += "';\n" + evaluate + "\n__p+='";
|
1192
|
+
}
|
1193
|
+
index = offset + match.length;
|
1194
|
+
return match;
|
1195
|
+
});
|
1196
|
+
source += "';\n";
|
1197
|
+
|
1198
|
+
// If a variable is not specified, place data values in local scope.
|
1199
|
+
if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
|
1200
|
+
|
1201
|
+
source = "var __t,__p='',__j=Array.prototype.join," +
|
1202
|
+
"print=function(){__p+=__j.call(arguments,'');};\n" +
|
1203
|
+
source + "return __p;\n";
|
1204
|
+
|
1205
|
+
try {
|
1206
|
+
render = new Function(settings.variable || 'obj', '_', source);
|
1207
|
+
} catch (e) {
|
1208
|
+
e.source = source;
|
1209
|
+
throw e;
|
1210
|
+
}
|
1211
|
+
|
1212
|
+
if (data) return render(data, _);
|
1213
|
+
var template = function(data) {
|
1214
|
+
return render.call(this, data, _);
|
1215
|
+
};
|
1216
|
+
|
1217
|
+
// Provide the compiled function source as a convenience for precompilation.
|
1218
|
+
template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}';
|
1219
|
+
|
1220
|
+
return template;
|
1221
|
+
};
|
1222
|
+
|
1223
|
+
// Add a "chain" function, which will delegate to the wrapper.
|
1224
|
+
_.chain = function(obj) {
|
1225
|
+
return _(obj).chain();
|
1226
|
+
};
|
1227
|
+
|
1228
|
+
// OOP
|
1229
|
+
// ---------------
|
1230
|
+
// If Underscore is called as a function, it returns a wrapped object that
|
1231
|
+
// can be used OO-style. This wrapper holds altered versions of all the
|
1232
|
+
// underscore functions. Wrapped objects may be chained.
|
1233
|
+
|
1234
|
+
// Helper function to continue chaining intermediate results.
|
1235
|
+
var result = function(obj) {
|
1236
|
+
return this._chain ? _(obj).chain() : obj;
|
1237
|
+
};
|
1238
|
+
|
1239
|
+
// Add all of the Underscore functions to the wrapper object.
|
1240
|
+
_.mixin(_);
|
1241
|
+
|
1242
|
+
// Add all mutator Array functions to the wrapper.
|
1243
|
+
each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
|
1244
|
+
var method = ArrayProto[name];
|
1245
|
+
_.prototype[name] = function() {
|
1246
|
+
var obj = this._wrapped;
|
1247
|
+
method.apply(obj, arguments);
|
1248
|
+
if ((name == 'shift' || name == 'splice') && obj.length === 0) delete obj[0];
|
1249
|
+
return result.call(this, obj);
|
1250
|
+
};
|
1251
|
+
});
|
1252
|
+
|
1253
|
+
// Add all accessor Array functions to the wrapper.
|
1254
|
+
each(['concat', 'join', 'slice'], function(name) {
|
1255
|
+
var method = ArrayProto[name];
|
1256
|
+
_.prototype[name] = function() {
|
1257
|
+
return result.call(this, method.apply(this._wrapped, arguments));
|
1258
|
+
};
|
1259
|
+
});
|
1260
|
+
|
1261
|
+
_.extend(_.prototype, {
|
1262
|
+
|
1263
|
+
// Start chaining a wrapped Underscore object.
|
1264
|
+
chain: function() {
|
1265
|
+
this._chain = true;
|
1266
|
+
return this;
|
1267
|
+
},
|
1268
|
+
|
1269
|
+
// Extracts the result from a wrapped and chained object.
|
1270
|
+
value: function() {
|
1271
|
+
return this._wrapped;
|
1272
|
+
}
|
1273
|
+
|
1274
|
+
});
|
1275
|
+
|
1276
|
+
}).call(this);
|