datasource-debug.js 105 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068
  1. /*
  2. Copyright (c) 2009, Yahoo! Inc. All rights reserved.
  3. Code licensed under the BSD License:
  4. http://developer.yahoo.net/yui/license.txt
  5. version: 2.8.0r4
  6. */
  7. (function () {
  8. var lang = YAHOO.lang,
  9. util = YAHOO.util,
  10. Ev = util.Event;
  11. /**
  12. * The DataSource utility provides a common configurable interface for widgets to
  13. * access a variety of data, from JavaScript arrays to online database servers.
  14. *
  15. * @module datasource
  16. * @requires yahoo, event
  17. * @optional json, get, connection
  18. * @title DataSource Utility
  19. */
  20. /****************************************************************************/
  21. /****************************************************************************/
  22. /****************************************************************************/
  23. /**
  24. * Base class for the YUI DataSource utility.
  25. *
  26. * @namespace YAHOO.util
  27. * @class YAHOO.util.DataSourceBase
  28. * @constructor
  29. * @param oLiveData {HTMLElement} Pointer to live data.
  30. * @param oConfigs {object} (optional) Object literal of configuration values.
  31. */
  32. util.DataSourceBase = function(oLiveData, oConfigs) {
  33. if(oLiveData === null || oLiveData === undefined) {
  34. YAHOO.log("Could not instantiate DataSource due to invalid live database",
  35. "error", this.toString());
  36. return;
  37. }
  38. this.liveData = oLiveData;
  39. this._oQueue = {interval:null, conn:null, requests:[]};
  40. this.responseSchema = {};
  41. // Set any config params passed in to override defaults
  42. if(oConfigs && (oConfigs.constructor == Object)) {
  43. for(var sConfig in oConfigs) {
  44. if(sConfig) {
  45. this[sConfig] = oConfigs[sConfig];
  46. }
  47. }
  48. }
  49. // Validate and initialize public configs
  50. var maxCacheEntries = this.maxCacheEntries;
  51. if(!lang.isNumber(maxCacheEntries) || (maxCacheEntries < 0)) {
  52. maxCacheEntries = 0;
  53. }
  54. // Initialize interval tracker
  55. this._aIntervals = [];
  56. /////////////////////////////////////////////////////////////////////////////
  57. //
  58. // Custom Events
  59. //
  60. /////////////////////////////////////////////////////////////////////////////
  61. /**
  62. * Fired when a request is made to the local cache.
  63. *
  64. * @event cacheRequestEvent
  65. * @param oArgs.request {Object} The request object.
  66. * @param oArgs.callback {Object} The callback object.
  67. * @param oArgs.caller {Object} (deprecated) Use callback.scope.
  68. */
  69. this.createEvent("cacheRequestEvent");
  70. /**
  71. * Fired when data is retrieved from the local cache.
  72. *
  73. * @event cacheResponseEvent
  74. * @param oArgs.request {Object} The request object.
  75. * @param oArgs.response {Object} The response object.
  76. * @param oArgs.callback {Object} The callback object.
  77. * @param oArgs.caller {Object} (deprecated) Use callback.scope.
  78. */
  79. this.createEvent("cacheResponseEvent");
  80. /**
  81. * Fired when a request is sent to the live data source.
  82. *
  83. * @event requestEvent
  84. * @param oArgs.request {Object} The request object.
  85. * @param oArgs.callback {Object} The callback object.
  86. * @param oArgs.tId {Number} Transaction ID.
  87. * @param oArgs.caller {Object} (deprecated) Use callback.scope.
  88. */
  89. this.createEvent("requestEvent");
  90. /**
  91. * Fired when live data source sends response.
  92. *
  93. * @event responseEvent
  94. * @param oArgs.request {Object} The request object.
  95. * @param oArgs.response {Object} The raw response object.
  96. * @param oArgs.callback {Object} The callback object.
  97. * @param oArgs.tId {Number} Transaction ID.
  98. * @param oArgs.caller {Object} (deprecated) Use callback.scope.
  99. */
  100. this.createEvent("responseEvent");
  101. /**
  102. * Fired when response is parsed.
  103. *
  104. * @event responseParseEvent
  105. * @param oArgs.request {Object} The request object.
  106. * @param oArgs.response {Object} The parsed response object.
  107. * @param oArgs.callback {Object} The callback object.
  108. * @param oArgs.caller {Object} (deprecated) Use callback.scope.
  109. */
  110. this.createEvent("responseParseEvent");
  111. /**
  112. * Fired when response is cached.
  113. *
  114. * @event responseCacheEvent
  115. * @param oArgs.request {Object} The request object.
  116. * @param oArgs.response {Object} The parsed response object.
  117. * @param oArgs.callback {Object} The callback object.
  118. * @param oArgs.caller {Object} (deprecated) Use callback.scope.
  119. */
  120. this.createEvent("responseCacheEvent");
  121. /**
  122. * Fired when an error is encountered with the live data source.
  123. *
  124. * @event dataErrorEvent
  125. * @param oArgs.request {Object} The request object.
  126. * @param oArgs.response {String} The response object (if available).
  127. * @param oArgs.callback {Object} The callback object.
  128. * @param oArgs.caller {Object} (deprecated) Use callback.scope.
  129. * @param oArgs.message {String} The error message.
  130. */
  131. this.createEvent("dataErrorEvent");
  132. /**
  133. * Fired when the local cache is flushed.
  134. *
  135. * @event cacheFlushEvent
  136. */
  137. this.createEvent("cacheFlushEvent");
  138. var DS = util.DataSourceBase;
  139. this._sName = "DataSource instance" + DS._nIndex;
  140. DS._nIndex++;
  141. YAHOO.log("DataSource initialized", "info", this.toString());
  142. };
  143. var DS = util.DataSourceBase;
  144. lang.augmentObject(DS, {
  145. /////////////////////////////////////////////////////////////////////////////
  146. //
  147. // DataSourceBase public constants
  148. //
  149. /////////////////////////////////////////////////////////////////////////////
  150. /**
  151. * Type is unknown.
  152. *
  153. * @property TYPE_UNKNOWN
  154. * @type Number
  155. * @final
  156. * @default -1
  157. */
  158. TYPE_UNKNOWN : -1,
  159. /**
  160. * Type is a JavaScript Array.
  161. *
  162. * @property TYPE_JSARRAY
  163. * @type Number
  164. * @final
  165. * @default 0
  166. */
  167. TYPE_JSARRAY : 0,
  168. /**
  169. * Type is a JavaScript Function.
  170. *
  171. * @property TYPE_JSFUNCTION
  172. * @type Number
  173. * @final
  174. * @default 1
  175. */
  176. TYPE_JSFUNCTION : 1,
  177. /**
  178. * Type is hosted on a server via an XHR connection.
  179. *
  180. * @property TYPE_XHR
  181. * @type Number
  182. * @final
  183. * @default 2
  184. */
  185. TYPE_XHR : 2,
  186. /**
  187. * Type is JSON.
  188. *
  189. * @property TYPE_JSON
  190. * @type Number
  191. * @final
  192. * @default 3
  193. */
  194. TYPE_JSON : 3,
  195. /**
  196. * Type is XML.
  197. *
  198. * @property TYPE_XML
  199. * @type Number
  200. * @final
  201. * @default 4
  202. */
  203. TYPE_XML : 4,
  204. /**
  205. * Type is plain text.
  206. *
  207. * @property TYPE_TEXT
  208. * @type Number
  209. * @final
  210. * @default 5
  211. */
  212. TYPE_TEXT : 5,
  213. /**
  214. * Type is an HTML TABLE element. Data is parsed out of TR elements from all TBODY elements.
  215. *
  216. * @property TYPE_HTMLTABLE
  217. * @type Number
  218. * @final
  219. * @default 6
  220. */
  221. TYPE_HTMLTABLE : 6,
  222. /**
  223. * Type is hosted on a server via a dynamic script node.
  224. *
  225. * @property TYPE_SCRIPTNODE
  226. * @type Number
  227. * @final
  228. * @default 7
  229. */
  230. TYPE_SCRIPTNODE : 7,
  231. /**
  232. * Type is local.
  233. *
  234. * @property TYPE_LOCAL
  235. * @type Number
  236. * @final
  237. * @default 8
  238. */
  239. TYPE_LOCAL : 8,
  240. /**
  241. * Error message for invalid dataresponses.
  242. *
  243. * @property ERROR_DATAINVALID
  244. * @type String
  245. * @final
  246. * @default "Invalid data"
  247. */
  248. ERROR_DATAINVALID : "Invalid data",
  249. /**
  250. * Error message for null data responses.
  251. *
  252. * @property ERROR_DATANULL
  253. * @type String
  254. * @final
  255. * @default "Null data"
  256. */
  257. ERROR_DATANULL : "Null data",
  258. /////////////////////////////////////////////////////////////////////////////
  259. //
  260. // DataSourceBase private static properties
  261. //
  262. /////////////////////////////////////////////////////////////////////////////
  263. /**
  264. * Internal class variable to index multiple DataSource instances.
  265. *
  266. * @property DataSourceBase._nIndex
  267. * @type Number
  268. * @private
  269. * @static
  270. */
  271. _nIndex : 0,
  272. /**
  273. * Internal class variable to assign unique transaction IDs.
  274. *
  275. * @property DataSourceBase._nTransactionId
  276. * @type Number
  277. * @private
  278. * @static
  279. */
  280. _nTransactionId : 0,
  281. /////////////////////////////////////////////////////////////////////////////
  282. //
  283. // DataSourceBase private static methods
  284. //
  285. /////////////////////////////////////////////////////////////////////////////
  286. /**
  287. * Get an XPath-specified value for a given field from an XML node or document.
  288. *
  289. * @method _getLocationValue
  290. * @param field {String | Object} Field definition.
  291. * @param context {Object} XML node or document to search within.
  292. * @return {Object} Data value or null.
  293. * @static
  294. * @private
  295. */
  296. _getLocationValue: function(field, context) {
  297. var locator = field.locator || field.key || field,
  298. xmldoc = context.ownerDocument || context,
  299. result, res, value = null;
  300. try {
  301. // Standards mode
  302. if(!lang.isUndefined(xmldoc.evaluate)) {
  303. result = xmldoc.evaluate(locator, context, xmldoc.createNSResolver(!context.ownerDocument ? context.documentElement : context.ownerDocument.documentElement), 0, null);
  304. while(res = result.iterateNext()) {
  305. value = res.textContent;
  306. }
  307. }
  308. // IE mode
  309. else {
  310. xmldoc.setProperty("SelectionLanguage", "XPath");
  311. result = context.selectNodes(locator)[0];
  312. value = result.value || result.text || null;
  313. }
  314. return value;
  315. }
  316. catch(e) {
  317. }
  318. },
  319. /////////////////////////////////////////////////////////////////////////////
  320. //
  321. // DataSourceBase public static methods
  322. //
  323. /////////////////////////////////////////////////////////////////////////////
  324. /**
  325. * Executes a configured callback. For object literal callbacks, the third
  326. * param determines whether to execute the success handler or failure handler.
  327. *
  328. * @method issueCallback
  329. * @param callback {Function|Object} the callback to execute
  330. * @param params {Array} params to be passed to the callback method
  331. * @param error {Boolean} whether an error occurred
  332. * @param scope {Object} the scope from which to execute the callback
  333. * (deprecated - use an object literal callback)
  334. * @static
  335. */
  336. issueCallback : function (callback,params,error,scope) {
  337. if (lang.isFunction(callback)) {
  338. callback.apply(scope, params);
  339. } else if (lang.isObject(callback)) {
  340. scope = callback.scope || scope || window;
  341. var callbackFunc = callback.success;
  342. if (error) {
  343. callbackFunc = callback.failure;
  344. }
  345. if (callbackFunc) {
  346. callbackFunc.apply(scope, params.concat([callback.argument]));
  347. }
  348. }
  349. },
  350. /**
  351. * Converts data to type String.
  352. *
  353. * @method DataSourceBase.parseString
  354. * @param oData {String | Number | Boolean | Date | Array | Object} Data to parse.
  355. * The special values null and undefined will return null.
  356. * @return {String} A string, or null.
  357. * @static
  358. */
  359. parseString : function(oData) {
  360. // Special case null and undefined
  361. if(!lang.isValue(oData)) {
  362. return null;
  363. }
  364. //Convert to string
  365. var string = oData + "";
  366. // Validate
  367. if(lang.isString(string)) {
  368. return string;
  369. }
  370. else {
  371. YAHOO.log("Could not convert data " + lang.dump(oData) + " to type String", "warn", this.toString());
  372. return null;
  373. }
  374. },
  375. /**
  376. * Converts data to type Number.
  377. *
  378. * @method DataSourceBase.parseNumber
  379. * @param oData {String | Number | Boolean} Data to convert. Note, the following
  380. * values return as null: null, undefined, NaN, "".
  381. * @return {Number} A number, or null.
  382. * @static
  383. */
  384. parseNumber : function(oData) {
  385. if(!lang.isValue(oData) || (oData === "")) {
  386. return null;
  387. }
  388. //Convert to number
  389. var number = oData * 1;
  390. // Validate
  391. if(lang.isNumber(number)) {
  392. return number;
  393. }
  394. else {
  395. YAHOO.log("Could not convert data " + lang.dump(oData) + " to type Number", "warn", this.toString());
  396. return null;
  397. }
  398. },
  399. // Backward compatibility
  400. convertNumber : function(oData) {
  401. YAHOO.log("The method YAHOO.util.DataSourceBase.convertNumber() has been" +
  402. " deprecated in favor of YAHOO.util.DataSourceBase.parseNumber()", "warn",
  403. this.toString());
  404. return DS.parseNumber(oData);
  405. },
  406. /**
  407. * Converts data to type Date.
  408. *
  409. * @method DataSourceBase.parseDate
  410. * @param oData {Date | String | Number} Data to convert.
  411. * @return {Date} A Date instance.
  412. * @static
  413. */
  414. parseDate : function(oData) {
  415. var date = null;
  416. //Convert to date
  417. if(!(oData instanceof Date)) {
  418. date = new Date(oData);
  419. }
  420. else {
  421. return oData;
  422. }
  423. // Validate
  424. if(date instanceof Date) {
  425. return date;
  426. }
  427. else {
  428. YAHOO.log("Could not convert data " + lang.dump(oData) + " to type Date", "warn", this.toString());
  429. return null;
  430. }
  431. },
  432. // Backward compatibility
  433. convertDate : function(oData) {
  434. YAHOO.log("The method YAHOO.util.DataSourceBase.convertDate() has been" +
  435. " deprecated in favor of YAHOO.util.DataSourceBase.parseDate()", "warn",
  436. this.toString());
  437. return DS.parseDate(oData);
  438. }
  439. });
  440. // Done in separate step so referenced functions are defined.
  441. /**
  442. * Data parsing functions.
  443. * @property DataSource.Parser
  444. * @type Object
  445. * @static
  446. */
  447. DS.Parser = {
  448. string : DS.parseString,
  449. number : DS.parseNumber,
  450. date : DS.parseDate
  451. };
  452. // Prototype properties and methods
  453. DS.prototype = {
  454. /////////////////////////////////////////////////////////////////////////////
  455. //
  456. // DataSourceBase private properties
  457. //
  458. /////////////////////////////////////////////////////////////////////////////
  459. /**
  460. * Name of DataSource instance.
  461. *
  462. * @property _sName
  463. * @type String
  464. * @private
  465. */
  466. _sName : null,
  467. /**
  468. * Local cache of data result object literals indexed chronologically.
  469. *
  470. * @property _aCache
  471. * @type Object[]
  472. * @private
  473. */
  474. _aCache : null,
  475. /**
  476. * Local queue of request connections, enabled if queue needs to be managed.
  477. *
  478. * @property _oQueue
  479. * @type Object
  480. * @private
  481. */
  482. _oQueue : null,
  483. /**
  484. * Array of polling interval IDs that have been enabled, needed to clear all intervals.
  485. *
  486. * @property _aIntervals
  487. * @type Array
  488. * @private
  489. */
  490. _aIntervals : null,
  491. /////////////////////////////////////////////////////////////////////////////
  492. //
  493. // DataSourceBase public properties
  494. //
  495. /////////////////////////////////////////////////////////////////////////////
  496. /**
  497. * Max size of the local cache. Set to 0 to turn off caching. Caching is
  498. * useful to reduce the number of server connections. Recommended only for data
  499. * sources that return comprehensive results for queries or when stale data is
  500. * not an issue.
  501. *
  502. * @property maxCacheEntries
  503. * @type Number
  504. * @default 0
  505. */
  506. maxCacheEntries : 0,
  507. /**
  508. * Pointer to live database.
  509. *
  510. * @property liveData
  511. * @type Object
  512. */
  513. liveData : null,
  514. /**
  515. * Where the live data is held:
  516. *
  517. * <dl>
  518. * <dt>TYPE_UNKNOWN</dt>
  519. * <dt>TYPE_LOCAL</dt>
  520. * <dt>TYPE_XHR</dt>
  521. * <dt>TYPE_SCRIPTNODE</dt>
  522. * <dt>TYPE_JSFUNCTION</dt>
  523. * </dl>
  524. *
  525. * @property dataType
  526. * @type Number
  527. * @default YAHOO.util.DataSourceBase.TYPE_UNKNOWN
  528. *
  529. */
  530. dataType : DS.TYPE_UNKNOWN,
  531. /**
  532. * Format of response:
  533. *
  534. * <dl>
  535. * <dt>TYPE_UNKNOWN</dt>
  536. * <dt>TYPE_JSARRAY</dt>
  537. * <dt>TYPE_JSON</dt>
  538. * <dt>TYPE_XML</dt>
  539. * <dt>TYPE_TEXT</dt>
  540. * <dt>TYPE_HTMLTABLE</dt>
  541. * </dl>
  542. *
  543. * @property responseType
  544. * @type Number
  545. * @default YAHOO.util.DataSourceBase.TYPE_UNKNOWN
  546. */
  547. responseType : DS.TYPE_UNKNOWN,
  548. /**
  549. * Response schema object literal takes a combination of the following properties:
  550. *
  551. * <dl>
  552. * <dt>resultsList</dt> <dd>Pointer to array of tabular data</dd>
  553. * <dt>resultNode</dt> <dd>Pointer to node name of row data (XML data only)</dd>
  554. * <dt>recordDelim</dt> <dd>Record delimiter (text data only)</dd>
  555. * <dt>fieldDelim</dt> <dd>Field delimiter (text data only)</dd>
  556. * <dt>fields</dt> <dd>Array of field names (aka keys), or array of object literals
  557. * such as: {key:"fieldname",parser:YAHOO.util.DataSourceBase.parseDate}</dd>
  558. * <dt>metaFields</dt> <dd>Object literal of keys to include in the oParsedResponse.meta collection</dd>
  559. * <dt>metaNode</dt> <dd>Name of the node under which to search for meta information in XML response data</dd>
  560. * </dl>
  561. *
  562. * @property responseSchema
  563. * @type Object
  564. */
  565. responseSchema : null,
  566. /**
  567. * Additional arguments passed to the JSON parse routine. The JSON string
  568. * is the assumed first argument (where applicable). This property is not
  569. * set by default, but the parse methods will use it if present.
  570. *
  571. * @property parseJSONArgs
  572. * @type {MIXED|Array} If an Array, contents are used as individual arguments.
  573. * Otherwise, value is used as an additional argument.
  574. */
  575. // property intentionally undefined
  576. /**
  577. * When working with XML data, setting this property to true enables support for
  578. * XPath-syntaxed locators in schema definitions.
  579. *
  580. * @property useXPath
  581. * @type Boolean
  582. * @default false
  583. */
  584. useXPath : false,
  585. /////////////////////////////////////////////////////////////////////////////
  586. //
  587. // DataSourceBase public methods
  588. //
  589. /////////////////////////////////////////////////////////////////////////////
  590. /**
  591. * Public accessor to the unique name of the DataSource instance.
  592. *
  593. * @method toString
  594. * @return {String} Unique name of the DataSource instance.
  595. */
  596. toString : function() {
  597. return this._sName;
  598. },
  599. /**
  600. * Overridable method passes request to cache and returns cached response if any,
  601. * refreshing the hit in the cache as the newest item. Returns null if there is
  602. * no cache hit.
  603. *
  604. * @method getCachedResponse
  605. * @param oRequest {Object} Request object.
  606. * @param oCallback {Object} Callback object.
  607. * @param oCaller {Object} (deprecated) Use callback object.
  608. * @return {Object} Cached response object or null.
  609. */
  610. getCachedResponse : function(oRequest, oCallback, oCaller) {
  611. var aCache = this._aCache;
  612. // If cache is enabled...
  613. if(this.maxCacheEntries > 0) {
  614. // Initialize local cache
  615. if(!aCache) {
  616. this._aCache = [];
  617. YAHOO.log("Cache initialized", "info", this.toString());
  618. }
  619. // Look in local cache
  620. else {
  621. var nCacheLength = aCache.length;
  622. if(nCacheLength > 0) {
  623. var oResponse = null;
  624. this.fireEvent("cacheRequestEvent", {request:oRequest,callback:oCallback,caller:oCaller});
  625. // Loop through each cached element
  626. for(var i = nCacheLength-1; i >= 0; i--) {
  627. var oCacheElem = aCache[i];
  628. // Defer cache hit logic to a public overridable method
  629. if(this.isCacheHit(oRequest,oCacheElem.request)) {
  630. // The cache returned a hit!
  631. // Grab the cached response
  632. oResponse = oCacheElem.response;
  633. this.fireEvent("cacheResponseEvent", {request:oRequest,response:oResponse,callback:oCallback,caller:oCaller});
  634. // Refresh the position of the cache hit
  635. if(i < nCacheLength-1) {
  636. // Remove element from its original location
  637. aCache.splice(i,1);
  638. // Add as newest
  639. this.addToCache(oRequest, oResponse);
  640. YAHOO.log("Refreshed cache position of the response for \"" + oRequest + "\"", "info", this.toString());
  641. }
  642. // Add a cache flag
  643. oResponse.cached = true;
  644. break;
  645. }
  646. }
  647. YAHOO.log("The cached response for \"" + lang.dump(oRequest) +
  648. "\" is " + lang.dump(oResponse), "info", this.toString());
  649. return oResponse;
  650. }
  651. }
  652. }
  653. else if(aCache) {
  654. this._aCache = null;
  655. YAHOO.log("Cache destroyed", "info", this.toString());
  656. }
  657. return null;
  658. },
  659. /**
  660. * Default overridable method matches given request to given cached request.
  661. * Returns true if is a hit, returns false otherwise. Implementers should
  662. * override this method to customize the cache-matching algorithm.
  663. *
  664. * @method isCacheHit
  665. * @param oRequest {Object} Request object.
  666. * @param oCachedRequest {Object} Cached request object.
  667. * @return {Boolean} True if given request matches cached request, false otherwise.
  668. */
  669. isCacheHit : function(oRequest, oCachedRequest) {
  670. return (oRequest === oCachedRequest);
  671. },
  672. /**
  673. * Adds a new item to the cache. If cache is full, evicts the stalest item
  674. * before adding the new item.
  675. *
  676. * @method addToCache
  677. * @param oRequest {Object} Request object.
  678. * @param oResponse {Object} Response object to cache.
  679. */
  680. addToCache : function(oRequest, oResponse) {
  681. var aCache = this._aCache;
  682. if(!aCache) {
  683. return;
  684. }
  685. // If the cache is full, make room by removing stalest element (index=0)
  686. while(aCache.length >= this.maxCacheEntries) {
  687. aCache.shift();
  688. }
  689. // Add to cache in the newest position, at the end of the array
  690. var oCacheElem = {request:oRequest,response:oResponse};
  691. aCache[aCache.length] = oCacheElem;
  692. this.fireEvent("responseCacheEvent", {request:oRequest,response:oResponse});
  693. YAHOO.log("Cached the response for \"" + oRequest + "\"", "info", this.toString());
  694. },
  695. /**
  696. * Flushes cache.
  697. *
  698. * @method flushCache
  699. */
  700. flushCache : function() {
  701. if(this._aCache) {
  702. this._aCache = [];
  703. this.fireEvent("cacheFlushEvent");
  704. YAHOO.log("Flushed the cache", "info", this.toString());
  705. }
  706. },
  707. /**
  708. * Sets up a polling mechanism to send requests at set intervals and forward
  709. * responses to given callback.
  710. *
  711. * @method setInterval
  712. * @param nMsec {Number} Length of interval in milliseconds.
  713. * @param oRequest {Object} Request object.
  714. * @param oCallback {Function} Handler function to receive the response.
  715. * @param oCaller {Object} (deprecated) Use oCallback.scope.
  716. * @return {Number} Interval ID.
  717. */
  718. setInterval : function(nMsec, oRequest, oCallback, oCaller) {
  719. if(lang.isNumber(nMsec) && (nMsec >= 0)) {
  720. YAHOO.log("Enabling polling to live data for \"" + oRequest + "\" at interval " + nMsec, "info", this.toString());
  721. var oSelf = this;
  722. var nId = setInterval(function() {
  723. oSelf.makeConnection(oRequest, oCallback, oCaller);
  724. }, nMsec);
  725. this._aIntervals.push(nId);
  726. return nId;
  727. }
  728. else {
  729. YAHOO.log("Could not enable polling to live data for \"" + oRequest + "\" at interval " + nMsec, "info", this.toString());
  730. }
  731. },
  732. /**
  733. * Disables polling mechanism associated with the given interval ID.
  734. *
  735. * @method clearInterval
  736. * @param nId {Number} Interval ID.
  737. */
  738. clearInterval : function(nId) {
  739. // Remove from tracker if there
  740. var tracker = this._aIntervals || [];
  741. for(var i=tracker.length-1; i>-1; i--) {
  742. if(tracker[i] === nId) {
  743. tracker.splice(i,1);
  744. clearInterval(nId);
  745. }
  746. }
  747. },
  748. /**
  749. * Disables all known polling intervals.
  750. *
  751. * @method clearAllIntervals
  752. */
  753. clearAllIntervals : function() {
  754. var tracker = this._aIntervals || [];
  755. for(var i=tracker.length-1; i>-1; i--) {
  756. clearInterval(tracker[i]);
  757. }
  758. tracker = [];
  759. },
  760. /**
  761. * First looks for cached response, then sends request to live data. The
  762. * following arguments are passed to the callback function:
  763. * <dl>
  764. * <dt><code>oRequest</code></dt>
  765. * <dd>The same value that was passed in as the first argument to sendRequest.</dd>
  766. * <dt><code>oParsedResponse</code></dt>
  767. * <dd>An object literal containing the following properties:
  768. * <dl>
  769. * <dt><code>tId</code></dt>
  770. * <dd>Unique transaction ID number.</dd>
  771. * <dt><code>results</code></dt>
  772. * <dd>Schema-parsed data results.</dd>
  773. * <dt><code>error</code></dt>
  774. * <dd>True in cases of data error.</dd>
  775. * <dt><code>cached</code></dt>
  776. * <dd>True when response is returned from DataSource cache.</dd>
  777. * <dt><code>meta</code></dt>
  778. * <dd>Schema-parsed meta data.</dd>
  779. * </dl>
  780. * <dt><code>oPayload</code></dt>
  781. * <dd>The same value as was passed in as <code>argument</code> in the oCallback object literal.</dd>
  782. * </dl>
  783. *
  784. * @method sendRequest
  785. * @param oRequest {Object} Request object.
  786. * @param oCallback {Object} An object literal with the following properties:
  787. * <dl>
  788. * <dt><code>success</code></dt>
  789. * <dd>The function to call when the data is ready.</dd>
  790. * <dt><code>failure</code></dt>
  791. * <dd>The function to call upon a response failure condition.</dd>
  792. * <dt><code>scope</code></dt>
  793. * <dd>The object to serve as the scope for the success and failure handlers.</dd>
  794. * <dt><code>argument</code></dt>
  795. * <dd>Arbitrary data that will be passed back to the success and failure handlers.</dd>
  796. * </dl>
  797. * @param oCaller {Object} (deprecated) Use oCallback.scope.
  798. * @return {Number} Transaction ID, or null if response found in cache.
  799. */
  800. sendRequest : function(oRequest, oCallback, oCaller) {
  801. // First look in cache
  802. var oCachedResponse = this.getCachedResponse(oRequest, oCallback, oCaller);
  803. if(oCachedResponse) {
  804. DS.issueCallback(oCallback,[oRequest,oCachedResponse],false,oCaller);
  805. return null;
  806. }
  807. // Not in cache, so forward request to live data
  808. YAHOO.log("Making connection to live data for \"" + oRequest + "\"", "info", this.toString());
  809. return this.makeConnection(oRequest, oCallback, oCaller);
  810. },
  811. /**
  812. * Overridable default method generates a unique transaction ID and passes
  813. * the live data reference directly to the handleResponse function. This
  814. * method should be implemented by subclasses to achieve more complex behavior
  815. * or to access remote data.
  816. *
  817. * @method makeConnection
  818. * @param oRequest {Object} Request object.
  819. * @param oCallback {Object} Callback object literal.
  820. * @param oCaller {Object} (deprecated) Use oCallback.scope.
  821. * @return {Number} Transaction ID.
  822. */
  823. makeConnection : function(oRequest, oCallback, oCaller) {
  824. var tId = DS._nTransactionId++;
  825. this.fireEvent("requestEvent", {tId:tId, request:oRequest,callback:oCallback,caller:oCaller});
  826. /* accounts for the following cases:
  827. YAHOO.util.DataSourceBase.TYPE_UNKNOWN
  828. YAHOO.util.DataSourceBase.TYPE_JSARRAY
  829. YAHOO.util.DataSourceBase.TYPE_JSON
  830. YAHOO.util.DataSourceBase.TYPE_HTMLTABLE
  831. YAHOO.util.DataSourceBase.TYPE_XML
  832. YAHOO.util.DataSourceBase.TYPE_TEXT
  833. */
  834. var oRawResponse = this.liveData;
  835. this.handleResponse(oRequest, oRawResponse, oCallback, oCaller, tId);
  836. return tId;
  837. },
  838. /**
  839. * Receives raw data response and type converts to XML, JSON, etc as necessary.
  840. * Forwards oFullResponse to appropriate parsing function to get turned into
  841. * oParsedResponse. Calls doBeforeCallback() and adds oParsedResponse to
  842. * the cache when appropriate before calling issueCallback().
  843. *
  844. * The oParsedResponse object literal has the following properties:
  845. * <dl>
  846. * <dd><dt>tId {Number}</dt> Unique transaction ID</dd>
  847. * <dd><dt>results {Array}</dt> Array of parsed data results</dd>
  848. * <dd><dt>meta {Object}</dt> Object literal of meta values</dd>
  849. * <dd><dt>error {Boolean}</dt> (optional) True if there was an error</dd>
  850. * <dd><dt>cached {Boolean}</dt> (optional) True if response was cached</dd>
  851. * </dl>
  852. *
  853. * @method handleResponse
  854. * @param oRequest {Object} Request object
  855. * @param oRawResponse {Object} The raw response from the live database.
  856. * @param oCallback {Object} Callback object literal.
  857. * @param oCaller {Object} (deprecated) Use oCallback.scope.
  858. * @param tId {Number} Transaction ID.
  859. */
  860. handleResponse : function(oRequest, oRawResponse, oCallback, oCaller, tId) {
  861. this.fireEvent("responseEvent", {tId:tId, request:oRequest, response:oRawResponse,
  862. callback:oCallback, caller:oCaller});
  863. YAHOO.log("Received live data response for \"" + oRequest + "\"", "info", this.toString());
  864. var xhr = (this.dataType == DS.TYPE_XHR) ? true : false;
  865. var oParsedResponse = null;
  866. var oFullResponse = oRawResponse;
  867. // Try to sniff data type if it has not been defined
  868. if(this.responseType === DS.TYPE_UNKNOWN) {
  869. var ctype = (oRawResponse && oRawResponse.getResponseHeader) ? oRawResponse.getResponseHeader["Content-Type"] : null;
  870. if(ctype) {
  871. // xml
  872. if(ctype.indexOf("text/xml") > -1) {
  873. this.responseType = DS.TYPE_XML;
  874. }
  875. else if(ctype.indexOf("application/json") > -1) { // json
  876. this.responseType = DS.TYPE_JSON;
  877. }
  878. else if(ctype.indexOf("text/plain") > -1) { // text
  879. this.responseType = DS.TYPE_TEXT;
  880. }
  881. }
  882. else {
  883. if(YAHOO.lang.isArray(oRawResponse)) { // array
  884. this.responseType = DS.TYPE_JSARRAY;
  885. }
  886. // xml
  887. else if(oRawResponse && oRawResponse.nodeType && (oRawResponse.nodeType === 9 || oRawResponse.nodeType === 1 || oRawResponse.nodeType === 11)) {
  888. this.responseType = DS.TYPE_XML;
  889. }
  890. else if(oRawResponse && oRawResponse.nodeName && (oRawResponse.nodeName.toLowerCase() == "table")) { // table
  891. this.responseType = DS.TYPE_HTMLTABLE;
  892. }
  893. else if(YAHOO.lang.isObject(oRawResponse)) { // json
  894. this.responseType = DS.TYPE_JSON;
  895. }
  896. else if(YAHOO.lang.isString(oRawResponse)) { // text
  897. this.responseType = DS.TYPE_TEXT;
  898. }
  899. }
  900. }
  901. switch(this.responseType) {
  902. case DS.TYPE_JSARRAY:
  903. if(xhr && oRawResponse && oRawResponse.responseText) {
  904. oFullResponse = oRawResponse.responseText;
  905. }
  906. try {
  907. // Convert to JS array if it's a string
  908. if(lang.isString(oFullResponse)) {
  909. var parseArgs = [oFullResponse].concat(this.parseJSONArgs);
  910. // Check for YUI JSON Util
  911. if(lang.JSON) {
  912. oFullResponse = lang.JSON.parse.apply(lang.JSON,parseArgs);
  913. }
  914. // Look for JSON parsers using an API similar to json2.js
  915. else if(window.JSON && JSON.parse) {
  916. oFullResponse = JSON.parse.apply(JSON,parseArgs);
  917. }
  918. // Look for JSON parsers using an API similar to json.js
  919. else if(oFullResponse.parseJSON) {
  920. oFullResponse = oFullResponse.parseJSON.apply(oFullResponse,parseArgs.slice(1));
  921. }
  922. // No JSON lib found so parse the string
  923. else {
  924. // Trim leading spaces
  925. while (oFullResponse.length > 0 &&
  926. (oFullResponse.charAt(0) != "{") &&
  927. (oFullResponse.charAt(0) != "[")) {
  928. oFullResponse = oFullResponse.substring(1, oFullResponse.length);
  929. }
  930. if(oFullResponse.length > 0) {
  931. // Strip extraneous stuff at the end
  932. var arrayEnd =
  933. Math.max(oFullResponse.lastIndexOf("]"),oFullResponse.lastIndexOf("}"));
  934. oFullResponse = oFullResponse.substring(0,arrayEnd+1);
  935. // Turn the string into an object literal...
  936. // ...eval is necessary here
  937. oFullResponse = eval("(" + oFullResponse + ")");
  938. }
  939. }
  940. }
  941. }
  942. catch(e1) {
  943. }
  944. oFullResponse = this.doBeforeParseData(oRequest, oFullResponse, oCallback);
  945. oParsedResponse = this.parseArrayData(oRequest, oFullResponse);
  946. break;
  947. case DS.TYPE_JSON:
  948. if(xhr && oRawResponse && oRawResponse.responseText) {
  949. oFullResponse = oRawResponse.responseText;
  950. }
  951. try {
  952. // Convert to JSON object if it's a string
  953. if(lang.isString(oFullResponse)) {
  954. var parseArgs = [oFullResponse].concat(this.parseJSONArgs);
  955. // Check for YUI JSON Util
  956. if(lang.JSON) {
  957. oFullResponse = lang.JSON.parse.apply(lang.JSON,parseArgs);
  958. }
  959. // Look for JSON parsers using an API similar to json2.js
  960. else if(window.JSON && JSON.parse) {
  961. oFullResponse = JSON.parse.apply(JSON,parseArgs);
  962. }
  963. // Look for JSON parsers using an API similar to json.js
  964. else if(oFullResponse.parseJSON) {
  965. oFullResponse = oFullResponse.parseJSON.apply(oFullResponse,parseArgs.slice(1));
  966. }
  967. // No JSON lib found so parse the string
  968. else {
  969. // Trim leading spaces
  970. while (oFullResponse.length > 0 &&
  971. (oFullResponse.charAt(0) != "{") &&
  972. (oFullResponse.charAt(0) != "[")) {
  973. oFullResponse = oFullResponse.substring(1, oFullResponse.length);
  974. }
  975. if(oFullResponse.length > 0) {
  976. // Strip extraneous stuff at the end
  977. var objEnd = Math.max(oFullResponse.lastIndexOf("]"),oFullResponse.lastIndexOf("}"));
  978. oFullResponse = oFullResponse.substring(0,objEnd+1);
  979. // Turn the string into an object literal...
  980. // ...eval is necessary here
  981. oFullResponse = eval("(" + oFullResponse + ")");
  982. }
  983. }
  984. }
  985. }
  986. catch(e) {
  987. }
  988. oFullResponse = this.doBeforeParseData(oRequest, oFullResponse, oCallback);
  989. oParsedResponse = this.parseJSONData(oRequest, oFullResponse);
  990. break;
  991. case DS.TYPE_HTMLTABLE:
  992. if(xhr && oRawResponse.responseText) {
  993. var el = document.createElement('div');
  994. el.innerHTML = oRawResponse.responseText;
  995. oFullResponse = el.getElementsByTagName('table')[0];
  996. }
  997. oFullResponse = this.doBeforeParseData(oRequest, oFullResponse, oCallback);
  998. oParsedResponse = this.parseHTMLTableData(oRequest, oFullResponse);
  999. break;
  1000. case DS.TYPE_XML:
  1001. if(xhr && oRawResponse.responseXML) {
  1002. oFullResponse = oRawResponse.responseXML;
  1003. }
  1004. oFullResponse = this.doBeforeParseData(oRequest, oFullResponse, oCallback);
  1005. oParsedResponse = this.parseXMLData(oRequest, oFullResponse);
  1006. break;
  1007. case DS.TYPE_TEXT:
  1008. if(xhr && lang.isString(oRawResponse.responseText)) {
  1009. oFullResponse = oRawResponse.responseText;
  1010. }
  1011. oFullResponse = this.doBeforeParseData(oRequest, oFullResponse, oCallback);
  1012. oParsedResponse = this.parseTextData(oRequest, oFullResponse);
  1013. break;
  1014. default:
  1015. oFullResponse = this.doBeforeParseData(oRequest, oFullResponse, oCallback);
  1016. oParsedResponse = this.parseData(oRequest, oFullResponse);
  1017. break;
  1018. }
  1019. // Clean up for consistent signature
  1020. oParsedResponse = oParsedResponse || {};
  1021. if(!oParsedResponse.results) {
  1022. oParsedResponse.results = [];
  1023. }
  1024. if(!oParsedResponse.meta) {
  1025. oParsedResponse.meta = {};
  1026. }
  1027. // Success
  1028. if(!oParsedResponse.error) {
  1029. // Last chance to touch the raw response or the parsed response
  1030. oParsedResponse = this.doBeforeCallback(oRequest, oFullResponse, oParsedResponse, oCallback);
  1031. this.fireEvent("responseParseEvent", {request:oRequest,
  1032. response:oParsedResponse, callback:oCallback, caller:oCaller});
  1033. // Cache the response
  1034. this.addToCache(oRequest, oParsedResponse);
  1035. }
  1036. // Error
  1037. else {
  1038. // Be sure the error flag is on
  1039. oParsedResponse.error = true;
  1040. this.fireEvent("dataErrorEvent", {request:oRequest, response: oRawResponse, callback:oCallback,
  1041. caller:oCaller, message:DS.ERROR_DATANULL});
  1042. YAHOO.log(DS.ERROR_DATANULL, "error", this.toString());
  1043. }
  1044. // Send the response back to the caller
  1045. oParsedResponse.tId = tId;
  1046. DS.issueCallback(oCallback,[oRequest,oParsedResponse],oParsedResponse.error,oCaller);
  1047. },
  1048. /**
  1049. * Overridable method gives implementers access to the original full response
  1050. * before the data gets parsed. Implementers should take care not to return an
  1051. * unparsable or otherwise invalid response.
  1052. *
  1053. * @method doBeforeParseData
  1054. * @param oRequest {Object} Request object.
  1055. * @param oFullResponse {Object} The full response from the live database.
  1056. * @param oCallback {Object} The callback object.
  1057. * @return {Object} Full response for parsing.
  1058. */
  1059. doBeforeParseData : function(oRequest, oFullResponse, oCallback) {
  1060. return oFullResponse;
  1061. },
  1062. /**
  1063. * Overridable method gives implementers access to the original full response and
  1064. * the parsed response (parsed against the given schema) before the data
  1065. * is added to the cache (if applicable) and then sent back to callback function.
  1066. * This is your chance to access the raw response and/or populate the parsed
  1067. * response with any custom data.
  1068. *
  1069. * @method doBeforeCallback
  1070. * @param oRequest {Object} Request object.
  1071. * @param oFullResponse {Object} The full response from the live database.
  1072. * @param oParsedResponse {Object} The parsed response to return to calling object.
  1073. * @param oCallback {Object} The callback object.
  1074. * @return {Object} Parsed response object.
  1075. */
  1076. doBeforeCallback : function(oRequest, oFullResponse, oParsedResponse, oCallback) {
  1077. return oParsedResponse;
  1078. },
  1079. /**
  1080. * Overridable method parses data of generic RESPONSE_TYPE into a response object.
  1081. *
  1082. * @method parseData
  1083. * @param oRequest {Object} Request object.
  1084. * @param oFullResponse {Object} The full Array from the live database.
  1085. * @return {Object} Parsed response object with the following properties:<br>
  1086. * - results {Array} Array of parsed data results<br>
  1087. * - meta {Object} Object literal of meta values<br>
  1088. * - error {Boolean} (optional) True if there was an error<br>
  1089. */
  1090. parseData : function(oRequest, oFullResponse) {
  1091. if(lang.isValue(oFullResponse)) {
  1092. var oParsedResponse = {results:oFullResponse,meta:{}};
  1093. YAHOO.log("Parsed generic data is " +
  1094. lang.dump(oParsedResponse), "info", this.toString());
  1095. return oParsedResponse;
  1096. }
  1097. YAHOO.log("Generic data could not be parsed: " + lang.dump(oFullResponse),
  1098. "error", this.toString());
  1099. return null;
  1100. },
  1101. /**
  1102. * Overridable method parses Array data into a response object.
  1103. *
  1104. * @method parseArrayData
  1105. * @param oRequest {Object} Request object.
  1106. * @param oFullResponse {Object} The full Array from the live database.
  1107. * @return {Object} Parsed response object with the following properties:<br>
  1108. * - results (Array) Array of parsed data results<br>
  1109. * - error (Boolean) True if there was an error
  1110. */
  1111. parseArrayData : function(oRequest, oFullResponse) {
  1112. if(lang.isArray(oFullResponse)) {
  1113. var results = [],
  1114. i, j,
  1115. rec, field, data;
  1116. // Parse for fields
  1117. if(lang.isArray(this.responseSchema.fields)) {
  1118. var fields = this.responseSchema.fields;
  1119. for (i = fields.length - 1; i >= 0; --i) {
  1120. if (typeof fields[i] !== 'object') {
  1121. fields[i] = { key : fields[i] };
  1122. }
  1123. }
  1124. var parsers = {}, p;
  1125. for (i = fields.length - 1; i >= 0; --i) {
  1126. p = (typeof fields[i].parser === 'function' ?
  1127. fields[i].parser :
  1128. DS.Parser[fields[i].parser+'']) || fields[i].converter;
  1129. if (p) {
  1130. parsers[fields[i].key] = p;
  1131. }
  1132. }
  1133. var arrType = lang.isArray(oFullResponse[0]);
  1134. for(i=oFullResponse.length-1; i>-1; i--) {
  1135. var oResult = {};
  1136. rec = oFullResponse[i];
  1137. if (typeof rec === 'object') {
  1138. for(j=fields.length-1; j>-1; j--) {
  1139. field = fields[j];
  1140. data = arrType ? rec[j] : rec[field.key];
  1141. if (parsers[field.key]) {
  1142. data = parsers[field.key].call(this,data);
  1143. }
  1144. // Safety measure
  1145. if(data === undefined) {
  1146. data = null;
  1147. }
  1148. oResult[field.key] = data;
  1149. }
  1150. }
  1151. else if (lang.isString(rec)) {
  1152. for(j=fields.length-1; j>-1; j--) {
  1153. field = fields[j];
  1154. data = rec;
  1155. if (parsers[field.key]) {
  1156. data = parsers[field.key].call(this,data);
  1157. }
  1158. // Safety measure
  1159. if(data === undefined) {
  1160. data = null;
  1161. }
  1162. oResult[field.key] = data;
  1163. }
  1164. }
  1165. results[i] = oResult;
  1166. }
  1167. }
  1168. // Return entire data set
  1169. else {
  1170. results = oFullResponse;
  1171. }
  1172. var oParsedResponse = {results:results};
  1173. YAHOO.log("Parsed array data is " +
  1174. lang.dump(oParsedResponse), "info", this.toString());
  1175. return oParsedResponse;
  1176. }
  1177. YAHOO.log("Array data could not be parsed: " + lang.dump(oFullResponse),
  1178. "error", this.toString());
  1179. return null;
  1180. },
  1181. /**
  1182. * Overridable method parses plain text data into a response object.
  1183. *
  1184. * @method parseTextData
  1185. * @param oRequest {Object} Request object.
  1186. * @param oFullResponse {Object} The full text response from the live database.
  1187. * @return {Object} Parsed response object with the following properties:<br>
  1188. * - results (Array) Array of parsed data results<br>
  1189. * - error (Boolean) True if there was an error
  1190. */
  1191. parseTextData : function(oRequest, oFullResponse) {
  1192. if(lang.isString(oFullResponse)) {
  1193. if(lang.isString(this.responseSchema.recordDelim) &&
  1194. lang.isString(this.responseSchema.fieldDelim)) {
  1195. var oParsedResponse = {results:[]};
  1196. var recDelim = this.responseSchema.recordDelim;
  1197. var fieldDelim = this.responseSchema.fieldDelim;
  1198. if(oFullResponse.length > 0) {
  1199. // Delete the last line delimiter at the end of the data if it exists
  1200. var newLength = oFullResponse.length-recDelim.length;
  1201. if(oFullResponse.substr(newLength) == recDelim) {
  1202. oFullResponse = oFullResponse.substr(0, newLength);
  1203. }
  1204. if(oFullResponse.length > 0) {
  1205. // Split along record delimiter to get an array of strings
  1206. var recordsarray = oFullResponse.split(recDelim);
  1207. // Cycle through each record
  1208. for(var i = 0, len = recordsarray.length, recIdx = 0; i < len; ++i) {
  1209. var bError = false,
  1210. sRecord = recordsarray[i];
  1211. if (lang.isString(sRecord) && (sRecord.length > 0)) {
  1212. // Split each record along field delimiter to get data
  1213. var fielddataarray = recordsarray[i].split(fieldDelim);
  1214. var oResult = {};
  1215. // Filter for fields data
  1216. if(lang.isArray(this.responseSchema.fields)) {
  1217. var fields = this.responseSchema.fields;
  1218. for(var j=fields.length-1; j>-1; j--) {
  1219. try {
  1220. // Remove quotation marks from edges, if applicable
  1221. var data = fielddataarray[j];
  1222. if (lang.isString(data)) {
  1223. if(data.charAt(0) == "\"") {
  1224. data = data.substr(1);
  1225. }
  1226. if(data.charAt(data.length-1) == "\"") {
  1227. data = data.substr(0,data.length-1);
  1228. }
  1229. var field = fields[j];
  1230. var key = (lang.isValue(field.key)) ? field.key : field;
  1231. // Backward compatibility
  1232. if(!field.parser && field.converter) {
  1233. field.parser = field.converter;
  1234. YAHOO.log("The field property converter has been deprecated" +
  1235. " in favor of parser", "warn", this.toString());
  1236. }
  1237. var parser = (typeof field.parser === 'function') ?
  1238. field.parser :
  1239. DS.Parser[field.parser+''];
  1240. if(parser) {
  1241. data = parser.call(this, data);
  1242. }
  1243. // Safety measure
  1244. if(data === undefined) {
  1245. data = null;
  1246. }
  1247. oResult[key] = data;
  1248. }
  1249. else {
  1250. bError = true;
  1251. }
  1252. }
  1253. catch(e) {
  1254. bError = true;
  1255. }
  1256. }
  1257. }
  1258. // No fields defined so pass along all data as an array
  1259. else {
  1260. oResult = fielddataarray;
  1261. }
  1262. if(!bError) {
  1263. oParsedResponse.results[recIdx++] = oResult;
  1264. }
  1265. }
  1266. }
  1267. }
  1268. }
  1269. YAHOO.log("Parsed text data is " +
  1270. lang.dump(oParsedResponse), "info", this.toString());
  1271. return oParsedResponse;
  1272. }
  1273. }
  1274. YAHOO.log("Text data could not be parsed: " + lang.dump(oFullResponse),
  1275. "error", this.toString());
  1276. return null;
  1277. },
  1278. /**
  1279. * Overridable method parses XML data for one result into an object literal.
  1280. *
  1281. * @method parseXMLResult
  1282. * @param result {XML} XML for one result.
  1283. * @return {Object} Object literal of data for one result.
  1284. */
  1285. parseXMLResult : function(result) {
  1286. var oResult = {},
  1287. schema = this.responseSchema;
  1288. try {
  1289. // Loop through each data field in each result using the schema
  1290. for(var m = schema.fields.length-1; m >= 0 ; m--) {
  1291. var field = schema.fields[m];
  1292. var key = (lang.isValue(field.key)) ? field.key : field;
  1293. var data = null;
  1294. if(this.useXPath) {
  1295. data = YAHOO.util.DataSource._getLocationValue(field, result);
  1296. }
  1297. else {
  1298. // Values may be held in an attribute...
  1299. var xmlAttr = result.attributes.getNamedItem(key);
  1300. if(xmlAttr) {
  1301. data = xmlAttr.value;
  1302. }
  1303. // ...or in a node
  1304. else {
  1305. var xmlNode = result.getElementsByTagName(key);
  1306. if(xmlNode && xmlNode.item(0)) {
  1307. var item = xmlNode.item(0);
  1308. // For IE, then DOM...
  1309. data = (item) ? ((item.text) ? item.text : (item.textContent) ? item.textContent : null) : null;
  1310. // ...then fallback, but check for multiple child nodes
  1311. if(!data) {
  1312. var datapieces = [];
  1313. for(var j=0, len=item.childNodes.length; j<len; j++) {
  1314. if(item.childNodes[j].nodeValue) {
  1315. datapieces[datapieces.length] = item.childNodes[j].nodeValue;
  1316. }
  1317. }
  1318. if(datapieces.length > 0) {
  1319. data = datapieces.join("");
  1320. }
  1321. }
  1322. }
  1323. }
  1324. }
  1325. // Safety net
  1326. if(data === null) {
  1327. data = "";
  1328. }
  1329. // Backward compatibility
  1330. if(!field.parser && field.converter) {
  1331. field.parser = field.converter;
  1332. YAHOO.log("The field property converter has been deprecated" +
  1333. " in favor of parser", "warn", this.toString());
  1334. }
  1335. var parser = (typeof field.parser === 'function') ?
  1336. field.parser :
  1337. DS.Parser[field.parser+''];
  1338. if(parser) {
  1339. data = parser.call(this, data);
  1340. }
  1341. // Safety measure
  1342. if(data === undefined) {
  1343. data = null;
  1344. }
  1345. oResult[key] = data;
  1346. }
  1347. }
  1348. catch(e) {
  1349. YAHOO.log("Error while parsing XML result: " + e.message);
  1350. }
  1351. return oResult;
  1352. },
  1353. /**
  1354. * Overridable method parses XML data into a response object.
  1355. *
  1356. * @method parseXMLData
  1357. * @param oRequest {Object} Request object.
  1358. * @param oFullResponse {Object} The full XML response from the live database.
  1359. * @return {Object} Parsed response object with the following properties<br>
  1360. * - results (Array) Array of parsed data results<br>
  1361. * - error (Boolean) True if there was an error
  1362. */
  1363. parseXMLData : function(oRequest, oFullResponse) {
  1364. var bError = false,
  1365. schema = this.responseSchema,
  1366. oParsedResponse = {meta:{}},
  1367. xmlList = null,
  1368. metaNode = schema.metaNode,
  1369. metaLocators = schema.metaFields || {},
  1370. i,k,loc,v;
  1371. // In case oFullResponse is something funky
  1372. try {
  1373. // Pull any meta identified
  1374. if(this.useXPath) {
  1375. for (k in metaLocators) {
  1376. oParsedResponse.meta[k] = YAHOO.util.DataSource._getLocationValue(metaLocators[k], oFullResponse);
  1377. }
  1378. }
  1379. else {
  1380. metaNode = metaNode ? oFullResponse.getElementsByTagName(metaNode)[0] :
  1381. oFullResponse;
  1382. if (metaNode) {
  1383. for (k in metaLocators) {
  1384. if (lang.hasOwnProperty(metaLocators, k)) {
  1385. loc = metaLocators[k];
  1386. // Look for a node
  1387. v = metaNode.getElementsByTagName(loc)[0];
  1388. if (v) {
  1389. v = v.firstChild.nodeValue;
  1390. } else {
  1391. // Look for an attribute
  1392. v = metaNode.attributes.getNamedItem(loc);
  1393. if (v) {
  1394. v = v.value;
  1395. }
  1396. }
  1397. if (lang.isValue(v)) {
  1398. oParsedResponse.meta[k] = v;
  1399. }
  1400. }
  1401. }
  1402. }
  1403. }
  1404. // For result data
  1405. xmlList = (schema.resultNode) ?
  1406. oFullResponse.getElementsByTagName(schema.resultNode) :
  1407. null;
  1408. }
  1409. catch(e) {
  1410. YAHOO.log("Error while parsing XML data: " + e.message);
  1411. }
  1412. if(!xmlList || !lang.isArray(schema.fields)) {
  1413. bError = true;
  1414. }
  1415. // Loop through each result
  1416. else {
  1417. oParsedResponse.results = [];
  1418. for(i = xmlList.length-1; i >= 0 ; --i) {
  1419. var oResult = this.parseXMLResult(xmlList.item(i));
  1420. // Capture each array of values into an array of results
  1421. oParsedResponse.results[i] = oResult;
  1422. }
  1423. }
  1424. if(bError) {
  1425. YAHOO.log("XML data could not be parsed: " +
  1426. lang.dump(oFullResponse), "error", this.toString());
  1427. oParsedResponse.error = true;
  1428. }
  1429. else {
  1430. YAHOO.log("Parsed XML data is " +
  1431. lang.dump(oParsedResponse), "info", this.toString());
  1432. }
  1433. return oParsedResponse;
  1434. },
  1435. /**
  1436. * Overridable method parses JSON data into a response object.
  1437. *
  1438. * @method parseJSONData
  1439. * @param oRequest {Object} Request object.
  1440. * @param oFullResponse {Object} The full JSON from the live database.
  1441. * @return {Object} Parsed response object with the following properties<br>
  1442. * - results (Array) Array of parsed data results<br>
  1443. * - error (Boolean) True if there was an error
  1444. */
  1445. parseJSONData : function(oRequest, oFullResponse) {
  1446. var oParsedResponse = {results:[],meta:{}};
  1447. if(lang.isObject(oFullResponse) && this.responseSchema.resultsList) {
  1448. var schema = this.responseSchema,
  1449. fields = schema.fields,
  1450. resultsList = oFullResponse,
  1451. results = [],
  1452. metaFields = schema.metaFields || {},
  1453. fieldParsers = [],
  1454. fieldPaths = [],
  1455. simpleFields = [],
  1456. bError = false,
  1457. i,len,j,v,key,parser,path;
  1458. // Function to convert the schema's fields into walk paths
  1459. var buildPath = function (needle) {
  1460. var path = null, keys = [], i = 0;
  1461. if (needle) {
  1462. // Strip the ["string keys"] and [1] array indexes
  1463. needle = needle.
  1464. replace(/\[(['"])(.*?)\1\]/g,
  1465. function (x,$1,$2) {keys[i]=$2;return '.@'+(i++);}).
  1466. replace(/\[(\d+)\]/g,
  1467. function (x,$1) {keys[i]=parseInt($1,10)|0;return '.@'+(i++);}).
  1468. replace(/^\./,''); // remove leading dot
  1469. // If the cleaned needle contains invalid characters, the
  1470. // path is invalid
  1471. if (!/[^\w\.\$@]/.test(needle)) {
  1472. path = needle.split('.');
  1473. for (i=path.length-1; i >= 0; --i) {
  1474. if (path[i].charAt(0) === '@') {
  1475. path[i] = keys[parseInt(path[i].substr(1),10)];
  1476. }
  1477. }
  1478. }
  1479. else {
  1480. YAHOO.log("Invalid locator: " + needle, "error", this.toString());
  1481. }
  1482. }
  1483. return path;
  1484. };
  1485. // Function to walk a path and return the pot of gold
  1486. var walkPath = function (path, origin) {
  1487. var v=origin,i=0,len=path.length;
  1488. for (;i<len && v;++i) {
  1489. v = v[path[i]];
  1490. }
  1491. return v;
  1492. };
  1493. // Parse the response
  1494. // Step 1. Pull the resultsList from oFullResponse (default assumes
  1495. // oFullResponse IS the resultsList)
  1496. path = buildPath(schema.resultsList);
  1497. if (path) {
  1498. resultsList = walkPath(path, oFullResponse);
  1499. if (resultsList === undefined) {
  1500. bError = true;
  1501. }
  1502. } else {
  1503. bError = true;
  1504. }
  1505. if (!resultsList) {
  1506. resultsList = [];
  1507. }
  1508. if (!lang.isArray(resultsList)) {
  1509. resultsList = [resultsList];
  1510. }
  1511. if (!bError) {
  1512. // Step 2. Parse out field data if identified
  1513. if(schema.fields) {
  1514. var field;
  1515. // Build the field parser map and location paths
  1516. for (i=0, len=fields.length; i<len; i++) {
  1517. field = fields[i];
  1518. key = field.key || field;
  1519. parser = ((typeof field.parser === 'function') ?
  1520. field.parser :
  1521. DS.Parser[field.parser+'']) || field.converter;
  1522. path = buildPath(key);
  1523. if (parser) {
  1524. fieldParsers[fieldParsers.length] = {key:key,parser:parser};
  1525. }
  1526. if (path) {
  1527. if (path.length > 1) {
  1528. fieldPaths[fieldPaths.length] = {key:key,path:path};
  1529. } else {
  1530. simpleFields[simpleFields.length] = {key:key,path:path[0]};
  1531. }
  1532. } else {
  1533. YAHOO.log("Invalid key syntax: " + key,"warn",this.toString());
  1534. }
  1535. }
  1536. // Process the results, flattening the records and/or applying parsers if needed
  1537. for (i = resultsList.length - 1; i >= 0; --i) {
  1538. var r = resultsList[i], rec = {};
  1539. if(r) {
  1540. for (j = simpleFields.length - 1; j >= 0; --j) {
  1541. // Bug 1777850: data might be held in an array
  1542. rec[simpleFields[j].key] =
  1543. (r[simpleFields[j].path] !== undefined) ?
  1544. r[simpleFields[j].path] : r[j];
  1545. }
  1546. for (j = fieldPaths.length - 1; j >= 0; --j) {
  1547. rec[fieldPaths[j].key] = walkPath(fieldPaths[j].path,r);
  1548. }
  1549. for (j = fieldParsers.length - 1; j >= 0; --j) {
  1550. var p = fieldParsers[j].key;
  1551. rec[p] = fieldParsers[j].parser(rec[p]);
  1552. if (rec[p] === undefined) {
  1553. rec[p] = null;
  1554. }
  1555. }
  1556. }
  1557. results[i] = rec;
  1558. }
  1559. }
  1560. else {
  1561. results = resultsList;
  1562. }
  1563. for (key in metaFields) {
  1564. if (lang.hasOwnProperty(metaFields,key)) {
  1565. path = buildPath(metaFields[key]);
  1566. if (path) {
  1567. v = walkPath(path, oFullResponse);
  1568. oParsedResponse.meta[key] = v;
  1569. }
  1570. }
  1571. }
  1572. } else {
  1573. YAHOO.log("JSON data could not be parsed due to invalid responseSchema.resultsList or invalid response: " +
  1574. lang.dump(oFullResponse), "error", this.toString());
  1575. oParsedResponse.error = true;
  1576. }
  1577. oParsedResponse.results = results;
  1578. }
  1579. else {
  1580. YAHOO.log("JSON data could not be parsed: " +
  1581. lang.dump(oFullResponse), "error", this.toString());
  1582. oParsedResponse.error = true;
  1583. }
  1584. return oParsedResponse;
  1585. },
  1586. /**
  1587. * Overridable method parses an HTML TABLE element reference into a response object.
  1588. * Data is parsed out of TR elements from all TBODY elements.
  1589. *
  1590. * @method parseHTMLTableData
  1591. * @param oRequest {Object} Request object.
  1592. * @param oFullResponse {Object} The full HTML element reference from the live database.
  1593. * @return {Object} Parsed response object with the following properties<br>
  1594. * - results (Array) Array of parsed data results<br>
  1595. * - error (Boolean) True if there was an error
  1596. */
  1597. parseHTMLTableData : function(oRequest, oFullResponse) {
  1598. var bError = false;
  1599. var elTable = oFullResponse;
  1600. var fields = this.responseSchema.fields;
  1601. var oParsedResponse = {results:[]};
  1602. if(lang.isArray(fields)) {
  1603. // Iterate through each TBODY
  1604. for(var i=0; i<elTable.tBodies.length; i++) {
  1605. var elTbody = elTable.tBodies[i];
  1606. // Iterate through each TR
  1607. for(var j=elTbody.rows.length-1; j>-1; j--) {
  1608. var elRow = elTbody.rows[j];
  1609. var oResult = {};
  1610. for(var k=fields.length-1; k>-1; k--) {
  1611. var field = fields[k];
  1612. var key = (lang.isValue(field.key)) ? field.key : field;
  1613. var data = elRow.cells[k].innerHTML;
  1614. // Backward compatibility
  1615. if(!field.parser && field.converter) {
  1616. field.parser = field.converter;
  1617. YAHOO.log("The field property converter has been deprecated" +
  1618. " in favor of parser", "warn", this.toString());
  1619. }
  1620. var parser = (typeof field.parser === 'function') ?
  1621. field.parser :
  1622. DS.Parser[field.parser+''];
  1623. if(parser) {
  1624. data = parser.call(this, data);
  1625. }
  1626. // Safety measure
  1627. if(data === undefined) {
  1628. data = null;
  1629. }
  1630. oResult[key] = data;
  1631. }
  1632. oParsedResponse.results[j] = oResult;
  1633. }
  1634. }
  1635. }
  1636. else {
  1637. bError = true;
  1638. YAHOO.log("Invalid responseSchema.fields", "error", this.toString());
  1639. }
  1640. if(bError) {
  1641. YAHOO.log("HTML TABLE data could not be parsed: " +
  1642. lang.dump(oFullResponse), "error", this.toString());
  1643. oParsedResponse.error = true;
  1644. }
  1645. else {
  1646. YAHOO.log("Parsed HTML TABLE data is " +
  1647. lang.dump(oParsedResponse), "info", this.toString());
  1648. }
  1649. return oParsedResponse;
  1650. }
  1651. };
  1652. // DataSourceBase uses EventProvider
  1653. lang.augmentProto(DS, util.EventProvider);
  1654. /****************************************************************************/
  1655. /****************************************************************************/
  1656. /****************************************************************************/
  1657. /**
  1658. * LocalDataSource class for in-memory data structs including JavaScript arrays,
  1659. * JavaScript object literals (JSON), XML documents, and HTML tables.
  1660. *
  1661. * @namespace YAHOO.util
  1662. * @class YAHOO.util.LocalDataSource
  1663. * @extends YAHOO.util.DataSourceBase
  1664. * @constructor
  1665. * @param oLiveData {HTMLElement} Pointer to live data.
  1666. * @param oConfigs {object} (optional) Object literal of configuration values.
  1667. */
  1668. util.LocalDataSource = function(oLiveData, oConfigs) {
  1669. this.dataType = DS.TYPE_LOCAL;
  1670. if(oLiveData) {
  1671. if(YAHOO.lang.isArray(oLiveData)) { // array
  1672. this.responseType = DS.TYPE_JSARRAY;
  1673. }
  1674. // xml
  1675. else if(oLiveData.nodeType && oLiveData.nodeType == 9) {
  1676. this.responseType = DS.TYPE_XML;
  1677. }
  1678. else if(oLiveData.nodeName && (oLiveData.nodeName.toLowerCase() == "table")) { // table
  1679. this.responseType = DS.TYPE_HTMLTABLE;
  1680. oLiveData = oLiveData.cloneNode(true);
  1681. }
  1682. else if(YAHOO.lang.isString(oLiveData)) { // text
  1683. this.responseType = DS.TYPE_TEXT;
  1684. }
  1685. else if(YAHOO.lang.isObject(oLiveData)) { // json
  1686. this.responseType = DS.TYPE_JSON;
  1687. }
  1688. }
  1689. else {
  1690. oLiveData = [];
  1691. this.responseType = DS.TYPE_JSARRAY;
  1692. }
  1693. util.LocalDataSource.superclass.constructor.call(this, oLiveData, oConfigs);
  1694. };
  1695. // LocalDataSource extends DataSourceBase
  1696. lang.extend(util.LocalDataSource, DS);
  1697. // Copy static members to LocalDataSource class
  1698. lang.augmentObject(util.LocalDataSource, DS);
  1699. /****************************************************************************/
  1700. /****************************************************************************/
  1701. /****************************************************************************/
  1702. /**
  1703. * FunctionDataSource class for JavaScript functions.
  1704. *
  1705. * @namespace YAHOO.util
  1706. * @class YAHOO.util.FunctionDataSource
  1707. * @extends YAHOO.util.DataSourceBase
  1708. * @constructor
  1709. * @param oLiveData {HTMLElement} Pointer to live data.
  1710. * @param oConfigs {object} (optional) Object literal of configuration values.
  1711. */
  1712. util.FunctionDataSource = function(oLiveData, oConfigs) {
  1713. this.dataType = DS.TYPE_JSFUNCTION;
  1714. oLiveData = oLiveData || function() {};
  1715. util.FunctionDataSource.superclass.constructor.call(this, oLiveData, oConfigs);
  1716. };
  1717. // FunctionDataSource extends DataSourceBase
  1718. lang.extend(util.FunctionDataSource, DS, {
  1719. /////////////////////////////////////////////////////////////////////////////
  1720. //
  1721. // FunctionDataSource public properties
  1722. //
  1723. /////////////////////////////////////////////////////////////////////////////
  1724. /**
  1725. * Context in which to execute the function. By default, is the DataSource
  1726. * instance itself. If set, the function will receive the DataSource instance
  1727. * as an additional argument.
  1728. *
  1729. * @property scope
  1730. * @type Object
  1731. * @default null
  1732. */
  1733. scope : null,
  1734. /////////////////////////////////////////////////////////////////////////////
  1735. //
  1736. // FunctionDataSource public methods
  1737. //
  1738. /////////////////////////////////////////////////////////////////////////////
  1739. /**
  1740. * Overriding method passes query to a function. The returned response is then
  1741. * forwarded to the handleResponse function.
  1742. *
  1743. * @method makeConnection
  1744. * @param oRequest {Object} Request object.
  1745. * @param oCallback {Object} Callback object literal.
  1746. * @param oCaller {Object} (deprecated) Use oCallback.scope.
  1747. * @return {Number} Transaction ID.
  1748. */
  1749. makeConnection : function(oRequest, oCallback, oCaller) {
  1750. var tId = DS._nTransactionId++;
  1751. this.fireEvent("requestEvent", {tId:tId,request:oRequest,callback:oCallback,caller:oCaller});
  1752. // Pass the request in as a parameter and
  1753. // forward the return value to the handler
  1754. var oRawResponse = (this.scope) ? this.liveData.call(this.scope, oRequest, this) : this.liveData(oRequest);
  1755. // Try to sniff data type if it has not been defined
  1756. if(this.responseType === DS.TYPE_UNKNOWN) {
  1757. if(YAHOO.lang.isArray(oRawResponse)) { // array
  1758. this.responseType = DS.TYPE_JSARRAY;
  1759. }
  1760. // xml
  1761. else if(oRawResponse && oRawResponse.nodeType && oRawResponse.nodeType == 9) {
  1762. this.responseType = DS.TYPE_XML;
  1763. }
  1764. else if(oRawResponse && oRawResponse.nodeName && (oRawResponse.nodeName.toLowerCase() == "table")) { // table
  1765. this.responseType = DS.TYPE_HTMLTABLE;
  1766. }
  1767. else if(YAHOO.lang.isObject(oRawResponse)) { // json
  1768. this.responseType = DS.TYPE_JSON;
  1769. }
  1770. else if(YAHOO.lang.isString(oRawResponse)) { // text
  1771. this.responseType = DS.TYPE_TEXT;
  1772. }
  1773. }
  1774. this.handleResponse(oRequest, oRawResponse, oCallback, oCaller, tId);
  1775. return tId;
  1776. }
  1777. });
  1778. // Copy static members to FunctionDataSource class
  1779. lang.augmentObject(util.FunctionDataSource, DS);
  1780. /****************************************************************************/
  1781. /****************************************************************************/
  1782. /****************************************************************************/
  1783. /**
  1784. * ScriptNodeDataSource class for accessing remote data via the YUI Get Utility.
  1785. *
  1786. * @namespace YAHOO.util
  1787. * @class YAHOO.util.ScriptNodeDataSource
  1788. * @extends YAHOO.util.DataSourceBase
  1789. * @constructor
  1790. * @param oLiveData {HTMLElement} Pointer to live data.
  1791. * @param oConfigs {object} (optional) Object literal of configuration values.
  1792. */
  1793. util.ScriptNodeDataSource = function(oLiveData, oConfigs) {
  1794. this.dataType = DS.TYPE_SCRIPTNODE;
  1795. oLiveData = oLiveData || "";
  1796. util.ScriptNodeDataSource.superclass.constructor.call(this, oLiveData, oConfigs);
  1797. };
  1798. // ScriptNodeDataSource extends DataSourceBase
  1799. lang.extend(util.ScriptNodeDataSource, DS, {
  1800. /////////////////////////////////////////////////////////////////////////////
  1801. //
  1802. // ScriptNodeDataSource public properties
  1803. //
  1804. /////////////////////////////////////////////////////////////////////////////
  1805. /**
  1806. * Alias to YUI Get Utility, to allow implementers to use a custom class.
  1807. *
  1808. * @property getUtility
  1809. * @type Object
  1810. * @default YAHOO.util.Get
  1811. */
  1812. getUtility : util.Get,
  1813. /**
  1814. * Defines request/response management in the following manner:
  1815. * <dl>
  1816. * <!--<dt>queueRequests</dt>
  1817. * <dd>If a request is already in progress, wait until response is returned before sending the next request.</dd>
  1818. * <dt>cancelStaleRequests</dt>
  1819. * <dd>If a request is already in progress, cancel it before sending the next request.</dd>-->
  1820. * <dt>ignoreStaleResponses</dt>
  1821. * <dd>Send all requests, but handle only the response for the most recently sent request.</dd>
  1822. * <dt>allowAll</dt>
  1823. * <dd>Send all requests and handle all responses.</dd>
  1824. * </dl>
  1825. *
  1826. * @property asyncMode
  1827. * @type String
  1828. * @default "allowAll"
  1829. */
  1830. asyncMode : "allowAll",
  1831. /**
  1832. * Callback string parameter name sent to the remote script. By default,
  1833. * requests are sent to
  1834. * &#60;URI&#62;?&#60;scriptCallbackParam&#62;=callbackFunction
  1835. *
  1836. * @property scriptCallbackParam
  1837. * @type String
  1838. * @default "callback"
  1839. */
  1840. scriptCallbackParam : "callback",
  1841. /////////////////////////////////////////////////////////////////////////////
  1842. //
  1843. // ScriptNodeDataSource public methods
  1844. //
  1845. /////////////////////////////////////////////////////////////////////////////
  1846. /**
  1847. * Creates a request callback that gets appended to the script URI. Implementers
  1848. * can customize this string to match their server's query syntax.
  1849. *
  1850. * @method generateRequestCallback
  1851. * @return {String} String fragment that gets appended to script URI that
  1852. * specifies the callback function
  1853. */
  1854. generateRequestCallback : function(id) {
  1855. return "&" + this.scriptCallbackParam + "=YAHOO.util.ScriptNodeDataSource.callbacks["+id+"]" ;
  1856. },
  1857. /**
  1858. * Overridable method gives implementers access to modify the URI before the dynamic
  1859. * script node gets inserted. Implementers should take care not to return an
  1860. * invalid URI.
  1861. *
  1862. * @method doBeforeGetScriptNode
  1863. * @param {String} URI to the script
  1864. * @return {String} URI to the script
  1865. */
  1866. doBeforeGetScriptNode : function(sUri) {
  1867. return sUri;
  1868. },
  1869. /**
  1870. * Overriding method passes query to Get Utility. The returned
  1871. * response is then forwarded to the handleResponse function.
  1872. *
  1873. * @method makeConnection
  1874. * @param oRequest {Object} Request object.
  1875. * @param oCallback {Object} Callback object literal.
  1876. * @param oCaller {Object} (deprecated) Use oCallback.scope.
  1877. * @return {Number} Transaction ID.
  1878. */
  1879. makeConnection : function(oRequest, oCallback, oCaller) {
  1880. var tId = DS._nTransactionId++;
  1881. this.fireEvent("requestEvent", {tId:tId,request:oRequest,callback:oCallback,caller:oCaller});
  1882. // If there are no global pending requests, it is safe to purge global callback stack and global counter
  1883. if(util.ScriptNodeDataSource._nPending === 0) {
  1884. util.ScriptNodeDataSource.callbacks = [];
  1885. util.ScriptNodeDataSource._nId = 0;
  1886. }
  1887. // ID for this request
  1888. var id = util.ScriptNodeDataSource._nId;
  1889. util.ScriptNodeDataSource._nId++;
  1890. // Dynamically add handler function with a closure to the callback stack
  1891. var oSelf = this;
  1892. util.ScriptNodeDataSource.callbacks[id] = function(oRawResponse) {
  1893. if((oSelf.asyncMode !== "ignoreStaleResponses")||
  1894. (id === util.ScriptNodeDataSource.callbacks.length-1)) { // Must ignore stale responses
  1895. // Try to sniff data type if it has not been defined
  1896. if(oSelf.responseType === DS.TYPE_UNKNOWN) {
  1897. if(YAHOO.lang.isArray(oRawResponse)) { // array
  1898. oSelf.responseType = DS.TYPE_JSARRAY;
  1899. }
  1900. // xml
  1901. else if(oRawResponse.nodeType && oRawResponse.nodeType == 9) {
  1902. oSelf.responseType = DS.TYPE_XML;
  1903. }
  1904. else if(oRawResponse.nodeName && (oRawResponse.nodeName.toLowerCase() == "table")) { // table
  1905. oSelf.responseType = DS.TYPE_HTMLTABLE;
  1906. }
  1907. else if(YAHOO.lang.isObject(oRawResponse)) { // json
  1908. oSelf.responseType = DS.TYPE_JSON;
  1909. }
  1910. else if(YAHOO.lang.isString(oRawResponse)) { // text
  1911. oSelf.responseType = DS.TYPE_TEXT;
  1912. }
  1913. }
  1914. oSelf.handleResponse(oRequest, oRawResponse, oCallback, oCaller, tId);
  1915. }
  1916. else {
  1917. YAHOO.log("DataSource ignored stale response for tId " + tId + "(" + oRequest + ")", "info", oSelf.toString());
  1918. }
  1919. delete util.ScriptNodeDataSource.callbacks[id];
  1920. };
  1921. // We are now creating a request
  1922. util.ScriptNodeDataSource._nPending++;
  1923. var sUri = this.liveData + oRequest + this.generateRequestCallback(id);
  1924. sUri = this.doBeforeGetScriptNode(sUri);
  1925. YAHOO.log("DataSource is querying URL " + sUri, "info", this.toString());
  1926. this.getUtility.script(sUri,
  1927. {autopurge: true,
  1928. onsuccess: util.ScriptNodeDataSource._bumpPendingDown,
  1929. onfail: util.ScriptNodeDataSource._bumpPendingDown});
  1930. return tId;
  1931. }
  1932. });
  1933. // Copy static members to ScriptNodeDataSource class
  1934. lang.augmentObject(util.ScriptNodeDataSource, DS);
  1935. // Copy static members to ScriptNodeDataSource class
  1936. lang.augmentObject(util.ScriptNodeDataSource, {
  1937. /////////////////////////////////////////////////////////////////////////////
  1938. //
  1939. // ScriptNodeDataSource private static properties
  1940. //
  1941. /////////////////////////////////////////////////////////////////////////////
  1942. /**
  1943. * Unique ID to track requests.
  1944. *
  1945. * @property _nId
  1946. * @type Number
  1947. * @private
  1948. * @static
  1949. */
  1950. _nId : 0,
  1951. /**
  1952. * Counter for pending requests. When this is 0, it is safe to purge callbacks
  1953. * array.
  1954. *
  1955. * @property _nPending
  1956. * @type Number
  1957. * @private
  1958. * @static
  1959. */
  1960. _nPending : 0,
  1961. /**
  1962. * Global array of callback functions, one for each request sent.
  1963. *
  1964. * @property callbacks
  1965. * @type Function[]
  1966. * @static
  1967. */
  1968. callbacks : []
  1969. });
  1970. /****************************************************************************/
  1971. /****************************************************************************/
  1972. /****************************************************************************/
  1973. /**
  1974. * XHRDataSource class for accessing remote data via the YUI Connection Manager
  1975. * Utility
  1976. *
  1977. * @namespace YAHOO.util
  1978. * @class YAHOO.util.XHRDataSource
  1979. * @extends YAHOO.util.DataSourceBase
  1980. * @constructor
  1981. * @param oLiveData {HTMLElement} Pointer to live data.
  1982. * @param oConfigs {object} (optional) Object literal of configuration values.
  1983. */
  1984. util.XHRDataSource = function(oLiveData, oConfigs) {
  1985. this.dataType = DS.TYPE_XHR;
  1986. this.connMgr = this.connMgr || util.Connect;
  1987. oLiveData = oLiveData || "";
  1988. util.XHRDataSource.superclass.constructor.call(this, oLiveData, oConfigs);
  1989. };
  1990. // XHRDataSource extends DataSourceBase
  1991. lang.extend(util.XHRDataSource, DS, {
  1992. /////////////////////////////////////////////////////////////////////////////
  1993. //
  1994. // XHRDataSource public properties
  1995. //
  1996. /////////////////////////////////////////////////////////////////////////////
  1997. /**
  1998. * Alias to YUI Connection Manager, to allow implementers to use a custom class.
  1999. *
  2000. * @property connMgr
  2001. * @type Object
  2002. * @default YAHOO.util.Connect
  2003. */
  2004. connMgr: null,
  2005. /**
  2006. * Defines request/response management in the following manner:
  2007. * <dl>
  2008. * <dt>queueRequests</dt>
  2009. * <dd>If a request is already in progress, wait until response is returned
  2010. * before sending the next request.</dd>
  2011. *
  2012. * <dt>cancelStaleRequests</dt>
  2013. * <dd>If a request is already in progress, cancel it before sending the next
  2014. * request.</dd>
  2015. *
  2016. * <dt>ignoreStaleResponses</dt>
  2017. * <dd>Send all requests, but handle only the response for the most recently
  2018. * sent request.</dd>
  2019. *
  2020. * <dt>allowAll</dt>
  2021. * <dd>Send all requests and handle all responses.</dd>
  2022. *
  2023. * </dl>
  2024. *
  2025. * @property connXhrMode
  2026. * @type String
  2027. * @default "allowAll"
  2028. */
  2029. connXhrMode: "allowAll",
  2030. /**
  2031. * True if data is to be sent via POST. By default, data will be sent via GET.
  2032. *
  2033. * @property connMethodPost
  2034. * @type Boolean
  2035. * @default false
  2036. */
  2037. connMethodPost: false,
  2038. /**
  2039. * The connection timeout defines how many milliseconds the XHR connection will
  2040. * wait for a server response. Any non-zero value will enable the Connection Manager's
  2041. * Auto-Abort feature.
  2042. *
  2043. * @property connTimeout
  2044. * @type Number
  2045. * @default 0
  2046. */
  2047. connTimeout: 0,
  2048. /////////////////////////////////////////////////////////////////////////////
  2049. //
  2050. // XHRDataSource public methods
  2051. //
  2052. /////////////////////////////////////////////////////////////////////////////
  2053. /**
  2054. * Overriding method passes query to Connection Manager. The returned
  2055. * response is then forwarded to the handleResponse function.
  2056. *
  2057. * @method makeConnection
  2058. * @param oRequest {Object} Request object.
  2059. * @param oCallback {Object} Callback object literal.
  2060. * @param oCaller {Object} (deprecated) Use oCallback.scope.
  2061. * @return {Number} Transaction ID.
  2062. */
  2063. makeConnection : function(oRequest, oCallback, oCaller) {
  2064. var oRawResponse = null;
  2065. var tId = DS._nTransactionId++;
  2066. this.fireEvent("requestEvent", {tId:tId,request:oRequest,callback:oCallback,caller:oCaller});
  2067. // Set up the callback object and
  2068. // pass the request in as a URL query and
  2069. // forward the response to the handler
  2070. var oSelf = this;
  2071. var oConnMgr = this.connMgr;
  2072. var oQueue = this._oQueue;
  2073. /**
  2074. * Define Connection Manager success handler
  2075. *
  2076. * @method _xhrSuccess
  2077. * @param oResponse {Object} HTTPXMLRequest object
  2078. * @private
  2079. */
  2080. var _xhrSuccess = function(oResponse) {
  2081. // If response ID does not match last made request ID,
  2082. // silently fail and wait for the next response
  2083. if(oResponse && (this.connXhrMode == "ignoreStaleResponses") &&
  2084. (oResponse.tId != oQueue.conn.tId)) {
  2085. YAHOO.log("Ignored stale response", "warn", this.toString());
  2086. return null;
  2087. }
  2088. // Error if no response
  2089. else if(!oResponse) {
  2090. this.fireEvent("dataErrorEvent", {request:oRequest, response:null,
  2091. callback:oCallback, caller:oCaller,
  2092. message:DS.ERROR_DATANULL});
  2093. YAHOO.log(DS.ERROR_DATANULL, "error", this.toString());
  2094. // Send error response back to the caller with the error flag on
  2095. DS.issueCallback(oCallback,[oRequest, {error:true}], true, oCaller);
  2096. return null;
  2097. }
  2098. // Forward to handler
  2099. else {
  2100. // Try to sniff data type if it has not been defined
  2101. if(this.responseType === DS.TYPE_UNKNOWN) {
  2102. var ctype = (oResponse.getResponseHeader) ? oResponse.getResponseHeader["Content-Type"] : null;
  2103. if(ctype) {
  2104. // xml
  2105. if(ctype.indexOf("text/xml") > -1) {
  2106. this.responseType = DS.TYPE_XML;
  2107. }
  2108. else if(ctype.indexOf("application/json") > -1) { // json
  2109. this.responseType = DS.TYPE_JSON;
  2110. }
  2111. else if(ctype.indexOf("text/plain") > -1) { // text
  2112. this.responseType = DS.TYPE_TEXT;
  2113. }
  2114. }
  2115. }
  2116. this.handleResponse(oRequest, oResponse, oCallback, oCaller, tId);
  2117. }
  2118. };
  2119. /**
  2120. * Define Connection Manager failure handler
  2121. *
  2122. * @method _xhrFailure
  2123. * @param oResponse {Object} HTTPXMLRequest object
  2124. * @private
  2125. */
  2126. var _xhrFailure = function(oResponse) {
  2127. this.fireEvent("dataErrorEvent", {request:oRequest, response: oResponse,
  2128. callback:oCallback, caller:oCaller,
  2129. message:DS.ERROR_DATAINVALID});
  2130. YAHOO.log(DS.ERROR_DATAINVALID + ": " +
  2131. oResponse.statusText, "error", this.toString());
  2132. // Backward compatibility
  2133. if(lang.isString(this.liveData) && lang.isString(oRequest) &&
  2134. (this.liveData.lastIndexOf("?") !== this.liveData.length-1) &&
  2135. (oRequest.indexOf("?") !== 0)){
  2136. YAHOO.log("DataSources using XHR no longer automatically supply " +
  2137. "a \"?\" between the host and query parameters" +
  2138. " -- please check that the request URL is correct", "warn", this.toString());
  2139. }
  2140. // Send failure response back to the caller with the error flag on
  2141. oResponse = oResponse || {};
  2142. oResponse.error = true;
  2143. DS.issueCallback(oCallback,[oRequest,oResponse],true, oCaller);
  2144. return null;
  2145. };
  2146. /**
  2147. * Define Connection Manager callback object
  2148. *
  2149. * @property _xhrCallback
  2150. * @param oResponse {Object} HTTPXMLRequest object
  2151. * @private
  2152. */
  2153. var _xhrCallback = {
  2154. success:_xhrSuccess,
  2155. failure:_xhrFailure,
  2156. scope: this
  2157. };
  2158. // Apply Connection Manager timeout
  2159. if(lang.isNumber(this.connTimeout)) {
  2160. _xhrCallback.timeout = this.connTimeout;
  2161. }
  2162. // Cancel stale requests
  2163. if(this.connXhrMode == "cancelStaleRequests") {
  2164. // Look in queue for stale requests
  2165. if(oQueue.conn) {
  2166. if(oConnMgr.abort) {
  2167. oConnMgr.abort(oQueue.conn);
  2168. oQueue.conn = null;
  2169. YAHOO.log("Canceled stale request", "warn", this.toString());
  2170. }
  2171. else {
  2172. YAHOO.log("Could not find Connection Manager abort() function", "error", this.toString());
  2173. }
  2174. }
  2175. }
  2176. // Get ready to send the request URL
  2177. if(oConnMgr && oConnMgr.asyncRequest) {
  2178. var sLiveData = this.liveData;
  2179. var isPost = this.connMethodPost;
  2180. var sMethod = (isPost) ? "POST" : "GET";
  2181. // Validate request
  2182. var sUri = (isPost || !lang.isValue(oRequest)) ? sLiveData : sLiveData+oRequest;
  2183. var sRequest = (isPost) ? oRequest : null;
  2184. // Send the request right away
  2185. if(this.connXhrMode != "queueRequests") {
  2186. oQueue.conn = oConnMgr.asyncRequest(sMethod, sUri, _xhrCallback, sRequest);
  2187. }
  2188. // Queue up then send the request
  2189. else {
  2190. // Found a request already in progress
  2191. if(oQueue.conn) {
  2192. var allRequests = oQueue.requests;
  2193. // Add request to queue
  2194. allRequests.push({request:oRequest, callback:_xhrCallback});
  2195. // Interval needs to be started
  2196. if(!oQueue.interval) {
  2197. oQueue.interval = setInterval(function() {
  2198. // Connection is in progress
  2199. if(oConnMgr.isCallInProgress(oQueue.conn)) {
  2200. return;
  2201. }
  2202. else {
  2203. // Send next request
  2204. if(allRequests.length > 0) {
  2205. // Validate request
  2206. sUri = (isPost || !lang.isValue(allRequests[0].request)) ? sLiveData : sLiveData+allRequests[0].request;
  2207. sRequest = (isPost) ? allRequests[0].request : null;
  2208. oQueue.conn = oConnMgr.asyncRequest(sMethod, sUri, allRequests[0].callback, sRequest);
  2209. // Remove request from queue
  2210. allRequests.shift();
  2211. }
  2212. // No more requests
  2213. else {
  2214. clearInterval(oQueue.interval);
  2215. oQueue.interval = null;
  2216. }
  2217. }
  2218. }, 50);
  2219. }
  2220. }
  2221. // Nothing is in progress
  2222. else {
  2223. oQueue.conn = oConnMgr.asyncRequest(sMethod, sUri, _xhrCallback, sRequest);
  2224. }
  2225. }
  2226. }
  2227. else {
  2228. YAHOO.log("Could not find Connection Manager asyncRequest() function", "error", this.toString());
  2229. // Send null response back to the caller with the error flag on
  2230. DS.issueCallback(oCallback,[oRequest,{error:true}],true,oCaller);
  2231. }
  2232. return tId;
  2233. }
  2234. });
  2235. // Copy static members to XHRDataSource class
  2236. lang.augmentObject(util.XHRDataSource, DS);
  2237. /****************************************************************************/
  2238. /****************************************************************************/
  2239. /****************************************************************************/
  2240. /**
  2241. * Factory class for creating a BaseDataSource subclass instance. The sublcass is
  2242. * determined by oLiveData's type, unless the dataType config is explicitly passed in.
  2243. *
  2244. * @namespace YAHOO.util
  2245. * @class YAHOO.util.DataSource
  2246. * @constructor
  2247. * @param oLiveData {HTMLElement} Pointer to live data.
  2248. * @param oConfigs {object} (optional) Object literal of configuration values.
  2249. */
  2250. util.DataSource = function(oLiveData, oConfigs) {
  2251. oConfigs = oConfigs || {};
  2252. // Point to one of the subclasses, first by dataType if given, then by sniffing oLiveData type.
  2253. var dataType = oConfigs.dataType;
  2254. if(dataType) {
  2255. if(dataType == DS.TYPE_LOCAL) {
  2256. lang.augmentObject(util.DataSource, util.LocalDataSource);
  2257. return new util.LocalDataSource(oLiveData, oConfigs);
  2258. }
  2259. else if(dataType == DS.TYPE_XHR) {
  2260. lang.augmentObject(util.DataSource, util.XHRDataSource);
  2261. return new util.XHRDataSource(oLiveData, oConfigs);
  2262. }
  2263. else if(dataType == DS.TYPE_SCRIPTNODE) {
  2264. lang.augmentObject(util.DataSource, util.ScriptNodeDataSource);
  2265. return new util.ScriptNodeDataSource(oLiveData, oConfigs);
  2266. }
  2267. else if(dataType == DS.TYPE_JSFUNCTION) {
  2268. lang.augmentObject(util.DataSource, util.FunctionDataSource);
  2269. return new util.FunctionDataSource(oLiveData, oConfigs);
  2270. }
  2271. }
  2272. if(YAHOO.lang.isString(oLiveData)) { // strings default to xhr
  2273. lang.augmentObject(util.DataSource, util.XHRDataSource);
  2274. return new util.XHRDataSource(oLiveData, oConfigs);
  2275. }
  2276. else if(YAHOO.lang.isFunction(oLiveData)) {
  2277. lang.augmentObject(util.DataSource, util.FunctionDataSource);
  2278. return new util.FunctionDataSource(oLiveData, oConfigs);
  2279. }
  2280. else { // ultimate default is local
  2281. lang.augmentObject(util.DataSource, util.LocalDataSource);
  2282. return new util.LocalDataSource(oLiveData, oConfigs);
  2283. }
  2284. };
  2285. // Copy static members to DataSource class
  2286. lang.augmentObject(util.DataSource, DS);
  2287. })();
  2288. /****************************************************************************/
  2289. /****************************************************************************/
  2290. /****************************************************************************/
  2291. /**
  2292. * The static Number class provides helper functions to deal with data of type
  2293. * Number.
  2294. *
  2295. * @namespace YAHOO.util
  2296. * @requires yahoo
  2297. * @class Number
  2298. * @static
  2299. */
  2300. YAHOO.util.Number = {
  2301. /**
  2302. * Takes a native JavaScript Number and formats to string for display to user.
  2303. *
  2304. * @method format
  2305. * @param nData {Number} Number.
  2306. * @param oConfig {Object} (Optional) Optional configuration values:
  2307. * <dl>
  2308. * <dt>prefix {String}</dd>
  2309. * <dd>String prepended before each number, like a currency designator "$"</dd>
  2310. * <dt>decimalPlaces {Number}</dd>
  2311. * <dd>Number of decimal places to round.</dd>
  2312. * <dt>decimalSeparator {String}</dd>
  2313. * <dd>Decimal separator</dd>
  2314. * <dt>thousandsSeparator {String}</dd>
  2315. * <dd>Thousands separator</dd>
  2316. * <dt>suffix {String}</dd>
  2317. * <dd>String appended after each number, like " items" (note the space)</dd>
  2318. * <dt>negativeFormat</dt>
  2319. * <dd>String used as a guide for how to indicate negative numbers. The first '#' character in the string will be replaced by the number. Default '-#'.</dd>
  2320. * </dl>
  2321. * @return {String} Formatted number for display. Note, the following values
  2322. * return as "": null, undefined, NaN, "".
  2323. */
  2324. format : function(n, cfg) {
  2325. if (!isFinite(+n)) {
  2326. return '';
  2327. }
  2328. n = !isFinite(+n) ? 0 : +n;
  2329. cfg = YAHOO.lang.merge(YAHOO.util.Number.format.defaults, (cfg || {}));
  2330. var neg = n < 0, absN = Math.abs(n),
  2331. places = cfg.decimalPlaces,
  2332. sep = cfg.thousandsSeparator,
  2333. s, bits, i;
  2334. if (places < 0) {
  2335. // Get rid of the decimal info
  2336. s = absN - (absN % 1) + '';
  2337. i = s.length + places;
  2338. // avoid 123 vs decimalPlaces -4 (should return "0")
  2339. if (i > 0) {
  2340. // leverage toFixed by making 123 => 0.123 for the rounding
  2341. // operation, then add the appropriate number of zeros back on
  2342. s = Number('.' + s).toFixed(i).slice(2) +
  2343. new Array(s.length - i + 1).join('0');
  2344. } else {
  2345. s = "0";
  2346. }
  2347. } else { // There is a bug in IE's toFixed implementation:
  2348. // for n in {(-0.94, -0.5], [0.5, 0.94)} n.toFixed() returns 0
  2349. // instead of -1 and 1. Manually handle that case.
  2350. s = absN < 1 && absN >= 0.5 && !places ? '1' : absN.toFixed(places);
  2351. }
  2352. if (absN > 1000) {
  2353. bits = s.split(/\D/);
  2354. i = bits[0].length % 3 || 3;
  2355. bits[0] = bits[0].slice(0,i) +
  2356. bits[0].slice(i).replace(/(\d{3})/g, sep + '$1');
  2357. s = bits.join(cfg.decimalSeparator);
  2358. }
  2359. s = cfg.prefix + s + cfg.suffix;
  2360. return neg ? cfg.negativeFormat.replace(/#/,s) : s;
  2361. }
  2362. };
  2363. YAHOO.util.Number.format.defaults = {
  2364. decimalSeparator : '.',
  2365. decimalPlaces : null,
  2366. thousandsSeparator : '',
  2367. prefix : '',
  2368. suffix : '',
  2369. negativeFormat : '-#'
  2370. };
  2371. /****************************************************************************/
  2372. /****************************************************************************/
  2373. /****************************************************************************/
  2374. (function () {
  2375. var xPad=function (x, pad, r)
  2376. {
  2377. if(typeof r === 'undefined')
  2378. {
  2379. r=10;
  2380. }
  2381. for( ; parseInt(x, 10)<r && r>1; r/=10) {
  2382. x = pad.toString() + x;
  2383. }
  2384. return x.toString();
  2385. };
  2386. /**
  2387. * The static Date class provides helper functions to deal with data of type Date.
  2388. *
  2389. * @namespace YAHOO.util
  2390. * @requires yahoo
  2391. * @class Date
  2392. * @static
  2393. */
  2394. var Dt = {
  2395. formats: {
  2396. a: function (d, l) { return l.a[d.getDay()]; },
  2397. A: function (d, l) { return l.A[d.getDay()]; },
  2398. b: function (d, l) { return l.b[d.getMonth()]; },
  2399. B: function (d, l) { return l.B[d.getMonth()]; },
  2400. C: function (d) { return xPad(parseInt(d.getFullYear()/100, 10), 0); },
  2401. d: ['getDate', '0'],
  2402. e: ['getDate', ' '],
  2403. g: function (d) { return xPad(parseInt(Dt.formats.G(d)%100, 10), 0); },
  2404. G: function (d) {
  2405. var y = d.getFullYear();
  2406. var V = parseInt(Dt.formats.V(d), 10);
  2407. var W = parseInt(Dt.formats.W(d), 10);
  2408. if(W > V) {
  2409. y++;
  2410. } else if(W===0 && V>=52) {
  2411. y--;
  2412. }
  2413. return y;
  2414. },
  2415. H: ['getHours', '0'],
  2416. I: function (d) { var I=d.getHours()%12; return xPad(I===0?12:I, 0); },
  2417. j: function (d) {
  2418. var gmd_1 = new Date('' + d.getFullYear() + '/1/1 GMT');
  2419. var gmdate = new Date('' + d.getFullYear() + '/' + (d.getMonth()+1) + '/' + d.getDate() + ' GMT');
  2420. var ms = gmdate - gmd_1;
  2421. var doy = parseInt(ms/60000/60/24, 10)+1;
  2422. return xPad(doy, 0, 100);
  2423. },
  2424. k: ['getHours', ' '],
  2425. l: function (d) { var I=d.getHours()%12; return xPad(I===0?12:I, ' '); },
  2426. m: function (d) { return xPad(d.getMonth()+1, 0); },
  2427. M: ['getMinutes', '0'],
  2428. p: function (d, l) { return l.p[d.getHours() >= 12 ? 1 : 0 ]; },
  2429. P: function (d, l) { return l.P[d.getHours() >= 12 ? 1 : 0 ]; },
  2430. s: function (d, l) { return parseInt(d.getTime()/1000, 10); },
  2431. S: ['getSeconds', '0'],
  2432. u: function (d) { var dow = d.getDay(); return dow===0?7:dow; },
  2433. U: function (d) {
  2434. var doy = parseInt(Dt.formats.j(d), 10);
  2435. var rdow = 6-d.getDay();
  2436. var woy = parseInt((doy+rdow)/7, 10);
  2437. return xPad(woy, 0);
  2438. },
  2439. V: function (d) {
  2440. var woy = parseInt(Dt.formats.W(d), 10);
  2441. var dow1_1 = (new Date('' + d.getFullYear() + '/1/1')).getDay();
  2442. // First week is 01 and not 00 as in the case of %U and %W,
  2443. // so we add 1 to the final result except if day 1 of the year
  2444. // is a Monday (then %W returns 01).
  2445. // We also need to subtract 1 if the day 1 of the year is
  2446. // Friday-Sunday, so the resulting equation becomes:
  2447. var idow = woy + (dow1_1 > 4 || dow1_1 <= 1 ? 0 : 1);
  2448. if(idow === 53 && (new Date('' + d.getFullYear() + '/12/31')).getDay() < 4)
  2449. {
  2450. idow = 1;
  2451. }
  2452. else if(idow === 0)
  2453. {
  2454. idow = Dt.formats.V(new Date('' + (d.getFullYear()-1) + '/12/31'));
  2455. }
  2456. return xPad(idow, 0);
  2457. },
  2458. w: 'getDay',
  2459. W: function (d) {
  2460. var doy = parseInt(Dt.formats.j(d), 10);
  2461. var rdow = 7-Dt.formats.u(d);
  2462. var woy = parseInt((doy+rdow)/7, 10);
  2463. return xPad(woy, 0, 10);
  2464. },
  2465. y: function (d) { return xPad(d.getFullYear()%100, 0); },
  2466. Y: 'getFullYear',
  2467. z: function (d) {
  2468. var o = d.getTimezoneOffset();
  2469. var H = xPad(parseInt(Math.abs(o/60), 10), 0);
  2470. var M = xPad(Math.abs(o%60), 0);
  2471. return (o>0?'-':'+') + H + M;
  2472. },
  2473. Z: function (d) {
  2474. var tz = d.toString().replace(/^.*:\d\d( GMT[+-]\d+)? \(?([A-Za-z ]+)\)?\d*$/, '$2').replace(/[a-z ]/g, '');
  2475. if(tz.length > 4) {
  2476. tz = Dt.formats.z(d);
  2477. }
  2478. return tz;
  2479. },
  2480. '%': function (d) { return '%'; }
  2481. },
  2482. aggregates: {
  2483. c: 'locale',
  2484. D: '%m/%d/%y',
  2485. F: '%Y-%m-%d',
  2486. h: '%b',
  2487. n: '\n',
  2488. r: 'locale',
  2489. R: '%H:%M',
  2490. t: '\t',
  2491. T: '%H:%M:%S',
  2492. x: 'locale',
  2493. X: 'locale'
  2494. //'+': '%a %b %e %T %Z %Y'
  2495. },
  2496. /**
  2497. * Takes a native JavaScript Date and formats to string for display to user.
  2498. *
  2499. * @method format
  2500. * @param oDate {Date} Date.
  2501. * @param oConfig {Object} (Optional) Object literal of configuration values:
  2502. * <dl>
  2503. * <dt>format &lt;String&gt;</dt>
  2504. * <dd>
  2505. * <p>
  2506. * Any strftime string is supported, such as "%I:%M:%S %p". strftime has several format specifiers defined by the Open group at
  2507. * <a href="http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html">http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html</a>
  2508. * </p>
  2509. * <p>
  2510. * PHP added a few of its own, defined at <a href="http://www.php.net/strftime">http://www.php.net/strftime</a>
  2511. * </p>
  2512. * <p>
  2513. * This javascript implementation supports all the PHP specifiers and a few more. The full list is below:
  2514. * </p>
  2515. * <dl>
  2516. * <dt>%a</dt> <dd>abbreviated weekday name according to the current locale</dd>
  2517. * <dt>%A</dt> <dd>full weekday name according to the current locale</dd>
  2518. * <dt>%b</dt> <dd>abbreviated month name according to the current locale</dd>
  2519. * <dt>%B</dt> <dd>full month name according to the current locale</dd>
  2520. * <dt>%c</dt> <dd>preferred date and time representation for the current locale</dd>
  2521. * <dt>%C</dt> <dd>century number (the year divided by 100 and truncated to an integer, range 00 to 99)</dd>
  2522. * <dt>%d</dt> <dd>day of the month as a decimal number (range 01 to 31)</dd>
  2523. * <dt>%D</dt> <dd>same as %m/%d/%y</dd>
  2524. * <dt>%e</dt> <dd>day of the month as a decimal number, a single digit is preceded by a space (range ' 1' to '31')</dd>
  2525. * <dt>%F</dt> <dd>same as %Y-%m-%d (ISO 8601 date format)</dd>
  2526. * <dt>%g</dt> <dd>like %G, but without the century</dd>
  2527. * <dt>%G</dt> <dd>The 4-digit year corresponding to the ISO week number</dd>
  2528. * <dt>%h</dt> <dd>same as %b</dd>
  2529. * <dt>%H</dt> <dd>hour as a decimal number using a 24-hour clock (range 00 to 23)</dd>
  2530. * <dt>%I</dt> <dd>hour as a decimal number using a 12-hour clock (range 01 to 12)</dd>
  2531. * <dt>%j</dt> <dd>day of the year as a decimal number (range 001 to 366)</dd>
  2532. * <dt>%k</dt> <dd>hour as a decimal number using a 24-hour clock (range 0 to 23); single digits are preceded by a blank. (See also %H.)</dd>
  2533. * <dt>%l</dt> <dd>hour as a decimal number using a 12-hour clock (range 1 to 12); single digits are preceded by a blank. (See also %I.) </dd>
  2534. * <dt>%m</dt> <dd>month as a decimal number (range 01 to 12)</dd>
  2535. * <dt>%M</dt> <dd>minute as a decimal number</dd>
  2536. * <dt>%n</dt> <dd>newline character</dd>
  2537. * <dt>%p</dt> <dd>either `AM' or `PM' according to the given time value, or the corresponding strings for the current locale</dd>
  2538. * <dt>%P</dt> <dd>like %p, but lower case</dd>
  2539. * <dt>%r</dt> <dd>time in a.m. and p.m. notation equal to %I:%M:%S %p</dd>
  2540. * <dt>%R</dt> <dd>time in 24 hour notation equal to %H:%M</dd>
  2541. * <dt>%s</dt> <dd>number of seconds since the Epoch, ie, since 1970-01-01 00:00:00 UTC</dd>
  2542. * <dt>%S</dt> <dd>second as a decimal number</dd>
  2543. * <dt>%t</dt> <dd>tab character</dd>
  2544. * <dt>%T</dt> <dd>current time, equal to %H:%M:%S</dd>
  2545. * <dt>%u</dt> <dd>weekday as a decimal number [1,7], with 1 representing Monday</dd>
  2546. * <dt>%U</dt> <dd>week number of the current year as a decimal number, starting with the
  2547. * first Sunday as the first day of the first week</dd>
  2548. * <dt>%V</dt> <dd>The ISO 8601:1988 week number of the current year as a decimal number,
  2549. * range 01 to 53, where week 1 is the first week that has at least 4 days
  2550. * in the current year, and with Monday as the first day of the week.</dd>
  2551. * <dt>%w</dt> <dd>day of the week as a decimal, Sunday being 0</dd>
  2552. * <dt>%W</dt> <dd>week number of the current year as a decimal number, starting with the
  2553. * first Monday as the first day of the first week</dd>
  2554. * <dt>%x</dt> <dd>preferred date representation for the current locale without the time</dd>
  2555. * <dt>%X</dt> <dd>preferred time representation for the current locale without the date</dd>
  2556. * <dt>%y</dt> <dd>year as a decimal number without a century (range 00 to 99)</dd>
  2557. * <dt>%Y</dt> <dd>year as a decimal number including the century</dd>
  2558. * <dt>%z</dt> <dd>numerical time zone representation</dd>
  2559. * <dt>%Z</dt> <dd>time zone name or abbreviation</dd>
  2560. * <dt>%%</dt> <dd>a literal `%' character</dd>
  2561. * </dl>
  2562. * </dd>
  2563. * </dl>
  2564. * @param sLocale {String} (Optional) The locale to use when displaying days of week,
  2565. * months of the year, and other locale specific strings. The following locales are
  2566. * built in:
  2567. * <dl>
  2568. * <dt>en</dt>
  2569. * <dd>English</dd>
  2570. * <dt>en-US</dt>
  2571. * <dd>US English</dd>
  2572. * <dt>en-GB</dt>
  2573. * <dd>British English</dd>
  2574. * <dt>en-AU</dt>
  2575. * <dd>Australian English (identical to British English)</dd>
  2576. * </dl>
  2577. * More locales may be added by subclassing of YAHOO.util.DateLocale.
  2578. * See YAHOO.util.DateLocale for more information.
  2579. * @return {String} Formatted date for display.
  2580. * @sa YAHOO.util.DateLocale
  2581. */
  2582. format : function (oDate, oConfig, sLocale) {
  2583. oConfig = oConfig || {};
  2584. if(!(oDate instanceof Date)) {
  2585. return YAHOO.lang.isValue(oDate) ? oDate : "";
  2586. }
  2587. var format = oConfig.format || "%m/%d/%Y";
  2588. // Be backwards compatible, support strings that are
  2589. // exactly equal to YYYY/MM/DD, DD/MM/YYYY and MM/DD/YYYY
  2590. if(format === 'YYYY/MM/DD') {
  2591. format = '%Y/%m/%d';
  2592. } else if(format === 'DD/MM/YYYY') {
  2593. format = '%d/%m/%Y';
  2594. } else if(format === 'MM/DD/YYYY') {
  2595. format = '%m/%d/%Y';
  2596. }
  2597. // end backwards compatibility block
  2598. sLocale = sLocale || "en";
  2599. // Make sure we have a definition for the requested locale, or default to en.
  2600. if(!(sLocale in YAHOO.util.DateLocale)) {
  2601. if(sLocale.replace(/-[a-zA-Z]+$/, '') in YAHOO.util.DateLocale) {
  2602. sLocale = sLocale.replace(/-[a-zA-Z]+$/, '');
  2603. } else {
  2604. sLocale = "en";
  2605. }
  2606. }
  2607. var aLocale = YAHOO.util.DateLocale[sLocale];
  2608. var replace_aggs = function (m0, m1) {
  2609. var f = Dt.aggregates[m1];
  2610. return (f === 'locale' ? aLocale[m1] : f);
  2611. };
  2612. var replace_formats = function (m0, m1) {
  2613. var f = Dt.formats[m1];
  2614. if(typeof f === 'string') { // string => built in date function
  2615. return oDate[f]();
  2616. } else if(typeof f === 'function') { // function => our own function
  2617. return f.call(oDate, oDate, aLocale);
  2618. } else if(typeof f === 'object' && typeof f[0] === 'string') { // built in function with padding
  2619. return xPad(oDate[f[0]](), f[1]);
  2620. } else {
  2621. return m1;
  2622. }
  2623. };
  2624. // First replace aggregates (run in a loop because an agg may be made up of other aggs)
  2625. while(format.match(/%[cDFhnrRtTxX]/)) {
  2626. format = format.replace(/%([cDFhnrRtTxX])/g, replace_aggs);
  2627. }
  2628. // Now replace formats (do not run in a loop otherwise %%a will be replace with the value of %a)
  2629. var str = format.replace(/%([aAbBCdegGHIjklmMpPsSuUVwWyYzZ%])/g, replace_formats);
  2630. replace_aggs = replace_formats = undefined;
  2631. return str;
  2632. }
  2633. };
  2634. YAHOO.namespace("YAHOO.util");
  2635. YAHOO.util.Date = Dt;
  2636. /**
  2637. * The DateLocale class is a container and base class for all
  2638. * localised date strings used by YAHOO.util.Date. It is used
  2639. * internally, but may be extended to provide new date localisations.
  2640. *
  2641. * To create your own DateLocale, follow these steps:
  2642. * <ol>
  2643. * <li>Find an existing locale that matches closely with your needs</li>
  2644. * <li>Use this as your base class. Use YAHOO.util.DateLocale if nothing
  2645. * matches.</li>
  2646. * <li>Create your own class as an extension of the base class using
  2647. * YAHOO.lang.merge, and add your own localisations where needed.</li>
  2648. * </ol>
  2649. * See the YAHOO.util.DateLocale['en-US'] and YAHOO.util.DateLocale['en-GB']
  2650. * classes which extend YAHOO.util.DateLocale['en'].
  2651. *
  2652. * For example, to implement locales for French french and Canadian french,
  2653. * we would do the following:
  2654. * <ol>
  2655. * <li>For French french, we have no existing similar locale, so use
  2656. * YAHOO.util.DateLocale as the base, and extend it:
  2657. * <pre>
  2658. * YAHOO.util.DateLocale['fr'] = YAHOO.lang.merge(YAHOO.util.DateLocale, {
  2659. * a: ['dim', 'lun', 'mar', 'mer', 'jeu', 'ven', 'sam'],
  2660. * A: ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'],
  2661. * b: ['jan', 'f&eacute;v', 'mar', 'avr', 'mai', 'jun', 'jui', 'ao&ucirc;', 'sep', 'oct', 'nov', 'd&eacute;c'],
  2662. * B: ['janvier', 'f&eacute;vrier', 'mars', 'avril', 'mai', 'juin', 'juillet', 'ao&ucirc;t', 'septembre', 'octobre', 'novembre', 'd&eacute;cembre'],
  2663. * c: '%a %d %b %Y %T %Z',
  2664. * p: ['', ''],
  2665. * P: ['', ''],
  2666. * x: '%d.%m.%Y',
  2667. * X: '%T'
  2668. * });
  2669. * </pre>
  2670. * </li>
  2671. * <li>For Canadian french, we start with French french and change the meaning of \%x:
  2672. * <pre>
  2673. * YAHOO.util.DateLocale['fr-CA'] = YAHOO.lang.merge(YAHOO.util.DateLocale['fr'], {
  2674. * x: '%Y-%m-%d'
  2675. * });
  2676. * </pre>
  2677. * </li>
  2678. * </ol>
  2679. *
  2680. * With that, you can use your new locales:
  2681. * <pre>
  2682. * var d = new Date("2008/04/22");
  2683. * YAHOO.util.Date.format(d, {format: "%A, %d %B == %x"}, "fr");
  2684. * </pre>
  2685. * will return:
  2686. * <pre>
  2687. * mardi, 22 avril == 22.04.2008
  2688. * </pre>
  2689. * And
  2690. * <pre>
  2691. * YAHOO.util.Date.format(d, {format: "%A, %d %B == %x"}, "fr-CA");
  2692. * </pre>
  2693. * Will return:
  2694. * <pre>
  2695. * mardi, 22 avril == 2008-04-22
  2696. * </pre>
  2697. * @namespace YAHOO.util
  2698. * @requires yahoo
  2699. * @class DateLocale
  2700. */
  2701. YAHOO.util.DateLocale = {
  2702. a: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
  2703. A: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
  2704. b: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  2705. B: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
  2706. c: '%a %d %b %Y %T %Z',
  2707. p: ['AM', 'PM'],
  2708. P: ['am', 'pm'],
  2709. r: '%I:%M:%S %p',
  2710. x: '%d/%m/%y',
  2711. X: '%T'
  2712. };
  2713. YAHOO.util.DateLocale['en'] = YAHOO.lang.merge(YAHOO.util.DateLocale, {});
  2714. YAHOO.util.DateLocale['en-US'] = YAHOO.lang.merge(YAHOO.util.DateLocale['en'], {
  2715. c: '%a %d %b %Y %I:%M:%S %p %Z',
  2716. x: '%m/%d/%Y',
  2717. X: '%I:%M:%S %p'
  2718. });
  2719. YAHOO.util.DateLocale['en-GB'] = YAHOO.lang.merge(YAHOO.util.DateLocale['en'], {
  2720. r: '%l:%M:%S %P %Z'
  2721. });
  2722. YAHOO.util.DateLocale['en-AU'] = YAHOO.lang.merge(YAHOO.util.DateLocale['en']);
  2723. })();
  2724. YAHOO.register("datasource", YAHOO.util.DataSource, {version: "2.8.0r4", build: "2449"});