prototype.js 123 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222
  1. /* Prototype JavaScript framework, version 1.6.0.2
  2. * (c) 2005-2008 Sam Stephenson
  3. *
  4. * Prototype is freely distributable under the terms of an MIT-style license.
  5. * For details, see the Prototype web site: http://www.prototypejs.org/
  6. *
  7. *--------------------------------------------------------------------------*/
  8. var Prototype = {
  9. Version: '1.6.0.2',
  10. Browser: {
  11. IE: !!(window.attachEvent && !window.opera),
  12. Opera: !!window.opera,
  13. WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
  14. Gecko: navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
  15. MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
  16. },
  17. BrowserFeatures: {
  18. XPath: !!document.evaluate,
  19. ElementExtensions: !!window.HTMLElement,
  20. SpecificElementExtensions:
  21. document.createElement('div').__proto__ &&
  22. document.createElement('div').__proto__ !==
  23. document.createElement('form').__proto__
  24. },
  25. ScriptFragment: '<script[^>]*>([\\S\\s]*?)<\/script>',
  26. JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/,
  27. emptyFunction: function() { },
  28. K: function(x) { return x }
  29. };
  30. if (Prototype.Browser.MobileSafari)
  31. Prototype.BrowserFeatures.SpecificElementExtensions = false;
  32. /* Based on Alex Arnell's inheritance implementation. */
  33. var Class = {
  34. create: function() {
  35. var parent = null, properties = $A(arguments);
  36. if (Object.isFunction(properties[0]))
  37. parent = properties.shift();
  38. function klass() {
  39. this.initialize.apply(this, arguments);
  40. }
  41. Object.extend(klass, Class.Methods);
  42. klass.superclass = parent;
  43. klass.subclasses = [];
  44. if (parent) {
  45. var subclass = function() { };
  46. subclass.prototype = parent.prototype;
  47. klass.prototype = new subclass;
  48. parent.subclasses.push(klass);
  49. }
  50. for (var i = 0; i < properties.length; i++)
  51. klass.addMethods(properties[i]);
  52. if (!klass.prototype.initialize)
  53. klass.prototype.initialize = Prototype.emptyFunction;
  54. klass.prototype.constructor = klass;
  55. return klass;
  56. }
  57. };
  58. Class.Methods = {
  59. addMethods: function(source) {
  60. var ancestor = this.superclass && this.superclass.prototype;
  61. var properties = Object.keys(source);
  62. if (!Object.keys({ toString: true }).length)
  63. properties.push("toString", "valueOf");
  64. for (var i = 0, length = properties.length; i < length; i++) {
  65. var property = properties[i], value = source[property];
  66. if (ancestor && Object.isFunction(value) &&
  67. value.argumentNames().first() == "$super") {
  68. var method = value, value = Object.extend((function(m) {
  69. return function() { return ancestor[m].apply(this, arguments) };
  70. })(property).wrap(method), {
  71. valueOf: function() { return method },
  72. toString: function() { return method.toString() }
  73. });
  74. }
  75. this.prototype[property] = value;
  76. }
  77. return this;
  78. }
  79. };
  80. var Abstract = { };
  81. Object.extend = function(destination, source) {
  82. for (var property in source)
  83. destination[property] = source[property];
  84. return destination;
  85. };
  86. Object.extend(Object, {
  87. inspect: function(object) {
  88. try {
  89. if (Object.isUndefined(object)) return 'undefined';
  90. if (object === null) return 'null';
  91. return object.inspect ? object.inspect() : String(object);
  92. } catch (e) {
  93. if (e instanceof RangeError) return '...';
  94. throw e;
  95. }
  96. },
  97. toJSON: function(object) {
  98. var type = typeof object;
  99. switch (type) {
  100. case 'undefined':
  101. case 'function':
  102. case 'unknown': return;
  103. case 'boolean': return object.toString();
  104. }
  105. if (object === null) return 'null';
  106. if (object.toJSON) return object.toJSON();
  107. if (Object.isElement(object)) return;
  108. var results = [];
  109. for (var property in object) {
  110. var value = Object.toJSON(object[property]);
  111. if (!Object.isUndefined(value))
  112. results.push(property.toJSON() + ': ' + value);
  113. }
  114. return '{' + results.join(', ') + '}';
  115. },
  116. toQueryString: function(object) {
  117. return $H(object).toQueryString();
  118. },
  119. toHTML: function(object) {
  120. return object && object.toHTML ? object.toHTML() : String.interpret(object);
  121. },
  122. keys: function(object) {
  123. var keys = [];
  124. for (var property in object)
  125. keys.push(property);
  126. return keys;
  127. },
  128. values: function(object) {
  129. var values = [];
  130. for (var property in object)
  131. values.push(object[property]);
  132. return values;
  133. },
  134. clone: function(object) {
  135. return Object.extend({ }, object);
  136. },
  137. isElement: function(object) {
  138. return object && object.nodeType == 1;
  139. },
  140. isArray: function(object) {
  141. return object != null && typeof object == "object" &&
  142. 'splice' in object && 'join' in object;
  143. },
  144. isHash: function(object) {
  145. return object instanceof Hash;
  146. },
  147. isFunction: function(object) {
  148. return typeof object == "function";
  149. },
  150. isString: function(object) {
  151. return typeof object == "string";
  152. },
  153. isNumber: function(object) {
  154. return typeof object == "number";
  155. },
  156. isUndefined: function(object) {
  157. return typeof object == "undefined";
  158. }
  159. });
  160. Object.extend(Function.prototype, {
  161. argumentNames: function() {
  162. var names = this.toString().match(/^[\s\(]*function[^(]*\((.*?)\)/)[1].split(",").invoke("strip");
  163. return names.length == 1 && !names[0] ? [] : names;
  164. },
  165. bind: function() {
  166. if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this;
  167. var __method = this, args = $A(arguments), object = args.shift();
  168. return function() {
  169. return __method.apply(object, args.concat($A(arguments)));
  170. }
  171. },
  172. bindAsEventListener: function() {
  173. var __method = this, args = $A(arguments), object = args.shift();
  174. return function(event) {
  175. return __method.apply(object, [event || window.event].concat(args));
  176. }
  177. },
  178. curry: function() {
  179. if (!arguments.length) return this;
  180. var __method = this, args = $A(arguments);
  181. return function() {
  182. return __method.apply(this, args.concat($A(arguments)));
  183. }
  184. },
  185. delay: function() {
  186. var __method = this, args = $A(arguments), timeout = args.shift() * 1000;
  187. return window.setTimeout(function() {
  188. return __method.apply(__method, args);
  189. }, timeout);
  190. },
  191. wrap: function(wrapper) {
  192. var __method = this;
  193. return function() {
  194. return wrapper.apply(this, [__method.bind(this)].concat($A(arguments)));
  195. }
  196. },
  197. methodize: function() {
  198. if (this._methodized) return this._methodized;
  199. var __method = this;
  200. return this._methodized = function() {
  201. return __method.apply(null, [this].concat($A(arguments)));
  202. };
  203. }
  204. });
  205. Function.prototype.defer = Function.prototype.delay.curry(0.01);
  206. Date.prototype.toJSON = function() {
  207. return '"' + this.getUTCFullYear() + '-' +
  208. (this.getUTCMonth() + 1).toPaddedString(2) + '-' +
  209. this.getUTCDate().toPaddedString(2) + 'T' +
  210. this.getUTCHours().toPaddedString(2) + ':' +
  211. this.getUTCMinutes().toPaddedString(2) + ':' +
  212. this.getUTCSeconds().toPaddedString(2) + 'Z"';
  213. };
  214. var Try = {
  215. these: function() {
  216. var returnValue;
  217. for (var i = 0, length = arguments.length; i < length; i++) {
  218. var lambda = arguments[i];
  219. try {
  220. returnValue = lambda();
  221. break;
  222. } catch (e) { }
  223. }
  224. return returnValue;
  225. }
  226. };
  227. RegExp.prototype.match = RegExp.prototype.test;
  228. RegExp.escape = function(str) {
  229. return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
  230. };
  231. /*--------------------------------------------------------------------------*/
  232. var PeriodicalExecuter = Class.create({
  233. initialize: function(callback, frequency) {
  234. this.callback = callback;
  235. this.frequency = frequency;
  236. this.currentlyExecuting = false;
  237. this.registerCallback();
  238. },
  239. registerCallback: function() {
  240. this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
  241. },
  242. execute: function() {
  243. this.callback(this);
  244. },
  245. stop: function() {
  246. if (!this.timer) return;
  247. clearInterval(this.timer);
  248. this.timer = null;
  249. },
  250. onTimerEvent: function() {
  251. if (!this.currentlyExecuting) {
  252. try {
  253. this.currentlyExecuting = true;
  254. this.execute();
  255. } finally {
  256. this.currentlyExecuting = false;
  257. }
  258. }
  259. }
  260. });
  261. Object.extend(String, {
  262. interpret: function(value) {
  263. return value == null ? '' : String(value);
  264. },
  265. specialChar: {
  266. '\b': '\\b',
  267. '\t': '\\t',
  268. '\n': '\\n',
  269. '\f': '\\f',
  270. '\r': '\\r',
  271. '\\': '\\\\'
  272. }
  273. });
  274. Object.extend(String.prototype, {
  275. gsub: function(pattern, replacement) {
  276. var result = '', source = this, match;
  277. replacement = arguments.callee.prepareReplacement(replacement);
  278. while (source.length > 0) {
  279. if (match = source.match(pattern)) {
  280. result += source.slice(0, match.index);
  281. result += String.interpret(replacement(match));
  282. source = source.slice(match.index + match[0].length);
  283. } else {
  284. result += source, source = '';
  285. }
  286. }
  287. return result;
  288. },
  289. sub: function(pattern, replacement, count) {
  290. replacement = this.gsub.prepareReplacement(replacement);
  291. count = Object.isUndefined(count) ? 1 : count;
  292. return this.gsub(pattern, function(match) {
  293. if (--count < 0) return match[0];
  294. return replacement(match);
  295. });
  296. },
  297. scan: function(pattern, iterator) {
  298. this.gsub(pattern, iterator);
  299. return String(this);
  300. },
  301. truncate: function(length, truncation) {
  302. length = length || 30;
  303. truncation = Object.isUndefined(truncation) ? '...' : truncation;
  304. return this.length > length ?
  305. this.slice(0, length - truncation.length) + truncation : String(this);
  306. },
  307. strip: function() {
  308. return this.replace(/^\s+/, '').replace(/\s+$/, '');
  309. },
  310. stripTags: function() {
  311. return this.replace(/<\/?[^>]+>/gi, '');
  312. },
  313. stripScripts: function() {
  314. return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), '');
  315. },
  316. extractScripts: function() {
  317. var matchAll = new RegExp(Prototype.ScriptFragment, 'img');
  318. var matchOne = new RegExp(Prototype.ScriptFragment, 'im');
  319. return (this.match(matchAll) || []).map(function(scriptTag) {
  320. return (scriptTag.match(matchOne) || ['', ''])[1];
  321. });
  322. },
  323. evalScripts: function() {
  324. return this.extractScripts().map(function(script) { return eval(script) });
  325. },
  326. escapeHTML: function() {
  327. var self = arguments.callee;
  328. self.text.data = this;
  329. return self.div.innerHTML;
  330. },
  331. unescapeHTML: function() {
  332. var div = new Element('div');
  333. div.innerHTML = this.stripTags();
  334. return div.childNodes[0] ? (div.childNodes.length > 1 ?
  335. $A(div.childNodes).inject('', function(memo, node) { return memo+node.nodeValue }) :
  336. div.childNodes[0].nodeValue) : '';
  337. },
  338. toQueryParams: function(separator) {
  339. var match = this.strip().match(/([^?#]*)(#.*)?$/);
  340. if (!match) return { };
  341. return match[1].split(separator || '&').inject({ }, function(hash, pair) {
  342. if ((pair = pair.split('='))[0]) {
  343. var key = decodeURIComponent(pair.shift());
  344. var value = pair.length > 1 ? pair.join('=') : pair[0];
  345. if (value != undefined) value = decodeURIComponent(value);
  346. if (key in hash) {
  347. if (!Object.isArray(hash[key])) hash[key] = [hash[key]];
  348. hash[key].push(value);
  349. }
  350. else hash[key] = value;
  351. }
  352. return hash;
  353. });
  354. },
  355. toArray: function() {
  356. return this.split('');
  357. },
  358. succ: function() {
  359. return this.slice(0, this.length - 1) +
  360. String.fromCharCode(this.charCodeAt(this.length - 1) + 1);
  361. },
  362. times: function(count) {
  363. return count < 1 ? '' : new Array(count + 1).join(this);
  364. },
  365. camelize: function() {
  366. var parts = this.split('-'), len = parts.length;
  367. if (len == 1) return parts[0];
  368. var camelized = this.charAt(0) == '-'
  369. ? parts[0].charAt(0).toUpperCase() + parts[0].substring(1)
  370. : parts[0];
  371. for (var i = 1; i < len; i++)
  372. camelized += parts[i].charAt(0).toUpperCase() + parts[i].substring(1);
  373. return camelized;
  374. },
  375. capitalize: function() {
  376. return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
  377. },
  378. underscore: function() {
  379. return this.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'#{1}_#{2}').gsub(/([a-z\d])([A-Z])/,'#{1}_#{2}').gsub(/-/,'_').toLowerCase();
  380. },
  381. dasherize: function() {
  382. return this.gsub(/_/,'-');
  383. },
  384. inspect: function(useDoubleQuotes) {
  385. var escapedString = this.gsub(/[\x00-\x1f\\]/, function(match) {
  386. var character = String.specialChar[match[0]];
  387. return character ? character : '\\u00' + match[0].charCodeAt().toPaddedString(2, 16);
  388. });
  389. if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"';
  390. return "'" + escapedString.replace(/'/g, '\\\'') + "'";
  391. },
  392. toJSON: function() {
  393. return this.inspect(true);
  394. },
  395. unfilterJSON: function(filter) {
  396. return this.sub(filter || Prototype.JSONFilter, '#{1}');
  397. },
  398. isJSON: function() {
  399. var str = this;
  400. if (str.blank()) return false;
  401. str = this.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, '');
  402. return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str);
  403. },
  404. evalJSON: function(sanitize) {
  405. var json = this.unfilterJSON();
  406. try {
  407. if (!sanitize || json.isJSON()) return eval('(' + json + ')');
  408. } catch (e) { }
  409. throw new SyntaxError('Badly formed JSON string: ' + this.inspect());
  410. },
  411. include: function(pattern) {
  412. return this.indexOf(pattern) > -1;
  413. },
  414. startsWith: function(pattern) {
  415. return this.indexOf(pattern) === 0;
  416. },
  417. endsWith: function(pattern) {
  418. var d = this.length - pattern.length;
  419. return d >= 0 && this.lastIndexOf(pattern) === d;
  420. },
  421. empty: function() {
  422. return this == '';
  423. },
  424. blank: function() {
  425. return /^\s*$/.test(this);
  426. },
  427. interpolate: function(object, pattern) {
  428. return new Template(this, pattern).evaluate(object);
  429. }
  430. });
  431. if (Prototype.Browser.WebKit || Prototype.Browser.IE) Object.extend(String.prototype, {
  432. escapeHTML: function() {
  433. return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
  434. },
  435. unescapeHTML: function() {
  436. return this.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>');
  437. }
  438. });
  439. String.prototype.gsub.prepareReplacement = function(replacement) {
  440. if (Object.isFunction(replacement)) return replacement;
  441. var template = new Template(replacement);
  442. return function(match) { return template.evaluate(match) };
  443. };
  444. String.prototype.parseQuery = String.prototype.toQueryParams;
  445. Object.extend(String.prototype.escapeHTML, {
  446. div: document.createElement('div'),
  447. text: document.createTextNode('')
  448. });
  449. with (String.prototype.escapeHTML) div.appendChild(text);
  450. var Template = Class.create({
  451. initialize: function(template, pattern) {
  452. this.template = template.toString();
  453. this.pattern = pattern || Template.Pattern;
  454. },
  455. evaluate: function(object) {
  456. if (Object.isFunction(object.toTemplateReplacements))
  457. object = object.toTemplateReplacements();
  458. return this.template.gsub(this.pattern, function(match) {
  459. if (object == null) return '';
  460. var before = match[1] || '';
  461. if (before == '\\') return match[2];
  462. var ctx = object, expr = match[3];
  463. var pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/;
  464. match = pattern.exec(expr);
  465. if (match == null) return before;
  466. while (match != null) {
  467. var comp = match[1].startsWith('[') ? match[2].gsub('\\\\]', ']') : match[1];
  468. ctx = ctx[comp];
  469. if (null == ctx || '' == match[3]) break;
  470. expr = expr.substring('[' == match[3] ? match[1].length : match[0].length);
  471. match = pattern.exec(expr);
  472. }
  473. return before + String.interpret(ctx);
  474. });
  475. }
  476. });
  477. Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;
  478. var $break = { };
  479. var Enumerable = {
  480. each: function(iterator, context) {
  481. var index = 0;
  482. iterator = iterator.bind(context);
  483. try {
  484. this._each(function(value) {
  485. iterator(value, index++);
  486. });
  487. } catch (e) {
  488. if (e != $break) throw e;
  489. }
  490. return this;
  491. },
  492. eachSlice: function(number, iterator, context) {
  493. iterator = iterator ? iterator.bind(context) : Prototype.K;
  494. var index = -number, slices = [], array = this.toArray();
  495. while ((index += number) < array.length)
  496. slices.push(array.slice(index, index+number));
  497. return slices.collect(iterator, context);
  498. },
  499. all: function(iterator, context) {
  500. iterator = iterator ? iterator.bind(context) : Prototype.K;
  501. var result = true;
  502. this.each(function(value, index) {
  503. result = result && !!iterator(value, index);
  504. if (!result) throw $break;
  505. });
  506. return result;
  507. },
  508. any: function(iterator, context) {
  509. iterator = iterator ? iterator.bind(context) : Prototype.K;
  510. var result = false;
  511. this.each(function(value, index) {
  512. if (result = !!iterator(value, index))
  513. throw $break;
  514. });
  515. return result;
  516. },
  517. collect: function(iterator, context) {
  518. iterator = iterator ? iterator.bind(context) : Prototype.K;
  519. var results = [];
  520. this.each(function(value, index) {
  521. results.push(iterator(value, index));
  522. });
  523. return results;
  524. },
  525. detect: function(iterator, context) {
  526. iterator = iterator.bind(context);
  527. var result;
  528. this.each(function(value, index) {
  529. if (iterator(value, index)) {
  530. result = value;
  531. throw $break;
  532. }
  533. });
  534. return result;
  535. },
  536. findAll: function(iterator, context) {
  537. iterator = iterator.bind(context);
  538. var results = [];
  539. this.each(function(value, index) {
  540. if (iterator(value, index))
  541. results.push(value);
  542. });
  543. return results;
  544. },
  545. grep: function(filter, iterator, context) {
  546. iterator = iterator ? iterator.bind(context) : Prototype.K;
  547. var results = [];
  548. if (Object.isString(filter))
  549. filter = new RegExp(filter);
  550. this.each(function(value, index) {
  551. if (filter.match(value))
  552. results.push(iterator(value, index));
  553. });
  554. return results;
  555. },
  556. include: function(object) {
  557. if (Object.isFunction(this.indexOf))
  558. if (this.indexOf(object) != -1) return true;
  559. var found = false;
  560. this.each(function(value) {
  561. if (value == object) {
  562. found = true;
  563. throw $break;
  564. }
  565. });
  566. return found;
  567. },
  568. inGroupsOf: function(number, fillWith) {
  569. fillWith = Object.isUndefined(fillWith) ? null : fillWith;
  570. return this.eachSlice(number, function(slice) {
  571. while(slice.length < number) slice.push(fillWith);
  572. return slice;
  573. });
  574. },
  575. inject: function(memo, iterator, context) {
  576. iterator = iterator.bind(context);
  577. this.each(function(value, index) {
  578. memo = iterator(memo, value, index);
  579. });
  580. return memo;
  581. },
  582. invoke: function(method) {
  583. var args = $A(arguments).slice(1);
  584. return this.map(function(value) {
  585. return value[method].apply(value, args);
  586. });
  587. },
  588. max: function(iterator, context) {
  589. iterator = iterator ? iterator.bind(context) : Prototype.K;
  590. var result;
  591. this.each(function(value, index) {
  592. value = iterator(value, index);
  593. if (result == null || value >= result)
  594. result = value;
  595. });
  596. return result;
  597. },
  598. min: function(iterator, context) {
  599. iterator = iterator ? iterator.bind(context) : Prototype.K;
  600. var result;
  601. this.each(function(value, index) {
  602. value = iterator(value, index);
  603. if (result == null || value < result)
  604. result = value;
  605. });
  606. return result;
  607. },
  608. partition: function(iterator, context) {
  609. iterator = iterator ? iterator.bind(context) : Prototype.K;
  610. var trues = [], falses = [];
  611. this.each(function(value, index) {
  612. (iterator(value, index) ?
  613. trues : falses).push(value);
  614. });
  615. return [trues, falses];
  616. },
  617. pluck: function(property) {
  618. var results = [];
  619. this.each(function(value) {
  620. results.push(value[property]);
  621. });
  622. return results;
  623. },
  624. reject: function(iterator, context) {
  625. iterator = iterator.bind(context);
  626. var results = [];
  627. this.each(function(value, index) {
  628. if (!iterator(value, index))
  629. results.push(value);
  630. });
  631. return results;
  632. },
  633. sortBy: function(iterator, context) {
  634. iterator = iterator.bind(context);
  635. return this.map(function(value, index) {
  636. return {value: value, criteria: iterator(value, index)};
  637. }).sort(function(left, right) {
  638. var a = left.criteria, b = right.criteria;
  639. return a < b ? -1 : a > b ? 1 : 0;
  640. }).pluck('value');
  641. },
  642. toArray: function() {
  643. return this.map();
  644. },
  645. zip: function() {
  646. var iterator = Prototype.K, args = $A(arguments);
  647. if (Object.isFunction(args.last()))
  648. iterator = args.pop();
  649. var collections = [this].concat(args).map($A);
  650. return this.map(function(value, index) {
  651. return iterator(collections.pluck(index));
  652. });
  653. },
  654. size: function() {
  655. return this.toArray().length;
  656. },
  657. inspect: function() {
  658. return '#<Enumerable:' + this.toArray().inspect() + '>';
  659. }
  660. };
  661. Object.extend(Enumerable, {
  662. map: Enumerable.collect,
  663. find: Enumerable.detect,
  664. select: Enumerable.findAll,
  665. filter: Enumerable.findAll,
  666. member: Enumerable.include,
  667. entries: Enumerable.toArray,
  668. every: Enumerable.all,
  669. some: Enumerable.any
  670. });
  671. function $A(iterable) {
  672. if (!iterable) return [];
  673. if (iterable.toArray) return iterable.toArray();
  674. var length = iterable.length || 0, results = new Array(length);
  675. while (length--) results[length] = iterable[length];
  676. return results;
  677. }
  678. if (Prototype.Browser.WebKit) {
  679. $A = function(iterable) {
  680. if (!iterable) return [];
  681. if (!(Object.isFunction(iterable) && iterable == '[object NodeList]') &&
  682. iterable.toArray) return iterable.toArray();
  683. var length = iterable.length || 0, results = new Array(length);
  684. while (length--) results[length] = iterable[length];
  685. return results;
  686. };
  687. }
  688. Array.from = $A;
  689. Object.extend(Array.prototype, Enumerable);
  690. if (!Array.prototype._reverse) Array.prototype._reverse = Array.prototype.reverse;
  691. Object.extend(Array.prototype, {
  692. _each: function(iterator) {
  693. for (var i = 0, length = this.length; i < length; i++)
  694. iterator(this[i]);
  695. },
  696. clear: function() {
  697. this.length = 0;
  698. return this;
  699. },
  700. first: function() {
  701. return this[0];
  702. },
  703. last: function() {
  704. return this[this.length - 1];
  705. },
  706. compact: function() {
  707. return this.select(function(value) {
  708. return value != null;
  709. });
  710. },
  711. flatten: function() {
  712. return this.inject([], function(array, value) {
  713. return array.concat(Object.isArray(value) ?
  714. value.flatten() : [value]);
  715. });
  716. },
  717. without: function() {
  718. var values = $A(arguments);
  719. return this.select(function(value) {
  720. return !values.include(value);
  721. });
  722. },
  723. reverse: function(inline) {
  724. return (inline !== false ? this : this.toArray())._reverse();
  725. },
  726. reduce: function() {
  727. return this.length > 1 ? this : this[0];
  728. },
  729. uniq: function(sorted) {
  730. return this.inject([], function(array, value, index) {
  731. if (0 == index || (sorted ? array.last() != value : !array.include(value)))
  732. array.push(value);
  733. return array;
  734. });
  735. },
  736. intersect: function(array) {
  737. return this.uniq().findAll(function(item) {
  738. return array.detect(function(value) { return item === value });
  739. });
  740. },
  741. clone: function() {
  742. return [].concat(this);
  743. },
  744. size: function() {
  745. return this.length;
  746. },
  747. inspect: function() {
  748. return '[' + this.map(Object.inspect).join(', ') + ']';
  749. },
  750. toJSON: function() {
  751. var results = [];
  752. this.each(function(object) {
  753. var value = Object.toJSON(object);
  754. if (!Object.isUndefined(value)) results.push(value);
  755. });
  756. return '[' + results.join(', ') + ']';
  757. }
  758. });
  759. // use native browser JS 1.6 implementation if available
  760. if (Object.isFunction(Array.prototype.forEach))
  761. Array.prototype._each = Array.prototype.forEach;
  762. if (!Array.prototype.indexOf) Array.prototype.indexOf = function(item, i) {
  763. i || (i = 0);
  764. var length = this.length;
  765. if (i < 0) i = length + i;
  766. for (; i < length; i++)
  767. if (this[i] === item) return i;
  768. return -1;
  769. };
  770. if (!Array.prototype.lastIndexOf) Array.prototype.lastIndexOf = function(item, i) {
  771. i = isNaN(i) ? this.length : (i < 0 ? this.length + i : i) + 1;
  772. var n = this.slice(0, i).reverse().indexOf(item);
  773. return (n < 0) ? n : i - n - 1;
  774. };
  775. Array.prototype.toArray = Array.prototype.clone;
  776. function $w(string) {
  777. if (!Object.isString(string)) return [];
  778. string = string.strip();
  779. return string ? string.split(/\s+/) : [];
  780. }
  781. if (Prototype.Browser.Opera){
  782. Array.prototype.concat = function() {
  783. var array = [];
  784. for (var i = 0, length = this.length; i < length; i++) array.push(this[i]);
  785. for (var i = 0, length = arguments.length; i < length; i++) {
  786. if (Object.isArray(arguments[i])) {
  787. for (var j = 0, arrayLength = arguments[i].length; j < arrayLength; j++)
  788. array.push(arguments[i][j]);
  789. } else {
  790. array.push(arguments[i]);
  791. }
  792. }
  793. return array;
  794. };
  795. }
  796. Object.extend(Number.prototype, {
  797. toColorPart: function() {
  798. return this.toPaddedString(2, 16);
  799. },
  800. succ: function() {
  801. return this + 1;
  802. },
  803. times: function(iterator) {
  804. $R(0, this, true).each(iterator);
  805. return this;
  806. },
  807. toPaddedString: function(length, radix) {
  808. var string = this.toString(radix || 10);
  809. return '0'.times(length - string.length) + string;
  810. },
  811. toJSON: function() {
  812. return isFinite(this) ? this.toString() : 'null';
  813. }
  814. });
  815. $w('abs round ceil floor').each(function(method){
  816. Number.prototype[method] = Math[method].methodize();
  817. });
  818. function $H(object) {
  819. return new Hash(object);
  820. };
  821. var Hash = Class.create(Enumerable, (function() {
  822. function toQueryPair(key, value) {
  823. if (Object.isUndefined(value)) return key;
  824. return key + '=' + encodeURIComponent(String.interpret(value));
  825. }
  826. return {
  827. initialize: function(object) {
  828. this._object = Object.isHash(object) ? object.toObject() : Object.clone(object);
  829. },
  830. _each: function(iterator) {
  831. for (var key in this._object) {
  832. var value = this._object[key], pair = [key, value];
  833. pair.key = key;
  834. pair.value = value;
  835. iterator(pair);
  836. }
  837. },
  838. set: function(key, value) {
  839. return this._object[key] = value;
  840. },
  841. get: function(key) {
  842. return this._object[key];
  843. },
  844. unset: function(key) {
  845. var value = this._object[key];
  846. delete this._object[key];
  847. return value;
  848. },
  849. toObject: function() {
  850. return Object.clone(this._object);
  851. },
  852. keys: function() {
  853. return this.pluck('key');
  854. },
  855. values: function() {
  856. return this.pluck('value');
  857. },
  858. index: function(value) {
  859. var match = this.detect(function(pair) {
  860. return pair.value === value;
  861. });
  862. return match && match.key;
  863. },
  864. merge: function(object) {
  865. return this.clone().update(object);
  866. },
  867. update: function(object) {
  868. return new Hash(object).inject(this, function(result, pair) {
  869. result.set(pair.key, pair.value);
  870. return result;
  871. });
  872. },
  873. toQueryString: function() {
  874. return this.map(function(pair) {
  875. var key = encodeURIComponent(pair.key), values = pair.value;
  876. if (values && typeof values == 'object') {
  877. if (Object.isArray(values))
  878. return values.map(toQueryPair.curry(key)).join('&');
  879. }
  880. return toQueryPair(key, values);
  881. }).join('&');
  882. },
  883. inspect: function() {
  884. return '#<Hash:{' + this.map(function(pair) {
  885. return pair.map(Object.inspect).join(': ');
  886. }).join(', ') + '}>';
  887. },
  888. toJSON: function() {
  889. return Object.toJSON(this.toObject());
  890. },
  891. clone: function() {
  892. return new Hash(this);
  893. }
  894. }
  895. })());
  896. Hash.prototype.toTemplateReplacements = Hash.prototype.toObject;
  897. Hash.from = $H;
  898. var ObjectRange = Class.create(Enumerable, {
  899. initialize: function(start, end, exclusive) {
  900. this.start = start;
  901. this.end = end;
  902. this.exclusive = exclusive;
  903. },
  904. _each: function(iterator) {
  905. var value = this.start;
  906. while (this.include(value)) {
  907. iterator(value);
  908. value = value.succ();
  909. }
  910. },
  911. include: function(value) {
  912. if (value < this.start)
  913. return false;
  914. if (this.exclusive)
  915. return value < this.end;
  916. return value <= this.end;
  917. }
  918. });
  919. var $R = function(start, end, exclusive) {
  920. return new ObjectRange(start, end, exclusive);
  921. };
  922. var Ajax = {
  923. getTransport: function() {
  924. return Try.these(
  925. function() {return new XMLHttpRequest()},
  926. function() {return new ActiveXObject('Msxml2.XMLHTTP')},
  927. function() {return new ActiveXObject('Microsoft.XMLHTTP')}
  928. ) || false;
  929. },
  930. activeRequestCount: 0
  931. };
  932. Ajax.Responders = {
  933. responders: [],
  934. _each: function(iterator) {
  935. this.responders._each(iterator);
  936. },
  937. register: function(responder) {
  938. if (!this.include(responder))
  939. this.responders.push(responder);
  940. },
  941. unregister: function(responder) {
  942. this.responders = this.responders.without(responder);
  943. },
  944. dispatch: function(callback, request, transport, json) {
  945. this.each(function(responder) {
  946. if (Object.isFunction(responder[callback])) {
  947. try {
  948. responder[callback].apply(responder, [request, transport, json]);
  949. } catch (e) { }
  950. }
  951. });
  952. }
  953. };
  954. Object.extend(Ajax.Responders, Enumerable);
  955. Ajax.Responders.register({
  956. onCreate: function() { Ajax.activeRequestCount++ },
  957. onComplete: function() { Ajax.activeRequestCount-- }
  958. });
  959. Ajax.Base = Class.create({
  960. initialize: function(options) {
  961. this.options = {
  962. method: 'post',
  963. asynchronous: true,
  964. contentType: 'application/x-www-form-urlencoded',
  965. encoding: 'UTF-8',
  966. parameters: '',
  967. evalJSON: true,
  968. evalJS: true
  969. };
  970. Object.extend(this.options, options || { });
  971. this.options.method = this.options.method.toLowerCase();
  972. if (Object.isString(this.options.parameters))
  973. this.options.parameters = this.options.parameters.toQueryParams();
  974. else if (Object.isHash(this.options.parameters))
  975. this.options.parameters = this.options.parameters.toObject();
  976. }
  977. });
  978. Ajax.Request = Class.create(Ajax.Base, {
  979. _complete: false,
  980. initialize: function($super, url, options) {
  981. $super(options);
  982. this.transport = Ajax.getTransport();
  983. this.request(url);
  984. },
  985. request: function(url) {
  986. this.url = url;
  987. this.method = this.options.method;
  988. var params = Object.clone(this.options.parameters);
  989. if (!['get', 'post'].include(this.method)) {
  990. // simulate other verbs over post
  991. params['_method'] = this.method;
  992. this.method = 'post';
  993. }
  994. this.parameters = params;
  995. if (params = Object.toQueryString(params)) {
  996. // when GET, append parameters to URL
  997. if (this.method == 'get')
  998. this.url += (this.url.include('?') ? '&' : '?') + params;
  999. else if (/Konqueror|Safari|KHTML/.test(navigator.userAgent))
  1000. params += '&_=';
  1001. }
  1002. try {
  1003. var response = new Ajax.Response(this);
  1004. if (this.options.onCreate) this.options.onCreate(response);
  1005. Ajax.Responders.dispatch('onCreate', this, response);
  1006. this.transport.open(this.method.toUpperCase(), this.url,
  1007. this.options.asynchronous);
  1008. if (this.options.asynchronous) this.respondToReadyState.bind(this).defer(1);
  1009. this.transport.onreadystatechange = this.onStateChange.bind(this);
  1010. this.setRequestHeaders();
  1011. this.body = this.method == 'post' ? (this.options.postBody || params) : null;
  1012. this.transport.send(this.body);
  1013. /* Force Firefox to handle ready state 4 for synchronous requests */
  1014. if (!this.options.asynchronous && this.transport.overrideMimeType)
  1015. this.onStateChange();
  1016. }
  1017. catch (e) {
  1018. this.dispatchException(e);
  1019. }
  1020. },
  1021. onStateChange: function() {
  1022. var readyState = this.transport.readyState;
  1023. if (readyState > 1 && !((readyState == 4) && this._complete))
  1024. this.respondToReadyState(this.transport.readyState);
  1025. },
  1026. setRequestHeaders: function() {
  1027. var headers = {
  1028. 'X-Requested-With': 'XMLHttpRequest',
  1029. 'X-Prototype-Version': Prototype.Version,
  1030. 'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
  1031. };
  1032. if (this.method == 'post') {
  1033. headers['Content-type'] = this.options.contentType +
  1034. (this.options.encoding ? '; charset=' + this.options.encoding : '');
  1035. /* Force "Connection: close" for older Mozilla browsers to work
  1036. * around a bug where XMLHttpRequest sends an incorrect
  1037. * Content-length header. See Mozilla Bugzilla #246651.
  1038. */
  1039. if (this.transport.overrideMimeType &&
  1040. (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)
  1041. headers['Connection'] = 'close';
  1042. }
  1043. // user-defined headers
  1044. if (typeof this.options.requestHeaders == 'object') {
  1045. var extras = this.options.requestHeaders;
  1046. if (Object.isFunction(extras.push))
  1047. for (var i = 0, length = extras.length; i < length; i += 2)
  1048. headers[extras[i]] = extras[i+1];
  1049. else
  1050. $H(extras).each(function(pair) { headers[pair.key] = pair.value });
  1051. }
  1052. for (var name in headers)
  1053. this.transport.setRequestHeader(name, headers[name]);
  1054. },
  1055. success: function() {
  1056. var status = this.getStatus();
  1057. return !status || (status >= 200 && status < 300);
  1058. },
  1059. getStatus: function() {
  1060. try {
  1061. return this.transport.status || 0;
  1062. } catch (e) { return 0 }
  1063. },
  1064. respondToReadyState: function(readyState) {
  1065. var state = Ajax.Request.Events[readyState], response = new Ajax.Response(this);
  1066. if (state == 'Complete') {
  1067. try {
  1068. this._complete = true;
  1069. (this.options['on' + response.status]
  1070. || this.options['on' + (this.success() ? 'Success' : 'Failure')]
  1071. || Prototype.emptyFunction)(response, response.headerJSON);
  1072. } catch (e) {
  1073. this.dispatchException(e);
  1074. }
  1075. var contentType = response.getHeader('Content-type');
  1076. if (this.options.evalJS == 'force'
  1077. || (this.options.evalJS && this.isSameOrigin() && contentType
  1078. && contentType.match(/^\s*(text|application)\/(x-)?(java|ecma)script(;.*)?\s*$/i)))
  1079. this.evalResponse();
  1080. }
  1081. try {
  1082. (this.options['on' + state] || Prototype.emptyFunction)(response, response.headerJSON);
  1083. Ajax.Responders.dispatch('on' + state, this, response, response.headerJSON);
  1084. } catch (e) {
  1085. this.dispatchException(e);
  1086. }
  1087. if (state == 'Complete') {
  1088. // avoid memory leak in MSIE: clean up
  1089. this.transport.onreadystatechange = Prototype.emptyFunction;
  1090. }
  1091. },
  1092. isSameOrigin: function() {
  1093. var m = this.url.match(/^\s*https?:\/\/[^\/]*/);
  1094. return !m || (m[0] == '#{protocol}//#{domain}#{port}'.interpolate({
  1095. protocol: location.protocol,
  1096. domain: document.domain,
  1097. port: location.port ? ':' + location.port : ''
  1098. }));
  1099. },
  1100. getHeader: function(name) {
  1101. try {
  1102. return this.transport.getResponseHeader(name) || null;
  1103. } catch (e) { return null }
  1104. },
  1105. evalResponse: function() {
  1106. try {
  1107. return eval((this.transport.responseText || '').unfilterJSON());
  1108. } catch (e) {
  1109. this.dispatchException(e);
  1110. }
  1111. },
  1112. dispatchException: function(exception) {
  1113. (this.options.onException || Prototype.emptyFunction)(this, exception);
  1114. Ajax.Responders.dispatch('onException', this, exception);
  1115. }
  1116. });
  1117. Ajax.Request.Events =
  1118. ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
  1119. Ajax.Response = Class.create({
  1120. initialize: function(request){
  1121. this.request = request;
  1122. var transport = this.transport = request.transport,
  1123. readyState = this.readyState = transport.readyState;
  1124. if((readyState > 2 && !Prototype.Browser.IE) || readyState == 4) {
  1125. this.status = this.getStatus();
  1126. this.statusText = this.getStatusText();
  1127. this.responseText = String.interpret(transport.responseText);
  1128. this.headerJSON = this._getHeaderJSON();
  1129. }
  1130. if(readyState == 4) {
  1131. var xml = transport.responseXML;
  1132. this.responseXML = Object.isUndefined(xml) ? null : xml;
  1133. this.responseJSON = this._getResponseJSON();
  1134. }
  1135. },
  1136. status: 0,
  1137. statusText: '',
  1138. getStatus: Ajax.Request.prototype.getStatus,
  1139. getStatusText: function() {
  1140. try {
  1141. return this.transport.statusText || '';
  1142. } catch (e) { return '' }
  1143. },
  1144. getHeader: Ajax.Request.prototype.getHeader,
  1145. getAllHeaders: function() {
  1146. try {
  1147. return this.getAllResponseHeaders();
  1148. } catch (e) { return null }
  1149. },
  1150. getResponseHeader: function(name) {
  1151. return this.transport.getResponseHeader(name);
  1152. },
  1153. getAllResponseHeaders: function() {
  1154. return this.transport.getAllResponseHeaders();
  1155. },
  1156. _getHeaderJSON: function() {
  1157. var json = this.getHeader('X-JSON');
  1158. if (!json) return null;
  1159. json = decodeURIComponent(escape(json));
  1160. try {
  1161. return json.evalJSON(this.request.options.sanitizeJSON ||
  1162. !this.request.isSameOrigin());
  1163. } catch (e) {
  1164. this.request.dispatchException(e);
  1165. }
  1166. },
  1167. _getResponseJSON: function() {
  1168. var options = this.request.options;
  1169. if (!options.evalJSON || (options.evalJSON != 'force' &&
  1170. !(this.getHeader('Content-type') || '').include('application/json')) ||
  1171. this.responseText.blank())
  1172. return null;
  1173. try {
  1174. return this.responseText.evalJSON(options.sanitizeJSON ||
  1175. !this.request.isSameOrigin());
  1176. } catch (e) {
  1177. this.request.dispatchException(e);
  1178. }
  1179. }
  1180. });
  1181. Ajax.Updater = Class.create(Ajax.Request, {
  1182. initialize: function($super, container, url, options) {
  1183. this.container = {
  1184. success: (container.success || container),
  1185. failure: (container.failure || (container.success ? null : container))
  1186. };
  1187. options = Object.clone(options);
  1188. var onComplete = options.onComplete;
  1189. options.onComplete = (function(response, json) {
  1190. this.updateContent(response.responseText);
  1191. if (Object.isFunction(onComplete)) onComplete(response, json);
  1192. }).bind(this);
  1193. $super(url, options);
  1194. },
  1195. updateContent: function(responseText) {
  1196. var receiver = this.container[this.success() ? 'success' : 'failure'],
  1197. options = this.options;
  1198. if (!options.evalScripts) responseText = responseText.stripScripts();
  1199. if (receiver = $(receiver)) {
  1200. if (options.insertion) {
  1201. if (Object.isString(options.insertion)) {
  1202. var insertion = { }; insertion[options.insertion] = responseText;
  1203. receiver.insert(insertion);
  1204. }
  1205. else options.insertion(receiver, responseText);
  1206. }
  1207. else receiver.update(responseText);
  1208. }
  1209. }
  1210. });
  1211. Ajax.PeriodicalUpdater = Class.create(Ajax.Base, {
  1212. initialize: function($super, container, url, options) {
  1213. $super(options);
  1214. this.onComplete = this.options.onComplete;
  1215. this.frequency = (this.options.frequency || 2);
  1216. this.decay = (this.options.decay || 1);
  1217. this.updater = { };
  1218. this.container = container;
  1219. this.url = url;
  1220. this.start();
  1221. },
  1222. start: function() {
  1223. this.options.onComplete = this.updateComplete.bind(this);
  1224. this.onTimerEvent();
  1225. },
  1226. stop: function() {
  1227. this.updater.options.onComplete = undefined;
  1228. clearTimeout(this.timer);
  1229. (this.onComplete || Prototype.emptyFunction).apply(this, arguments);
  1230. },
  1231. updateComplete: function(response) {
  1232. if (this.options.decay) {
  1233. this.decay = (response.responseText == this.lastText ?
  1234. this.decay * this.options.decay : 1);
  1235. this.lastText = response.responseText;
  1236. }
  1237. this.timer = this.onTimerEvent.bind(this).delay(this.decay * this.frequency);
  1238. },
  1239. onTimerEvent: function() {
  1240. this.updater = new Ajax.Updater(this.container, this.url, this.options);
  1241. }
  1242. });
  1243. function $(element) {
  1244. if (arguments.length > 1) {
  1245. for (var i = 0, elements = [], length = arguments.length; i < length; i++)
  1246. elements.push($(arguments[i]));
  1247. return elements;
  1248. }
  1249. if (Object.isString(element))
  1250. element = document.getElementById(element);
  1251. return Element.extend(element);
  1252. }
  1253. if (Prototype.BrowserFeatures.XPath) {
  1254. document._getElementsByXPath = function(expression, parentElement) {
  1255. var results = [];
  1256. var query = document.evaluate(expression, $(parentElement) || document,
  1257. null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  1258. for (var i = 0, length = query.snapshotLength; i < length; i++)
  1259. results.push(Element.extend(query.snapshotItem(i)));
  1260. return results;
  1261. };
  1262. }
  1263. /*--------------------------------------------------------------------------*/
  1264. if (!window.Node) var Node = { };
  1265. if (!Node.ELEMENT_NODE) {
  1266. // DOM level 2 ECMAScript Language Binding
  1267. Object.extend(Node, {
  1268. ELEMENT_NODE: 1,
  1269. ATTRIBUTE_NODE: 2,
  1270. TEXT_NODE: 3,
  1271. CDATA_SECTION_NODE: 4,
  1272. ENTITY_REFERENCE_NODE: 5,
  1273. ENTITY_NODE: 6,
  1274. PROCESSING_INSTRUCTION_NODE: 7,
  1275. COMMENT_NODE: 8,
  1276. DOCUMENT_NODE: 9,
  1277. DOCUMENT_TYPE_NODE: 10,
  1278. DOCUMENT_FRAGMENT_NODE: 11,
  1279. NOTATION_NODE: 12
  1280. });
  1281. }
  1282. (function() {
  1283. var element = this.Element;
  1284. this.Element = function(tagName, attributes) {
  1285. attributes = attributes || { };
  1286. tagName = tagName.toLowerCase();
  1287. var cache = Element.cache;
  1288. if (Prototype.Browser.IE && attributes.name) {
  1289. tagName = '<' + tagName + ' name="' + attributes.name + '">';
  1290. delete attributes.name;
  1291. return Element.writeAttribute(document.createElement(tagName), attributes);
  1292. }
  1293. if (!cache[tagName]) cache[tagName] = Element.extend(document.createElement(tagName));
  1294. return Element.writeAttribute(cache[tagName].cloneNode(false), attributes);
  1295. };
  1296. Object.extend(this.Element, element || { });
  1297. }).call(window);
  1298. Element.cache = { };
  1299. Element.Methods = {
  1300. visible: function(element) {
  1301. return $(element).style.display != 'none';
  1302. },
  1303. toggle: function(element) {
  1304. element = $(element);
  1305. Element[Element.visible(element) ? 'hide' : 'show'](element);
  1306. return element;
  1307. },
  1308. hide: function(element) {
  1309. $(element).style.display = 'none';
  1310. return element;
  1311. },
  1312. show: function(element) {
  1313. $(element).style.display = '';
  1314. return element;
  1315. },
  1316. remove: function(element) {
  1317. element = $(element);
  1318. element.parentNode.removeChild(element);
  1319. return element;
  1320. },
  1321. update: function(element, content) {
  1322. element = $(element);
  1323. if (content && content.toElement) content = content.toElement();
  1324. if (Object.isElement(content)) return element.update().insert(content);
  1325. content = Object.toHTML(content);
  1326. element.innerHTML = content.stripScripts();
  1327. content.evalScripts.bind(content).defer();
  1328. return element;
  1329. },
  1330. replace: function(element, content) {
  1331. element = $(element);
  1332. if (content && content.toElement) content = content.toElement();
  1333. else if (!Object.isElement(content)) {
  1334. content = Object.toHTML(content);
  1335. var range = element.ownerDocument.createRange();
  1336. range.selectNode(element);
  1337. content.evalScripts.bind(content).defer();
  1338. content = range.createContextualFragment(content.stripScripts());
  1339. }
  1340. element.parentNode.replaceChild(content, element);
  1341. return element;
  1342. },
  1343. insert: function(element, insertions) {
  1344. element = $(element);
  1345. if (Object.isString(insertions) || Object.isNumber(insertions) ||
  1346. Object.isElement(insertions) || (insertions && (insertions.toElement || insertions.toHTML)))
  1347. insertions = {bottom:insertions};
  1348. var content, insert, tagName, childNodes;
  1349. for (var position in insertions) {
  1350. content = insertions[position];
  1351. position = position.toLowerCase();
  1352. insert = Element._insertionTranslations[position];
  1353. if (content && content.toElement) content = content.toElement();
  1354. if (Object.isElement(content)) {
  1355. insert(element, content);
  1356. continue;
  1357. }
  1358. content = Object.toHTML(content);
  1359. tagName = ((position == 'before' || position == 'after')
  1360. ? element.parentNode : element).tagName.toUpperCase();
  1361. childNodes = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
  1362. if (position == 'top' || position == 'after') childNodes.reverse();
  1363. childNodes.each(insert.curry(element));
  1364. content.evalScripts.bind(content).defer();
  1365. }
  1366. return element;
  1367. },
  1368. wrap: function(element, wrapper, attributes) {
  1369. element = $(element);
  1370. if (Object.isElement(wrapper))
  1371. $(wrapper).writeAttribute(attributes || { });
  1372. else if (Object.isString(wrapper)) wrapper = new Element(wrapper, attributes);
  1373. else wrapper = new Element('div', wrapper);
  1374. if (element.parentNode)
  1375. element.parentNode.replaceChild(wrapper, element);
  1376. wrapper.appendChild(element);
  1377. return wrapper;
  1378. },
  1379. inspect: function(element) {
  1380. element = $(element);
  1381. var result = '<' + element.tagName.toLowerCase();
  1382. $H({'id': 'id', 'className': 'class'}).each(function(pair) {
  1383. var property = pair.first(), attribute = pair.last();
  1384. var value = (element[property] || '').toString();
  1385. if (value) result += ' ' + attribute + '=' + value.inspect(true);
  1386. });
  1387. return result + '>';
  1388. },
  1389. recursivelyCollect: function(element, property) {
  1390. element = $(element);
  1391. var elements = [];
  1392. while (element = element[property])
  1393. if (element.nodeType == 1)
  1394. elements.push(Element.extend(element));
  1395. return elements;
  1396. },
  1397. ancestors: function(element) {
  1398. return $(element).recursivelyCollect('parentNode');
  1399. },
  1400. descendants: function(element) {
  1401. return $(element).select("*");
  1402. },
  1403. firstDescendant: function(element) {
  1404. element = $(element).firstChild;
  1405. while (element && element.nodeType != 1) element = element.nextSibling;
  1406. return $(element);
  1407. },
  1408. immediateDescendants: function(element) {
  1409. if (!(element = $(element).firstChild)) return [];
  1410. while (element && element.nodeType != 1) element = element.nextSibling;
  1411. if (element) return [element].concat($(element).nextSiblings());
  1412. return [];
  1413. },
  1414. previousSiblings: function(element) {
  1415. return $(element).recursivelyCollect('previousSibling');
  1416. },
  1417. nextSiblings: function(element) {
  1418. return $(element).recursivelyCollect('nextSibling');
  1419. },
  1420. siblings: function(element) {
  1421. element = $(element);
  1422. return element.previousSiblings().reverse().concat(element.nextSiblings());
  1423. },
  1424. match: function(element, selector) {
  1425. if (Object.isString(selector))
  1426. selector = new Selector(selector);
  1427. return selector.match($(element));
  1428. },
  1429. up: function(element, expression, index) {
  1430. element = $(element);
  1431. if (arguments.length == 1) return $(element.parentNode);
  1432. var ancestors = element.ancestors();
  1433. return Object.isNumber(expression) ? ancestors[expression] :
  1434. Selector.findElement(ancestors, expression, index);
  1435. },
  1436. down: function(element, expression, index) {
  1437. element = $(element);
  1438. if (arguments.length == 1) return element.firstDescendant();
  1439. return Object.isNumber(expression) ? element.descendants()[expression] :
  1440. element.select(expression)[index || 0];
  1441. },
  1442. previous: function(element, expression, index) {
  1443. element = $(element);
  1444. if (arguments.length == 1) return $(Selector.handlers.previousElementSibling(element));
  1445. var previousSiblings = element.previousSiblings();
  1446. return Object.isNumber(expression) ? previousSiblings[expression] :
  1447. Selector.findElement(previousSiblings, expression, index);
  1448. },
  1449. next: function(element, expression, index) {
  1450. element = $(element);
  1451. if (arguments.length == 1) return $(Selector.handlers.nextElementSibling(element));
  1452. var nextSiblings = element.nextSiblings();
  1453. return Object.isNumber(expression) ? nextSiblings[expression] :
  1454. Selector.findElement(nextSiblings, expression, index);
  1455. },
  1456. select: function() {
  1457. var args = $A(arguments), element = $(args.shift());
  1458. return Selector.findChildElements(element, args);
  1459. },
  1460. adjacent: function() {
  1461. var args = $A(arguments), element = $(args.shift());
  1462. return Selector.findChildElements(element.parentNode, args).without(element);
  1463. },
  1464. identify: function(element) {
  1465. element = $(element);
  1466. var id = element.readAttribute('id'), self = arguments.callee;
  1467. if (id) return id;
  1468. do { id = 'anonymous_element_' + self.counter++ } while ($(id));
  1469. element.writeAttribute('id', id);
  1470. return id;
  1471. },
  1472. readAttribute: function(element, name) {
  1473. element = $(element);
  1474. if (Prototype.Browser.IE) {
  1475. var t = Element._attributeTranslations.read;
  1476. if (t.values[name]) return t.values[name](element, name);
  1477. if (t.names[name]) name = t.names[name];
  1478. if (name.include(':')) {
  1479. return (!element.attributes || !element.attributes[name]) ? null :
  1480. element.attributes[name].value;
  1481. }
  1482. }
  1483. return element.getAttribute(name);
  1484. },
  1485. writeAttribute: function(element, name, value) {
  1486. element = $(element);
  1487. var attributes = { }, t = Element._attributeTranslations.write;
  1488. if (typeof name == 'object') attributes = name;
  1489. else attributes[name] = Object.isUndefined(value) ? true : value;
  1490. for (var attr in attributes) {
  1491. name = t.names[attr] || attr;
  1492. value = attributes[attr];
  1493. if (t.values[attr]) name = t.values[attr](element, value);
  1494. if (value === false || value === null)
  1495. element.removeAttribute(name);
  1496. else if (value === true)
  1497. element.setAttribute(name, name);
  1498. else element.setAttribute(name, value);
  1499. }
  1500. return element;
  1501. },
  1502. getHeight: function(element) {
  1503. return $(element).getDimensions().height;
  1504. },
  1505. getWidth: function(element) {
  1506. return $(element).getDimensions().width;
  1507. },
  1508. classNames: function(element) {
  1509. return new Element.ClassNames(element);
  1510. },
  1511. hasClassName: function(element, className) {
  1512. if (!(element = $(element))) return;
  1513. var elementClassName = element.className;
  1514. return (elementClassName.length > 0 && (elementClassName == className ||
  1515. new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));
  1516. },
  1517. addClassName: function(element, className) {
  1518. if (!(element = $(element))) return;
  1519. if (!element.hasClassName(className))
  1520. element.className += (element.className ? ' ' : '') + className;
  1521. return element;
  1522. },
  1523. removeClassName: function(element, className) {
  1524. if (!(element = $(element))) return;
  1525. element.className = element.className.replace(
  1526. new RegExp("(^|\\s+)" + className + "(\\s+|$)"), ' ').strip();
  1527. return element;
  1528. },
  1529. toggleClassName: function(element, className) {
  1530. if (!(element = $(element))) return;
  1531. return element[element.hasClassName(className) ?
  1532. 'removeClassName' : 'addClassName'](className);
  1533. },
  1534. // removes whitespace-only text node children
  1535. cleanWhitespace: function(element) {
  1536. element = $(element);
  1537. var node = element.firstChild;
  1538. while (node) {
  1539. var nextNode = node.nextSibling;
  1540. if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
  1541. element.removeChild(node);
  1542. node = nextNode;
  1543. }
  1544. return element;
  1545. },
  1546. empty: function(element) {
  1547. return $(element).innerHTML.blank();
  1548. },
  1549. descendantOf: function(element, ancestor) {
  1550. element = $(element), ancestor = $(ancestor);
  1551. var originalAncestor = ancestor;
  1552. if (element.compareDocumentPosition)
  1553. return (element.compareDocumentPosition(ancestor) & 8) === 8;
  1554. if (element.sourceIndex && !Prototype.Browser.Opera) {
  1555. var e = element.sourceIndex, a = ancestor.sourceIndex,
  1556. nextAncestor = ancestor.nextSibling;
  1557. if (!nextAncestor) {
  1558. do { ancestor = ancestor.parentNode; }
  1559. while (!(nextAncestor = ancestor.nextSibling) && ancestor.parentNode);
  1560. }
  1561. if (nextAncestor && nextAncestor.sourceIndex)
  1562. return (e > a && e < nextAncestor.sourceIndex);
  1563. }
  1564. while (element = element.parentNode)
  1565. if (element == originalAncestor) return true;
  1566. return false;
  1567. },
  1568. scrollTo: function(element) {
  1569. element = $(element);
  1570. var pos = element.cumulativeOffset();
  1571. window.scrollTo(pos[0], pos[1]);
  1572. return element;
  1573. },
  1574. getStyle: function(element, style) {
  1575. element = $(element);
  1576. style = style == 'float' ? 'cssFloat' : style.camelize();
  1577. var value = element.style[style];
  1578. if (!value) {
  1579. var css = document.defaultView.getComputedStyle(element, null);
  1580. value = css ? css[style] : null;
  1581. }
  1582. if (style == 'opacity') return value ? parseFloat(value) : 1.0;
  1583. return value == 'auto' ? null : value;
  1584. },
  1585. getOpacity: function(element) {
  1586. return $(element).getStyle('opacity');
  1587. },
  1588. setStyle: function(element, styles) {
  1589. element = $(element);
  1590. var elementStyle = element.style, match;
  1591. if (Object.isString(styles)) {
  1592. element.style.cssText += ';' + styles;
  1593. return styles.include('opacity') ?
  1594. element.setOpacity(styles.match(/opacity:\s*(\d?\.?\d*)/)[1]) : element;
  1595. }
  1596. for (var property in styles)
  1597. if (property == 'opacity') element.setOpacity(styles[property]);
  1598. else
  1599. elementStyle[(property == 'float' || property == 'cssFloat') ?
  1600. (Object.isUndefined(elementStyle.styleFloat) ? 'cssFloat' : 'styleFloat') :
  1601. property] = styles[property];
  1602. return element;
  1603. },
  1604. setOpacity: function(element, value) {
  1605. element = $(element);
  1606. element.style.opacity = (value == 1 || value === '') ? '' :
  1607. (value < 0.00001) ? 0 : value;
  1608. return element;
  1609. },
  1610. getDimensions: function(element) {
  1611. element = $(element);
  1612. var display = $(element).getStyle('display');
  1613. if (display != 'none' && display != null) // Safari bug
  1614. return {width: element.offsetWidth, height: element.offsetHeight};
  1615. // All *Width and *Height properties give 0 on elements with display none,
  1616. // so enable the element temporarily
  1617. var els = element.style;
  1618. var originalVisibility = els.visibility;
  1619. var originalPosition = els.position;
  1620. var originalDisplay = els.display;
  1621. els.visibility = 'hidden';
  1622. els.position = 'absolute';
  1623. els.display = 'block';
  1624. var originalWidth = element.clientWidth;
  1625. var originalHeight = element.clientHeight;
  1626. els.display = originalDisplay;
  1627. els.position = originalPosition;
  1628. els.visibility = originalVisibility;
  1629. return {width: originalWidth, height: originalHeight};
  1630. },
  1631. makePositioned: function(element) {
  1632. element = $(element);
  1633. var pos = Element.getStyle(element, 'position');
  1634. if (pos == 'static' || !pos) {
  1635. element._madePositioned = true;
  1636. element.style.position = 'relative';
  1637. // Opera returns the offset relative to the positioning context, when an
  1638. // element is position relative but top and left have not been defined
  1639. if (window.opera) {
  1640. element.style.top = 0;
  1641. element.style.left = 0;
  1642. }
  1643. }
  1644. return element;
  1645. },
  1646. undoPositioned: function(element) {
  1647. element = $(element);
  1648. if (element._madePositioned) {
  1649. element._madePositioned = undefined;
  1650. element.style.position =
  1651. element.style.top =
  1652. element.style.left =
  1653. element.style.bottom =
  1654. element.style.right = '';
  1655. }
  1656. return element;
  1657. },
  1658. makeClipping: function(element) {
  1659. element = $(element);
  1660. if (element._overflow) return element;
  1661. element._overflow = Element.getStyle(element, 'overflow') || 'auto';
  1662. if (element._overflow !== 'hidden')
  1663. element.style.overflow = 'hidden';
  1664. return element;
  1665. },
  1666. undoClipping: function(element) {
  1667. element = $(element);
  1668. if (!element._overflow) return element;
  1669. element.style.overflow = element._overflow == 'auto' ? '' : element._overflow;
  1670. element._overflow = null;
  1671. return element;
  1672. },
  1673. cumulativeOffset: function(element) {
  1674. var valueT = 0, valueL = 0;
  1675. do {
  1676. valueT += element.offsetTop || 0;
  1677. valueL += element.offsetLeft || 0;
  1678. element = element.offsetParent;
  1679. } while (element);
  1680. return Element._returnOffset(valueL, valueT);
  1681. },
  1682. positionedOffset: function(element) {
  1683. var valueT = 0, valueL = 0;
  1684. do {
  1685. valueT += element.offsetTop || 0;
  1686. valueL += element.offsetLeft || 0;
  1687. element = element.offsetParent;
  1688. if (element) {
  1689. if (element.tagName == 'BODY') break;
  1690. var p = Element.getStyle(element, 'position');
  1691. if (p !== 'static') break;
  1692. }
  1693. } while (element);
  1694. return Element._returnOffset(valueL, valueT);
  1695. },
  1696. absolutize: function(element) {
  1697. element = $(element);
  1698. if (element.getStyle('position') == 'absolute') return;
  1699. // Position.prepare(); // To be done manually by Scripty when it needs it.
  1700. var offsets = element.positionedOffset();
  1701. var top = offsets[1];
  1702. var left = offsets[0];
  1703. var width = element.clientWidth;
  1704. var height = element.clientHeight;
  1705. element._originalLeft = left - parseFloat(element.style.left || 0);
  1706. element._originalTop = top - parseFloat(element.style.top || 0);
  1707. element._originalWidth = element.style.width;
  1708. element._originalHeight = element.style.height;
  1709. element.style.position = 'absolute';
  1710. element.style.top = top + 'px';
  1711. element.style.left = left + 'px';
  1712. element.style.width = width + 'px';
  1713. element.style.height = height + 'px';
  1714. return element;
  1715. },
  1716. relativize: function(element) {
  1717. element = $(element);
  1718. if (element.getStyle('position') == 'relative') return;
  1719. // Position.prepare(); // To be done manually by Scripty when it needs it.
  1720. element.style.position = 'relative';
  1721. var top = parseFloat(element.style.top || 0) - (element._originalTop || 0);
  1722. var left = parseFloat(element.style.left || 0) - (element._originalLeft || 0);
  1723. element.style.top = top + 'px';
  1724. element.style.left = left + 'px';
  1725. element.style.height = element._originalHeight;
  1726. element.style.width = element._originalWidth;
  1727. return element;
  1728. },
  1729. cumulativeScrollOffset: function(element) {
  1730. var valueT = 0, valueL = 0;
  1731. do {
  1732. valueT += element.scrollTop || 0;
  1733. valueL += element.scrollLeft || 0;
  1734. element = element.parentNode;
  1735. } while (element);
  1736. return Element._returnOffset(valueL, valueT);
  1737. },
  1738. getOffsetParent: function(element) {
  1739. if (element.offsetParent) return $(element.offsetParent);
  1740. if (element == document.body) return $(element);
  1741. while ((element = element.parentNode) && element != document.body)
  1742. if (Element.getStyle(element, 'position') != 'static')
  1743. return $(element);
  1744. return $(document.body);
  1745. },
  1746. viewportOffset: function(forElement) {
  1747. var valueT = 0, valueL = 0;
  1748. var element = forElement;
  1749. do {
  1750. valueT += element.offsetTop || 0;
  1751. valueL += element.offsetLeft || 0;
  1752. // Safari fix
  1753. if (element.offsetParent == document.body &&
  1754. Element.getStyle(element, 'position') == 'absolute') break;
  1755. } while (element = element.offsetParent);
  1756. element = forElement;
  1757. do {
  1758. if (!Prototype.Browser.Opera || element.tagName == 'BODY') {
  1759. valueT -= element.scrollTop || 0;
  1760. valueL -= element.scrollLeft || 0;
  1761. }
  1762. } while (element = element.parentNode);
  1763. return Element._returnOffset(valueL, valueT);
  1764. },
  1765. clonePosition: function(element, source) {
  1766. var options = Object.extend({
  1767. setLeft: true,
  1768. setTop: true,
  1769. setWidth: true,
  1770. setHeight: true,
  1771. offsetTop: 0,
  1772. offsetLeft: 0
  1773. }, arguments[2] || { });
  1774. // find page position of source
  1775. source = $(source);
  1776. var p = source.viewportOffset();
  1777. // find coordinate system to use
  1778. element = $(element);
  1779. var delta = [0, 0];
  1780. var parent = null;
  1781. // delta [0,0] will do fine with position: fixed elements,
  1782. // position:absolute needs offsetParent deltas
  1783. if (Element.getStyle(element, 'position') == 'absolute') {
  1784. parent = element.getOffsetParent();
  1785. delta = parent.viewportOffset();
  1786. }
  1787. // correct by body offsets (fixes Safari)
  1788. if (parent == document.body) {
  1789. delta[0] -= document.body.offsetLeft;
  1790. delta[1] -= document.body.offsetTop;
  1791. }
  1792. // set position
  1793. if (options.setLeft) element.style.left = (p[0] - delta[0] + options.offsetLeft) + 'px';
  1794. if (options.setTop) element.style.top = (p[1] - delta[1] + options.offsetTop) + 'px';
  1795. if (options.setWidth) element.style.width = source.offsetWidth + 'px';
  1796. if (options.setHeight) element.style.height = source.offsetHeight + 'px';
  1797. return element;
  1798. }
  1799. };
  1800. Element.Methods.identify.counter = 1;
  1801. Object.extend(Element.Methods, {
  1802. getElementsBySelector: Element.Methods.select,
  1803. childElements: Element.Methods.immediateDescendants
  1804. });
  1805. Element._attributeTranslations = {
  1806. write: {
  1807. names: {
  1808. className: 'class',
  1809. htmlFor: 'for'
  1810. },
  1811. values: { }
  1812. }
  1813. };
  1814. if (Prototype.Browser.Opera) {
  1815. Element.Methods.getStyle = Element.Methods.getStyle.wrap(
  1816. function(proceed, element, style) {
  1817. switch (style) {
  1818. case 'left': case 'top': case 'right': case 'bottom':
  1819. if (proceed(element, 'position') === 'static') return null;
  1820. case 'height': case 'width':
  1821. // returns '0px' for hidden elements; we want it to return null
  1822. if (!Element.visible(element)) return null;
  1823. // returns the border-box dimensions rather than the content-box
  1824. // dimensions, so we subtract padding and borders from the value
  1825. var dim = parseInt(proceed(element, style), 10);
  1826. if (dim !== element['offset' + style.capitalize()])
  1827. return dim + 'px';
  1828. var properties;
  1829. if (style === 'height') {
  1830. properties = ['border-top-width', 'padding-top',
  1831. 'padding-bottom', 'border-bottom-width'];
  1832. }
  1833. else {
  1834. properties = ['border-left-width', 'padding-left',
  1835. 'padding-right', 'border-right-width'];
  1836. }
  1837. return properties.inject(dim, function(memo, property) {
  1838. var val = proceed(element, property);
  1839. return val === null ? memo : memo - parseInt(val, 10);
  1840. }) + 'px';
  1841. default: return proceed(element, style);
  1842. }
  1843. }
  1844. );
  1845. Element.Methods.readAttribute = Element.Methods.readAttribute.wrap(
  1846. function(proceed, element, attribute) {
  1847. if (attribute === 'title') return element.title;
  1848. return proceed(element, attribute);
  1849. }
  1850. );
  1851. }
  1852. else if (Prototype.Browser.IE) {
  1853. // IE doesn't report offsets correctly for static elements, so we change them
  1854. // to "relative" to get the values, then change them back.
  1855. Element.Methods.getOffsetParent = Element.Methods.getOffsetParent.wrap(
  1856. function(proceed, element) {
  1857. element = $(element);
  1858. var position = element.getStyle('position');
  1859. if (position !== 'static') return proceed(element);
  1860. element.setStyle({ position: 'relative' });
  1861. var value = proceed(element);
  1862. element.setStyle({ position: position });
  1863. return value;
  1864. }
  1865. );
  1866. $w('positionedOffset viewportOffset').each(function(method) {
  1867. Element.Methods[method] = Element.Methods[method].wrap(
  1868. function(proceed, element) {
  1869. element = $(element);
  1870. var position = element.getStyle('position');
  1871. if (position !== 'static') return proceed(element);
  1872. // Trigger hasLayout on the offset parent so that IE6 reports
  1873. // accurate offsetTop and offsetLeft values for position: fixed.
  1874. var offsetParent = element.getOffsetParent();
  1875. if (offsetParent && offsetParent.getStyle('position') === 'fixed')
  1876. offsetParent.setStyle({ zoom: 1 });
  1877. element.setStyle({ position: 'relative' });
  1878. var value = proceed(element);
  1879. element.setStyle({ position: position });
  1880. return value;
  1881. }
  1882. );
  1883. });
  1884. Element.Methods.getStyle = function(element, style) {
  1885. element = $(element);
  1886. style = (style == 'float' || style == 'cssFloat') ? 'styleFloat' : style.camelize();
  1887. var value = element.style[style];
  1888. if (!value && element.currentStyle) value = element.currentStyle[style];
  1889. if (style == 'opacity') {
  1890. if (value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/))
  1891. if (value[1]) return parseFloat(value[1]) / 100;
  1892. return 1.0;
  1893. }
  1894. if (value == 'auto') {
  1895. if ((style == 'width' || style == 'height') && (element.getStyle('display') != 'none'))
  1896. return element['offset' + style.capitalize()] + 'px';
  1897. return null;
  1898. }
  1899. return value;
  1900. };
  1901. Element.Methods.setOpacity = function(element, value) {
  1902. function stripAlpha(filter){
  1903. return filter.replace(/alpha\([^\)]*\)/gi,'');
  1904. }
  1905. element = $(element);
  1906. var currentStyle = element.currentStyle;
  1907. if ((currentStyle && !currentStyle.hasLayout) ||
  1908. (!currentStyle && element.style.zoom == 'normal'))
  1909. element.style.zoom = 1;
  1910. var filter = element.getStyle('filter'), style = element.style;
  1911. if (value == 1 || value === '') {
  1912. (filter = stripAlpha(filter)) ?
  1913. style.filter = filter : style.removeAttribute('filter');
  1914. return element;
  1915. } else if (value < 0.00001) value = 0;
  1916. style.filter = stripAlpha(filter) +
  1917. 'alpha(opacity=' + (value * 100) + ')';
  1918. return element;
  1919. };
  1920. Element._attributeTranslations = {
  1921. read: {
  1922. names: {
  1923. 'class': 'className',
  1924. 'for': 'htmlFor'
  1925. },
  1926. values: {
  1927. _getAttr: function(element, attribute) {
  1928. return element.getAttribute(attribute, 2);
  1929. },
  1930. _getAttrNode: function(element, attribute) {
  1931. var node = element.getAttributeNode(attribute);
  1932. return node ? node.value : "";
  1933. },
  1934. _getEv: function(element, attribute) {
  1935. attribute = element.getAttribute(attribute);
  1936. return attribute ? attribute.toString().slice(23, -2) : null;
  1937. },
  1938. _flag: function(element, attribute) {
  1939. return $(element).hasAttribute(attribute) ? attribute : null;
  1940. },
  1941. style: function(element) {
  1942. return element.style.cssText.toLowerCase();
  1943. },
  1944. title: function(element) {
  1945. return element.title;
  1946. }
  1947. }
  1948. }
  1949. };
  1950. Element._attributeTranslations.write = {
  1951. names: Object.extend({
  1952. cellpadding: 'cellPadding',
  1953. cellspacing: 'cellSpacing'
  1954. }, Element._attributeTranslations.read.names),
  1955. values: {
  1956. checked: function(element, value) {
  1957. element.checked = !!value;
  1958. },
  1959. style: function(element, value) {
  1960. element.style.cssText = value ? value : '';
  1961. }
  1962. }
  1963. };
  1964. Element._attributeTranslations.has = {};
  1965. $w('colSpan rowSpan vAlign dateTime accessKey tabIndex ' +
  1966. 'encType maxLength readOnly longDesc').each(function(attr) {
  1967. Element._attributeTranslations.write.names[attr.toLowerCase()] = attr;
  1968. Element._attributeTranslations.has[attr.toLowerCase()] = attr;
  1969. });
  1970. (function(v) {
  1971. Object.extend(v, {
  1972. href: v._getAttr,
  1973. src: v._getAttr,
  1974. type: v._getAttr,
  1975. action: v._getAttrNode,
  1976. disabled: v._flag,
  1977. checked: v._flag,
  1978. readonly: v._flag,
  1979. multiple: v._flag,
  1980. onload: v._getEv,
  1981. onunload: v._getEv,
  1982. onclick: v._getEv,
  1983. ondblclick: v._getEv,
  1984. onmousedown: v._getEv,
  1985. onmouseup: v._getEv,
  1986. onmouseover: v._getEv,
  1987. onmousemove: v._getEv,
  1988. onmouseout: v._getEv,
  1989. onfocus: v._getEv,
  1990. onblur: v._getEv,
  1991. onkeypress: v._getEv,
  1992. onkeydown: v._getEv,
  1993. onkeyup: v._getEv,
  1994. onsubmit: v._getEv,
  1995. onreset: v._getEv,
  1996. onselect: v._getEv,
  1997. onchange: v._getEv
  1998. });
  1999. })(Element._attributeTranslations.read.values);
  2000. }
  2001. else if (Prototype.Browser.Gecko && /rv:1\.8\.0/.test(navigator.userAgent)) {
  2002. Element.Methods.setOpacity = function(element, value) {
  2003. element = $(element);
  2004. element.style.opacity = (value == 1) ? 0.999999 :
  2005. (value === '') ? '' : (value < 0.00001) ? 0 : value;
  2006. return element;
  2007. };
  2008. }
  2009. else if (Prototype.Browser.WebKit) {
  2010. Element.Methods.setOpacity = function(element, value) {
  2011. element = $(element);
  2012. element.style.opacity = (value == 1 || value === '') ? '' :
  2013. (value < 0.00001) ? 0 : value;
  2014. if (value == 1)
  2015. if(element.tagName == 'IMG' && element.width) {
  2016. element.width++; element.width--;
  2017. } else try {
  2018. var n = document.createTextNode(' ');
  2019. element.appendChild(n);
  2020. element.removeChild(n);
  2021. } catch (e) { }
  2022. return element;
  2023. };
  2024. // Safari returns margins on body which is incorrect if the child is absolutely
  2025. // positioned. For performance reasons, redefine Element#cumulativeOffset for
  2026. // KHTML/WebKit only.
  2027. Element.Methods.cumulativeOffset = function(element) {
  2028. var valueT = 0, valueL = 0;
  2029. do {
  2030. valueT += element.offsetTop || 0;
  2031. valueL += element.offsetLeft || 0;
  2032. if (element.offsetParent == document.body)
  2033. if (Element.getStyle(element, 'position') == 'absolute') break;
  2034. element = element.offsetParent;
  2035. } while (element);
  2036. return Element._returnOffset(valueL, valueT);
  2037. };
  2038. }
  2039. if (Prototype.Browser.IE || Prototype.Browser.Opera) {
  2040. // IE and Opera are missing .innerHTML support for TABLE-related and SELECT elements
  2041. Element.Methods.update = function(element, content) {
  2042. element = $(element);
  2043. if (content && content.toElement) content = content.toElement();
  2044. if (Object.isElement(content)) return element.update().insert(content);
  2045. content = Object.toHTML(content);
  2046. var tagName = element.tagName.toUpperCase();
  2047. if (tagName in Element._insertionTranslations.tags) {
  2048. $A(element.childNodes).each(function(node) { element.removeChild(node) });
  2049. Element._getContentFromAnonymousElement(tagName, content.stripScripts())
  2050. .each(function(node) { element.appendChild(node) });
  2051. }
  2052. else element.innerHTML = content.stripScripts();
  2053. content.evalScripts.bind(content).defer();
  2054. return element;
  2055. };
  2056. }
  2057. if ('outerHTML' in document.createElement('div')) {
  2058. Element.Methods.replace = function(element, content) {
  2059. element = $(element);
  2060. if (content && content.toElement) content = content.toElement();
  2061. if (Object.isElement(content)) {
  2062. element.parentNode.replaceChild(content, element);
  2063. return element;
  2064. }
  2065. content = Object.toHTML(content);
  2066. var parent = element.parentNode, tagName = parent.tagName.toUpperCase();
  2067. if (Element._insertionTranslations.tags[tagName]) {
  2068. var nextSibling = element.next();
  2069. var fragments = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
  2070. parent.removeChild(element);
  2071. if (nextSibling)
  2072. fragments.each(function(node) { parent.insertBefore(node, nextSibling) });
  2073. else
  2074. fragments.each(function(node) { parent.appendChild(node) });
  2075. }
  2076. else element.outerHTML = content.stripScripts();
  2077. content.evalScripts.bind(content).defer();
  2078. return element;
  2079. };
  2080. }
  2081. Element._returnOffset = function(l, t) {
  2082. var result = [l, t];
  2083. result.left = l;
  2084. result.top = t;
  2085. return result;
  2086. };
  2087. Element._getContentFromAnonymousElement = function(tagName, html) {
  2088. var div = new Element('div'), t = Element._insertionTranslations.tags[tagName];
  2089. if (t) {
  2090. div.innerHTML = t[0] + html + t[1];
  2091. t[2].times(function() { div = div.firstChild });
  2092. } else div.innerHTML = html;
  2093. return $A(div.childNodes);
  2094. };
  2095. Element._insertionTranslations = {
  2096. before: function(element, node) {
  2097. element.parentNode.insertBefore(node, element);
  2098. },
  2099. top: function(element, node) {
  2100. element.insertBefore(node, element.firstChild);
  2101. },
  2102. bottom: function(element, node) {
  2103. element.appendChild(node);
  2104. },
  2105. after: function(element, node) {
  2106. element.parentNode.insertBefore(node, element.nextSibling);
  2107. },
  2108. tags: {
  2109. TABLE: ['<table>', '</table>', 1],
  2110. TBODY: ['<table><tbody>', '</tbody></table>', 2],
  2111. TR: ['<table><tbody><tr>', '</tr></tbody></table>', 3],
  2112. TD: ['<table><tbody><tr><td>', '</td></tr></tbody></table>', 4],
  2113. SELECT: ['<select>', '</select>', 1]
  2114. }
  2115. };
  2116. (function() {
  2117. Object.extend(this.tags, {
  2118. THEAD: this.tags.TBODY,
  2119. TFOOT: this.tags.TBODY,
  2120. TH: this.tags.TD
  2121. });
  2122. }).call(Element._insertionTranslations);
  2123. Element.Methods.Simulated = {
  2124. hasAttribute: function(element, attribute) {
  2125. attribute = Element._attributeTranslations.has[attribute] || attribute;
  2126. var node = $(element).getAttributeNode(attribute);
  2127. return node && node.specified;
  2128. }
  2129. };
  2130. Element.Methods.ByTag = { };
  2131. Object.extend(Element, Element.Methods);
  2132. if (!Prototype.BrowserFeatures.ElementExtensions &&
  2133. document.createElement('div').__proto__) {
  2134. window.HTMLElement = { };
  2135. window.HTMLElement.prototype = document.createElement('div').__proto__;
  2136. Prototype.BrowserFeatures.ElementExtensions = true;
  2137. }
  2138. Element.extend = (function() {
  2139. if (Prototype.BrowserFeatures.SpecificElementExtensions)
  2140. return Prototype.K;
  2141. var Methods = { }, ByTag = Element.Methods.ByTag;
  2142. var extend = Object.extend(function(element) {
  2143. if (!element || element._extendedByPrototype ||
  2144. element.nodeType != 1 || element == window) return element;
  2145. var methods = Object.clone(Methods),
  2146. tagName = element.tagName, property, value;
  2147. // extend methods for specific tags
  2148. if (ByTag[tagName]) Object.extend(methods, ByTag[tagName]);
  2149. for (property in methods) {
  2150. value = methods[property];
  2151. if (Object.isFunction(value) && !(property in element))
  2152. element[property] = value.methodize();
  2153. }
  2154. element._extendedByPrototype = Prototype.emptyFunction;
  2155. return element;
  2156. }, {
  2157. refresh: function() {
  2158. // extend methods for all tags (Safari doesn't need this)
  2159. if (!Prototype.BrowserFeatures.ElementExtensions) {
  2160. Object.extend(Methods, Element.Methods);
  2161. Object.extend(Methods, Element.Methods.Simulated);
  2162. }
  2163. }
  2164. });
  2165. extend.refresh();
  2166. return extend;
  2167. })();
  2168. Element.hasAttribute = function(element, attribute) {
  2169. if (element.hasAttribute) return element.hasAttribute(attribute);
  2170. return Element.Methods.Simulated.hasAttribute(element, attribute);
  2171. };
  2172. Element.addMethods = function(methods) {
  2173. var F = Prototype.BrowserFeatures, T = Element.Methods.ByTag;
  2174. if (!methods) {
  2175. Object.extend(Form, Form.Methods);
  2176. Object.extend(Form.Element, Form.Element.Methods);
  2177. Object.extend(Element.Methods.ByTag, {
  2178. "FORM": Object.clone(Form.Methods),
  2179. "INPUT": Object.clone(Form.Element.Methods),
  2180. "SELECT": Object.clone(Form.Element.Methods),
  2181. "TEXTAREA": Object.clone(Form.Element.Methods)
  2182. });
  2183. }
  2184. if (arguments.length == 2) {
  2185. var tagName = methods;
  2186. methods = arguments[1];
  2187. }
  2188. if (!tagName) Object.extend(Element.Methods, methods || { });
  2189. else {
  2190. if (Object.isArray(tagName)) tagName.each(extend);
  2191. else extend(tagName);
  2192. }
  2193. function extend(tagName) {
  2194. tagName = tagName.toUpperCase();
  2195. if (!Element.Methods.ByTag[tagName])
  2196. Element.Methods.ByTag[tagName] = { };
  2197. Object.extend(Element.Methods.ByTag[tagName], methods);
  2198. }
  2199. function copy(methods, destination, onlyIfAbsent) {
  2200. onlyIfAbsent = onlyIfAbsent || false;
  2201. for (var property in methods) {
  2202. var value = methods[property];
  2203. if (!Object.isFunction(value)) continue;
  2204. if (!onlyIfAbsent || !(property in destination))
  2205. destination[property] = value.methodize();
  2206. }
  2207. }
  2208. function findDOMClass(tagName) {
  2209. var klass;
  2210. var trans = {
  2211. "OPTGROUP": "OptGroup", "TEXTAREA": "TextArea", "P": "Paragraph",
  2212. "FIELDSET": "FieldSet", "UL": "UList", "OL": "OList", "DL": "DList",
  2213. "DIR": "Directory", "H1": "Heading", "H2": "Heading", "H3": "Heading",
  2214. "H4": "Heading", "H5": "Heading", "H6": "Heading", "Q": "Quote",
  2215. "INS": "Mod", "DEL": "Mod", "A": "Anchor", "IMG": "Image", "CAPTION":
  2216. "TableCaption", "COL": "TableCol", "COLGROUP": "TableCol", "THEAD":
  2217. "TableSection", "TFOOT": "TableSection", "TBODY": "TableSection", "TR":
  2218. "TableRow", "TH": "TableCell", "TD": "TableCell", "FRAMESET":
  2219. "FrameSet", "IFRAME": "IFrame"
  2220. };
  2221. if (trans[tagName]) klass = 'HTML' + trans[tagName] + 'Element';
  2222. if (window[klass]) return window[klass];
  2223. klass = 'HTML' + tagName + 'Element';
  2224. if (window[klass]) return window[klass];
  2225. klass = 'HTML' + tagName.capitalize() + 'Element';
  2226. if (window[klass]) return window[klass];
  2227. window[klass] = { };
  2228. window[klass].prototype = document.createElement(tagName).__proto__;
  2229. return window[klass];
  2230. }
  2231. if (F.ElementExtensions) {
  2232. copy(Element.Methods, HTMLElement.prototype);
  2233. copy(Element.Methods.Simulated, HTMLElement.prototype, true);
  2234. }
  2235. if (F.SpecificElementExtensions) {
  2236. for (var tag in Element.Methods.ByTag) {
  2237. var klass = findDOMClass(tag);
  2238. if (Object.isUndefined(klass)) continue;
  2239. copy(T[tag], klass.prototype);
  2240. }
  2241. }
  2242. Object.extend(Element, Element.Methods);
  2243. delete Element.ByTag;
  2244. if (Element.extend.refresh) Element.extend.refresh();
  2245. Element.cache = { };
  2246. };
  2247. document.viewport = {
  2248. getDimensions: function() {
  2249. var dimensions = { };
  2250. var B = Prototype.Browser;
  2251. $w('width height').each(function(d) {
  2252. var D = d.capitalize();
  2253. dimensions[d] = (B.WebKit && !document.evaluate) ? self['inner' + D] :
  2254. (B.Opera) ? document.body['client' + D] : document.documentElement['client' + D];
  2255. });
  2256. return dimensions;
  2257. },
  2258. getWidth: function() {
  2259. return this.getDimensions().width;
  2260. },
  2261. getHeight: function() {
  2262. return this.getDimensions().height;
  2263. },
  2264. getScrollOffsets: function() {
  2265. return Element._returnOffset(
  2266. window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft,
  2267. window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop);
  2268. }
  2269. };
  2270. /* Portions of the Selector class are derived from Jack Slocum’s DomQuery,
  2271. * part of YUI-Ext version 0.40, distributed under the terms of an MIT-style
  2272. * license. Please see http://www.yui-ext.com/ for more information. */
  2273. var Selector = Class.create({
  2274. initialize: function(expression) {
  2275. this.expression = expression.strip();
  2276. this.compileMatcher();
  2277. },
  2278. shouldUseXPath: function() {
  2279. if (!Prototype.BrowserFeatures.XPath) return false;
  2280. var e = this.expression;
  2281. // Safari 3 chokes on :*-of-type and :empty
  2282. if (Prototype.Browser.WebKit &&
  2283. (e.include("-of-type") || e.include(":empty")))
  2284. return false;
  2285. // XPath can't do namespaced attributes, nor can it read
  2286. // the "checked" property from DOM nodes
  2287. if ((/(\[[\w-]*?:|:checked)/).test(this.expression))
  2288. return false;
  2289. return true;
  2290. },
  2291. compileMatcher: function() {
  2292. if (this.shouldUseXPath())
  2293. return this.compileXPathMatcher();
  2294. var e = this.expression, ps = Selector.patterns, h = Selector.handlers,
  2295. c = Selector.criteria, le, p, m;
  2296. if (Selector._cache[e]) {
  2297. this.matcher = Selector._cache[e];
  2298. return;
  2299. }
  2300. this.matcher = ["this.matcher = function(root) {",
  2301. "var r = root, h = Selector.handlers, c = false, n;"];
  2302. while (e && le != e && (/\S/).test(e)) {
  2303. le = e;
  2304. for (var i in ps) {
  2305. p = ps[i];
  2306. if (m = e.match(p)) {
  2307. this.matcher.push(Object.isFunction(c[i]) ? c[i](m) :
  2308. new Template(c[i]).evaluate(m));
  2309. e = e.replace(m[0], '');
  2310. break;
  2311. }
  2312. }
  2313. }
  2314. this.matcher.push("return h.unique(n);\n}");
  2315. eval(this.matcher.join('\n'));
  2316. Selector._cache[this.expression] = this.matcher;
  2317. },
  2318. compileXPathMatcher: function() {
  2319. var e = this.expression, ps = Selector.patterns,
  2320. x = Selector.xpath, le, m;
  2321. if (Selector._cache[e]) {
  2322. this.xpath = Selector._cache[e]; return;
  2323. }
  2324. this.matcher = ['.//*'];
  2325. while (e && le != e && (/\S/).test(e)) {
  2326. le = e;
  2327. for (var i in ps) {
  2328. if (m = e.match(ps[i])) {
  2329. this.matcher.push(Object.isFunction(x[i]) ? x[i](m) :
  2330. new Template(x[i]).evaluate(m));
  2331. e = e.replace(m[0], '');
  2332. break;
  2333. }
  2334. }
  2335. }
  2336. this.xpath = this.matcher.join('');
  2337. Selector._cache[this.expression] = this.xpath;
  2338. },
  2339. findElements: function(root) {
  2340. root = root || document;
  2341. if (this.xpath) return document._getElementsByXPath(this.xpath, root);
  2342. return this.matcher(root);
  2343. },
  2344. match: function(element) {
  2345. this.tokens = [];
  2346. var e = this.expression, ps = Selector.patterns, as = Selector.assertions;
  2347. var le, p, m;
  2348. while (e && le !== e && (/\S/).test(e)) {
  2349. le = e;
  2350. for (var i in ps) {
  2351. p = ps[i];
  2352. if (m = e.match(p)) {
  2353. // use the Selector.assertions methods unless the selector
  2354. // is too complex.
  2355. if (as[i]) {
  2356. this.tokens.push([i, Object.clone(m)]);
  2357. e = e.replace(m[0], '');
  2358. } else {
  2359. // reluctantly do a document-wide search
  2360. // and look for a match in the array
  2361. return this.findElements(document).include(element);
  2362. }
  2363. }
  2364. }
  2365. }
  2366. var match = true, name, matches;
  2367. for (var i = 0, token; token = this.tokens[i]; i++) {
  2368. name = token[0], matches = token[1];
  2369. if (!Selector.assertions[name](element, matches)) {
  2370. match = false; break;
  2371. }
  2372. }
  2373. return match;
  2374. },
  2375. toString: function() {
  2376. return this.expression;
  2377. },
  2378. inspect: function() {
  2379. return "#<Selector:" + this.expression.inspect() + ">";
  2380. }
  2381. });
  2382. Object.extend(Selector, {
  2383. _cache: { },
  2384. xpath: {
  2385. descendant: "//*",
  2386. child: "/*",
  2387. adjacent: "/following-sibling::*[1]",
  2388. laterSibling: '/following-sibling::*',
  2389. tagName: function(m) {
  2390. if (m[1] == '*') return '';
  2391. return "[local-name()='" + m[1].toLowerCase() +
  2392. "' or local-name()='" + m[1].toUpperCase() + "']";
  2393. },
  2394. className: "[contains(concat(' ', @class, ' '), ' #{1} ')]",
  2395. id: "[@id='#{1}']",
  2396. attrPresence: function(m) {
  2397. m[1] = m[1].toLowerCase();
  2398. return new Template("[@#{1}]").evaluate(m);
  2399. },
  2400. attr: function(m) {
  2401. m[1] = m[1].toLowerCase();
  2402. m[3] = m[5] || m[6];
  2403. return new Template(Selector.xpath.operators[m[2]]).evaluate(m);
  2404. },
  2405. pseudo: function(m) {
  2406. var h = Selector.xpath.pseudos[m[1]];
  2407. if (!h) return '';
  2408. if (Object.isFunction(h)) return h(m);
  2409. return new Template(Selector.xpath.pseudos[m[1]]).evaluate(m);
  2410. },
  2411. operators: {
  2412. '=': "[@#{1}='#{3}']",
  2413. '!=': "[@#{1}!='#{3}']",
  2414. '^=': "[starts-with(@#{1}, '#{3}')]",
  2415. '$=': "[substring(@#{1}, (string-length(@#{1}) - string-length('#{3}') + 1))='#{3}']",
  2416. '*=': "[contains(@#{1}, '#{3}')]",
  2417. '~=': "[contains(concat(' ', @#{1}, ' '), ' #{3} ')]",
  2418. '|=': "[contains(concat('-', @#{1}, '-'), '-#{3}-')]"
  2419. },
  2420. pseudos: {
  2421. 'first-child': '[not(preceding-sibling::*)]',
  2422. 'last-child': '[not(following-sibling::*)]',
  2423. 'only-child': '[not(preceding-sibling::* or following-sibling::*)]',
  2424. 'empty': "[count(*) = 0 and (count(text()) = 0 or translate(text(), ' \t\r\n', '') = '')]",
  2425. 'checked': "[@checked]",
  2426. 'disabled': "[@disabled]",
  2427. 'enabled': "[not(@disabled)]",
  2428. 'not': function(m) {
  2429. var e = m[6], p = Selector.patterns,
  2430. x = Selector.xpath, le, v;
  2431. var exclusion = [];
  2432. while (e && le != e && (/\S/).test(e)) {
  2433. le = e;
  2434. for (var i in p) {
  2435. if (m = e.match(p[i])) {
  2436. v = Object.isFunction(x[i]) ? x[i](m) : new Template(x[i]).evaluate(m);
  2437. exclusion.push("(" + v.substring(1, v.length - 1) + ")");
  2438. e = e.replace(m[0], '');
  2439. break;
  2440. }
  2441. }
  2442. }
  2443. return "[not(" + exclusion.join(" and ") + ")]";
  2444. },
  2445. 'nth-child': function(m) {
  2446. return Selector.xpath.pseudos.nth("(count(./preceding-sibling::*) + 1) ", m);
  2447. },
  2448. 'nth-last-child': function(m) {
  2449. return Selector.xpath.pseudos.nth("(count(./following-sibling::*) + 1) ", m);
  2450. },
  2451. 'nth-of-type': function(m) {
  2452. return Selector.xpath.pseudos.nth("position() ", m);
  2453. },
  2454. 'nth-last-of-type': function(m) {
  2455. return Selector.xpath.pseudos.nth("(last() + 1 - position()) ", m);
  2456. },
  2457. 'first-of-type': function(m) {
  2458. m[6] = "1"; return Selector.xpath.pseudos['nth-of-type'](m);
  2459. },
  2460. 'last-of-type': function(m) {
  2461. m[6] = "1"; return Selector.xpath.pseudos['nth-last-of-type'](m);
  2462. },
  2463. 'only-of-type': function(m) {
  2464. var p = Selector.xpath.pseudos; return p['first-of-type'](m) + p['last-of-type'](m);
  2465. },
  2466. nth: function(fragment, m) {
  2467. var mm, formula = m[6], predicate;
  2468. if (formula == 'even') formula = '2n+0';
  2469. if (formula == 'odd') formula = '2n+1';
  2470. if (mm = formula.match(/^(\d+)$/)) // digit only
  2471. return '[' + fragment + "= " + mm[1] + ']';
  2472. if (mm = formula.match(/^(-?\d*)?n(([+-])(\d+))?/)) { // an+b
  2473. if (mm[1] == "-") mm[1] = -1;
  2474. var a = mm[1] ? Number(mm[1]) : 1;
  2475. var b = mm[2] ? Number(mm[2]) : 0;
  2476. predicate = "[((#{fragment} - #{b}) mod #{a} = 0) and " +
  2477. "((#{fragment} - #{b}) div #{a} >= 0)]";
  2478. return new Template(predicate).evaluate({
  2479. fragment: fragment, a: a, b: b });
  2480. }
  2481. }
  2482. }
  2483. },
  2484. criteria: {
  2485. tagName: 'n = h.tagName(n, r, "#{1}", c); c = false;',
  2486. className: 'n = h.className(n, r, "#{1}", c); c = false;',
  2487. id: 'n = h.id(n, r, "#{1}", c); c = false;',
  2488. attrPresence: 'n = h.attrPresence(n, r, "#{1}", c); c = false;',
  2489. attr: function(m) {
  2490. m[3] = (m[5] || m[6]);
  2491. return new Template('n = h.attr(n, r, "#{1}", "#{3}", "#{2}", c); c = false;').evaluate(m);
  2492. },
  2493. pseudo: function(m) {
  2494. if (m[6]) m[6] = m[6].replace(/"/g, '\\"');
  2495. return new Template('n = h.pseudo(n, "#{1}", "#{6}", r, c); c = false;').evaluate(m);
  2496. },
  2497. descendant: 'c = "descendant";',
  2498. child: 'c = "child";',
  2499. adjacent: 'c = "adjacent";',
  2500. laterSibling: 'c = "laterSibling";'
  2501. },
  2502. patterns: {
  2503. // combinators must be listed first
  2504. // (and descendant needs to be last combinator)
  2505. laterSibling: /^\s*~\s*/,
  2506. child: /^\s*>\s*/,
  2507. adjacent: /^\s*\+\s*/,
  2508. descendant: /^\s/,
  2509. // selectors follow
  2510. tagName: /^\s*(\*|[\w\-]+)(\b|$)?/,
  2511. id: /^#([\w\-\*]+)(\b|$)/,
  2512. className: /^\.([\w\-\*]+)(\b|$)/,
  2513. pseudo:
  2514. /^:((first|last|nth|nth-last|only)(-child|-of-type)|empty|checked|(en|dis)abled|not)(\((.*?)\))?(\b|$|(?=\s|[:+~>]))/,
  2515. attrPresence: /^\[([\w]+)\]/,
  2516. attr: /\[((?:[\w-]*:)?[\w-]+)\s*(?:([!^$*~|]?=)\s*((['"])([^\4]*?)\4|([^'"][^\]]*?)))?\]/
  2517. },
  2518. // for Selector.match and Element#match
  2519. assertions: {
  2520. tagName: function(element, matches) {
  2521. return matches[1].toUpperCase() == element.tagName.toUpperCase();
  2522. },
  2523. className: function(element, matches) {
  2524. return Element.hasClassName(element, matches[1]);
  2525. },
  2526. id: function(element, matches) {
  2527. return element.id === matches[1];
  2528. },
  2529. attrPresence: function(element, matches) {
  2530. return Element.hasAttribute(element, matches[1]);
  2531. },
  2532. attr: function(element, matches) {
  2533. var nodeValue = Element.readAttribute(element, matches[1]);
  2534. return nodeValue && Selector.operators[matches[2]](nodeValue, matches[5] || matches[6]);
  2535. }
  2536. },
  2537. handlers: {
  2538. // UTILITY FUNCTIONS
  2539. // joins two collections
  2540. concat: function(a, b) {
  2541. for (var i = 0, node; node = b[i]; i++)
  2542. a.push(node);
  2543. return a;
  2544. },
  2545. // marks an array of nodes for counting
  2546. mark: function(nodes) {
  2547. var _true = Prototype.emptyFunction;
  2548. for (var i = 0, node; node = nodes[i]; i++)
  2549. node._countedByPrototype = _true;
  2550. return nodes;
  2551. },
  2552. unmark: function(nodes) {
  2553. for (var i = 0, node; node = nodes[i]; i++)
  2554. node._countedByPrototype = undefined;
  2555. return nodes;
  2556. },
  2557. // mark each child node with its position (for nth calls)
  2558. // "ofType" flag indicates whether we're indexing for nth-of-type
  2559. // rather than nth-child
  2560. index: function(parentNode, reverse, ofType) {
  2561. parentNode._countedByPrototype = Prototype.emptyFunction;
  2562. if (reverse) {
  2563. for (var nodes = parentNode.childNodes, i = nodes.length - 1, j = 1; i >= 0; i--) {
  2564. var node = nodes[i];
  2565. if (node.nodeType == 1 && (!ofType || node._countedByPrototype)) node.nodeIndex = j++;
  2566. }
  2567. } else {
  2568. for (var i = 0, j = 1, nodes = parentNode.childNodes; node = nodes[i]; i++)
  2569. if (node.nodeType == 1 && (!ofType || node._countedByPrototype)) node.nodeIndex = j++;
  2570. }
  2571. },
  2572. // filters out duplicates and extends all nodes
  2573. unique: function(nodes) {
  2574. if (nodes.length == 0) return nodes;
  2575. var results = [], n;
  2576. for (var i = 0, l = nodes.length; i < l; i++)
  2577. if (!(n = nodes[i])._countedByPrototype) {
  2578. n._countedByPrototype = Prototype.emptyFunction;
  2579. results.push(Element.extend(n));
  2580. }
  2581. return Selector.handlers.unmark(results);
  2582. },
  2583. // COMBINATOR FUNCTIONS
  2584. descendant: function(nodes) {
  2585. var h = Selector.handlers;
  2586. for (var i = 0, results = [], node; node = nodes[i]; i++)
  2587. h.concat(results, node.getElementsByTagName('*'));
  2588. return results;
  2589. },
  2590. child: function(nodes) {
  2591. var h = Selector.handlers;
  2592. for (var i = 0, results = [], node; node = nodes[i]; i++) {
  2593. for (var j = 0, child; child = node.childNodes[j]; j++)
  2594. if (child.nodeType == 1 && child.tagName != '!') results.push(child);
  2595. }
  2596. return results;
  2597. },
  2598. adjacent: function(nodes) {
  2599. for (var i = 0, results = [], node; node = nodes[i]; i++) {
  2600. var next = this.nextElementSibling(node);
  2601. if (next) results.push(next);
  2602. }
  2603. return results;
  2604. },
  2605. laterSibling: function(nodes) {
  2606. var h = Selector.handlers;
  2607. for (var i = 0, results = [], node; node = nodes[i]; i++)
  2608. h.concat(results, Element.nextSiblings(node));
  2609. return results;
  2610. },
  2611. nextElementSibling: function(node) {
  2612. while (node = node.nextSibling)
  2613. if (node.nodeType == 1) return node;
  2614. return null;
  2615. },
  2616. previousElementSibling: function(node) {
  2617. while (node = node.previousSibling)
  2618. if (node.nodeType == 1) return node;
  2619. return null;
  2620. },
  2621. // TOKEN FUNCTIONS
  2622. tagName: function(nodes, root, tagName, combinator) {
  2623. var uTagName = tagName.toUpperCase();
  2624. var results = [], h = Selector.handlers;
  2625. if (nodes) {
  2626. if (combinator) {
  2627. // fastlane for ordinary descendant combinators
  2628. if (combinator == "descendant") {
  2629. for (var i = 0, node; node = nodes[i]; i++)
  2630. h.concat(results, node.getElementsByTagName(tagName));
  2631. return results;
  2632. } else nodes = this[combinator](nodes);
  2633. if (tagName == "*") return nodes;
  2634. }
  2635. for (var i = 0, node; node = nodes[i]; i++)
  2636. if (node.tagName.toUpperCase() === uTagName) results.push(node);
  2637. return results;
  2638. } else return root.getElementsByTagName(tagName);
  2639. },
  2640. id: function(nodes, root, id, combinator) {
  2641. var targetNode = $(id), h = Selector.handlers;
  2642. if (!targetNode) return [];
  2643. if (!nodes && root == document) return [targetNode];
  2644. if (nodes) {
  2645. if (combinator) {
  2646. if (combinator == 'child') {
  2647. for (var i = 0, node; node = nodes[i]; i++)
  2648. if (targetNode.parentNode == node) return [targetNode];
  2649. } else if (combinator == 'descendant') {
  2650. for (var i = 0, node; node = nodes[i]; i++)
  2651. if (Element.descendantOf(targetNode, node)) return [targetNode];
  2652. } else if (combinator == 'adjacent') {
  2653. for (var i = 0, node; node = nodes[i]; i++)
  2654. if (Selector.handlers.previousElementSibling(targetNode) == node)
  2655. return [targetNode];
  2656. } else nodes = h[combinator](nodes);
  2657. }
  2658. for (var i = 0, node; node = nodes[i]; i++)
  2659. if (node == targetNode) return [targetNode];
  2660. return [];
  2661. }
  2662. return (targetNode && Element.descendantOf(targetNode, root)) ? [targetNode] : [];
  2663. },
  2664. className: function(nodes, root, className, combinator) {
  2665. if (nodes && combinator) nodes = this[combinator](nodes);
  2666. return Selector.handlers.byClassName(nodes, root, className);
  2667. },
  2668. byClassName: function(nodes, root, className) {
  2669. if (!nodes) nodes = Selector.handlers.descendant([root]);
  2670. var needle = ' ' + className + ' ';
  2671. for (var i = 0, results = [], node, nodeClassName; node = nodes[i]; i++) {
  2672. nodeClassName = node.className;
  2673. if (nodeClassName.length == 0) continue;
  2674. if (nodeClassName == className || (' ' + nodeClassName + ' ').include(needle))
  2675. results.push(node);
  2676. }
  2677. return results;
  2678. },
  2679. attrPresence: function(nodes, root, attr, combinator) {
  2680. if (!nodes) nodes = root.getElementsByTagName("*");
  2681. if (nodes && combinator) nodes = this[combinator](nodes);
  2682. var results = [];
  2683. for (var i = 0, node; node = nodes[i]; i++)
  2684. if (Element.hasAttribute(node, attr)) results.push(node);
  2685. return results;
  2686. },
  2687. attr: function(nodes, root, attr, value, operator, combinator) {
  2688. if (!nodes) nodes = root.getElementsByTagName("*");
  2689. if (nodes && combinator) nodes = this[combinator](nodes);
  2690. var handler = Selector.operators[operator], results = [];
  2691. for (var i = 0, node; node = nodes[i]; i++) {
  2692. var nodeValue = Element.readAttribute(node, attr);
  2693. if (nodeValue === null) continue;
  2694. if (handler(nodeValue, value)) results.push(node);
  2695. }
  2696. return results;
  2697. },
  2698. pseudo: function(nodes, name, value, root, combinator) {
  2699. if (nodes && combinator) nodes = this[combinator](nodes);
  2700. if (!nodes) nodes = root.getElementsByTagName("*");
  2701. return Selector.pseudos[name](nodes, value, root);
  2702. }
  2703. },
  2704. pseudos: {
  2705. 'first-child': function(nodes, value, root) {
  2706. for (var i = 0, results = [], node; node = nodes[i]; i++) {
  2707. if (Selector.handlers.previousElementSibling(node)) continue;
  2708. results.push(node);
  2709. }
  2710. return results;
  2711. },
  2712. 'last-child': function(nodes, value, root) {
  2713. for (var i = 0, results = [], node; node = nodes[i]; i++) {
  2714. if (Selector.handlers.nextElementSibling(node)) continue;
  2715. results.push(node);
  2716. }
  2717. return results;
  2718. },
  2719. 'only-child': function(nodes, value, root) {
  2720. var h = Selector.handlers;
  2721. for (var i = 0, results = [], node; node = nodes[i]; i++)
  2722. if (!h.previousElementSibling(node) && !h.nextElementSibling(node))
  2723. results.push(node);
  2724. return results;
  2725. },
  2726. 'nth-child': function(nodes, formula, root) {
  2727. return Selector.pseudos.nth(nodes, formula, root);
  2728. },
  2729. 'nth-last-child': function(nodes, formula, root) {
  2730. return Selector.pseudos.nth(nodes, formula, root, true);
  2731. },
  2732. 'nth-of-type': function(nodes, formula, root) {
  2733. return Selector.pseudos.nth(nodes, formula, root, false, true);
  2734. },
  2735. 'nth-last-of-type': function(nodes, formula, root) {
  2736. return Selector.pseudos.nth(nodes, formula, root, true, true);
  2737. },
  2738. 'first-of-type': function(nodes, formula, root) {
  2739. return Selector.pseudos.nth(nodes, "1", root, false, true);
  2740. },
  2741. 'last-of-type': function(nodes, formula, root) {
  2742. return Selector.pseudos.nth(nodes, "1", root, true, true);
  2743. },
  2744. 'only-of-type': function(nodes, formula, root) {
  2745. var p = Selector.pseudos;
  2746. return p['last-of-type'](p['first-of-type'](nodes, formula, root), formula, root);
  2747. },
  2748. // handles the an+b logic
  2749. getIndices: function(a, b, total) {
  2750. if (a == 0) return b > 0 ? [b] : [];
  2751. return $R(1, total).inject([], function(memo, i) {
  2752. if (0 == (i - b) % a && (i - b) / a >= 0) memo.push(i);
  2753. return memo;
  2754. });
  2755. },
  2756. // handles nth(-last)-child, nth(-last)-of-type, and (first|last)-of-type
  2757. nth: function(nodes, formula, root, reverse, ofType) {
  2758. if (nodes.length == 0) return [];
  2759. if (formula == 'even') formula = '2n+0';
  2760. if (formula == 'odd') formula = '2n+1';
  2761. var h = Selector.handlers, results = [], indexed = [], m;
  2762. h.mark(nodes);
  2763. for (var i = 0, node; node = nodes[i]; i++) {
  2764. if (!node.parentNode._countedByPrototype) {
  2765. h.index(node.parentNode, reverse, ofType);
  2766. indexed.push(node.parentNode);
  2767. }
  2768. }
  2769. if (formula.match(/^\d+$/)) { // just a number
  2770. formula = Number(formula);
  2771. for (var i = 0, node; node = nodes[i]; i++)
  2772. if (node.nodeIndex == formula) results.push(node);
  2773. } else if (m = formula.match(/^(-?\d*)?n(([+-])(\d+))?/)) { // an+b
  2774. if (m[1] == "-") m[1] = -1;
  2775. var a = m[1] ? Number(m[1]) : 1;
  2776. var b = m[2] ? Number(m[2]) : 0;
  2777. var indices = Selector.pseudos.getIndices(a, b, nodes.length);
  2778. for (var i = 0, node, l = indices.length; node = nodes[i]; i++) {
  2779. for (var j = 0; j < l; j++)
  2780. if (node.nodeIndex == indices[j]) results.push(node);
  2781. }
  2782. }
  2783. h.unmark(nodes);
  2784. h.unmark(indexed);
  2785. return results;
  2786. },
  2787. 'empty': function(nodes, value, root) {
  2788. for (var i = 0, results = [], node; node = nodes[i]; i++) {
  2789. // IE treats comments as element nodes
  2790. if (node.tagName == '!' || (node.firstChild && !node.innerHTML.match(/^\s*$/))) continue;
  2791. results.push(node);
  2792. }
  2793. return results;
  2794. },
  2795. 'not': function(nodes, selector, root) {
  2796. var h = Selector.handlers, selectorType, m;
  2797. var exclusions = new Selector(selector).findElements(root);
  2798. h.mark(exclusions);
  2799. for (var i = 0, results = [], node; node = nodes[i]; i++)
  2800. if (!node._countedByPrototype) results.push(node);
  2801. h.unmark(exclusions);
  2802. return results;
  2803. },
  2804. 'enabled': function(nodes, value, root) {
  2805. for (var i = 0, results = [], node; node = nodes[i]; i++)
  2806. if (!node.disabled) results.push(node);
  2807. return results;
  2808. },
  2809. 'disabled': function(nodes, value, root) {
  2810. for (var i = 0, results = [], node; node = nodes[i]; i++)
  2811. if (node.disabled) results.push(node);
  2812. return results;
  2813. },
  2814. 'checked': function(nodes, value, root) {
  2815. for (var i = 0, results = [], node; node = nodes[i]; i++)
  2816. if (node.checked) results.push(node);
  2817. return results;
  2818. }
  2819. },
  2820. operators: {
  2821. '=': function(nv, v) { return nv == v; },
  2822. '!=': function(nv, v) { return nv != v; },
  2823. '^=': function(nv, v) { return nv.startsWith(v); },
  2824. '$=': function(nv, v) { return nv.endsWith(v); },
  2825. '*=': function(nv, v) { return nv.include(v); },
  2826. '~=': function(nv, v) { return (' ' + nv + ' ').include(' ' + v + ' '); },
  2827. '|=': function(nv, v) { return ('-' + nv.toUpperCase() + '-').include('-' + v.toUpperCase() + '-'); }
  2828. },
  2829. split: function(expression) {
  2830. var expressions = [];
  2831. expression.scan(/(([\w#:.~>+()\s-]+|\*|\[.*?\])+)\s*(,|$)/, function(m) {
  2832. expressions.push(m[1].strip());
  2833. });
  2834. return expressions;
  2835. },
  2836. matchElements: function(elements, expression) {
  2837. var matches = $$(expression), h = Selector.handlers;
  2838. h.mark(matches);
  2839. for (var i = 0, results = [], element; element = elements[i]; i++)
  2840. if (element._countedByPrototype) results.push(element);
  2841. h.unmark(matches);
  2842. return results;
  2843. },
  2844. findElement: function(elements, expression, index) {
  2845. if (Object.isNumber(expression)) {
  2846. index = expression; expression = false;
  2847. }
  2848. return Selector.matchElements(elements, expression || '*')[index || 0];
  2849. },
  2850. findChildElements: function(element, expressions) {
  2851. expressions = Selector.split(expressions.join(','));
  2852. var results = [], h = Selector.handlers;
  2853. for (var i = 0, l = expressions.length, selector; i < l; i++) {
  2854. selector = new Selector(expressions[i].strip());
  2855. h.concat(results, selector.findElements(element));
  2856. }
  2857. return (l > 1) ? h.unique(results) : results;
  2858. }
  2859. });
  2860. if (Prototype.Browser.IE) {
  2861. Object.extend(Selector.handlers, {
  2862. // IE returns comment nodes on getElementsByTagName("*").
  2863. // Filter them out.
  2864. concat: function(a, b) {
  2865. for (var i = 0, node; node = b[i]; i++)
  2866. if (node.tagName !== "!") a.push(node);
  2867. return a;
  2868. },
  2869. // IE improperly serializes _countedByPrototype in (inner|outer)HTML.
  2870. unmark: function(nodes) {
  2871. for (var i = 0, node; node = nodes[i]; i++)
  2872. node.removeAttribute('_countedByPrototype');
  2873. return nodes;
  2874. }
  2875. });
  2876. }
  2877. function $$() {
  2878. return Selector.findChildElements(document, $A(arguments));
  2879. }
  2880. var Form = {
  2881. reset: function(form) {
  2882. $(form).reset();
  2883. return form;
  2884. },
  2885. serializeElements: function(elements, options) {
  2886. if (typeof options != 'object') options = { hash: !!options };
  2887. else if (Object.isUndefined(options.hash)) options.hash = true;
  2888. var key, value, submitted = false, submit = options.submit;
  2889. var data = elements.inject({ }, function(result, element) {
  2890. if (!element.disabled && element.name) {
  2891. key = element.name; value = $(element).getValue();
  2892. if (value != null && (element.type != 'submit' || (!submitted &&
  2893. submit !== false && (!submit || key == submit) && (submitted = true)))) {
  2894. if (key in result) {
  2895. // a key is already present; construct an array of values
  2896. if (!Object.isArray(result[key])) result[key] = [result[key]];
  2897. result[key].push(value);
  2898. }
  2899. else result[key] = value;
  2900. }
  2901. }
  2902. return result;
  2903. });
  2904. return options.hash ? data : Object.toQueryString(data);
  2905. }
  2906. };
  2907. Form.Methods = {
  2908. serialize: function(form, options) {
  2909. return Form.serializeElements(Form.getElements(form), options);
  2910. },
  2911. getElements: function(form) {
  2912. return $A($(form).getElementsByTagName('*')).inject([],
  2913. function(elements, child) {
  2914. if (Form.Element.Serializers[child.tagName.toLowerCase()])
  2915. elements.push(Element.extend(child));
  2916. return elements;
  2917. }
  2918. );
  2919. },
  2920. getInputs: function(form, typeName, name) {
  2921. form = $(form);
  2922. var inputs = form.getElementsByTagName('input');
  2923. if (!typeName && !name) return $A(inputs).map(Element.extend);
  2924. for (var i = 0, matchingInputs = [], length = inputs.length; i < length; i++) {
  2925. var input = inputs[i];
  2926. if ((typeName && input.type != typeName) || (name && input.name != name))
  2927. continue;
  2928. matchingInputs.push(Element.extend(input));
  2929. }
  2930. return matchingInputs;
  2931. },
  2932. disable: function(form) {
  2933. form = $(form);
  2934. Form.getElements(form).invoke('disable');
  2935. return form;
  2936. },
  2937. enable: function(form) {
  2938. form = $(form);
  2939. Form.getElements(form).invoke('enable');
  2940. return form;
  2941. },
  2942. findFirstElement: function(form) {
  2943. var elements = $(form).getElements().findAll(function(element) {
  2944. return 'hidden' != element.type && !element.disabled;
  2945. });
  2946. var firstByIndex = elements.findAll(function(element) {
  2947. return element.hasAttribute('tabIndex') && element.tabIndex >= 0;
  2948. }).sortBy(function(element) { return element.tabIndex }).first();
  2949. return firstByIndex ? firstByIndex : elements.find(function(element) {
  2950. return ['input', 'select', 'textarea'].include(element.tagName.toLowerCase());
  2951. });
  2952. },
  2953. focusFirstElement: function(form) {
  2954. form = $(form);
  2955. form.findFirstElement().activate();
  2956. return form;
  2957. },
  2958. request: function(form, options) {
  2959. form = $(form), options = Object.clone(options || { });
  2960. var params = options.parameters, action = form.readAttribute('action') || '';
  2961. if (action.blank()) action = window.location.href;
  2962. options.parameters = form.serialize(true);
  2963. if (params) {
  2964. if (Object.isString(params)) params = params.toQueryParams();
  2965. Object.extend(options.parameters, params);
  2966. }
  2967. if (form.hasAttribute('method') && !options.method)
  2968. options.method = form.method;
  2969. return new Ajax.Request(action, options);
  2970. }
  2971. };
  2972. /*--------------------------------------------------------------------------*/
  2973. Form.Element = {
  2974. focus: function(element) {
  2975. $(element).focus();
  2976. return element;
  2977. },
  2978. select: function(element) {
  2979. $(element).select();
  2980. return element;
  2981. }
  2982. };
  2983. Form.Element.Methods = {
  2984. serialize: function(element) {
  2985. element = $(element);
  2986. if (!element.disabled && element.name) {
  2987. var value = element.getValue();
  2988. if (value != undefined) {
  2989. var pair = { };
  2990. pair[element.name] = value;
  2991. return Object.toQueryString(pair);
  2992. }
  2993. }
  2994. return '';
  2995. },
  2996. getValue: function(element) {
  2997. element = $(element);
  2998. var method = element.tagName.toLowerCase();
  2999. return Form.Element.Serializers[method](element);
  3000. },
  3001. setValue: function(element, value) {
  3002. element = $(element);
  3003. var method = element.tagName.toLowerCase();
  3004. Form.Element.Serializers[method](element, value);
  3005. return element;
  3006. },
  3007. clear: function(element) {
  3008. $(element).value = '';
  3009. return element;
  3010. },
  3011. present: function(element) {
  3012. return $(element).value != '';
  3013. },
  3014. activate: function(element) {
  3015. element = $(element);
  3016. try {
  3017. element.focus();
  3018. if (element.select && (element.tagName.toLowerCase() != 'input' ||
  3019. !['button', 'reset', 'submit'].include(element.type)))
  3020. element.select();
  3021. } catch (e) { }
  3022. return element;
  3023. },
  3024. disable: function(element) {
  3025. element = $(element);
  3026. element.blur();
  3027. element.disabled = true;
  3028. return element;
  3029. },
  3030. enable: function(element) {
  3031. element = $(element);
  3032. element.disabled = false;
  3033. return element;
  3034. }
  3035. };
  3036. /*--------------------------------------------------------------------------*/
  3037. var Field = Form.Element;
  3038. var $F = Form.Element.Methods.getValue;
  3039. /*--------------------------------------------------------------------------*/
  3040. Form.Element.Serializers = {
  3041. input: function(element, value) {
  3042. switch (element.type.toLowerCase()) {
  3043. case 'checkbox':
  3044. case 'radio':
  3045. return Form.Element.Serializers.inputSelector(element, value);
  3046. default:
  3047. return Form.Element.Serializers.textarea(element, value);
  3048. }
  3049. },
  3050. inputSelector: function(element, value) {
  3051. if (Object.isUndefined(value)) return element.checked ? element.value : null;
  3052. else element.checked = !!value;
  3053. },
  3054. textarea: function(element, value) {
  3055. if (Object.isUndefined(value)) return element.value;
  3056. else element.value = value;
  3057. },
  3058. select: function(element, index) {
  3059. if (Object.isUndefined(index))
  3060. return this[element.type == 'select-one' ?
  3061. 'selectOne' : 'selectMany'](element);
  3062. else {
  3063. var opt, value, single = !Object.isArray(index);
  3064. for (var i = 0, length = element.length; i < length; i++) {
  3065. opt = element.options[i];
  3066. value = this.optionValue(opt);
  3067. if (single) {
  3068. if (value == index) {
  3069. opt.selected = true;
  3070. return;
  3071. }
  3072. }
  3073. else opt.selected = index.include(value);
  3074. }
  3075. }
  3076. },
  3077. selectOne: function(element) {
  3078. var index = element.selectedIndex;
  3079. return index >= 0 ? this.optionValue(element.options[index]) : null;
  3080. },
  3081. selectMany: function(element) {
  3082. var values, length = element.length;
  3083. if (!length) return null;
  3084. for (var i = 0, values = []; i < length; i++) {
  3085. var opt = element.options[i];
  3086. if (opt.selected) values.push(this.optionValue(opt));
  3087. }
  3088. return values;
  3089. },
  3090. optionValue: function(opt) {
  3091. // extend element because hasAttribute may not be native
  3092. return Element.extend(opt).hasAttribute('value') ? opt.value : opt.text;
  3093. }
  3094. };
  3095. /*--------------------------------------------------------------------------*/
  3096. Abstract.TimedObserver = Class.create(PeriodicalExecuter, {
  3097. initialize: function($super, element, frequency, callback) {
  3098. $super(callback, frequency);
  3099. this.element = $(element);
  3100. this.lastValue = this.getValue();
  3101. },
  3102. execute: function() {
  3103. var value = this.getValue();
  3104. if (Object.isString(this.lastValue) && Object.isString(value) ?
  3105. this.lastValue != value : String(this.lastValue) != String(value)) {
  3106. this.callback(this.element, value);
  3107. this.lastValue = value;
  3108. }
  3109. }
  3110. });
  3111. Form.Element.Observer = Class.create(Abstract.TimedObserver, {
  3112. getValue: function() {
  3113. return Form.Element.getValue(this.element);
  3114. }
  3115. });
  3116. Form.Observer = Class.create(Abstract.TimedObserver, {
  3117. getValue: function() {
  3118. return Form.serialize(this.element);
  3119. }
  3120. });
  3121. /*--------------------------------------------------------------------------*/
  3122. Abstract.EventObserver = Class.create({
  3123. initialize: function(element, callback) {
  3124. this.element = $(element);
  3125. this.callback = callback;
  3126. this.lastValue = this.getValue();
  3127. if (this.element.tagName.toLowerCase() == 'form')
  3128. this.registerFormCallbacks();
  3129. else
  3130. this.registerCallback(this.element);
  3131. },
  3132. onElementEvent: function() {
  3133. var value = this.getValue();
  3134. if (this.lastValue != value) {
  3135. this.callback(this.element, value);
  3136. this.lastValue = value;
  3137. }
  3138. },
  3139. registerFormCallbacks: function() {
  3140. Form.getElements(this.element).each(this.registerCallback, this);
  3141. },
  3142. registerCallback: function(element) {
  3143. if (element.type) {
  3144. switch (element.type.toLowerCase()) {
  3145. case 'checkbox':
  3146. case 'radio':
  3147. Event.observe(element, 'click', this.onElementEvent.bind(this));
  3148. break;
  3149. default:
  3150. Event.observe(element, 'change', this.onElementEvent.bind(this));
  3151. break;
  3152. }
  3153. }
  3154. }
  3155. });
  3156. Form.Element.EventObserver = Class.create(Abstract.EventObserver, {
  3157. getValue: function() {
  3158. return Form.Element.getValue(this.element);
  3159. }
  3160. });
  3161. Form.EventObserver = Class.create(Abstract.EventObserver, {
  3162. getValue: function() {
  3163. return Form.serialize(this.element);
  3164. }
  3165. });
  3166. if (!window.Event) var Event = { };
  3167. Object.extend(Event, {
  3168. KEY_BACKSPACE: 8,
  3169. KEY_TAB: 9,
  3170. KEY_RETURN: 13,
  3171. KEY_ESC: 27,
  3172. KEY_LEFT: 37,
  3173. KEY_UP: 38,
  3174. KEY_RIGHT: 39,
  3175. KEY_DOWN: 40,
  3176. KEY_DELETE: 46,
  3177. KEY_HOME: 36,
  3178. KEY_END: 35,
  3179. KEY_PAGEUP: 33,
  3180. KEY_PAGEDOWN: 34,
  3181. KEY_INSERT: 45,
  3182. cache: { },
  3183. relatedTarget: function(event) {
  3184. var element;
  3185. switch(event.type) {
  3186. case 'mouseover': element = event.fromElement; break;
  3187. case 'mouseout': element = event.toElement; break;
  3188. default: return null;
  3189. }
  3190. return Element.extend(element);
  3191. }
  3192. });
  3193. Event.Methods = (function() {
  3194. var isButton;
  3195. if (Prototype.Browser.IE) {
  3196. var buttonMap = { 0: 1, 1: 4, 2: 2 };
  3197. isButton = function(event, code) {
  3198. return event.button == buttonMap[code];
  3199. };
  3200. } else if (Prototype.Browser.WebKit) {
  3201. isButton = function(event, code) {
  3202. switch (code) {
  3203. case 0: return event.which == 1 && !event.metaKey;
  3204. case 1: return event.which == 1 && event.metaKey;
  3205. default: return false;
  3206. }
  3207. };
  3208. } else {
  3209. isButton = function(event, code) {
  3210. return event.which ? (event.which === code + 1) : (event.button === code);
  3211. };
  3212. }
  3213. return {
  3214. isLeftClick: function(event) { return isButton(event, 0) },
  3215. isMiddleClick: function(event) { return isButton(event, 1) },
  3216. isRightClick: function(event) { return isButton(event, 2) },
  3217. element: function(event) {
  3218. var node = Event.extend(event).target;
  3219. return Element.extend(node.nodeType == Node.TEXT_NODE ? node.parentNode : node);
  3220. },
  3221. findElement: function(event, expression) {
  3222. var element = Event.element(event);
  3223. if (!expression) return element;
  3224. var elements = [element].concat(element.ancestors());
  3225. return Selector.findElement(elements, expression, 0);
  3226. },
  3227. pointer: function(event) {
  3228. return {
  3229. x: event.pageX || (event.clientX +
  3230. (document.documentElement.scrollLeft || document.body.scrollLeft)),
  3231. y: event.pageY || (event.clientY +
  3232. (document.documentElement.scrollTop || document.body.scrollTop))
  3233. };
  3234. },
  3235. pointerX: function(event) { return Event.pointer(event).x },
  3236. pointerY: function(event) { return Event.pointer(event).y },
  3237. stop: function(event) {
  3238. Event.extend(event);
  3239. event.preventDefault();
  3240. event.stopPropagation();
  3241. event.stopped = true;
  3242. }
  3243. };
  3244. })();
  3245. Event.extend = (function() {
  3246. var methods = Object.keys(Event.Methods).inject({ }, function(m, name) {
  3247. m[name] = Event.Methods[name].methodize();
  3248. return m;
  3249. });
  3250. if (Prototype.Browser.IE) {
  3251. Object.extend(methods, {
  3252. stopPropagation: function() { this.cancelBubble = true },
  3253. preventDefault: function() { this.returnValue = false },
  3254. inspect: function() { return "[object Event]" }
  3255. });
  3256. return function(event) {
  3257. if (!event) return false;
  3258. if (event._extendedByPrototype) return event;
  3259. event._extendedByPrototype = Prototype.emptyFunction;
  3260. var pointer = Event.pointer(event);
  3261. Object.extend(event, {
  3262. target: event.srcElement,
  3263. relatedTarget: Event.relatedTarget(event),
  3264. pageX: pointer.x,
  3265. pageY: pointer.y
  3266. });
  3267. return Object.extend(event, methods);
  3268. };
  3269. } else {
  3270. Event.prototype = Event.prototype || document.createEvent("HTMLEvents").__proto__;
  3271. Object.extend(Event.prototype, methods);
  3272. return Prototype.K;
  3273. }
  3274. })();
  3275. Object.extend(Event, (function() {
  3276. var cache = Event.cache;
  3277. function getEventID(element) {
  3278. if (element._prototypeEventID) return element._prototypeEventID[0];
  3279. arguments.callee.id = arguments.callee.id || 1;
  3280. return element._prototypeEventID = [++arguments.callee.id];
  3281. }
  3282. function getDOMEventName(eventName) {
  3283. if (eventName && eventName.include(':')) return "dataavailable";
  3284. return eventName;
  3285. }
  3286. function getCacheForID(id) {
  3287. return cache[id] = cache[id] || { };
  3288. }
  3289. function getWrappersForEventName(id, eventName) {
  3290. var c = getCacheForID(id);
  3291. return c[eventName] = c[eventName] || [];
  3292. }
  3293. function createWrapper(element, eventName, handler) {
  3294. var id = getEventID(element);
  3295. var c = getWrappersForEventName(id, eventName);
  3296. if (c.pluck("handler").include(handler)) return false;
  3297. var wrapper = function(event) {
  3298. if (!Event || !Event.extend ||
  3299. (event.eventName && event.eventName != eventName))
  3300. return false;
  3301. Event.extend(event);
  3302. handler.call(element, event);
  3303. };
  3304. wrapper.handler = handler;
  3305. c.push(wrapper);
  3306. return wrapper;
  3307. }
  3308. function findWrapper(id, eventName, handler) {
  3309. var c = getWrappersForEventName(id, eventName);
  3310. return c.find(function(wrapper) { return wrapper.handler == handler });
  3311. }
  3312. function destroyWrapper(id, eventName, handler) {
  3313. var c = getCacheForID(id);
  3314. if (!c[eventName]) return false;
  3315. c[eventName] = c[eventName].without(findWrapper(id, eventName, handler));
  3316. }
  3317. function destroyCache() {
  3318. for (var id in cache)
  3319. for (var eventName in cache[id])
  3320. cache[id][eventName] = null;
  3321. }
  3322. if (window.attachEvent) {
  3323. window.attachEvent("onunload", destroyCache);
  3324. }
  3325. return {
  3326. observe: function(element, eventName, handler) {
  3327. element = $(element);
  3328. var name = getDOMEventName(eventName);
  3329. var wrapper = createWrapper(element, eventName, handler);
  3330. if (!wrapper) return element;
  3331. if (element.addEventListener) {
  3332. element.addEventListener(name, wrapper, false);
  3333. } else {
  3334. element.attachEvent("on" + name, wrapper);
  3335. }
  3336. return element;
  3337. },
  3338. stopObserving: function(element, eventName, handler) {
  3339. element = $(element);
  3340. var id = getEventID(element), name = getDOMEventName(eventName);
  3341. if (!handler && eventName) {
  3342. getWrappersForEventName(id, eventName).each(function(wrapper) {
  3343. element.stopObserving(eventName, wrapper.handler);
  3344. });
  3345. return element;
  3346. } else if (!eventName) {
  3347. Object.keys(getCacheForID(id)).each(function(eventName) {
  3348. element.stopObserving(eventName);
  3349. });
  3350. return element;
  3351. }
  3352. var wrapper = findWrapper(id, eventName, handler);
  3353. if (!wrapper) return element;
  3354. if (element.removeEventListener) {
  3355. element.removeEventListener(name, wrapper, false);
  3356. } else {
  3357. element.detachEvent("on" + name, wrapper);
  3358. }
  3359. destroyWrapper(id, eventName, handler);
  3360. return element;
  3361. },
  3362. fire: function(element, eventName, memo) {
  3363. element = $(element);
  3364. if (element == document && document.createEvent && !element.dispatchEvent)
  3365. element = document.documentElement;
  3366. var event;
  3367. if (document.createEvent) {
  3368. event = document.createEvent("HTMLEvents");
  3369. event.initEvent("dataavailable", true, true);
  3370. } else {
  3371. event = document.createEventObject();
  3372. event.eventType = "ondataavailable";
  3373. }
  3374. event.eventName = eventName;
  3375. event.memo = memo || { };
  3376. if (document.createEvent) {
  3377. element.dispatchEvent(event);
  3378. } else {
  3379. element.fireEvent(event.eventType, event);
  3380. }
  3381. return Event.extend(event);
  3382. }
  3383. };
  3384. })());
  3385. Object.extend(Event, Event.Methods);
  3386. Element.addMethods({
  3387. fire: Event.fire,
  3388. observe: Event.observe,
  3389. stopObserving: Event.stopObserving
  3390. });
  3391. Object.extend(document, {
  3392. fire: Element.Methods.fire.methodize(),
  3393. observe: Element.Methods.observe.methodize(),
  3394. stopObserving: Element.Methods.stopObserving.methodize(),
  3395. loaded: false
  3396. });
  3397. (function() {
  3398. /* Support for the DOMContentLoaded event is based on work by Dan Webb,
  3399. Matthias Miller, Dean Edwards and John Resig. */
  3400. var timer;
  3401. function fireContentLoadedEvent() {
  3402. if (document.loaded) return;
  3403. if (timer) window.clearInterval(timer);
  3404. document.fire("dom:loaded");
  3405. document.loaded = true;
  3406. }
  3407. if (document.addEventListener) {
  3408. if (Prototype.Browser.WebKit) {
  3409. timer = window.setInterval(function() {
  3410. if (/loaded|complete/.test(document.readyState))
  3411. fireContentLoadedEvent();
  3412. }, 0);
  3413. Event.observe(window, "load", fireContentLoadedEvent);
  3414. } else {
  3415. document.addEventListener("DOMContentLoaded",
  3416. fireContentLoadedEvent, false);
  3417. }
  3418. } else {
  3419. document.write("<script id=__onDOMContentLoaded defer src=//:><\/script>");
  3420. $("__onDOMContentLoaded").onreadystatechange = function() {
  3421. if (this.readyState == "complete") {
  3422. this.onreadystatechange = null;
  3423. fireContentLoadedEvent();
  3424. }
  3425. };
  3426. }
  3427. })();
  3428. /*------------------------------- DEPRECATED -------------------------------*/
  3429. Hash.toQueryString = Object.toQueryString;
  3430. var Toggle = { display: Element.toggle };
  3431. Element.Methods.childOf = Element.Methods.descendantOf;
  3432. var Insertion = {
  3433. Before: function(element, content) {
  3434. return Element.insert(element, {before:content});
  3435. },
  3436. Top: function(element, content) {
  3437. return Element.insert(element, {top:content});
  3438. },
  3439. Bottom: function(element, content) {
  3440. return Element.insert(element, {bottom:content});
  3441. },
  3442. After: function(element, content) {
  3443. return Element.insert(element, {after:content});
  3444. }
  3445. };
  3446. var $continue = new Error('"throw $continue" is deprecated, use "return" instead');
  3447. // This should be moved to script.aculo.us; notice the deprecated methods
  3448. // further below, that map to the newer Element methods.
  3449. var Position = {
  3450. // set to true if needed, warning: firefox performance problems
  3451. // NOT neeeded for page scrolling, only if draggable contained in
  3452. // scrollable elements
  3453. includeScrollOffsets: false,
  3454. // must be called before calling withinIncludingScrolloffset, every time the
  3455. // page is scrolled
  3456. prepare: function() {
  3457. this.deltaX = window.pageXOffset
  3458. || document.documentElement.scrollLeft
  3459. || document.body.scrollLeft
  3460. || 0;
  3461. this.deltaY = window.pageYOffset
  3462. || document.documentElement.scrollTop
  3463. || document.body.scrollTop
  3464. || 0;
  3465. },
  3466. // caches x/y coordinate pair to use with overlap
  3467. within: function(element, x, y) {
  3468. if (this.includeScrollOffsets)
  3469. return this.withinIncludingScrolloffsets(element, x, y);
  3470. this.xcomp = x;
  3471. this.ycomp = y;
  3472. this.offset = Element.cumulativeOffset(element);
  3473. return (y >= this.offset[1] &&
  3474. y < this.offset[1] + element.offsetHeight &&
  3475. x >= this.offset[0] &&
  3476. x < this.offset[0] + element.offsetWidth);
  3477. },
  3478. withinIncludingScrolloffsets: function(element, x, y) {
  3479. var offsetcache = Element.cumulativeScrollOffset(element);
  3480. this.xcomp = x + offsetcache[0] - this.deltaX;
  3481. this.ycomp = y + offsetcache[1] - this.deltaY;
  3482. this.offset = Element.cumulativeOffset(element);
  3483. return (this.ycomp >= this.offset[1] &&
  3484. this.ycomp < this.offset[1] + element.offsetHeight &&
  3485. this.xcomp >= this.offset[0] &&
  3486. this.xcomp < this.offset[0] + element.offsetWidth);
  3487. },
  3488. // within must be called directly before
  3489. overlap: function(mode, element) {
  3490. if (!mode) return 0;
  3491. if (mode == 'vertical')
  3492. return ((this.offset[1] + element.offsetHeight) - this.ycomp) /
  3493. element.offsetHeight;
  3494. if (mode == 'horizontal')
  3495. return ((this.offset[0] + element.offsetWidth) - this.xcomp) /
  3496. element.offsetWidth;
  3497. },
  3498. // Deprecation layer -- use newer Element methods now (1.5.2).
  3499. cumulativeOffset: Element.Methods.cumulativeOffset,
  3500. positionedOffset: Element.Methods.positionedOffset,
  3501. absolutize: function(element) {
  3502. Position.prepare();
  3503. return Element.absolutize(element);
  3504. },
  3505. relativize: function(element) {
  3506. Position.prepare();
  3507. return Element.relativize(element);
  3508. },
  3509. realOffset: Element.Methods.cumulativeScrollOffset,
  3510. offsetParent: Element.Methods.getOffsetParent,
  3511. page: Element.Methods.viewportOffset,
  3512. clone: function(source, target, options) {
  3513. options = options || { };
  3514. return Element.clonePosition(target, source, options);
  3515. }
  3516. };
  3517. /*--------------------------------------------------------------------------*/
  3518. if (!document.getElementsByClassName) document.getElementsByClassName = function(instanceMethods){
  3519. function iter(name) {
  3520. return name.blank() ? null : "[contains(concat(' ', @class, ' '), ' " + name + " ')]";
  3521. }
  3522. instanceMethods.getElementsByClassName = Prototype.BrowserFeatures.XPath ?
  3523. function(element, className) {
  3524. className = className.toString().strip();
  3525. var cond = /\s/.test(className) ? $w(className).map(iter).join('') : iter(className);
  3526. return cond ? document._getElementsByXPath('.//*' + cond, element) : [];
  3527. } : function(element, className) {
  3528. className = className.toString().strip();
  3529. var elements = [], classNames = (/\s/.test(className) ? $w(className) : null);
  3530. if (!classNames && !className) return elements;
  3531. var nodes = $(element).getElementsByTagName('*');
  3532. className = ' ' + className + ' ';
  3533. for (var i = 0, child, cn; child = nodes[i]; i++) {
  3534. if (child.className && (cn = ' ' + child.className + ' ') && (cn.include(className) ||
  3535. (classNames && classNames.all(function(name) {
  3536. return !name.toString().blank() && cn.include(' ' + name + ' ');
  3537. }))))
  3538. elements.push(Element.extend(child));
  3539. }
  3540. return elements;
  3541. };
  3542. return function(className, parentElement) {
  3543. return $(parentElement || document.body).getElementsByClassName(className);
  3544. };
  3545. }(Element.Methods);
  3546. /*--------------------------------------------------------------------------*/
  3547. Element.ClassNames = Class.create();
  3548. Element.ClassNames.prototype = {
  3549. initialize: function(element) {
  3550. this.element = $(element);
  3551. },
  3552. _each: function(iterator) {
  3553. this.element.className.split(/\s+/).select(function(name) {
  3554. return name.length > 0;
  3555. })._each(iterator);
  3556. },
  3557. set: function(className) {
  3558. this.element.className = className;
  3559. },
  3560. add: function(classNameToAdd) {
  3561. if (this.include(classNameToAdd)) return;
  3562. this.set($A(this).concat(classNameToAdd).join(' '));
  3563. },
  3564. remove: function(classNameToRemove) {
  3565. if (!this.include(classNameToRemove)) return;
  3566. this.set($A(this).without(classNameToRemove).join(' '));
  3567. },
  3568. toString: function() {
  3569. return $A(this).join(' ');
  3570. }
  3571. };
  3572. Object.extend(Element.ClassNames.prototype, Enumerable);
  3573. /*--------------------------------------------------------------------------*/
  3574. Element.addMethods();