initialServiceScriptText.js 102 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274
  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. print(uri);
  2011. switch (method.toLowerCase()){
  2012. case "get":
  2013. res = bind.applications.getQuery(this.root, uri);
  2014. break;
  2015. case "post":
  2016. res = bind.applications.postQuery(this.root, uri, JSON.stringify(option.data));
  2017. break;
  2018. case "put":
  2019. res = bind.applications.putQuery(this.root, uri, JSON.stringify(option.data));
  2020. break;
  2021. case "delete":
  2022. res = bind.applications.deleteQuery(this.root, uri);
  2023. break;
  2024. default:
  2025. res = bind.applications.getQuery(this.root, uri);
  2026. }
  2027. if (res && res.getType().toString()==="success"){
  2028. var json = JSON.parse(res.toString());
  2029. if (option.success) option.success(json);
  2030. }else{
  2031. if (option.failure) option.failure(((res) ? JSON.parse(res.toString()) : null));
  2032. }
  2033. return res;
  2034. }catch(e){
  2035. if (option.failure) option.failure(e);
  2036. }
  2037. }
  2038. };
  2039. }
  2040. })();
  2041. var _Actions = {
  2042. "loadedActions": {},
  2043. "load": function(root){
  2044. if (this.loadedActions[root]) return this.loadedActions[root];
  2045. var jaxrsString = bind.applications.describeApi(root);
  2046. var json = JSON.parse(jaxrsString.toString());
  2047. if (json && json.jaxrs){
  2048. var actionObj = {};
  2049. json.jaxrs.each(function(o){
  2050. if (o.methods && o.methods.length){
  2051. var actions = {};
  2052. o.methods.each(function(m){
  2053. var o = {"uri": "/"+m.uri};
  2054. if (m.method) o.method = m.method;
  2055. if (m.enctype) o.enctype = m.enctype;
  2056. actions[m.name] = o;
  2057. }.bind(this));
  2058. actionObj[o.name] = new bind.Action(root, actions);
  2059. }
  2060. }.bind(this));
  2061. this.loadedActions[root] = actionObj;
  2062. return actionObj;
  2063. }
  2064. return null;
  2065. }
  2066. };
  2067. bind.Actions = _Actions;
  2068. //定义所需的服务
  2069. var _processActions = new _Action("x_processplatform_assemble_surface", {
  2070. "getDictionary": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{applicationFlag}"},
  2071. "getDictRoot": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/data"},
  2072. "getDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data"},
  2073. "setDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data", "method": "PUT"},
  2074. "addDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data", "method": "POST"},
  2075. "deleteDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data", "method": "DELETE"},
  2076. "getScript": {"uri": "/jaxrs/script/{flag}/application/{applicationFlag}", "method": "POST"},
  2077. });
  2078. var _cmsActions = new _Action("x_cms_assemble_control", {
  2079. "getDictionary": {"uri": "/jaxrs/design/appdict/{appDictId}"},
  2080. "getDictRoot": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/data"},
  2081. "getDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data"},
  2082. "setDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data", "method": "PUT"},
  2083. "addDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data", "method": "POST"},
  2084. "deleteDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data", "method": "DELETE"},
  2085. "getDictRootAnonymous" : {"uri": "/jaxrs/anonymous/surface/appdict/{appDictId}/appInfo/{appId}/data"},
  2086. "getDictDataAnonymous" : {"uri": "/jaxrs/anonymous/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data"},
  2087. "getScript": {"uri": "/jaxrs/script/{flag}/appInfo/{appInfoFlag}", "method": "POST"},
  2088. });
  2089. var _portalActions = new _Action("x_portal_assemble_surface", {
  2090. "getScript": {"uri": "/jaxrs/script/portal/{portal}/name/{ }","method": "POST"}
  2091. });
  2092. //include 引用脚本
  2093. //optionsOrName : {
  2094. // type : "", 默认为process, 可以为 portal process cms
  2095. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  2096. // name : "" // 脚本名称/别名/id
  2097. //}
  2098. //或者name: "" // 脚本名称/别名/id
  2099. var _exec = function(code, _self){
  2100. var returnValue;
  2101. //try{
  2102. if (!_self) _self = this;
  2103. try {
  2104. var f = eval("(function(){return function(){\n"+code+"\n}})();");
  2105. returnValue = f.apply(_self);
  2106. }catch(e){
  2107. console.log("exec", new Error("exec script error"));
  2108. console.log(e);
  2109. }
  2110. return returnValue;
  2111. }
  2112. var includedScripts = this.includedScripts || {};
  2113. this.includedScripts = includedScripts;
  2114. var _include = function( optionsOrName , callback ){
  2115. var options = optionsOrName;
  2116. if( typeOf( options ) == "string" ){
  2117. options = { name : options };
  2118. }
  2119. var name = options.name;
  2120. var type = ( options.type && options.application ) ? options.type : "process";
  2121. var application = options.application
  2122. if (!name || !type || !application){
  2123. console.log("include", new Error("can not find script. missing script name or application"));
  2124. return false;
  2125. }
  2126. if (!includedScripts[application]) includedScripts[application] = [];
  2127. if (includedScripts[application].indexOf( name )> -1){
  2128. if (callback) callback.apply(this);
  2129. return;
  2130. }
  2131. var scriptAction;
  2132. var scriptData;
  2133. switch ( type ){
  2134. case "portal" :
  2135. _portalActions.getScript( application, name, {"importedList":includedScripts[application]}, function(json){
  2136. if (json.data){
  2137. includedScripts[application] = includedScripts[application].concat(json.data.importedList);
  2138. scriptData = json.data;
  2139. }
  2140. }.bind(this));
  2141. break;
  2142. case "process" :
  2143. _processActions.getScript( name, application, {"importedList":includedScripts[application]}, function(json){
  2144. if (json.data){
  2145. includedScripts[application] = includedScripts[application].concat(json.data.importedList);
  2146. scriptData = json.data;
  2147. }
  2148. }.bind(this));
  2149. break;
  2150. case "cms" :
  2151. _cmsActions.getScript(name, application, {"importedList":includedScripts[application]}, function(json){
  2152. if (json.data){
  2153. includedScripts[application] = includedScripts[application].concat(json.data.importedList);
  2154. scriptData = json.data;
  2155. }
  2156. }.bind(this));
  2157. break;
  2158. }
  2159. includedScripts[application].push(name);
  2160. if (scriptData && scriptData.text){
  2161. bind.exec(scriptData.text, this);
  2162. if (callback) callback.apply(this);
  2163. }
  2164. };
  2165. var _createDict = function(application){
  2166. //optionsOrName : {
  2167. // type : "", //默认为process, 可以为 process cms
  2168. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  2169. // name : "", // 数据字典名称/别名/id
  2170. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  2171. //}
  2172. //或者name: "" // 数据字典名称/别名/id
  2173. return function(optionsOrName){
  2174. var options = optionsOrName;
  2175. if( typeOf( options ) == "string" ){
  2176. options = { name : options };
  2177. }
  2178. var name = this.name = options.name;
  2179. var type = ( options.type && options.application ) ? options.type : "process";
  2180. var applicationId = options.application || application;
  2181. var enableAnonymous = options.enableAnonymous || false;
  2182. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  2183. if( type == "cms" ){
  2184. var action = bind.cmsActions;
  2185. }else{
  2186. var action = bind.processActions;
  2187. }
  2188. var encodePath = function( path ){
  2189. var arr = path.split(/\./g);
  2190. var ar = arr.map(function(v){
  2191. return encodeURIComponent(v);
  2192. });
  2193. return ar.join("/");
  2194. };
  2195. this.get = function(path, success, failure){
  2196. var value = null;
  2197. if (path){
  2198. var p = encodePath( path );
  2199. action[(enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData"](encodeURIComponent(this.name), applicationId, p, function(json){
  2200. value = json.data;
  2201. if (success) success(json.data);
  2202. }, function(xhr, text, error){
  2203. if (failure) failure(xhr, text, error);
  2204. });
  2205. }else{
  2206. action[(enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot"](encodeURIComponent(this.name), applicationId, function(json){
  2207. value = json.data;
  2208. if (success) success(json.data);
  2209. }, function(xhr, text, error){
  2210. if (failure) failure(xhr, text, error);
  2211. }, false);
  2212. }
  2213. return value;
  2214. };
  2215. this.set = function(path, value, success, failure){
  2216. var p = encodePath( path );
  2217. //var p = path.replace(/\./g, "/");
  2218. action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  2219. if (success) success(json.data);
  2220. }, function(xhr, text, error){
  2221. if (failure) failure(xhr, text, error);
  2222. }, false, false);
  2223. };
  2224. this.add = function(path, value, success, failure){
  2225. var p = encodePath( path );
  2226. //var p = path.replace(/\./g, "/");
  2227. action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  2228. if (success) success(json.data);
  2229. }, function(xhr, text, error){
  2230. if (failure) failure(xhr, text, error);
  2231. }, false, false);
  2232. };
  2233. this["delete"] = function(path, success, failure){
  2234. var p = encodePath( path );
  2235. //var p = path.replace(/\./g, "/");
  2236. action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  2237. if (success) success(json.data);
  2238. }, function(xhr, text, error){
  2239. if (failure) failure(xhr, text, error);
  2240. }, false, false);
  2241. };
  2242. this.destory = this["delete"];
  2243. }
  2244. };
  2245. var getNameFlag = function(name){
  2246. var t = library.typeOf(name);
  2247. if (t==="array"){
  2248. var v = [];
  2249. name.forEach(function(id){
  2250. v.push((library.typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id);
  2251. });
  2252. return v;
  2253. }else{
  2254. return [(t==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name];
  2255. }
  2256. };
  2257. var _org = {
  2258. "oGroup": this.organization.group(),
  2259. "oIdentity": this.organization.identity(),
  2260. "oPerson": this.organization.person(),
  2261. "oPersonAttribute": this.organization.personAttribute(),
  2262. "oRole": this.organization.role(),
  2263. "oUnit": this.organization.unit(),
  2264. "oUnitAttribute": this.organization.unitAttribute(),
  2265. "oUnitDuty": this.organization.unitDuty(),
  2266. "group": function() { return this.oGroup},
  2267. "identity": function() { return this.oIdentity},
  2268. "person": function() { return this.oPerson},
  2269. "personAttribute": function() { return this.oPersonAttribute},
  2270. "role": function() { return this.oRole},
  2271. "unit": function() { return this.oUnit},
  2272. "unitAttribute": function() { return this.oUnitAttribute},
  2273. "unitDuty": function() { return this.oUnitDuty},
  2274. "getObject": function(o, v){
  2275. var arr = [];
  2276. if (!v || !v.length){
  2277. return null;
  2278. }else{
  2279. for (var i=0; i<v.length; i++){
  2280. var g = o.getObject(v[i]);
  2281. if (g) arr.push(JSON.parse(g.toString()));
  2282. }
  2283. }
  2284. return arr;
  2285. },
  2286. //群组***************
  2287. //获取群组--返回群组的对象数组
  2288. getGroup: function(name){
  2289. var v = this.oGroup.listObject(getNameFlag(name));
  2290. var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  2291. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  2292. },
  2293. //查询下级群组--返回群组的对象数组
  2294. //nested 布尔 true嵌套下级;false直接下级;默认false;
  2295. listSubGroup: function(name, nested){
  2296. var v = null;
  2297. if (nested){
  2298. v = this.oGroup.listWithGroupSubNested(getNameFlag(name));
  2299. }else{
  2300. v = this.oGroup.listWithGroupSubDirect(getNameFlag(name));
  2301. }
  2302. return this.getObject(this.oGroup, v);
  2303. },
  2304. //查询上级群组--返回群组的对象数组
  2305. //nested 布尔 true嵌套上级;false直接上级;默认false;
  2306. listSupGroup:function(name, nested){
  2307. var v = null;
  2308. if (nested){
  2309. v = this.oGroup.listWithGroupSupNested(getNameFlag(name));
  2310. }else{
  2311. v = this.oGroup.listWithGroupSupDirect(getNameFlag(name));
  2312. }
  2313. return this.getObject(this.oGroup, v);
  2314. },
  2315. //人员所在群组(嵌套)--返回群组的对象数组
  2316. listGroupWithPerson:function(name){
  2317. var v = this.oGroup.listWithPerson(getNameFlag(name));
  2318. return this.getObject(this.oGroup, v);
  2319. },
  2320. //群组是否拥有角色--返回true, false
  2321. groupHasRole: function(name, role){
  2322. nameFlag = (library.typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  2323. return this.oGroup.hasRole(nameFlag, getNameFlag(role));
  2324. },
  2325. //角色***************
  2326. //获取角色--返回角色的对象数组
  2327. getRole: function(name){
  2328. var v = this.oRole.listObject(getNameFlag(name));
  2329. var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  2330. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  2331. },
  2332. //人员所有角色(嵌套)--返回角色的对象数组
  2333. listRoleWithPerson:function(name){
  2334. var v = this.oRole.listWithPerson(getNameFlag(name));
  2335. return this.getObject(this.oRole, v);
  2336. },
  2337. //人员***************
  2338. //人员是否拥有角色--返回true, false
  2339. personHasRole: function(name, role){
  2340. nameFlag = (library.typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  2341. return this.oPerson.hasRole(nameFlag, getNameFlag(role));
  2342. },
  2343. //获取人员--返回人员的对象数组
  2344. getPerson: function(name){
  2345. var v = this.oPerson.listObject(getNameFlag(name));
  2346. var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  2347. // if (!v || !v.length) v = null;
  2348. // return (v && v.length===1) ? v[0] : v;
  2349. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  2350. },
  2351. //查询下级人员--返回人员的对象数组
  2352. //nested 布尔 true嵌套下级;false直接下级;默认false;
  2353. listSubPerson: function(name, nested){
  2354. var v = null;
  2355. if (nested){
  2356. v = this.oPerson.listWithPersonSubNested(getNameFlag(name));
  2357. }else{
  2358. v = this.oPerson.listWithPersonSubDirect(getNameFlag(name));
  2359. }
  2360. return this.getObject(this.oPerson, v);
  2361. },
  2362. //查询上级人员--返回人员的对象数组
  2363. //nested 布尔 true嵌套上级;false直接上级;默认false;
  2364. listSupPerson: function(name, nested){
  2365. var v = null;
  2366. if (nested){
  2367. v = this.oPerson.listWithPersonSupNested(getNameFlag(name));
  2368. }else{
  2369. v = this.oPerson.listWithPersonSupDirect(getNameFlag(name));
  2370. }
  2371. return this.getObject(this.oPerson, v);
  2372. },
  2373. //获取群组的所有人员--返回人员的对象数组
  2374. listPersonWithGroup: function(name){
  2375. var v = this.oPerson.listWithGroup(getNameFlag(name));
  2376. return this.getObject(this.oPerson, v);
  2377. // if (!v || !v.length) v = null;
  2378. // return v;
  2379. // var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  2380. // return v_json;
  2381. },
  2382. //获取角色的所有人员--返回人员的对象数组
  2383. listPersonWithRole: function(name){
  2384. var v = this.oPerson.listWithRole(getNameFlag(name));
  2385. return this.getObject(this.oPerson, v);
  2386. },
  2387. //获取身份的所有人员--返回人员的对象数组
  2388. listPersonWithIdentity: function(name){
  2389. var v = this.oPerson.listWithIdentity(getNameFlag(name));
  2390. return this.getObject(this.oPerson, v);
  2391. },
  2392. //获取身份的所有人员--返回人员的对象数组
  2393. getPersonWithIdentity: function(name){
  2394. var v = this.oPerson.listWithIdentity(getNameFlag(name));
  2395. var arr = this.getObject(this.oPerson, v);
  2396. return (arr && arr.length) ? arr[0] : null;
  2397. },
  2398. //查询组织成员的人员--返回人员的对象数组
  2399. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  2400. listPersonWithUnit: function(name, nested){
  2401. var v = null;
  2402. if (nested){
  2403. v = this.oPerson.listWithUnitSubNested(getNameFlag(name));
  2404. }else{
  2405. v = this.oPerson.listWithUnitSubDirect(getNameFlag(name));
  2406. }
  2407. return this.getObject(this.oPerson, v);
  2408. },
  2409. //人员属性************
  2410. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  2411. appendPersonAttribute: function(person, attr, values){
  2412. var personFlag = (library.typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  2413. return this.oPersonAttribute.appendWithPersonWithName(personFlag, attr, values);
  2414. },
  2415. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  2416. setPersonAttribute: function(person, attr, values){
  2417. var personFlag = (library.typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  2418. return this.oPersonAttribute.setWithPersonWithName(personFlag, attr, values);
  2419. },
  2420. //获取人员属性值
  2421. getPersonAttribute: function(person, attr){
  2422. var personFlag = (library.typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  2423. var v = this.oPersonAttribute.listAttributeWithPersonWithName(personFlag, attr);
  2424. var v_json = [];
  2425. if (v && v.length){
  2426. for (var i=0; i<v.length; i++){
  2427. v_json.push(v[i].toString());
  2428. }
  2429. }
  2430. return v_json;
  2431. },
  2432. //列出人员所有属性的名称
  2433. listPersonAttributeName: function(name){
  2434. var p = getNameFlag(name);
  2435. var nameList = [];
  2436. for (var i=0; i<p.length; i++){
  2437. var v = this.oPersonAttribute.listNameWithPerson(p[i]);
  2438. if (v && v.length){
  2439. for (var j=0; j<v.length; j++){
  2440. if (nameList.indexOf(v[j])==-1) nameList.push(v[j].toString());
  2441. }
  2442. }
  2443. }
  2444. return nameList;
  2445. },
  2446. //列出人员的所有属性
  2447. //listPersonAllAttribute: function(name){
  2448. // getOrgActions();
  2449. // var data = {"personList":getNameFlag(name)};
  2450. // var v = null;
  2451. // orgActions.listPersonAllAttribute(data, function(json){v = json.data;}, null, false);
  2452. // return v;
  2453. //},
  2454. //身份**********
  2455. //获取身份
  2456. getIdentity: function(name){
  2457. var v = this.oIdentity.listObject(getNameFlag(name));
  2458. var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  2459. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  2460. // if (!v || !v.length) v = null;
  2461. // return (v && v.length===1) ? v[0] : v;
  2462. },
  2463. //列出人员的身份
  2464. listIdentityWithPerson: function(name){
  2465. var v = this.oIdentity.listWithPerson(getNameFlag(name));
  2466. return this.getObject(this.oIdentity, v);
  2467. },
  2468. //查询组织成员身份--返回身份的对象数组
  2469. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  2470. listIdentityWithUnit: function(name, nested){
  2471. var v = null;
  2472. if (nested){
  2473. v = this.oIdentity.listWithUnitSubNested(getNameFlag(name));
  2474. }else{
  2475. v = this.oIdentity.listWithUnitSubDirect(getNameFlag(name));
  2476. }
  2477. return this.getObject(this.oIdentity, v);
  2478. },
  2479. //组织**********
  2480. //获取组织
  2481. getUnit: function(name){
  2482. var v = this.oUnit.listObject(getNameFlag(name));
  2483. var v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  2484. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  2485. // if (!v || !v.length) v = null;
  2486. // return (v && v.length===1) ? v[0] : v;
  2487. },
  2488. //查询组织的下级--返回组织的对象数组
  2489. //nested 布尔 true嵌套下级;false直接下级;默认false;
  2490. listSubUnit: function(name, nested){
  2491. var v = null;
  2492. if (nested){
  2493. v = this.oUnit.listWithUnitSubNested(getNameFlag(name));
  2494. }else{
  2495. v = this.oUnit.listWithUnitSubDirect(getNameFlag(name));
  2496. }
  2497. return this.getObject(this.oUnit, v);
  2498. },
  2499. //查询组织的上级--返回组织的对象数组
  2500. //nested 布尔 true嵌套上级;false直接上级;默认false;
  2501. listSupUnit: function(name, nested){
  2502. var v = null;
  2503. if (nested){
  2504. v = this.oUnit.listWithUnitSupNested(getNameFlag(name));
  2505. }else{
  2506. v = this.oUnit.listWithUnitSupDirect(getNameFlag(name));
  2507. }
  2508. return this.getObject(this.oUnit, v);
  2509. },
  2510. //根据个人身份获取组织
  2511. //flag 数字 表示获取第几层的组织
  2512. // 字符串 表示获取指定类型的组织
  2513. // 空 表示获取直接所在的组织
  2514. getUnitByIdentity: function(name, flag){
  2515. //getOrgActions();
  2516. var getUnitMethod = "current";
  2517. var v;
  2518. if (flag){
  2519. if (library.typeOf(flag)==="string") getUnitMethod = "type";
  2520. if (library.typeOf(flag)==="number") getUnitMethod = "level";
  2521. }
  2522. var n = getNameFlag(name)[0];
  2523. switch (getUnitMethod){
  2524. case "current":
  2525. v = this.oUnit.getWithIdentity(n);
  2526. break;
  2527. case "type":
  2528. v = this.oUnit.getWithIdentityWithType(n, flag);
  2529. break;
  2530. case "level":
  2531. v = this.oUnit.getWithIdentityWithLevel(n, flag);
  2532. break;
  2533. }
  2534. var o = this.getObject(this.oUnit, [v]);
  2535. return (o && o.length===1) ? o[0] : o;
  2536. },
  2537. //列出身份所在组织的所有上级组织
  2538. listAllSupUnitWithIdentity: function(name){
  2539. var v = this.oUnit.listWithIdentitySupNested(getNameFlag(name));
  2540. return this.getObject(this.oUnit, v);
  2541. },
  2542. //获取人员所在的所有组织(直接所在组织)
  2543. listUnitWithPerson: function(name){
  2544. var v = this.oUnit.listWithPerson(getNameFlag(name));
  2545. return this.getObject(this.oUnit, v);
  2546. },
  2547. //列出人员所在组织的所有上级组织
  2548. listAllSupUnitWithPerson: function(name){
  2549. var v = this.oUnit.listWithPersonSupNested(getNameFlag(name));
  2550. return this.getObject(this.oUnit, v);
  2551. },
  2552. //根据组织属性,获取所有符合的组织
  2553. listUnitWithAttribute: function(name, attribute){
  2554. var v = this.oUnit.listWithUnitAttribute(name, attribute);
  2555. return this.getObject(this.oUnit, v);
  2556. },
  2557. //根据组织职务,获取所有符合的组织
  2558. listUnitWithDuty: function(name, id){
  2559. var idflag = (library.typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id;
  2560. var v = this.oUnit.listWithUnitDuty(name, idflag);
  2561. return this.getObject(this.oUnit, v);
  2562. },
  2563. //组织职务***********
  2564. //获取指定的组织职务的身份
  2565. getDuty: function(duty, id){
  2566. var unit = (library.typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id;
  2567. var v = this.oUnitDuty.listIdentityWithUnitWithName(unit, duty);
  2568. return this.getObject(this.oIdentity, v);
  2569. },
  2570. //获取身份的所有职务名称
  2571. listDutyNameWithIdentity: function(name){
  2572. var ids = getNameFlag(name);
  2573. var nameList = [];
  2574. for (var i=0; i<ids.length; i++){
  2575. var v = this.oUnitDuty.listNameWithIdentity(ids[i]);
  2576. if (v && v.length){
  2577. for (var j=0; j<v.length; j++){
  2578. if (nameList.indexOf(v[j])==-1) nameList.push(v[j].toString());
  2579. }
  2580. }
  2581. }
  2582. return nameList;
  2583. },
  2584. //获取组织的所有职务名称
  2585. listDutyNameWithUnit: function(name){
  2586. var ids = getNameFlag(name);
  2587. var nameList = [];
  2588. for (var i=0; i<ids.length; i++){
  2589. var v = this.oUnitDuty.listNameWithUnit(ids[i]);
  2590. if (v && v.length){
  2591. for (var j=0; j<v.length; j++){
  2592. if (nameList.indexOf(v[j])==-1) nameList.push(v[j].toString());
  2593. }
  2594. }
  2595. }
  2596. return nameList;
  2597. },
  2598. //获取组织的所有职务
  2599. listUnitAllDuty: function(name){
  2600. var u = getNameFlag(name)[0];
  2601. var ds = this.oUnitDuty.listNameWithUnit(u);
  2602. var o = []
  2603. for (var i=0; i<ds.length; i++){
  2604. v = this.oUnitDuty.listIdentityWithUnitWithName(u, ds[i]);
  2605. o.push({"name": ds[i], "identityList": this.getObject(this.oIdentity, v)});
  2606. }
  2607. return o;
  2608. },
  2609. //组织属性**************
  2610. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  2611. appendUnitAttribute: function(unit, attr, values){
  2612. var unitFlag = (library.typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  2613. return this.oUnitAttribute.appendWithUnitWithName(unitFlag, attr, values);
  2614. },
  2615. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  2616. setUnitAttribute: function(unit, attr, values){
  2617. var unitFlag = (library.typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  2618. return this.oUnitAttribute.setWithUnitWithName(unitFlag, attr, values);
  2619. },
  2620. //获取组织属性值
  2621. getUnitAttribute: function(unit, attr){
  2622. var unitFlag = (library.typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  2623. var v = this.oUnitAttribute.listAttributeWithUnitWithName(unitFlag, attr);
  2624. var v_json = [];
  2625. if (v && v.length){
  2626. for (var i=0; i<v.length; i++){
  2627. v_json.push(v[i].toString());
  2628. }
  2629. }
  2630. return v_json;
  2631. },
  2632. //列出组织所有属性的名称
  2633. listUnitAttributeName: function(name){
  2634. var p = getNameFlag(name);
  2635. var nameList = [];
  2636. for (var i=0; i<p.length; i++){
  2637. var v = this.oUnitAttribute.listNameWithUnit(p[i]);
  2638. if (v && v.length){
  2639. for (var j=0; j<v.length; j++){
  2640. if (nameList.indexOf(v[j])==-1) nameList.push(v[j]);
  2641. }
  2642. }
  2643. }
  2644. return nameList;
  2645. },
  2646. //列出组织的所有属性
  2647. listUnitAllAttribute: function(name){
  2648. var u = getNameFlag(name)[0];
  2649. var ds = this.oUnitAttribute.listNameWithUnit(u);
  2650. var o = []
  2651. for (var i=0; i<ds.length; i++){
  2652. v = this.getUnitAttribute(u, ds[i]);
  2653. o.push({"name": ds[i], "valueList":v});
  2654. }
  2655. return o;
  2656. }
  2657. };
  2658. bind.org = _org;
  2659. bind.library = library;
  2660. bind.define = _define;
  2661. bind.Action = _Action;
  2662. bind.Actions = _Actions;
  2663. bind.processActions = _processActions;
  2664. bind.cmsActions = _cmsActions;
  2665. bind.portalActions = _portalActions;
  2666. bind.exec = _exec;
  2667. bind.include = _include;
  2668. bind.Dict = _createDict();