initialServiceScriptText.js 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273
  1. //Core, Array, String, Function, Number, Class, Object, Object.Extras, Locale, Date, Locale.en-US.Date, Locale.zh-CH.Date, JSON
  2. /*
  3. ---
  4. name: Prefix
  5. description: Loads MooTools as a CommonJS Module.
  6. license: MIT-style license.
  7. copyright: Copyright (c) 2010 [Christoph Pojer](http://cpojer.net/).
  8. authors: Christoph Pojer
  9. provides: [Prefix]
  10. ...
  11. */
  12. var GLOBAL_ITEMS = function(){
  13. var items = [];
  14. for (var key in this)
  15. items.push(key);
  16. return items;
  17. }();
  18. /*
  19. ---
  20. name: Core
  21. description: The heart of MooTools.
  22. license: MIT-style license.
  23. copyright: Copyright (c) 2006-2012 [Valerio Proietti](http://mad4milk.net/).
  24. authors: The MooTools production team (http://mootools.net/developers/)
  25. inspiration:
  26. - Class implementation inspired by [Base.js](http://dean.edwards.name/weblog/2006/03/base/) Copyright (c) 2006 Dean Edwards, [GNU Lesser General Public License](http://opensource.org/licenses/lgpl-license.php)
  27. - Some functionality inspired by [Prototype.js](http://prototypejs.org) Copyright (c) 2005-2007 Sam Stephenson, [MIT License](http://opensource.org/licenses/mit-license.php)
  28. provides: [Core, MooTools, Type, typeOf, instanceOf, Native]
  29. ...
  30. */
  31. (function(){
  32. this.MooTools = {
  33. version: '1.5.0dev',
  34. build: '%build%'
  35. };
  36. // typeOf, instanceOf
  37. var typeOf = this.typeOf = function(item){
  38. if (item == null) return 'null';
  39. if (item.$family != null) return item.$family();
  40. if (item.nodeName){
  41. if (item.nodeType == 1) return 'element';
  42. if (item.nodeType == 3) return (/\S/).test(item.nodeValue) ? 'textnode' : 'whitespace';
  43. } else if (typeof item.length == 'number'){
  44. if (item.callee) return 'arguments';
  45. if ('item' in item) return 'collection';
  46. }
  47. return typeof item;
  48. };
  49. var instanceOf = this.instanceOf = function(item, object){
  50. if (item == null) return false;
  51. var constructor = item.$constructor || item.constructor;
  52. while (constructor){
  53. if (constructor === object) return true;
  54. constructor = constructor.parent;
  55. }
  56. /*<ltIE8>*/
  57. if (!item.hasOwnProperty) return false;
  58. /*</ltIE8>*/
  59. return item instanceof object;
  60. };
  61. // Function overloading
  62. var Function = this.Function;
  63. var enumerables = true;
  64. for (var i in {toString: 1}) enumerables = null;
  65. if (enumerables) enumerables = ['hasOwnProperty', 'valueOf', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'constructor'];
  66. Function.prototype.overloadSetter = function(usePlural){
  67. var self = this;
  68. return function(a, b){
  69. if (a == null) return this;
  70. if (usePlural || typeof a != 'string'){
  71. for (var k in a) self.call(this, k, a[k]);
  72. if (enumerables) for (var i = enumerables.length; i--;){
  73. k = enumerables[i];
  74. if (a.hasOwnProperty(k)) self.call(this, k, a[k]);
  75. }
  76. } else {
  77. self.call(this, a, b);
  78. }
  79. return this;
  80. };
  81. };
  82. Function.prototype.overloadGetter = function(usePlural){
  83. var self = this;
  84. return function(a){
  85. var args, result;
  86. if (typeof a != 'string') args = a;
  87. else if (arguments.length > 1) args = arguments;
  88. else if (usePlural) args = [a];
  89. if (args){
  90. result = {};
  91. for (var i = 0; i < args.length; i++) result[args[i]] = self.call(this, args[i]);
  92. } else {
  93. result = self.call(this, a);
  94. }
  95. return result;
  96. };
  97. };
  98. Function.prototype.extend = function(key, value){
  99. this[key] = value;
  100. }.overloadSetter();
  101. Function.prototype.implement = function(key, value){
  102. this.prototype[key] = value;
  103. }.overloadSetter();
  104. // From
  105. var slice = Array.prototype.slice;
  106. Function.from = function(item){
  107. return (typeOf(item) == 'function') ? item : function(){
  108. return item;
  109. };
  110. };
  111. Function.convert = Function.from;
  112. Array.from = function(item){
  113. if (item == null) return [];
  114. return (Type.isEnumerable(item) && typeof item != 'string') ? (typeOf(item) == 'array') ? item : slice.call(item) : [item];
  115. };
  116. Array.convert = Array.from;
  117. Number.from = function(item){
  118. var number = parseFloat(item);
  119. return isFinite(number) ? number : null;
  120. };
  121. Number.convert = Number.from;
  122. String.from = function(item){
  123. return item + '';
  124. };
  125. String.convert = String.from;
  126. // hide, protect
  127. Function.implement({
  128. hide: function(){
  129. this.$hidden = true;
  130. return this;
  131. },
  132. protect: function(){
  133. this.$protected = true;
  134. return this;
  135. }
  136. });
  137. // Type
  138. var Type = this.Type = function(name, object){
  139. if (name){
  140. var lower = name.toLowerCase();
  141. var typeCheck = function(item){
  142. return (typeOf(item) == lower);
  143. };
  144. Type['is' + name] = typeCheck;
  145. if (object != null){
  146. object.prototype.$family = (function(){
  147. return lower;
  148. }).hide();
  149. }
  150. }
  151. if (object == null) return null;
  152. object.extend(this);
  153. object.$constructor = Type;
  154. object.prototype.$constructor = object;
  155. return object;
  156. };
  157. var toString = Object.prototype.toString;
  158. Type.isEnumerable = function(item){
  159. return (item != null && typeof item.length == 'number' && toString.call(item) != '[object Function]' );
  160. };
  161. var hooks = {};
  162. var hooksOf = function(object){
  163. var type = typeOf(object.prototype);
  164. return hooks[type] || (hooks[type] = []);
  165. };
  166. var implement = function(name, method){
  167. if (method && method.$hidden) return;
  168. var hooks = hooksOf(this);
  169. for (var i = 0; i < hooks.length; i++){
  170. var hook = hooks[i];
  171. if (typeOf(hook) == 'type') implement.call(hook, name, method);
  172. else hook.call(this, name, method);
  173. }
  174. var previous = this.prototype[name];
  175. if (previous == null || !previous.$protected) this.prototype[name] = method;
  176. if (this[name] == null && typeOf(method) == 'function') extend.call(this, name, function(item){
  177. return method.apply(item, slice.call(arguments, 1));
  178. });
  179. };
  180. var extend = function(name, method){
  181. if (method && method.$hidden) return;
  182. var previous = this[name];
  183. if (previous == null || !previous.$protected) this[name] = method;
  184. };
  185. Type.implement({
  186. implement: implement.overloadSetter(),
  187. extend: extend.overloadSetter(),
  188. alias: function(name, existing){
  189. implement.call(this, name, this.prototype[existing]);
  190. }.overloadSetter(),
  191. mirror: function(hook){
  192. hooksOf(this).push(hook);
  193. return this;
  194. }
  195. });
  196. new Type('Type', Type);
  197. // Default Types
  198. var force = function(name, object, methods){
  199. var isType = (object != Object),
  200. prototype = object.prototype;
  201. if (isType) object = new Type(name, object);
  202. for (var i = 0, l = methods.length; i < l; i++){
  203. var key = methods[i],
  204. generic = object[key],
  205. proto = prototype[key];
  206. if (generic) generic.protect();
  207. if (isType && proto) object.implement(key, proto.protect());
  208. }
  209. if (isType){
  210. var methodsEnumerable = prototype.propertyIsEnumerable(methods[0]);
  211. object.forEachMethod = function(fn){
  212. if (!methodsEnumerable) for (var i = 0, l = methods.length; i < l; i++){
  213. fn.call(prototype, prototype[methods[i]], methods[i]);
  214. }
  215. for (var key in prototype) fn.call(prototype, prototype[key], key);
  216. };
  217. }
  218. return force;
  219. };
  220. force('String', String, [
  221. 'charAt', 'charCodeAt', 'concat', 'indexOf', 'lastIndexOf', 'match', 'quote', 'replace', 'search',
  222. 'slice', 'split', 'substr', 'substring', 'trim', 'toLowerCase', 'toUpperCase'
  223. ])('Array', Array, [
  224. 'pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift', 'concat', 'join', 'slice',
  225. 'indexOf', 'lastIndexOf', 'filter', 'forEach', 'every', 'map', 'some', 'reduce', 'reduceRight'
  226. ])('Number', Number, [
  227. 'toExponential', 'toFixed', 'toLocaleString', 'toPrecision'
  228. ])('Function', Function, [
  229. 'apply', 'call', 'bind'
  230. ])('RegExp', RegExp, [
  231. 'exec', 'test'
  232. ])('Object', Object, [
  233. 'create', 'defineProperty', 'defineProperties', 'keys',
  234. 'getPrototypeOf', 'getOwnPropertyDescriptor', 'getOwnPropertyNames',
  235. 'preventExtensions', 'isExtensible', 'seal', 'isSealed', 'freeze', 'isFrozen'
  236. ])('Date', Date, ['now']);
  237. Object.extend = extend.overloadSetter();
  238. Date.extend('now', function(){
  239. return +(new Date);
  240. });
  241. new Type('Boolean', Boolean);
  242. // fixes NaN returning as Number
  243. Number.prototype.$family = function(){
  244. return isFinite(this) ? 'number' : 'null';
  245. }.hide();
  246. // Number.random
  247. Number.extend('random', function(min, max){
  248. return Math.floor(Math.random() * (max - min + 1) + min);
  249. });
  250. // forEach, each
  251. var hasOwnProperty = Object.prototype.hasOwnProperty;
  252. Object.extend('forEach', function(object, fn, bind){
  253. for (var key in object){
  254. if (hasOwnProperty.call(object, key)) fn.call(bind, object[key], key, object);
  255. }
  256. });
  257. Object.each = Object.forEach;
  258. Array.implement({
  259. /*<!ES5>*/
  260. forEach: function(fn, bind){
  261. for (var i = 0, l = this.length; i < l; i++){
  262. if (i in this) fn.call(bind, this[i], i, this);
  263. }
  264. },
  265. /*</!ES5>*/
  266. each: function(fn, bind){
  267. Array.forEach(this, fn, bind);
  268. return this;
  269. }
  270. });
  271. // Array & Object cloning, Object merging and appending
  272. var cloneOf = function(item){
  273. switch (typeOf(item)){
  274. case 'array': return item.clone();
  275. case 'object': return Object.clone(item);
  276. default: return item;
  277. }
  278. };
  279. Array.implement('clone', function(){
  280. var i = this.length, clone = new Array(i);
  281. while (i--) clone[i] = cloneOf(this[i]);
  282. return clone;
  283. });
  284. var mergeOne = function(source, key, current){
  285. switch (typeOf(current)){
  286. case 'object':
  287. if (typeOf(source[key]) == 'object') Object.merge(source[key], current);
  288. else source[key] = Object.clone(current);
  289. break;
  290. case 'array': source[key] = current.clone(); break;
  291. default: source[key] = current;
  292. }
  293. return source;
  294. };
  295. Object.extend({
  296. merge: function(source, k, v){
  297. if (typeOf(k) == 'string') return mergeOne(source, k, v);
  298. for (var i = 1, l = arguments.length; i < l; i++){
  299. var object = arguments[i];
  300. for (var key in object) mergeOne(source, key, object[key]);
  301. }
  302. return source;
  303. },
  304. clone: function(object){
  305. var clone = {};
  306. for (var key in object) clone[key] = cloneOf(object[key]);
  307. return clone;
  308. },
  309. append: function(original){
  310. for (var i = 1, l = arguments.length; i < l; i++){
  311. var extended = arguments[i] || {};
  312. for (var key in extended) original[key] = extended[key];
  313. }
  314. return original;
  315. }
  316. });
  317. // Object-less types
  318. ['Object', 'WhiteSpace', 'TextNode', 'Collection', 'Arguments'].each(function(name){
  319. new Type(name);
  320. });
  321. // Unique ID
  322. var UID = Date.now();
  323. String.extend('uniqueID', function(){
  324. return (UID++).toString(36);
  325. });
  326. })();
  327. /*
  328. ---
  329. name: Array
  330. description: Contains Array Prototypes like each, contains, and erase.
  331. license: MIT-style license.
  332. requires: Type
  333. provides: Array
  334. ...
  335. */
  336. Array.implement({
  337. /*<!ES5>*/
  338. every: function(fn, bind){
  339. for (var i = 0, l = this.length >>> 0; i < l; i++){
  340. if ((i in this) && !fn.call(bind, this[i], i, this)) return false;
  341. }
  342. return true;
  343. },
  344. filter: function(fn, bind){
  345. var results = [];
  346. for (var value, i = 0, l = this.length >>> 0; i < l; i++) if (i in this){
  347. value = this[i];
  348. if (fn.call(bind, value, i, this)) results.push(value);
  349. }
  350. return results;
  351. },
  352. indexOf: function(item, from){
  353. var length = this.length >>> 0;
  354. for (var i = (from < 0) ? Math.max(0, length + from) : from || 0; i < length; i++){
  355. if (this[i] === item) return i;
  356. }
  357. return -1;
  358. },
  359. map: function(fn, bind){
  360. var length = this.length >>> 0, results = Array(length);
  361. for (var i = 0; i < length; i++){
  362. if (i in this) results[i] = fn.call(bind, this[i], i, this);
  363. }
  364. return results;
  365. },
  366. some: function(fn, bind){
  367. for (var i = 0, l = this.length >>> 0; i < l; i++){
  368. if ((i in this) && fn.call(bind, this[i], i, this)) return true;
  369. }
  370. return false;
  371. },
  372. /*</!ES5>*/
  373. clean: function(){
  374. return this.filter(function(item){
  375. return item != null;
  376. });
  377. },
  378. invoke: function(methodName){
  379. var args = Array.slice(arguments, 1);
  380. return this.map(function(item){
  381. return item[methodName].apply(item, args);
  382. });
  383. },
  384. associate: function(keys){
  385. var obj = {}, length = Math.min(this.length, keys.length);
  386. for (var i = 0; i < length; i++) obj[keys[i]] = this[i];
  387. return obj;
  388. },
  389. link: function(object){
  390. var result = {};
  391. for (var i = 0, l = this.length; i < l; i++){
  392. for (var key in object){
  393. if (object[key](this[i])){
  394. result[key] = this[i];
  395. delete object[key];
  396. break;
  397. }
  398. }
  399. }
  400. return result;
  401. },
  402. contains: function(item, from){
  403. return this.indexOf(item, from) != -1;
  404. },
  405. append: function(array){
  406. this.push.apply(this, array);
  407. return this;
  408. },
  409. getLast: function(){
  410. return (this.length) ? this[this.length - 1] : null;
  411. },
  412. getRandom: function(){
  413. return (this.length) ? this[Number.random(0, this.length - 1)] : null;
  414. },
  415. include: function(item){
  416. if (!this.contains(item)) this.push(item);
  417. return this;
  418. },
  419. combine: function(array){
  420. for (var i = 0, l = array.length; i < l; i++) this.include(array[i]);
  421. return this;
  422. },
  423. erase: function(item){
  424. for (var i = this.length; i--;){
  425. if (this[i] === item) this.splice(i, 1);
  426. }
  427. return this;
  428. },
  429. empty: function(){
  430. this.length = 0;
  431. return this;
  432. },
  433. flatten: function(){
  434. var array = [];
  435. for (var i = 0, l = this.length; i < l; i++){
  436. var type = typeOf(this[i]);
  437. if (type == 'null') continue;
  438. array = array.concat((type == 'array' || type == 'collection' || type == 'arguments' || instanceOf(this[i], Array)) ? Array.flatten(this[i]) : this[i]);
  439. }
  440. return array;
  441. },
  442. pick: function(){
  443. for (var i = 0, l = this.length; i < l; i++){
  444. if (this[i] != null) return this[i];
  445. }
  446. return null;
  447. },
  448. hexToRgb: function(array){
  449. if (this.length != 3) return null;
  450. var rgb = this.map(function(value){
  451. if (value.length == 1) value += value;
  452. return value.toInt(16);
  453. });
  454. return (array) ? rgb : 'rgb(' + rgb + ')';
  455. },
  456. rgbToHex: function(array){
  457. if (this.length < 3) return null;
  458. if (this.length == 4 && this[3] == 0 && !array) return 'transparent';
  459. var hex = [];
  460. for (var i = 0; i < 3; i++){
  461. var bit = (this[i] - 0).toString(16);
  462. hex.push((bit.length == 1) ? '0' + bit : bit);
  463. }
  464. return (array) ? hex : '#' + hex.join('');
  465. }
  466. });
  467. /*
  468. ---
  469. name: String
  470. description: Contains String Prototypes like camelCase, capitalize, test, and toInt.
  471. license: MIT-style license.
  472. requires: Type
  473. provides: String
  474. ...
  475. */
  476. String.implement({
  477. test: function(regex, params){
  478. return ((typeOf(regex) == 'regexp') ? regex : new RegExp('' + regex, params)).test(this);
  479. },
  480. contains: function(string, separator){
  481. return (separator) ? (separator + this + separator).indexOf(separator + string + separator) > -1 : String(this).indexOf(string) > -1;
  482. },
  483. trim: function(){
  484. return String(this).replace(/^\s+|\s+$/g, '');
  485. },
  486. clean: function(){
  487. return String(this).replace(/\s+/g, ' ').trim();
  488. },
  489. camelCase: function(){
  490. return String(this).replace(/-\D/g, function(match){
  491. return match.charAt(1).toUpperCase();
  492. });
  493. },
  494. hyphenate: function(){
  495. return String(this).replace(/[A-Z]/g, function(match){
  496. return ('-' + match.charAt(0).toLowerCase());
  497. });
  498. },
  499. capitalize: function(){
  500. return String(this).replace(/\b[a-z]/g, function(match){
  501. return match.toUpperCase();
  502. });
  503. },
  504. escapeRegExp: function(){
  505. return String(this).replace(/([-.*+?^${}()|[\]\/\\])/g, '\\$1');
  506. },
  507. toInt: function(base){
  508. return parseInt(this, base || 10);
  509. },
  510. toFloat: function(){
  511. return parseFloat(this);
  512. },
  513. hexToRgb: function(array){
  514. var hex = String(this).match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);
  515. return (hex) ? hex.slice(1).hexToRgb(array) : null;
  516. },
  517. rgbToHex: function(array){
  518. var rgb = String(this).match(/\d{1,3}/g);
  519. return (rgb) ? rgb.rgbToHex(array) : null;
  520. },
  521. substitute: function(object, regexp){
  522. return String(this).replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){
  523. if (match.charAt(0) == '\\') return match.slice(1);
  524. return (object[name] != null) ? object[name] : '';
  525. });
  526. }
  527. });
  528. /*
  529. ---
  530. name: Function
  531. description: Contains Function Prototypes like create, bind, pass, and delay.
  532. license: MIT-style license.
  533. requires: Type
  534. provides: Function
  535. ...
  536. */
  537. Function.extend({
  538. attempt: function(){
  539. for (var i = 0, l = arguments.length; i < l; i++){
  540. try {
  541. return arguments[i]();
  542. } catch (e){}
  543. }
  544. return null;
  545. }
  546. });
  547. Function.implement({
  548. attempt: function(args, bind){
  549. try {
  550. return this.apply(bind, Array.from(args));
  551. } catch (e){}
  552. return null;
  553. },
  554. /*<!ES5-bind>*/
  555. bind: function(that){
  556. var self = this,
  557. args = arguments.length > 1 ? Array.slice(arguments, 1) : null,
  558. F = function(){};
  559. var bound = function(){
  560. var context = that, length = arguments.length;
  561. if (this instanceof bound){
  562. F.prototype = self.prototype;
  563. context = new F;
  564. }
  565. var result = (!args && !length)
  566. ? self.call(context)
  567. : self.apply(context, args && length ? args.concat(Array.slice(arguments)) : args || arguments);
  568. return context == that ? result : context;
  569. };
  570. return bound;
  571. },
  572. /*</!ES5-bind>*/
  573. pass: function(args, bind){
  574. var self = this;
  575. if (args != null) args = Array.from(args);
  576. return function(){
  577. return self.apply(bind, args || arguments);
  578. };
  579. },
  580. delay: function(delay, bind, args){
  581. return setTimeout(this.pass((args == null ? [] : args), bind), delay);
  582. },
  583. periodical: function(periodical, bind, args){
  584. return setInterval(this.pass((args == null ? [] : args), bind), periodical);
  585. }
  586. });
  587. /*
  588. ---
  589. name: Number
  590. description: Contains Number Prototypes like limit, round, times, and ceil.
  591. license: MIT-style license.
  592. requires: Type
  593. provides: Number
  594. ...
  595. */
  596. Number.implement({
  597. limit: function(min, max){
  598. return Math.min(max, Math.max(min, this));
  599. },
  600. round: function(precision){
  601. precision = Math.pow(10, precision || 0).toFixed(precision < 0 ? -precision : 0);
  602. return Math.round(this * precision) / precision;
  603. },
  604. times: function(fn, bind){
  605. for (var i = 0; i < this; i++) fn.call(bind, i, this);
  606. },
  607. toFloat: function(){
  608. return parseFloat(this);
  609. },
  610. toInt: function(base){
  611. return parseInt(this, base || 10);
  612. }
  613. });
  614. Number.alias('each', 'times');
  615. (function(math){
  616. var methods = {};
  617. math.each(function(name){
  618. if (!Number[name]) methods[name] = function(){
  619. return Math[name].apply(null, [this].concat(Array.from(arguments)));
  620. };
  621. });
  622. Number.implement(methods);
  623. })(['abs', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'exp', 'floor', 'log', 'max', 'min', 'pow', 'sin', 'sqrt', 'tan']);
  624. /*
  625. ---
  626. name: Class
  627. description: Contains the Class Function for easily creating, extending, and implementing reusable Classes.
  628. license: MIT-style license.
  629. requires: [Array, String, Function, Number]
  630. provides: Class
  631. ...
  632. */
  633. (function(){
  634. var Class = this.Class = new Type('Class', function(params){
  635. if (instanceOf(params, Function)) params = {initialize: params};
  636. var newClass = function(){
  637. reset(this);
  638. if (newClass.$prototyping) return this;
  639. this.$caller = null;
  640. var value = (this.initialize) ? this.initialize.apply(this, arguments) : this;
  641. this.$caller = this.caller = null;
  642. return value;
  643. }.extend(this).implement(params);
  644. newClass.$constructor = Class;
  645. newClass.prototype.$constructor = newClass;
  646. newClass.prototype.parent = parent;
  647. return newClass;
  648. });
  649. var parent = function(){
  650. if (!this.$caller) throw new Error('The method "parent" cannot be called.');
  651. var name = this.$caller.$name,
  652. parent = this.$caller.$owner.parent,
  653. previous = (parent) ? parent.prototype[name] : null;
  654. if (!previous) throw new Error('The method "' + name + '" has no parent.');
  655. return previous.apply(this, arguments);
  656. };
  657. var reset = function(object){
  658. for (var key in object){
  659. var value = object[key];
  660. switch (typeOf(value)){
  661. case 'object':
  662. var F = function(){};
  663. F.prototype = value;
  664. object[key] = reset(new F);
  665. break;
  666. case 'array': object[key] = value.clone(); break;
  667. }
  668. }
  669. return object;
  670. };
  671. var wrap = function(self, key, method){
  672. if (method.$origin) method = method.$origin;
  673. var wrapper = function(){
  674. if (method.$protected && this.$caller == null) throw new Error('The method "' + key + '" cannot be called.');
  675. var caller = this.caller, current = this.$caller;
  676. this.caller = current; this.$caller = wrapper;
  677. var result = method.apply(this, arguments);
  678. this.$caller = current; this.caller = caller;
  679. return result;
  680. }.extend({$owner: self, $origin: method, $name: key});
  681. return wrapper;
  682. };
  683. var implement = function(key, value, retain){
  684. if (Class.Mutators.hasOwnProperty(key)){
  685. value = Class.Mutators[key].call(this, value);
  686. if (value == null) return this;
  687. }
  688. if (typeOf(value) == 'function'){
  689. if (value.$hidden) return this;
  690. this.prototype[key] = (retain) ? value : wrap(this, key, value);
  691. } else {
  692. Object.merge(this.prototype, key, value);
  693. }
  694. return this;
  695. };
  696. var getInstance = function(klass){
  697. klass.$prototyping = true;
  698. var proto = new klass;
  699. delete klass.$prototyping;
  700. return proto;
  701. };
  702. Class.implement('implement', implement.overloadSetter());
  703. Class.Mutators = {
  704. Extends: function(parent){
  705. this.parent = parent;
  706. this.prototype = getInstance(parent);
  707. },
  708. Implements: function(items){
  709. Array.from(items).each(function(item){
  710. var instance = new item;
  711. for (var key in instance) implement.call(this, key, instance[key], true);
  712. }, this);
  713. }
  714. };
  715. })();
  716. /*
  717. ---
  718. name: Class.Extras
  719. description: Contains Utility Classes that can be implemented into your own Classes to ease the execution of many common tasks.
  720. license: MIT-style license.
  721. requires: Class
  722. provides: [Class.Extras, Chain, Events, Options]
  723. ...
  724. */
  725. (function(){
  726. this.Chain = new Class({
  727. $chain: [],
  728. chain: function(){
  729. this.$chain.append(Array.flatten(arguments));
  730. return this;
  731. },
  732. callChain: function(){
  733. return (this.$chain.length) ? this.$chain.shift().apply(this, arguments) : false;
  734. },
  735. clearChain: function(){
  736. this.$chain.empty();
  737. return this;
  738. }
  739. });
  740. var removeOn = function(string){
  741. return string.replace(/^on([A-Z])/, function(full, first){
  742. return first.toLowerCase();
  743. });
  744. };
  745. this.Events = new Class({
  746. $events: {},
  747. addEvent: function(type, fn, internal){
  748. type = removeOn(type);
  749. this.$events[type] = (this.$events[type] || []).include(fn);
  750. if (internal) fn.internal = true;
  751. return this;
  752. },
  753. addEvents: function(events){
  754. for (var type in events) this.addEvent(type, events[type]);
  755. return this;
  756. },
  757. fireEvent: function(type, args, delay){
  758. type = removeOn(type);
  759. var events = this.$events[type];
  760. if (!events) return this;
  761. args = Array.from(args);
  762. events.each(function(fn){
  763. if (delay) fn.delay(delay, this, args);
  764. else fn.apply(this, args);
  765. }, this);
  766. return this;
  767. },
  768. removeEvent: function(type, fn){
  769. type = removeOn(type);
  770. var events = this.$events[type];
  771. if (events && !fn.internal){
  772. var index = events.indexOf(fn);
  773. if (index != -1) delete events[index];
  774. }
  775. return this;
  776. },
  777. removeEvents: function(events){
  778. var type;
  779. if (typeOf(events) == 'object'){
  780. for (type in events) this.removeEvent(type, events[type]);
  781. return this;
  782. }
  783. if (events) events = removeOn(events);
  784. for (type in this.$events){
  785. if (events && events != type) continue;
  786. var fns = this.$events[type];
  787. for (var i = fns.length; i--;) if (i in fns){
  788. this.removeEvent(type, fns[i]);
  789. }
  790. }
  791. return this;
  792. }
  793. });
  794. this.Options = new Class({
  795. setOptions: function(){
  796. var options = this.options = Object.merge.apply(null, [{}, this.options].append(arguments));
  797. if (this.addEvent) for (var option in options){
  798. if (typeOf(options[option]) != 'function' || !(/^on[A-Z]/).test(option)) continue;
  799. this.addEvent(option, options[option]);
  800. delete options[option];
  801. }
  802. return this;
  803. }
  804. });
  805. })();
  806. /*
  807. ---
  808. name: Object
  809. description: Object generic methods
  810. license: MIT-style license.
  811. requires: Type
  812. provides: [Object, Hash]
  813. ...
  814. */
  815. (function(){
  816. var hasOwnProperty = Object.prototype.hasOwnProperty;
  817. Object.extend({
  818. subset: function(object, keys){
  819. var results = {};
  820. for (var i = 0, l = keys.length; i < l; i++){
  821. var k = keys[i];
  822. if (k in object) results[k] = object[k];
  823. }
  824. return results;
  825. },
  826. map: function(object, fn, bind){
  827. var results = {};
  828. for (var key in object){
  829. if (hasOwnProperty.call(object, key)) results[key] = fn.call(bind, object[key], key, object);
  830. }
  831. return results;
  832. },
  833. filter: function(object, fn, bind){
  834. var results = {};
  835. for (var key in object){
  836. var value = object[key];
  837. if (hasOwnProperty.call(object, key) && fn.call(bind, value, key, object)) results[key] = value;
  838. }
  839. return results;
  840. },
  841. every: function(object, fn, bind){
  842. for (var key in object){
  843. if (hasOwnProperty.call(object, key) && !fn.call(bind, object[key], key)) return false;
  844. }
  845. return true;
  846. },
  847. some: function(object, fn, bind){
  848. for (var key in object){
  849. if (hasOwnProperty.call(object, key) && fn.call(bind, object[key], key)) return true;
  850. }
  851. return false;
  852. },
  853. keys: function(object){
  854. var keys = [];
  855. for (var key in object){
  856. if (hasOwnProperty.call(object, key)) keys.push(key);
  857. }
  858. return keys;
  859. },
  860. values: function(object){
  861. var values = [];
  862. for (var key in object){
  863. if (hasOwnProperty.call(object, key)) values.push(object[key]);
  864. }
  865. return values;
  866. },
  867. getLength: function(object){
  868. return Object.keys(object).length;
  869. },
  870. keyOf: function(object, value){
  871. for (var key in object){
  872. if (hasOwnProperty.call(object, key) && object[key] === value) return key;
  873. }
  874. return null;
  875. },
  876. contains: function(object, value){
  877. return Object.keyOf(object, value) != null;
  878. },
  879. toQueryString: function(object, base){
  880. var queryString = [];
  881. Object.each(object, function(value, key){
  882. if (base) key = base + '[' + key + ']';
  883. var result;
  884. switch (typeOf(value)){
  885. case 'object': result = Object.toQueryString(value, key); break;
  886. case 'array':
  887. var qs = {};
  888. value.each(function(val, i){
  889. qs[i] = val;
  890. });
  891. result = Object.toQueryString(qs, key);
  892. break;
  893. default: result = key + '=' + encodeURIComponent(value);
  894. }
  895. if (value != null) queryString.push(result);
  896. });
  897. return queryString.join('&');
  898. }
  899. });
  900. })();
  901. /*
  902. ---
  903. name: Loader
  904. description: Loads MooTools as a CommonJS Module.
  905. license: MIT-style license.
  906. copyright: Copyright (c) 2010 [Christoph Pojer](http://cpojer.net/).
  907. authors: Christoph Pojer
  908. requires: [Core/Core, Core/Object]
  909. provides: [Loader]
  910. ...
  911. */
  912. if (typeof exports != 'undefined') (function(){
  913. for (var key in this) if (!GLOBAL_ITEMS.contains(key)){
  914. exports[key] = this[key];
  915. }
  916. exports.apply = function(object){
  917. Object.append(object, exports);
  918. };
  919. })();
  920. /*
  921. ---
  922. script: More.js
  923. name: More
  924. description: MooTools More
  925. license: MIT-style license
  926. authors:
  927. - Guillermo Rauch
  928. - Thomas Aylott
  929. - Scott Kyle
  930. - Arian Stolwijk
  931. - Tim Wienk
  932. - Christoph Pojer
  933. - Aaron Newton
  934. - Jacob Thornton
  935. requires:
  936. - Core/MooTools
  937. provides: [MooTools.More]
  938. ...
  939. */
  940. MooTools.More = {
  941. version: '1.6.1-dev',
  942. build: '%build%'
  943. };
  944. /*
  945. ---
  946. script: Object.Extras.js
  947. name: Object.Extras
  948. description: Extra Object generics, like getFromPath which allows a path notation to child elements.
  949. license: MIT-style license
  950. authors:
  951. - Aaron Newton
  952. requires:
  953. - Core/Object
  954. - MooTools.More
  955. provides: [Object.Extras]
  956. ...
  957. */
  958. (function(){
  959. var defined = function(value){
  960. return value != null;
  961. };
  962. var hasOwnProperty = Object.prototype.hasOwnProperty;
  963. Object.extend({
  964. getFromPath: function(source, parts){
  965. if (typeof parts == 'string') parts = parts.split('.');
  966. for (var i = 0, l = parts.length; i < l; i++){
  967. if (hasOwnProperty.call(source, parts[i])) source = source[parts[i]];
  968. else return null;
  969. }
  970. return source;
  971. },
  972. cleanValues: function(object, method){
  973. method = method || defined;
  974. for (var key in object) if (!method(object[key])){
  975. delete object[key];
  976. }
  977. return object;
  978. },
  979. erase: function(object, key){
  980. if (hasOwnProperty.call(object, key)) delete object[key];
  981. return object;
  982. },
  983. run: function(object){
  984. var args = Array.slice(arguments, 1);
  985. for (var key in object) if (object[key].apply){
  986. object[key].apply(object, args);
  987. }
  988. return object;
  989. }
  990. });
  991. })();
  992. /*
  993. ---
  994. script: Locale.js
  995. name: Locale
  996. description: Provides methods for localization.
  997. license: MIT-style license
  998. authors:
  999. - Aaron Newton
  1000. - Arian Stolwijk
  1001. requires:
  1002. - Core/Events
  1003. - Object.Extras
  1004. - MooTools.More
  1005. provides: [Locale, Lang]
  1006. ...
  1007. */
  1008. (function(){
  1009. var current = null,
  1010. locales = {},
  1011. inherits = {};
  1012. var getSet = function(set){
  1013. if (instanceOf(set, Locale.Set)) return set;
  1014. else return locales[set];
  1015. };
  1016. var Locale = this.Locale = {
  1017. define: function(locale, set, key, value){
  1018. var name;
  1019. if (instanceOf(locale, Locale.Set)){
  1020. name = locale.name;
  1021. if (name) locales[name] = locale;
  1022. } else {
  1023. name = locale;
  1024. if (!locales[name]) locales[name] = new Locale.Set(name);
  1025. locale = locales[name];
  1026. }
  1027. if (set) locale.define(set, key, value);
  1028. if (!current) current = locale;
  1029. return locale;
  1030. },
  1031. use: function(locale){
  1032. locale = getSet(locale);
  1033. if (locale){
  1034. current = locale;
  1035. this.fireEvent('change', locale);
  1036. }
  1037. return this;
  1038. },
  1039. getCurrent: function(){
  1040. return current;
  1041. },
  1042. get: function(key, args){
  1043. return (current) ? current.get(key, args) : '';
  1044. },
  1045. inherit: function(locale, inherits, set){
  1046. locale = getSet(locale);
  1047. if (locale) locale.inherit(inherits, set);
  1048. return this;
  1049. },
  1050. list: function(){
  1051. return Object.keys(locales);
  1052. }
  1053. };
  1054. Object.append(Locale, new Events);
  1055. Locale.Set = new Class({
  1056. sets: {},
  1057. inherits: {
  1058. locales: [],
  1059. sets: {}
  1060. },
  1061. initialize: function(name){
  1062. this.name = name || '';
  1063. },
  1064. define: function(set, key, value){
  1065. var defineData = this.sets[set];
  1066. if (!defineData) defineData = {};
  1067. if (key){
  1068. if (typeOf(key) == 'object') defineData = Object.merge(defineData, key);
  1069. else defineData[key] = value;
  1070. }
  1071. this.sets[set] = defineData;
  1072. return this;
  1073. },
  1074. get: function(key, args, _base){
  1075. var value = Object.getFromPath(this.sets, key);
  1076. if (value != null){
  1077. var type = typeOf(value);
  1078. if (type == 'function') value = value.apply(null, Array.convert(args));
  1079. else if (type == 'object') value = Object.clone(value);
  1080. return value;
  1081. }
  1082. // get value of inherited locales
  1083. var index = key.indexOf('.'),
  1084. set = index < 0 ? key : key.substr(0, index),
  1085. names = (this.inherits.sets[set] || []).combine(this.inherits.locales).include('en-US');
  1086. if (!_base) _base = [];
  1087. for (var i = 0, l = names.length; i < l; i++){
  1088. if (_base.contains(names[i])) continue;
  1089. _base.include(names[i]);
  1090. var locale = locales[names[i]];
  1091. if (!locale) continue;
  1092. value = locale.get(key, args, _base);
  1093. if (value != null) return value;
  1094. }
  1095. return '';
  1096. },
  1097. inherit: function(names, set){
  1098. names = Array.convert(names);
  1099. if (set && !this.inherits.sets[set]) this.inherits.sets[set] = [];
  1100. var l = names.length;
  1101. while (l--) (set ? this.inherits.sets[set] : this.inherits.locales).unshift(names[l]);
  1102. return this;
  1103. }
  1104. });
  1105. })();
  1106. /*
  1107. ---
  1108. name: Locale.en-US.Date
  1109. description: Date messages for US English.
  1110. license: MIT-style license
  1111. authors:
  1112. - Aaron Newton
  1113. requires:
  1114. - Locale
  1115. provides: [Locale.en-US.Date]
  1116. ...
  1117. */
  1118. Locale.define('en-US', 'Date', {
  1119. months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
  1120. months_abbr: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  1121. days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
  1122. days_abbr: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
  1123. // Culture's date order: MM/DD/YYYY
  1124. dateOrder: ['month', 'date', 'year'],
  1125. shortDate: '%m/%d/%Y',
  1126. shortTime: '%I:%M%p',
  1127. AM: 'AM',
  1128. PM: 'PM',
  1129. firstDayOfWeek: 0,
  1130. // Date.Extras
  1131. ordinal: function(dayOfMonth){
  1132. // 1st, 2nd, 3rd, etc.
  1133. return (dayOfMonth > 3 && dayOfMonth < 21) ? 'th' : ['th', 'st', 'nd', 'rd', 'th'][Math.min(dayOfMonth % 10, 4)];
  1134. },
  1135. lessThanMinuteAgo: 'less than a minute ago',
  1136. minuteAgo: 'about a minute ago',
  1137. minutesAgo: '{delta} minutes ago',
  1138. hourAgo: 'about an hour ago',
  1139. hoursAgo: 'about {delta} hours ago',
  1140. dayAgo: '1 day ago',
  1141. daysAgo: '{delta} days ago',
  1142. weekAgo: '1 week ago',
  1143. weeksAgo: '{delta} weeks ago',
  1144. monthAgo: '1 month ago',
  1145. monthsAgo: '{delta} months ago',
  1146. yearAgo: '1 year ago',
  1147. yearsAgo: '{delta} years ago',
  1148. lessThanMinuteUntil: 'less than a minute from now',
  1149. minuteUntil: 'about a minute from now',
  1150. minutesUntil: '{delta} minutes from now',
  1151. hourUntil: 'about an hour from now',
  1152. hoursUntil: 'about {delta} hours from now',
  1153. dayUntil: '1 day from now',
  1154. daysUntil: '{delta} days from now',
  1155. weekUntil: '1 week from now',
  1156. weeksUntil: '{delta} weeks from now',
  1157. monthUntil: '1 month from now',
  1158. monthsUntil: '{delta} months from now',
  1159. yearUntil: '1 year from now',
  1160. yearsUntil: '{delta} years from now'
  1161. });
  1162. /*
  1163. ---
  1164. script: Date.js
  1165. name: Date
  1166. description: Extends the Date native object to include methods useful in managing dates.
  1167. license: MIT-style license
  1168. authors:
  1169. - Aaron Newton
  1170. - Nicholas Barthelemy - https://svn.nbarthelemy.com/date-js/
  1171. - Harald Kirshner - mail [at] digitarald.de; http://digitarald.de
  1172. - Scott Kyle - scott [at] appden.com; http://appden.com
  1173. requires:
  1174. - Core/Array
  1175. - Core/String
  1176. - Core/Number
  1177. - MooTools.More
  1178. - Locale
  1179. - Locale.en-US.Date
  1180. provides: [Date]
  1181. ...
  1182. */
  1183. (function(){
  1184. var Date = this.Date;
  1185. var DateMethods = Date.Methods = {
  1186. ms: 'Milliseconds',
  1187. year: 'FullYear',
  1188. min: 'Minutes',
  1189. mo: 'Month',
  1190. sec: 'Seconds',
  1191. hr: 'Hours'
  1192. };
  1193. [
  1194. 'Date', 'Day', 'FullYear', 'Hours', 'Milliseconds', 'Minutes', 'Month', 'Seconds', 'Time', 'TimezoneOffset',
  1195. 'Week', 'Timezone', 'GMTOffset', 'DayOfYear', 'LastMonth', 'LastDayOfMonth', 'UTCDate', 'UTCDay', 'UTCFullYear',
  1196. 'AMPM', 'Ordinal', 'UTCHours', 'UTCMilliseconds', 'UTCMinutes', 'UTCMonth', 'UTCSeconds', 'UTCMilliseconds'
  1197. ].each(function(method){
  1198. Date.Methods[method.toLowerCase()] = method;
  1199. });
  1200. var pad = function(n, digits, string){
  1201. if (digits == 1) return n;
  1202. return n < Math.pow(10, digits - 1) ? (string || '0') + pad(n, digits - 1, string) : n;
  1203. };
  1204. Date.implement({
  1205. set: function(prop, value){
  1206. prop = prop.toLowerCase();
  1207. var method = DateMethods[prop] && 'set' + DateMethods[prop];
  1208. if (method && this[method]) this[method](value);
  1209. return this;
  1210. }.overloadSetter(),
  1211. get: function(prop){
  1212. prop = prop.toLowerCase();
  1213. var method = DateMethods[prop] && 'get' + DateMethods[prop];
  1214. if (method && this[method]) return this[method]();
  1215. return null;
  1216. }.overloadGetter(),
  1217. clone: function(){
  1218. return new Date(this.get('time'));
  1219. },
  1220. increment: function(interval, times){
  1221. interval = interval || 'day';
  1222. times = times != null ? times : 1;
  1223. switch (interval){
  1224. case 'year':
  1225. return this.increment('month', times * 12);
  1226. case 'month':
  1227. var d = this.get('date');
  1228. this.set('date', 1).set('mo', this.get('mo') + times);
  1229. return this.set('date', d.min(this.get('lastdayofmonth')));
  1230. case 'week':
  1231. return this.increment('day', times * 7);
  1232. case 'day':
  1233. return this.set('date', this.get('date') + times);
  1234. }
  1235. if (!Date.units[interval]) throw new Error(interval + ' is not a supported interval');
  1236. return this.set('time', this.get('time') + times * Date.units[interval]());
  1237. },
  1238. decrement: function(interval, times){
  1239. return this.increment(interval, -1 * (times != null ? times : 1));
  1240. },
  1241. isLeapYear: function(){
  1242. return Date.isLeapYear(this.get('year'));
  1243. },
  1244. clearTime: function(){
  1245. return this.set({hr: 0, min: 0, sec: 0, ms: 0});
  1246. },
  1247. diff: function(date, resolution){
  1248. if (typeOf(date) == 'string') date = Date.parse(date);
  1249. return ((date - this) / Date.units[resolution || 'day'](3, 3)).round(); // non-leap year, 30-day month
  1250. },
  1251. getLastDayOfMonth: function(){
  1252. return Date.daysInMonth(this.get('mo'), this.get('year'));
  1253. },
  1254. getDayOfYear: function(){
  1255. return (Date.UTC(this.get('year'), this.get('mo'), this.get('date') + 1)
  1256. - Date.UTC(this.get('year'), 0, 1)) / Date.units.day();
  1257. },
  1258. setDay: function(day, firstDayOfWeek){
  1259. if (firstDayOfWeek == null){
  1260. firstDayOfWeek = Date.getMsg('firstDayOfWeek');
  1261. if (firstDayOfWeek === '') firstDayOfWeek = 1;
  1262. }
  1263. day = (7 + Date.parseDay(day, true) - firstDayOfWeek) % 7;
  1264. var currentDay = (7 + this.get('day') - firstDayOfWeek) % 7;
  1265. return this.increment('day', day - currentDay);
  1266. },
  1267. getWeek: function(firstDayOfWeek){
  1268. if (firstDayOfWeek == null){
  1269. firstDayOfWeek = Date.getMsg('firstDayOfWeek');
  1270. if (firstDayOfWeek === '') firstDayOfWeek = 1;
  1271. }
  1272. var date = this,
  1273. dayOfWeek = (7 + date.get('day') - firstDayOfWeek) % 7,
  1274. dividend = 0,
  1275. firstDayOfYear;
  1276. if (firstDayOfWeek == 1){
  1277. // ISO-8601, week belongs to year that has the most days of the week (i.e. has the thursday of the week)
  1278. var month = date.get('month'),
  1279. startOfWeek = date.get('date') - dayOfWeek;
  1280. if (month == 11 && startOfWeek > 28) return 1; // Week 1 of next year
  1281. if (month == 0 && startOfWeek < -2){
  1282. // Use a date from last year to determine the week
  1283. date = new Date(date).decrement('day', dayOfWeek);
  1284. dayOfWeek = 0;
  1285. }
  1286. firstDayOfYear = new Date(date.get('year'), 0, 1).get('day') || 7;
  1287. if (firstDayOfYear > 4) dividend = -7; // First week of the year is not week 1
  1288. } else {
  1289. // In other cultures the first week of the year is always week 1 and the last week always 53 or 54.
  1290. // Days in the same week can have a different weeknumber if the week spreads across two years.
  1291. firstDayOfYear = new Date(date.get('year'), 0, 1).get('day');
  1292. }
  1293. dividend += date.get('dayofyear');
  1294. dividend += 6 - dayOfWeek; // Add days so we calculate the current date's week as a full week
  1295. dividend += (7 + firstDayOfYear - firstDayOfWeek) % 7; // Make up for first week of the year not being a full week
  1296. return (dividend / 7);
  1297. },
  1298. getOrdinal: function(day){
  1299. return Date.getMsg('ordinal', day || this.get('date'));
  1300. },
  1301. getTimezone: function(){
  1302. return this.toString()
  1303. .replace(/^.*? ([A-Z]{3}).[0-9]{4}.*$/, '$1')
  1304. .replace(/^.*?\(([A-Z])[a-z]+ ([A-Z])[a-z]+ ([A-Z])[a-z]+\)$/, '$1$2$3');
  1305. },
  1306. getGMTOffset: function(){
  1307. var off = this.get('timezoneOffset');
  1308. return ((off > 0) ? '-' : '+') + pad((off.abs() / 60).floor(), 2) + pad(off % 60, 2);
  1309. },
  1310. setAMPM: function(ampm){
  1311. ampm = ampm.toUpperCase();
  1312. var hr = this.get('hr');
  1313. if (hr > 11 && ampm == 'AM') return this.decrement('hour', 12);
  1314. else if (hr < 12 && ampm == 'PM') return this.increment('hour', 12);
  1315. return this;
  1316. },
  1317. getAMPM: function(){
  1318. return (this.get('hr') < 12) ? 'AM' : 'PM';
  1319. },
  1320. parse: function(str){
  1321. this.set('time', Date.parse(str));
  1322. return this;
  1323. },
  1324. isValid: function(date){
  1325. if (!date) date = this;
  1326. return typeOf(date) == 'date' && !isNaN(date.valueOf());
  1327. },
  1328. format: function(format){
  1329. if (!this.isValid()) return 'invalid date';
  1330. if (!format) format = '%x %X';
  1331. if (typeof format == 'string') format = formats[format.toLowerCase()] || format;
  1332. if (typeof format == 'function') return format(this);
  1333. var d = this;
  1334. return format.replace(/%([a-z%])/gi,
  1335. function($0, $1){
  1336. switch ($1){
  1337. case 'a': return Date.getMsg('days_abbr')[d.get('day')];
  1338. case 'A': return Date.getMsg('days')[d.get('day')];
  1339. case 'b': return Date.getMsg('months_abbr')[d.get('month')];
  1340. case 'B': return Date.getMsg('months')[d.get('month')];
  1341. case 'c': return d.format('%a %b %d %H:%M:%S %Y');
  1342. case 'd': return pad(d.get('date'), 2);
  1343. case 'e': return pad(d.get('date'), 2, ' ');
  1344. case 'H': return pad(d.get('hr'), 2);
  1345. case 'I': return pad((d.get('hr') % 12) || 12, 2);
  1346. case 'j': return pad(d.get('dayofyear'), 3);
  1347. case 'k': return pad(d.get('hr'), 2, ' ');
  1348. case 'l': return pad((d.get('hr') % 12) || 12, 2, ' ');
  1349. case 'L': return pad(d.get('ms'), 3);
  1350. case 'm': return pad((d.get('mo') + 1), 2);
  1351. case 'M': return pad(d.get('min'), 2);
  1352. case 'o': return d.get('ordinal');
  1353. case 'p': return Date.getMsg(d.get('ampm'));
  1354. case 's': return Math.round(d / 1000);
  1355. case 'S': return pad(d.get('seconds'), 2);
  1356. case 'T': return d.format('%H:%M:%S');
  1357. case 'U': return pad(d.get('week'), 2);
  1358. case 'w': return d.get('day');
  1359. case 'x': return d.format(Date.getMsg('shortDate'));
  1360. case 'X': return d.format(Date.getMsg('shortTime'));
  1361. case 'y': return d.get('year').toString().substr(2);
  1362. case 'Y': return d.get('year');
  1363. case 'z': return d.get('GMTOffset');
  1364. case 'Z': return d.get('Timezone');
  1365. }
  1366. return $1;
  1367. }
  1368. );
  1369. },
  1370. toISOString: function(){
  1371. return this.format('iso8601');
  1372. }
  1373. }).alias({
  1374. toJSON: 'toISOString',
  1375. compare: 'diff',
  1376. strftime: 'format'
  1377. });
  1378. // The day and month abbreviations are standardized, so we cannot use simply %a and %b because they will get localized
  1379. var rfcDayAbbr = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
  1380. rfcMonthAbbr = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
  1381. var formats = {
  1382. db: '%Y-%m-%d %H:%M:%S',
  1383. compact: '%Y%m%dT%H%M%S',
  1384. 'short': '%d %b %H:%M',
  1385. 'long': '%B %d, %Y %H:%M',
  1386. rfc822: function(date){
  1387. return rfcDayAbbr[date.get('day')] + date.format(', %d ') + rfcMonthAbbr[date.get('month')] + date.format(' %Y %H:%M:%S %Z');
  1388. },
  1389. rfc2822: function(date){
  1390. return rfcDayAbbr[date.get('day')] + date.format(', %d ') + rfcMonthAbbr[date.get('month')] + date.format(' %Y %H:%M:%S %z');
  1391. },
  1392. iso8601: function(date){
  1393. return (
  1394. date.getUTCFullYear() + '-' +
  1395. pad(date.getUTCMonth() + 1, 2) + '-' +
  1396. pad(date.getUTCDate(), 2) + 'T' +
  1397. pad(date.getUTCHours(), 2) + ':' +
  1398. pad(date.getUTCMinutes(), 2) + ':' +
  1399. pad(date.getUTCSeconds(), 2) + '.' +
  1400. pad(date.getUTCMilliseconds(), 3) + 'Z'
  1401. );
  1402. }
  1403. };
  1404. var parsePatterns = [],
  1405. nativeParse = Date.parse;
  1406. var parseWord = function(type, word, num){
  1407. var ret = -1,
  1408. translated = Date.getMsg(type + 's');
  1409. switch (typeOf(word)){
  1410. case 'object':
  1411. ret = translated[word.get(type)];
  1412. break;
  1413. case 'number':
  1414. ret = translated[word];
  1415. if (!ret) throw new Error('Invalid ' + type + ' index: ' + word);
  1416. break;
  1417. case 'string':
  1418. var match = translated.filter(function(name){
  1419. return this.test(name);
  1420. }, new RegExp('^' + word, 'i'));
  1421. if (!match.length) throw new Error('Invalid ' + type + ' string');
  1422. if (match.length > 1) throw new Error('Ambiguous ' + type);
  1423. ret = match[0];
  1424. }
  1425. return (num) ? translated.indexOf(ret) : ret;
  1426. };
  1427. var startCentury = 1900,
  1428. startYear = 70;
  1429. Date.extend({
  1430. getMsg: function(key, args){
  1431. return Locale.get('Date.' + key, args);
  1432. },
  1433. units: {
  1434. ms: Function.convert(1),
  1435. second: Function.convert(1000),
  1436. minute: Function.convert(60000),
  1437. hour: Function.convert(3600000),
  1438. day: Function.convert(86400000),
  1439. week: Function.convert(608400000),
  1440. month: function(month, year){
  1441. var d = new Date;
  1442. return Date.daysInMonth(month != null ? month : d.get('mo'), year != null ? year : d.get('year')) * 86400000;
  1443. },
  1444. year: function(year){
  1445. year = year || new Date().get('year');
  1446. return Date.isLeapYear(year) ? 31622400000 : 31536000000;
  1447. }
  1448. },
  1449. daysInMonth: function(month, year){
  1450. return [31, Date.isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
  1451. },
  1452. isLeapYear: function(year){
  1453. return ((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0);
  1454. },
  1455. parse: function(from){
  1456. var t = typeOf(from);
  1457. if (t == 'number') return new Date(from);
  1458. if (t != 'string') return from;
  1459. from = from.clean();
  1460. if (!from.length) return null;
  1461. var parsed;
  1462. parsePatterns.some(function(pattern){
  1463. var bits = pattern.re.exec(from);
  1464. return (bits) ? (parsed = pattern.handler(bits)) : false;
  1465. });
  1466. if (!(parsed && parsed.isValid())){
  1467. parsed = new Date(nativeParse(from));
  1468. if (!(parsed && parsed.isValid())) parsed = new Date(from.toInt());
  1469. }
  1470. return parsed;
  1471. },
  1472. parseDay: function(day, num){
  1473. return parseWord('day', day, num);
  1474. },
  1475. parseMonth: function(month, num){
  1476. return parseWord('month', month, num);
  1477. },
  1478. parseUTC: function(value){
  1479. var localDate = new Date(value);
  1480. var utcSeconds = Date.UTC(
  1481. localDate.get('year'),
  1482. localDate.get('mo'),
  1483. localDate.get('date'),
  1484. localDate.get('hr'),
  1485. localDate.get('min'),
  1486. localDate.get('sec'),
  1487. localDate.get('ms')
  1488. );
  1489. return new Date(utcSeconds);
  1490. },
  1491. orderIndex: function(unit){
  1492. return Date.getMsg('dateOrder').indexOf(unit) + 1;
  1493. },
  1494. defineFormat: function(name, format){
  1495. formats[name] = format;
  1496. return this;
  1497. },
  1498. defineParser: function(pattern){
  1499. parsePatterns.push((pattern.re && pattern.handler) ? pattern : build(pattern));
  1500. return this;
  1501. },
  1502. defineParsers: function(){
  1503. Array.flatten(arguments).each(Date.defineParser);
  1504. return this;
  1505. },
  1506. define2DigitYearStart: function(year){
  1507. startYear = year % 100;
  1508. startCentury = year - startYear;
  1509. return this;
  1510. }
  1511. }).extend({
  1512. defineFormats: Date.defineFormat.overloadSetter()
  1513. });
  1514. var regexOf = function(type){
  1515. return new RegExp('(?:' + Date.getMsg(type).map(function(name){
  1516. return name.substr(0, 3);
  1517. }).join('|') + ')[a-z]*');
  1518. };
  1519. var replacers = function(key){
  1520. switch (key){
  1521. case 'T':
  1522. return '%H:%M:%S';
  1523. case 'x': // iso8601 covers yyyy-mm-dd, so just check if month is first
  1524. return ((Date.orderIndex('month') == 1) ? '%m[-./]%d' : '%d[-./]%m') + '([-./]%y)?';
  1525. case 'X':
  1526. return '%H([.:]%M)?([.:]%S([.:]%s)?)? ?%p? ?%z?';
  1527. }
  1528. return null;
  1529. };
  1530. var keys = {
  1531. d: /[0-2]?[0-9]|3[01]/,
  1532. H: /[01]?[0-9]|2[0-3]/,
  1533. I: /0?[1-9]|1[0-2]/,
  1534. M: /[0-5]?\d/,
  1535. s: /\d+/,
  1536. o: /[a-z]*/,
  1537. p: /[ap]\.?m\.?/,
  1538. y: /\d{2}|\d{4}/,
  1539. Y: /\d{4}/,
  1540. z: /Z|[+-]\d{2}(?::?\d{2})?/
  1541. };
  1542. keys.m = keys.I;
  1543. keys.S = keys.M;
  1544. var currentLanguage;
  1545. var recompile = function(language){
  1546. currentLanguage = language;
  1547. keys.a = keys.A = regexOf('days');
  1548. keys.b = keys.B = regexOf('months');
  1549. parsePatterns.each(function(pattern, i){
  1550. if (pattern.format) parsePatterns[i] = build(pattern.format);
  1551. });
  1552. };
  1553. var build = function(format){
  1554. if (!currentLanguage) return {format: format};
  1555. var parsed = [];
  1556. var re = (format.source || format) // allow format to be regex
  1557. .replace(/%([a-z])/gi,
  1558. function($0, $1){
  1559. return replacers($1) || $0;
  1560. }
  1561. ).replace(/\((?!\?)/g, '(?:') // make all groups non-capturing
  1562. .replace(/ (?!\?|\*)/g, ',? ') // be forgiving with spaces and commas
  1563. .replace(/%([a-z%])/gi,
  1564. function($0, $1){
  1565. var p = keys[$1];
  1566. if (!p) return $1;
  1567. parsed.push($1);
  1568. return '(' + p.source + ')';
  1569. }
  1570. ).replace(/\[a-z\]/gi, '[a-z\\u00c0-\\uffff;\&]'); // handle unicode words
  1571. return {
  1572. format: format,
  1573. re: new RegExp('^' + re + '$', 'i'),
  1574. handler: function(bits){
  1575. bits = bits.slice(1).associate(parsed);
  1576. var date = new Date().clearTime(),
  1577. year = bits.y || bits.Y;
  1578. if (year != null) handle.call(date, 'y', year); // need to start in the right year
  1579. if ('d' in bits) handle.call(date, 'd', 1);
  1580. if ('m' in bits || bits.b || bits.B) handle.call(date, 'm', 1);
  1581. for (var key in bits) handle.call(date, key, bits[key]);
  1582. return date;
  1583. }
  1584. };
  1585. };
  1586. var handle = function(key, value){
  1587. if (!value) return this;
  1588. switch (key){
  1589. case 'a': case 'A': return this.set('day', Date.parseDay(value, true));
  1590. case 'b': case 'B': return this.set('mo', Date.parseMonth(value, true));
  1591. case 'd': return this.set('date', value);
  1592. case 'H': case 'I': return this.set('hr', value);
  1593. case 'm': return this.set('mo', value - 1);
  1594. case 'M': return this.set('min', value);
  1595. case 'p': return this.set('ampm', value.replace(/\./g, ''));
  1596. case 'S': return this.set('sec', value);
  1597. case 's': return this.set('ms', ('0.' + value) * 1000);
  1598. case 'w': return this.set('day', value);
  1599. case 'Y': return this.set('year', value);
  1600. case 'y':
  1601. value = +value;
  1602. if (value < 100) value += startCentury + (value < startYear ? 100 : 0);
  1603. return this.set('year', value);
  1604. case 'z':
  1605. if (value == 'Z') value = '+00';
  1606. var offset = value.match(/([+-])(\d{2}):?(\d{2})?/);
  1607. offset = (offset[1] + '1') * (offset[2] * 60 + (+offset[3] || 0)) + this.getTimezoneOffset();
  1608. return this.set('time', this - offset * 60000);
  1609. }
  1610. return this;
  1611. };
  1612. Date.defineParsers(
  1613. '%Y([-./]%m([-./]%d((T| )%X)?)?)?', // "1999-12-31", "1999-12-31 11:59pm", "1999-12-31 23:59:59", ISO8601
  1614. '%Y%m%d(T%H(%M%S?)?)?', // "19991231", "19991231T1159", compact
  1615. '%x( %X)?', // "12/31", "12.31.99", "12-31-1999", "12/31/2008 11:59 PM"
  1616. '%d%o( %b( %Y)?)?( %X)?', // "31st", "31st December", "31 Dec 1999", "31 Dec 1999 11:59pm"
  1617. '%b( %d%o)?( %Y)?( %X)?', // Same as above with month and day switched
  1618. '%Y %b( %d%o( %X)?)?', // Same as above with year coming first
  1619. '%o %b %d %X %z %Y', // "Thu Oct 22 08:11:23 +0000 2009"
  1620. '%T', // %H:%M:%S
  1621. '%H:%M( ?%p)?' // "11:05pm", "11:05 am" and "11:05"
  1622. );
  1623. Locale.addEvent('change', function(language){
  1624. if (Locale.get('Date')) recompile(language);
  1625. }).fireEvent('change', Locale.getCurrent());
  1626. })();
  1627. /*
  1628. ---
  1629. name: Locale.zh-CH.Date
  1630. description: Date messages for Chinese (simplified and traditional).
  1631. license: MIT-style license
  1632. authors:
  1633. - YMind Chan
  1634. requires:
  1635. - Locale
  1636. provides: [Locale.zh-CH.Date]
  1637. ...
  1638. */
  1639. // Simplified Chinese
  1640. Locale.define('zh-CHS', 'Date', {
  1641. months: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
  1642. months_abbr: ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'],
  1643. days: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
  1644. days_abbr: ['日', '一', '二', '三', '四', '五', '六'],
  1645. // Culture's date order: YYYY-MM-DD
  1646. dateOrder: ['year', 'month', 'date'],
  1647. shortDate: '%Y-%m-%d',
  1648. shortTime: '%I:%M%p',
  1649. AM: 'AM',
  1650. PM: 'PM',
  1651. firstDayOfWeek: 1,
  1652. // Date.Extras
  1653. ordinal: '',
  1654. lessThanMinuteAgo: '不到1分钟前',
  1655. minuteAgo: '大约1分钟前',
  1656. minutesAgo: '{delta}分钟之前',
  1657. hourAgo: '大约1小时前',
  1658. hoursAgo: '大约{delta}小时前',
  1659. dayAgo: '1天前',
  1660. daysAgo: '{delta}天前',
  1661. weekAgo: '1星期前',
  1662. weeksAgo: '{delta}星期前',
  1663. monthAgo: '1个月前',
  1664. monthsAgo: '{delta}个月前',
  1665. yearAgo: '1年前',
  1666. yearsAgo: '{delta}年前',
  1667. lessThanMinuteUntil: '从现在开始不到1分钟',
  1668. minuteUntil: '从现在开始約1分钟',
  1669. minutesUntil: '从现在开始约{delta}分钟',
  1670. hourUntil: '从现在开始1小时',
  1671. hoursUntil: '从现在开始约{delta}小时',
  1672. dayUntil: '从现在开始1天',
  1673. daysUntil: '从现在开始{delta}天',
  1674. weekUntil: '从现在开始1星期',
  1675. weeksUntil: '从现在开始{delta}星期',
  1676. monthUntil: '从现在开始一个月',
  1677. monthsUntil: '从现在开始{delta}个月',
  1678. yearUntil: '从现在开始1年',
  1679. yearsUntil: '从现在开始{delta}年'
  1680. });
  1681. // Traditional Chinese
  1682. Locale.define('zh-CHT', 'Date', {
  1683. months: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
  1684. months_abbr: ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'],
  1685. days: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
  1686. days_abbr: ['日', '一', '二', '三', '四', '五', '六'],
  1687. // Culture's date order: YYYY-MM-DD
  1688. dateOrder: ['year', 'month', 'date'],
  1689. shortDate: '%Y-%m-%d',
  1690. shortTime: '%I:%M%p',
  1691. AM: 'AM',
  1692. PM: 'PM',
  1693. firstDayOfWeek: 1,
  1694. // Date.Extras
  1695. ordinal: '',
  1696. lessThanMinuteAgo: '不到1分鐘前',
  1697. minuteAgo: '大約1分鐘前',
  1698. minutesAgo: '{delta}分鐘之前',
  1699. hourAgo: '大約1小時前',
  1700. hoursAgo: '大約{delta}小時前',
  1701. dayAgo: '1天前',
  1702. daysAgo: '{delta}天前',
  1703. weekAgo: '1星期前',
  1704. weeksAgo: '{delta}星期前',
  1705. monthAgo: '1个月前',
  1706. monthsAgo: '{delta}个月前',
  1707. yearAgo: '1年前',
  1708. yearsAgo: '{delta}年前',
  1709. lessThanMinuteUntil: '從現在開始不到1分鐘',
  1710. minuteUntil: '從現在開始約1分鐘',
  1711. minutesUntil: '從現在開始約{delta}分鐘',
  1712. hourUntil: '從現在開始1小時',
  1713. hoursUntil: '從現在開始約{delta}小時',
  1714. dayUntil: '從現在開始1天',
  1715. daysUntil: '從現在開始{delta}天',
  1716. weekUntil: '從現在開始1星期',
  1717. weeksUntil: '從現在開始{delta}星期',
  1718. monthUntil: '從現在開始一個月',
  1719. monthsUntil: '從現在開始{delta}個月',
  1720. yearUntil: '從現在開始1年',
  1721. yearsUntil: '從現在開始{delta}年'
  1722. });
  1723. /*
  1724. ---
  1725. name: JSON
  1726. description: JSON encoder and decoder.
  1727. license: MIT-style license.
  1728. SeeAlso: <http://www.json.org/>
  1729. requires: [Array, String, Number, Function]
  1730. provides: JSON
  1731. ...
  1732. */
  1733. if (typeof JSON == 'undefined') this.JSON = {};
  1734. (function(){
  1735. var special = {'\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\'};
  1736. var escape = function(chr){
  1737. return special[chr] || '\\u' + ('0000' + chr.charCodeAt(0).toString(16)).slice(-4);
  1738. };
  1739. JSON.validate = function(string){
  1740. string = string.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
  1741. replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
  1742. replace(/(?:^|:|,)(?:\s*\[)+/g, '');
  1743. return (/^[\],:{}\s]*$/).test(string);
  1744. };
  1745. JSON.encode = JSON.stringify ? function(obj){
  1746. return JSON.stringify(obj);
  1747. } : function(obj){
  1748. if (obj && obj.toJSON) obj = obj.toJSON();
  1749. switch (typeOf(obj)){
  1750. case 'string':
  1751. return '"' + obj.replace(/[\x00-\x1f\\"]/g, escape) + '"';
  1752. case 'array':
  1753. return '[' + obj.map(JSON.encode).clean() + ']';
  1754. case 'object': case 'hash':
  1755. var string = [];
  1756. Object.each(obj, function(value, key){
  1757. var json = JSON.encode(value);
  1758. if (json) string.push(JSON.encode(key) + ':' + json);
  1759. });
  1760. return '{' + string + '}';
  1761. case 'number': case 'boolean': return '' + obj;
  1762. case 'null': return 'null';
  1763. }
  1764. return null;
  1765. };
  1766. JSON.decode = function(string, secure){
  1767. if (!string || typeOf(string) != 'string') return null;
  1768. if (secure || JSON.secure){
  1769. if (JSON.parse) return JSON.parse(string);
  1770. if (!JSON.validate(string)) throw new Error('JSON could not decode the input; security is enabled and the value is not secure.');
  1771. }
  1772. return eval('(' + string + ')');
  1773. };
  1774. })();
  1775. //以上是mootools代码。
  1776. bind = this;
  1777. var library = {
  1778. 'version': '4.0',
  1779. "defineProperties": Object.defineProperties || function (obj, properties) {
  1780. function convertToDescriptor(desc) {
  1781. function hasProperty(obj, prop) {
  1782. return Object.prototype.hasOwnProperty.call(obj, prop);
  1783. }
  1784. function isCallable(v) {
  1785. // NB: modify as necessary if other values than functions are callable.
  1786. return typeof v === "function";
  1787. }
  1788. if (typeof desc !== "object" || desc === null)
  1789. throw new TypeError("bad desc");
  1790. var d = {};
  1791. if (hasProperty(desc, "enumerable"))
  1792. d.enumerable = !!obj.enumerable;
  1793. if (hasProperty(desc, "configurable"))
  1794. d.configurable = !!obj.configurable;
  1795. if (hasProperty(desc, "value"))
  1796. d.value = obj.value;
  1797. if (hasProperty(desc, "writable"))
  1798. d.writable = !!desc.writable;
  1799. if (hasProperty(desc, "get")) {
  1800. var g = desc.get;
  1801. if (!isCallable(g) && typeof g !== "undefined")
  1802. throw new TypeError("bad get");
  1803. d.get = g;
  1804. }
  1805. if (hasProperty(desc, "set")) {
  1806. var s = desc.set;
  1807. if (!isCallable(s) && typeof s !== "undefined")
  1808. throw new TypeError("bad set");
  1809. d.set = s;
  1810. }
  1811. if (("get" in d || "set" in d) && ("value" in d || "writable" in d))
  1812. throw new TypeError("identity-confused descriptor");
  1813. return d;
  1814. }
  1815. if (typeof obj !== "object" || obj === null)
  1816. throw new TypeError("bad obj");
  1817. properties = Object(properties);
  1818. var keys = Object.keys(properties);
  1819. var descs = [];
  1820. for (var i = 0; i < keys.length; i++)
  1821. descs.push([keys[i], convertToDescriptor(properties[keys[i]])]);
  1822. for (var i = 0; i < descs.length; i++)
  1823. Object.defineProperty(obj, descs[i][0], descs[i][1]);
  1824. return obj;
  1825. },
  1826. 'typeOf': function(item){
  1827. if (item == null) return 'null';
  1828. if (item.$family != null) return item.$family();
  1829. if (item.constructor == Array) return 'array';
  1830. if (item.nodeName){
  1831. if (item.nodeType == 1) return 'element';
  1832. if (item.nodeType == 3) return (/\S/).test(item.nodeValue) ? 'textnode' : 'whitespace';
  1833. } else if (typeof item.length == 'number'){
  1834. if (item.callee) return 'arguments';
  1835. //if ('item' in item) return 'collection';
  1836. }
  1837. return typeof item;
  1838. },
  1839. 'JSONDecode': function(string, secure){
  1840. if (!string || library.typeOf(string) != 'string') return null;
  1841. return eval('(' + string + ')');
  1842. },
  1843. 'JSONEncode': function(obj){
  1844. if (obj && obj.toJSON) obj = obj.toJSON();
  1845. switch (library.typeOf(obj)){
  1846. case 'string':
  1847. return '"' + obj.replace(/[\x00-\x1f\\"]/g, escape) + '"';
  1848. case 'array':
  1849. var string = [];
  1850. for (var i=0; i<obj.length; i++){
  1851. var json = library.JSONEncode(obj[i]);
  1852. if (json) string.push(json);
  1853. }
  1854. return '[' + string + ']';
  1855. case 'object': case 'hash':
  1856. var string = [];
  1857. for (key in obj){
  1858. var json = library.JSONEncode(obj[key]);
  1859. if (json) string.push(library.JSONEncode(key) + ':' + json);
  1860. }
  1861. return '{' + string + '}';
  1862. case 'number': case 'boolean': return '' + obj;
  1863. case 'null': return 'null';
  1864. }
  1865. return null;
  1866. }
  1867. };
  1868. (function(){
  1869. var o={"indexOf": {
  1870. "value": function(item, from){
  1871. var length = this.length >>> 0;
  1872. for (var i = (from < 0) ? Math.max(0, length + from) : from || 0; i < length; i++){
  1873. if (this[i] === item) return i;
  1874. }
  1875. return -1;
  1876. }
  1877. }};
  1878. library.defineProperties(Array.prototype, o);
  1879. })();
  1880. /********************
  1881. this.entityManager; //实体管理器
  1882. this.context; //上下文根
  1883. this.applications;
  1884. this.org; //组织访问
  1885. this.service;//webSerivces客户端
  1886. this.response;
  1887. this.response.seeOther(url); //303跳转
  1888. this.response.temporaryRedirect(url); //304跳转
  1889. this.response.setBody(body); //设置返回
  1890. this.requestText//请求正文
  1891. this.request//请求
  1892. this.currentPerson//当前用户
  1893. this.Actions;
  1894. this.Actions.load(root); //获取接口服务
  1895. ********************/
  1896. bind.entityManager = resources.getEntityManagerContainer();
  1897. bind.context = resources.getContext();
  1898. bind.applications = resources.getApplications();
  1899. bind.organization = resources.getOrganization();
  1900. bind.service = resources.getWebservicesClient();
  1901. //bind.response = customResponse;
  1902. //bind.customResponse = customResponse;
  1903. bind.requestText = this.requestText || null;
  1904. bind.request = this.request || null;
  1905. if (this.effectivePerson) bind.currentPerson = bind.effectivePerson = effectivePerson;
  1906. if (this.parameters) bind.parameters = JSON.parse(this.parameters); //JPQL语句传入参数
  1907. if (this.customResponse){
  1908. var _response = {
  1909. "customResponse": this.customResponse || "",
  1910. seeOther: function(url){
  1911. customResponse.seeOther(url);
  1912. },
  1913. temporaryRedirect: function(url){
  1914. customResponse.temporaryRedirect(url);
  1915. },
  1916. setBody: function(o, contentType){
  1917. var body = o;
  1918. if (typeOf(o)=="object"){
  1919. body = JSON.stringify(o);
  1920. }
  1921. customResponse.setBody(body, contentType || "");
  1922. }
  1923. };
  1924. bind.response = _response;
  1925. }
  1926. //定义方法
  1927. var _define = function(name, fun, overwrite){
  1928. var over = true;
  1929. if (overwrite===false) over = false;
  1930. var o = {};
  1931. o[name] = {"value": fun, "configurable": over};
  1932. library.defineProperties(bind, o);
  1933. };
  1934. //Action对象
  1935. var restfulAcpplication = resources.getApplications();
  1936. var _Action = (function(){
  1937. //var actions = [];
  1938. return function(root, json){
  1939. this.actions = json;
  1940. // Object.keys(json).forEach(function(key){
  1941. // this.actions[key] = json[key];
  1942. // });
  1943. //Object.merge(actions[root], json);
  1944. this.root = root;
  1945. //this.actions = actions[root];
  1946. var invokeFunction = function(service, parameters, key){
  1947. var _self = this;
  1948. return function(){
  1949. var i = parameters.length-1;
  1950. var n = arguments.length;
  1951. var functionArguments = arguments;
  1952. var parameter = {};
  1953. var success, failure, async, data, file;
  1954. if (typeOf(functionArguments[0])==="function"){
  1955. i=-1;
  1956. success = (n>++i) ? functionArguments[i] : null;
  1957. failure = (n>++i) ? functionArguments[i] : null;
  1958. parameters.each(function(p, x){
  1959. parameter[p] = (n>++i) ? functionArguments[i] : null;
  1960. });
  1961. if (service.method && (service.method.toLowerCase()==="post" || service.method.toLowerCase()==="put")){
  1962. data = (n>++i) ? functionArguments[i] : null;
  1963. }
  1964. }else{
  1965. parameters.each(function(p, x){
  1966. parameter[p] = (n>x) ? functionArguments[x] : null;
  1967. });
  1968. if (service.method && (service.method.toLowerCase()==="post" || service.method.toLowerCase()==="put")){
  1969. data = (n>++i) ? functionArguments[i] : null;
  1970. }
  1971. success = (n>++i) ? functionArguments[i] : null;
  1972. failure = (n>++i) ? functionArguments[i] : null;
  1973. }
  1974. return _self.invoke({"name": key, "data": data, "parameter": parameter, "success": success, "failure": failure});
  1975. };
  1976. };
  1977. var createMethod = function(service, key){
  1978. var jaxrsUri = service.uri;
  1979. var re = new RegExp("\{.+?\}", "g");
  1980. var replaceWords = jaxrsUri.match(re);
  1981. var parameters = [];
  1982. if (replaceWords) parameters = replaceWords.map(function(s){
  1983. return s.substring(1,s.length-1);
  1984. });
  1985. this[key] = invokeFunction.call(this, service, parameters, key);
  1986. };
  1987. Object.keys(this.actions).forEach(function(key){
  1988. var service = this.actions[key];
  1989. if (service.uri) if (!this[key]) createMethod.call(this, service, key);
  1990. }, this);
  1991. this.invoke = function(option){
  1992. // {
  1993. // "name": "",
  1994. // "data": "",
  1995. // "parameter": "",,
  1996. // "success": function(){}
  1997. // "failure": function(){}
  1998. // }
  1999. if (this.actions[option.name]){
  2000. var uri = this.actions[option.name].uri;
  2001. var method = this.actions[option.name].method || "get";
  2002. if (option.parameter){
  2003. Object.keys(option.parameter).forEach(function(key){
  2004. var v = option.parameter[key];
  2005. uri = uri.replace("{"+key+"}", v);
  2006. });
  2007. }
  2008. var res = null;
  2009. try{
  2010. switch (method.toLowerCase()){
  2011. case "get":
  2012. res = bind.applications.getQuery(this.root, uri);
  2013. break;
  2014. case "post":
  2015. res = bind.applications.postQuery(this.root, uri, JSON.stringify(option.data));
  2016. break;
  2017. case "put":
  2018. res = bind.applications.putQuery(this.root, uri, JSON.stringify(option.data));
  2019. break;
  2020. case "delete":
  2021. res = bind.applications.deleteQuery(this.root, uri);
  2022. break;
  2023. default:
  2024. res = bind.applications.getQuery(this.root, uri);
  2025. }
  2026. if (res && res.getType().toString()==="success"){
  2027. var json = JSON.parse(res.toString());
  2028. if (option.success) option.success(json);
  2029. }else{
  2030. if (option.failure) option.failure(((res) ? JSON.parse(res.toString()) : null));
  2031. }
  2032. return res;
  2033. }catch(e){
  2034. if (option.failure) option.failure(e);
  2035. }
  2036. }
  2037. };
  2038. }
  2039. })();
  2040. var _Actions = {
  2041. "loadedActions": {},
  2042. "load": function(root){
  2043. if (this.loadedActions[root]) return this.loadedActions[root];
  2044. var jaxrsString = bind.applications.describeApi(root);
  2045. var json = JSON.parse(jaxrsString.toString());
  2046. if (json && json.jaxrs){
  2047. var actionObj = {};
  2048. json.jaxrs.each(function(o){
  2049. if (o.methods && o.methods.length){
  2050. var actions = {};
  2051. o.methods.each(function(m){
  2052. var o = {"uri": "/"+m.uri};
  2053. if (m.method) o.method = m.method;
  2054. if (m.enctype) o.enctype = m.enctype;
  2055. actions[m.name] = o;
  2056. }.bind(this));
  2057. actionObj[o.name] = new bind.Action(root, actions);
  2058. }
  2059. }.bind(this));
  2060. this.loadedActions[root] = actionObj;
  2061. return actionObj;
  2062. }
  2063. return null;
  2064. }
  2065. };
  2066. bind.Actions = _Actions;
  2067. //定义所需的服务
  2068. var _processActions = new _Action("x_processplatform_assemble_surface", {
  2069. "getDictionary": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{applicationFlag}"},
  2070. "getDictRoot": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/data"},
  2071. "getDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data"},
  2072. "setDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data", "method": "PUT"},
  2073. "addDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data", "method": "POST"},
  2074. "deleteDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data", "method": "DELETE"},
  2075. "getScript": {"uri": "/jaxrs/script/{flag}/application/{applicationFlag}", "method": "POST"},
  2076. });
  2077. var _cmsActions = new _Action("x_cms_assemble_control", {
  2078. "getDictionary": {"uri": "/jaxrs/design/appdict/{appDictId}"},
  2079. "getDictRoot": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/data"},
  2080. "getDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data"},
  2081. "setDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data", "method": "PUT"},
  2082. "addDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data", "method": "POST"},
  2083. "deleteDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data", "method": "DELETE"},
  2084. "getDictRootAnonymous" : {"uri": "/jaxrs/anonymous/surface/appdict/{appDictId}/appInfo/{appId}/data"},
  2085. "getDictDataAnonymous" : {"uri": "/jaxrs/anonymous/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data"},
  2086. "getScript": {"uri": "/jaxrs/script/{flag}/appInfo/{appInfoFlag}", "method": "POST"},
  2087. });
  2088. var _portalActions = new _Action("x_portal_assemble_surface", {
  2089. "getScript": {"uri": "/jaxrs/script/portal/{portal}/name/{ }","method": "POST"}
  2090. });
  2091. //include 引用脚本
  2092. //optionsOrName : {
  2093. // type : "", 默认为process, 可以为 portal process cms
  2094. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  2095. // name : "" // 脚本名称/别名/id
  2096. //}
  2097. //或者name: "" // 脚本名称/别名/id
  2098. var _exec = function(code, _self){
  2099. var returnValue;
  2100. //try{
  2101. if (!_self) _self = this;
  2102. try {
  2103. var f = eval("(function(){return function(){\n"+code+"\n}})();");
  2104. returnValue = f.apply(_self);
  2105. }catch(e){
  2106. console.log("exec", new Error("exec script error"));
  2107. console.log(e);
  2108. }
  2109. return returnValue;
  2110. }
  2111. var includedScripts = this.includedScripts || {};
  2112. this.includedScripts = includedScripts;
  2113. var _include = function( optionsOrName , callback ){
  2114. var options = optionsOrName;
  2115. if( typeOf( options ) == "string" ){
  2116. options = { name : options };
  2117. }
  2118. var name = options.name;
  2119. var type = ( options.type && options.application ) ? options.type : "process";
  2120. var application = options.application
  2121. if (!name || !type || !application){
  2122. console.log("include", new Error("can not find script. missing script name or application"));
  2123. return false;
  2124. }
  2125. if (!includedScripts[application]) includedScripts[application] = [];
  2126. if (includedScripts[application].indexOf( name )> -1){
  2127. if (callback) callback.apply(this);
  2128. return;
  2129. }
  2130. var scriptAction;
  2131. var scriptData;
  2132. switch ( type ){
  2133. case "portal" :
  2134. _portalActions.getScript( application, name, {"importedList":includedScripts[application]}, function(json){
  2135. if (json.data){
  2136. includedScripts[application] = includedScripts[application].concat(json.data.importedList);
  2137. scriptData = json.data;
  2138. }
  2139. }.bind(this));
  2140. break;
  2141. case "process" :
  2142. _processActions.getScript( name, application, {"importedList":includedScripts[application]}, function(json){
  2143. if (json.data){
  2144. includedScripts[application] = includedScripts[application].concat(json.data.importedList);
  2145. scriptData = json.data;
  2146. }
  2147. }.bind(this));
  2148. break;
  2149. case "cms" :
  2150. _cmsActions.getScript(name, application, {"importedList":includedScripts[application]}, function(json){
  2151. if (json.data){
  2152. includedScripts[application] = includedScripts[application].concat(json.data.importedList);
  2153. scriptData = json.data;
  2154. }
  2155. }.bind(this));
  2156. break;
  2157. }
  2158. includedScripts[application].push(name);
  2159. if (scriptData && scriptData.text){
  2160. bind.exec(scriptData.text, this);
  2161. if (callback) callback.apply(this);
  2162. }
  2163. };
  2164. var _createDict = function(application){
  2165. //optionsOrName : {
  2166. // type : "", //默认为process, 可以为 process cms
  2167. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  2168. // name : "", // 数据字典名称/别名/id
  2169. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  2170. //}
  2171. //或者name: "" // 数据字典名称/别名/id
  2172. return function(optionsOrName){
  2173. var options = optionsOrName;
  2174. if( typeOf( options ) == "string" ){
  2175. options = { name : options };
  2176. }
  2177. var name = this.name = options.name;
  2178. var type = ( options.type && options.application ) ? options.type : "process";
  2179. var applicationId = options.application || application;
  2180. var enableAnonymous = options.enableAnonymous || false;
  2181. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  2182. if( type == "cms" ){
  2183. var action = bind.cmsActions;
  2184. }else{
  2185. var action = bind.processActions;
  2186. }
  2187. var encodePath = function( path ){
  2188. var arr = path.split(/\./g);
  2189. var ar = arr.map(function(v){
  2190. return encodeURIComponent(v);
  2191. });
  2192. return ar.join("/");
  2193. };
  2194. this.get = function(path, success, failure){
  2195. var value = null;
  2196. if (path){
  2197. var p = encodePath( path );
  2198. action[(enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData"](encodeURIComponent(this.name), applicationId, p, function(json){
  2199. value = json.data;
  2200. if (success) success(json.data);
  2201. }, function(xhr, text, error){
  2202. if (failure) failure(xhr, text, error);
  2203. });
  2204. }else{
  2205. action[(enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot"](encodeURIComponent(this.name), applicationId, function(json){
  2206. value = json.data;
  2207. if (success) success(json.data);
  2208. }, function(xhr, text, error){
  2209. if (failure) failure(xhr, text, error);
  2210. }, false);
  2211. }
  2212. return value;
  2213. };
  2214. this.set = function(path, value, success, failure){
  2215. var p = encodePath( path );
  2216. //var p = path.replace(/\./g, "/");
  2217. action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  2218. if (success) success(json.data);
  2219. }, function(xhr, text, error){
  2220. if (failure) failure(xhr, text, error);
  2221. }, false, false);
  2222. };
  2223. this.add = function(path, value, success, failure){
  2224. var p = encodePath( path );
  2225. //var p = path.replace(/\./g, "/");
  2226. action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  2227. if (success) success(json.data);
  2228. }, function(xhr, text, error){
  2229. if (failure) failure(xhr, text, error);
  2230. }, false, false);
  2231. };
  2232. this["delete"] = function(path, success, failure){
  2233. var p = encodePath( path );
  2234. //var p = path.replace(/\./g, "/");
  2235. action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  2236. if (success) success(json.data);
  2237. }, function(xhr, text, error){
  2238. if (failure) failure(xhr, text, error);
  2239. }, false, false);
  2240. };
  2241. this.destory = this["delete"];
  2242. }
  2243. };
  2244. var getNameFlag = function(name){
  2245. var t = library.typeOf(name);
  2246. if (t==="array"){
  2247. var v = [];
  2248. name.forEach(function(id){
  2249. v.push((library.typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id);
  2250. });
  2251. return v;
  2252. }else{
  2253. return [(t==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name];
  2254. }
  2255. };
  2256. var _org = {
  2257. "oGroup": this.organization.group(),
  2258. "oIdentity": this.organization.identity(),
  2259. "oPerson": this.organization.person(),
  2260. "oPersonAttribute": this.organization.personAttribute(),
  2261. "oRole": this.organization.role(),
  2262. "oUnit": this.organization.unit(),
  2263. "oUnitAttribute": this.organization.unitAttribute(),
  2264. "oUnitDuty": this.organization.unitDuty(),
  2265. "group": function() { return this.oGroup},
  2266. "identity": function() { return this.oIdentity},
  2267. "person": function() { return this.oPerson},
  2268. "personAttribute": function() { return this.oPersonAttribute},
  2269. "role": function() { return this.oRole},
  2270. "unit": function() { return this.oUnit},
  2271. "unitAttribute": function() { return this.oUnitAttribute},
  2272. "unitDuty": function() { return this.oUnitDuty},
  2273. "getObject": function(o, v){
  2274. var arr = [];
  2275. if (!v || !v.length){
  2276. return null;
  2277. }else{
  2278. for (var i=0; i<v.length; i++){
  2279. var g = o.getObject(v[i]);
  2280. if (g) arr.push(JSON.parse(g.toString()));
  2281. }
  2282. }
  2283. return arr;
  2284. },
  2285. //群组***************
  2286. //获取群组--返回群组的对象数组
  2287. getGroup: function(name){
  2288. var v = this.oGroup.listObject(getNameFlag(name));
  2289. var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  2290. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  2291. },
  2292. //查询下级群组--返回群组的对象数组
  2293. //nested 布尔 true嵌套下级;false直接下级;默认false;
  2294. listSubGroup: function(name, nested){
  2295. var v = null;
  2296. if (nested){
  2297. v = this.oGroup.listWithGroupSubNested(getNameFlag(name));
  2298. }else{
  2299. v = this.oGroup.listWithGroupSubDirect(getNameFlag(name));
  2300. }
  2301. return this.getObject(this.oGroup, v);
  2302. },
  2303. //查询上级群组--返回群组的对象数组
  2304. //nested 布尔 true嵌套上级;false直接上级;默认false;
  2305. listSupGroup:function(name, nested){
  2306. var v = null;
  2307. if (nested){
  2308. v = this.oGroup.listWithGroupSupNested(getNameFlag(name));
  2309. }else{
  2310. v = this.oGroup.listWithGroupSupDirect(getNameFlag(name));
  2311. }
  2312. return this.getObject(this.oGroup, v);
  2313. },
  2314. //人员所在群组(嵌套)--返回群组的对象数组
  2315. listGroupWithPerson:function(name){
  2316. var v = this.oGroup.listWithPerson(getNameFlag(name));
  2317. return this.getObject(this.oGroup, v);
  2318. },
  2319. //群组是否拥有角色--返回true, false
  2320. groupHasRole: function(name, role){
  2321. nameFlag = (library.typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  2322. return this.oGroup.hasRole(nameFlag, getNameFlag(role));
  2323. },
  2324. //角色***************
  2325. //获取角色--返回角色的对象数组
  2326. getRole: function(name){
  2327. var v = this.oRole.listObject(getNameFlag(name));
  2328. var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  2329. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  2330. },
  2331. //人员所有角色(嵌套)--返回角色的对象数组
  2332. listRoleWithPerson:function(name){
  2333. var v = this.oRole.listWithPerson(getNameFlag(name));
  2334. return this.getObject(this.oRole, v);
  2335. },
  2336. //人员***************
  2337. //人员是否拥有角色--返回true, false
  2338. personHasRole: function(name, role){
  2339. nameFlag = (library.typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  2340. return this.oPerson.hasRole(nameFlag, getNameFlag(role));
  2341. },
  2342. //获取人员--返回人员的对象数组
  2343. getPerson: function(name){
  2344. var v = this.oPerson.listObject(getNameFlag(name));
  2345. var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  2346. // if (!v || !v.length) v = null;
  2347. // return (v && v.length===1) ? v[0] : v;
  2348. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  2349. },
  2350. //查询下级人员--返回人员的对象数组
  2351. //nested 布尔 true嵌套下级;false直接下级;默认false;
  2352. listSubPerson: function(name, nested){
  2353. var v = null;
  2354. if (nested){
  2355. v = this.oPerson.listWithPersonSubNested(getNameFlag(name));
  2356. }else{
  2357. v = this.oPerson.listWithPersonSubDirect(getNameFlag(name));
  2358. }
  2359. return this.getObject(this.oPerson, v);
  2360. },
  2361. //查询上级人员--返回人员的对象数组
  2362. //nested 布尔 true嵌套上级;false直接上级;默认false;
  2363. listSupPerson: function(name, nested){
  2364. var v = null;
  2365. if (nested){
  2366. v = this.oPerson.listWithPersonSupNested(getNameFlag(name));
  2367. }else{
  2368. v = this.oPerson.listWithPersonSupDirect(getNameFlag(name));
  2369. }
  2370. return this.getObject(this.oPerson, v);
  2371. },
  2372. //获取群组的所有人员--返回人员的对象数组
  2373. listPersonWithGroup: function(name){
  2374. var v = this.oPerson.listWithGroup(getNameFlag(name));
  2375. return this.getObject(this.oPerson, v);
  2376. // if (!v || !v.length) v = null;
  2377. // return v;
  2378. // var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  2379. // return v_json;
  2380. },
  2381. //获取角色的所有人员--返回人员的对象数组
  2382. listPersonWithRole: function(name){
  2383. var v = this.oPerson.listWithRole(getNameFlag(name));
  2384. return this.getObject(this.oPerson, v);
  2385. },
  2386. //获取身份的所有人员--返回人员的对象数组
  2387. listPersonWithIdentity: function(name){
  2388. var v = this.oPerson.listWithIdentity(getNameFlag(name));
  2389. return this.getObject(this.oPerson, v);
  2390. },
  2391. //获取身份的所有人员--返回人员的对象数组
  2392. getPersonWithIdentity: function(name){
  2393. var v = this.oPerson.listWithIdentity(getNameFlag(name));
  2394. var arr = this.getObject(this.oPerson, v);
  2395. return (arr && arr.length) ? arr[0] : null;
  2396. },
  2397. //查询组织成员的人员--返回人员的对象数组
  2398. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  2399. listPersonWithUnit: function(name, nested){
  2400. var v = null;
  2401. if (nested){
  2402. v = this.oPerson.listWithUnitSubNested(getNameFlag(name));
  2403. }else{
  2404. v = this.oPerson.listWithUnitSubDirect(getNameFlag(name));
  2405. }
  2406. return this.getObject(this.oPerson, v);
  2407. },
  2408. //人员属性************
  2409. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  2410. appendPersonAttribute: function(person, attr, values){
  2411. var personFlag = (library.typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  2412. return this.oPersonAttribute.appendWithPersonWithName(personFlag, attr, values);
  2413. },
  2414. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  2415. setPersonAttribute: function(person, attr, values){
  2416. var personFlag = (library.typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  2417. return this.oPersonAttribute.setWithPersonWithName(personFlag, attr, values);
  2418. },
  2419. //获取人员属性值
  2420. getPersonAttribute: function(person, attr){
  2421. var personFlag = (library.typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  2422. var v = this.oPersonAttribute.listAttributeWithPersonWithName(personFlag, attr);
  2423. var v_json = [];
  2424. if (v && v.length){
  2425. for (var i=0; i<v.length; i++){
  2426. v_json.push(v[i].toString());
  2427. }
  2428. }
  2429. return v_json;
  2430. },
  2431. //列出人员所有属性的名称
  2432. listPersonAttributeName: function(name){
  2433. var p = getNameFlag(name);
  2434. var nameList = [];
  2435. for (var i=0; i<p.length; i++){
  2436. var v = this.oPersonAttribute.listNameWithPerson(p[i]);
  2437. if (v && v.length){
  2438. for (var j=0; j<v.length; j++){
  2439. if (nameList.indexOf(v[j])==-1) nameList.push(v[j].toString());
  2440. }
  2441. }
  2442. }
  2443. return nameList;
  2444. },
  2445. //列出人员的所有属性
  2446. //listPersonAllAttribute: function(name){
  2447. // getOrgActions();
  2448. // var data = {"personList":getNameFlag(name)};
  2449. // var v = null;
  2450. // orgActions.listPersonAllAttribute(data, function(json){v = json.data;}, null, false);
  2451. // return v;
  2452. //},
  2453. //身份**********
  2454. //获取身份
  2455. getIdentity: function(name){
  2456. var v = this.oIdentity.listObject(getNameFlag(name));
  2457. var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  2458. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  2459. // if (!v || !v.length) v = null;
  2460. // return (v && v.length===1) ? v[0] : v;
  2461. },
  2462. //列出人员的身份
  2463. listIdentityWithPerson: function(name){
  2464. var v = this.oIdentity.listWithPerson(getNameFlag(name));
  2465. return this.getObject(this.oIdentity, v);
  2466. },
  2467. //查询组织成员身份--返回身份的对象数组
  2468. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  2469. listIdentityWithUnit: function(name, nested){
  2470. var v = null;
  2471. if (nested){
  2472. v = this.oIdentity.listWithUnitSubNested(getNameFlag(name));
  2473. }else{
  2474. v = this.oIdentity.listWithUnitSubDirect(getNameFlag(name));
  2475. }
  2476. return this.getObject(this.oIdentity, v);
  2477. },
  2478. //组织**********
  2479. //获取组织
  2480. getUnit: function(name){
  2481. var v = this.oUnit.listObject(getNameFlag(name));
  2482. var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  2483. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  2484. // if (!v || !v.length) v = null;
  2485. // return (v && v.length===1) ? v[0] : v;
  2486. },
  2487. //查询组织的下级--返回组织的对象数组
  2488. //nested 布尔 true嵌套下级;false直接下级;默认false;
  2489. listSubUnit: function(name, nested){
  2490. var v = null;
  2491. if (nested){
  2492. v = this.oUnit.listWithUnitSubNested(getNameFlag(name));
  2493. }else{
  2494. v = this.oUnit.listWithUnitSubDirect(getNameFlag(name));
  2495. }
  2496. return this.getObject(this.oUnit, v);
  2497. },
  2498. //查询组织的上级--返回组织的对象数组
  2499. //nested 布尔 true嵌套上级;false直接上级;默认false;
  2500. listSupUnit: function(name, nested){
  2501. var v = null;
  2502. if (nested){
  2503. v = this.oUnit.listWithUnitSupNested(getNameFlag(name));
  2504. }else{
  2505. v = this.oUnit.listWithUnitSupDirect(getNameFlag(name));
  2506. }
  2507. return this.getObject(this.oUnit, v);
  2508. },
  2509. //根据个人身份获取组织
  2510. //flag 数字 表示获取第几层的组织
  2511. // 字符串 表示获取指定类型的组织
  2512. // 空 表示获取直接所在的组织
  2513. getUnitByIdentity: function(name, flag){
  2514. //getOrgActions();
  2515. var getUnitMethod = "current";
  2516. var v;
  2517. if (flag){
  2518. if (library.typeOf(flag)==="string") getUnitMethod = "type";
  2519. if (library.typeOf(flag)==="number") getUnitMethod = "level";
  2520. }
  2521. var n = getNameFlag(name)[0];
  2522. switch (getUnitMethod){
  2523. case "current":
  2524. v = this.oUnit.getWithIdentity(n);
  2525. break;
  2526. case "type":
  2527. v = this.oUnit.getWithIdentityWithType(n, flag);
  2528. break;
  2529. case "level":
  2530. v = this.oUnit.getWithIdentityWithLevel(n, flag);
  2531. break;
  2532. }
  2533. var o = this.getObject(this.oUnit, [v]);
  2534. return (o && o.length===1) ? o[0] : o;
  2535. },
  2536. //列出身份所在组织的所有上级组织
  2537. listAllSupUnitWithIdentity: function(name){
  2538. var v = this.oUnit.listWithIdentitySupNested(getNameFlag(name));
  2539. return this.getObject(this.oUnit, v);
  2540. },
  2541. //获取人员所在的所有组织(直接所在组织)
  2542. listUnitWithPerson: function(name){
  2543. var v = this.oUnit.listWithPerson(getNameFlag(name));
  2544. return this.getObject(this.oUnit, v);
  2545. },
  2546. //列出人员所在组织的所有上级组织
  2547. listAllSupUnitWithPerson: function(name){
  2548. var v = this.oUnit.listWithPersonSupNested(getNameFlag(name));
  2549. return this.getObject(this.oUnit, v);
  2550. },
  2551. //根据组织属性,获取所有符合的组织
  2552. listUnitWithAttribute: function(name, attribute){
  2553. var v = this.oUnit.listWithUnitAttribute(name, attribute);
  2554. return this.getObject(this.oUnit, v);
  2555. },
  2556. //根据组织职务,获取所有符合的组织
  2557. listUnitWithDuty: function(name, id){
  2558. var idflag = (library.typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id;
  2559. var v = this.oUnit.listWithUnitDuty(name, idflag);
  2560. return this.getObject(this.oUnit, v);
  2561. },
  2562. //组织职务***********
  2563. //获取指定的组织职务的身份
  2564. getDuty: function(duty, id){
  2565. var unit = (library.typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id;
  2566. var v = this.oUnitDuty.listIdentityWithUnitWithName(unit, duty);
  2567. return this.getObject(this.oIdentity, v);
  2568. },
  2569. //获取身份的所有职务名称
  2570. listDutyNameWithIdentity: function(name){
  2571. var ids = getNameFlag(name);
  2572. var nameList = [];
  2573. for (var i=0; i<ids.length; i++){
  2574. var v = this.oUnitDuty.listNameWithIdentity(ids[i]);
  2575. if (v && v.length){
  2576. for (var j=0; j<v.length; j++){
  2577. if (nameList.indexOf(v[j])==-1) nameList.push(v[j].toString());
  2578. }
  2579. }
  2580. }
  2581. return nameList;
  2582. },
  2583. //获取组织的所有职务名称
  2584. listDutyNameWithUnit: function(name){
  2585. var ids = getNameFlag(name);
  2586. var nameList = [];
  2587. for (var i=0; i<ids.length; i++){
  2588. var v = this.oUnitDuty.listNameWithUnit(ids[i]);
  2589. if (v && v.length){
  2590. for (var j=0; j<v.length; j++){
  2591. if (nameList.indexOf(v[j])==-1) nameList.push(v[j].toString());
  2592. }
  2593. }
  2594. }
  2595. return nameList;
  2596. },
  2597. //获取组织的所有职务
  2598. listUnitAllDuty: function(name){
  2599. var u = getNameFlag(name)[0];
  2600. var ds = this.oUnitDuty.listNameWithUnit(u);
  2601. var o = []
  2602. for (var i=0; i<ds.length; i++){
  2603. v = this.oUnitDuty.listIdentityWithUnitWithName(u, ds[i]);
  2604. o.push({"name": ds[i], "identityList": this.getObject(this.oIdentity, v)});
  2605. }
  2606. return o;
  2607. },
  2608. //组织属性**************
  2609. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  2610. appendUnitAttribute: function(unit, attr, values){
  2611. var unitFlag = (library.typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  2612. return this.oUnitAttribute.appendWithUnitWithName(unitFlag, attr, values);
  2613. },
  2614. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  2615. setUnitAttribute: function(unit, attr, values){
  2616. var unitFlag = (library.typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  2617. return this.oUnitAttribute.setWithUnitWithName(unitFlag, attr, values);
  2618. },
  2619. //获取组织属性值
  2620. getUnitAttribute: function(unit, attr){
  2621. var unitFlag = (library.typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  2622. var v = this.oUnitAttribute.listAttributeWithUnitWithName(unitFlag, attr);
  2623. var v_json = [];
  2624. if (v && v.length){
  2625. for (var i=0; i<v.length; i++){
  2626. v_json.push(v[i].toString());
  2627. }
  2628. }
  2629. return v_json;
  2630. },
  2631. //列出组织所有属性的名称
  2632. listUnitAttributeName: function(name){
  2633. var p = getNameFlag(name);
  2634. var nameList = [];
  2635. for (var i=0; i<p.length; i++){
  2636. var v = this.oUnitAttribute.listNameWithUnit(p[i]);
  2637. if (v && v.length){
  2638. for (var j=0; j<v.length; j++){
  2639. if (nameList.indexOf(v[j])==-1) nameList.push(v[j]);
  2640. }
  2641. }
  2642. }
  2643. return nameList;
  2644. },
  2645. //列出组织的所有属性
  2646. listUnitAllAttribute: function(name){
  2647. var u = getNameFlag(name)[0];
  2648. var ds = this.oUnitAttribute.listNameWithUnit(u);
  2649. var o = []
  2650. for (var i=0; i<ds.length; i++){
  2651. v = this.getUnitAttribute(u, ds[i]);
  2652. o.push({"name": ds[i], "valueList":v});
  2653. }
  2654. return o;
  2655. }
  2656. };
  2657. bind.org = _org;
  2658. bind.library = library;
  2659. bind.define = _define;
  2660. bind.Action = _Action;
  2661. bind.Actions = _Actions;
  2662. bind.processActions = _processActions;
  2663. bind.cmsActions = _cmsActions;
  2664. bind.portalActions = _portalActions;
  2665. bind.exec = _exec;
  2666. bind.include = _include;
  2667. bind.Dict = _createDict();