fragments.js 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: cpscrn
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2022
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. //
  9. //
  10. /*
  11. * Global objects:
  12. * _F_Ajax : Allows AJAX calls back to IBM Cognos gateway or web content.
  13. * _F_Config : Configuration (browser, XMLHttpRequest, URI, etc.)
  14. * _F_Document : Allows high-level modification of the HTML document.
  15. * _F_DOM : Helper functions for reading XML document.
  16. * _F_Drag : Drag & Drop functionality
  17. * _F_Event : Event module
  18. * _F_Form : Form helper functions
  19. * _F_Queue : Queue and runable management
  20. * _F_Resource : Resource loading (LINK & SCRIPT)
  21. * _F_Strings : String helper functions
  22. */
  23. /**
  24. * _F_Config : Configuration (browser, XMLHttpRequest, URI, etc.)
  25. */
  26. _F_Config =
  27. {
  28. origObj: window._F_Config !== undefined? window._F_Config : null,
  29. version: (window._F_Config !== undefined && window._F_Config.version !== undefined)? window._F_Config.version: "1.0.2",
  30. browser: "unknown",
  31. browserVersion: "unknown",
  32. OS: "unknown",
  33. enableLog: false,
  34. xmlHttpDefault: null,
  35. webContent: (window._F_Config !== undefined && window._F_Config.webContent !== undefined)? window._F_Config.webContent:null,
  36. gateway: (window._F_Config !== undefined && window._F_Config.gateway !== undefined)? window._F_Config.gateway:null,
  37. application: (window._F_Config !== undefined && window._F_Config.application !== undefined)? window._F_Config.application:null,
  38. help: (window._F_Config !== undefined && window._F_Config.help !== undefined)? window._F_Config.help:null,
  39. responsePattern: (window._F_Config !== undefined && window._F_Config.responsePattern !== undefined)? window._F_Config.responsePattern:null,
  40. cookieSecure: (window._F_Config !== undefined && window._F_Config.cookieSecure !== undefined)? window._F_Config.cookieSecure:null,
  41. initialize: function()
  42. {
  43. this.browser = this.lookup(this.browsers).toLowerCase() || "unknown";
  44. this.browserVersion = this.parseVersion(navigator.userAgent) || this.parseVersion(navigator.appVersion) || "unknown";
  45. this.OS = this.lookup(this.systems) || "unknown";
  46. this.xmlHttpDefault = this.findXMLHttpActiveXVersion();
  47. if (this.origObj != null){
  48. for (var key in this.origObj){
  49. if ((this[key] === undefined)&& !(this.origObj[key] instanceof Function)){
  50. this[key] = this.origObj[key];
  51. }
  52. }
  53. delete this.origObj;
  54. }
  55. // create authtoken
  56. if(window.CAMAuthenticityTokenSession){
  57. var authTokenSession = new CAMAuthenticityTokenSession();
  58. this.authToken = authTokenSession.generate();
  59. }
  60. },
  61. getSecure: function()
  62. {
  63. if (this.cookieSecure === 'true') {
  64. return true;
  65. }
  66. return null;
  67. },
  68. /**
  69. * Expands the $CGI$ and $WEB$ macros to their configured values or values passed in the params parameter
  70. * E.g. $CGI$/dashboard?x=1 ==> /cognos8/cgi-bin/cognos.cgi
  71. * @param text usually an url
  72. * @param params an associative array containing values to replace the macros with. This param is optional
  73. */
  74. expandMacros: function(text, params)
  75. {
  76. var theGateway = this.gateway;
  77. var theWebContent = this.webContent;
  78. var theProductLocale = this.productLocale;
  79. var theSkin = this.skin;
  80. if (typeof params !== 'undefined'){
  81. if (typeof params.gateway !== 'undefined'){
  82. theGateway = params.gateway;
  83. }
  84. if (typeof params.webContent !== 'undefined'){
  85. theWebContent = params.webContent;
  86. }
  87. if (typeof params.productLocale !== 'undefined'){
  88. theProductLocale = params.productLocale;
  89. }
  90. if (typeof params.skin !== 'undefined'){
  91. theSkin = params.skin;
  92. }
  93. }
  94. return text.replace(/\$CGI\$/g, theGateway).replace(/\$WEB\$/g, theWebContent).replace(/\$PRODUCT_LOCALE\$/g, theProductLocale).replace(/\$SKIN\$/g, theSkin);
  95. },
  96. /**
  97. * Builds a url to the gateway.
  98. * @param uri (e.g. /xts.run?m=/portal/main.xts)
  99. */
  100. buildGatewayURI: function(uri)
  101. {
  102. return this.gateway + (uri||"");
  103. },
  104. /**
  105. * Builds a url to an fragment application.
  106. * @param app (e.g. "/dashboard") if not specified, _F_Config.application will be used.
  107. * @param uri (e.g. "/pages/dashboard.xml)
  108. */
  109. buildApplicationURI: function(app, uri)
  110. {
  111. return this.gateway + (app||this.application) + (uri||"");
  112. },
  113. /**
  114. * Builds a url to a web content resource.
  115. * @param uri
  116. */
  117. buildWebContentURI: function(uri)
  118. {
  119. return this.webContent + (uri||"");
  120. },
  121. lookup: function(data)
  122. {
  123. var i, l = data.length;
  124. for (i = 0; i < l; i++)
  125. {
  126. this.versionKey = data[i].partialKey || data[i].identity;
  127. var agent = data[i].agent;
  128. if (agent) {
  129. if (agent.indexOf(data[i].key) != -1) {
  130. return data[i].identity;
  131. }
  132. } else if (data[i].prop) {
  133. return data[i].identity;
  134. }
  135. }
  136. },
  137. parseVersion: function(s)
  138. {
  139. var index = s.indexOf(this.versionKey);
  140. if (index == -1) {
  141. return;
  142. }
  143. return parseFloat(s.substring(index + this.versionKey.length + 1).replace(/[^\d\.\-\+]/g, '_')); //sanitize before parse to avoid XSS vulnerability!
  144. },
  145. findXMLHttpActiveXVersion: function()
  146. {
  147. if (window.ActiveXObject || "ActiveXObject" in window)
  148. {
  149. var i, l = this.xmlHttpVersions.length;
  150. for (i = 0; i < l; i++)
  151. {
  152. try
  153. {
  154. // Try and create the ActiveXObject for Internet Explorer, if it doesn't work, try again.
  155. var xmlhttp = new ActiveXObject(this.xmlHttpVersions[i]);
  156. if (xmlhttp) {
  157. return this.xmlHttpVersions[i];
  158. }
  159. }
  160. catch (e)
  161. {
  162. // this ActiveX is not there, continue with next one in list
  163. }
  164. }
  165. }
  166. return null;
  167. },
  168. emptyFunction: function() {},
  169. browsers: [
  170. { agent: navigator.userAgent, key: "MSIE", identity: "Explorer", partialKey: "MSIE" },
  171. { agent: navigator.userAgent, key: "Firefox", identity: "Firefox" },
  172. { agent: navigator.userAgent, key: "Gecko", identity: "Mozilla", partialKey: "rv" },
  173. { agent: navigator.userAgent, key: "Mozilla", identity: "Netscape", partialKey: "Mozilla" },
  174. { agent: navigator.userAgent, key: "Netscape", identity: "Netscape" },
  175. { prop: window.opera, identity: "Opera" },
  176. { agent: navigator.vendor, key: "Apple", identity: "Safari" }
  177. ],
  178. systems: [
  179. { agent: navigator.platform, key: "Win", identity: "Windows" },
  180. { agent: navigator.platform, key: "Mac", identity: "Mac" },
  181. { agent: navigator.platform, key: "Linux", identity: "Linux" }
  182. ],
  183. xmlHttpVersions: [
  184. "Msxml2.XMLHTTP.6.0",
  185. "Msxml2.XMLHTTP.3.0",
  186. "Msxml2.XMLHTTP",
  187. "Microsoft.XMLHTTP"
  188. ]
  189. };
  190. /**
  191. * @deprecated: use _F_Config variable
  192. */
  193. var _F_config = _F_Config;
  194. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  195. // utility functions
  196. function $()
  197. {
  198. var element;
  199. if (arguments.length == 1) {
  200. element = arguments[0];
  201. if (typeof element == 'string') {
  202. return document.getElementById(element);
  203. }
  204. return element;
  205. } else {
  206. var elements = [];
  207. var i, l = arguments.length;
  208. for (i = 0; i < l; i++) {
  209. element = arguments[i];
  210. if (typeof element == 'string') {
  211. element = document.getElementById(element);
  212. }
  213. elements.push(element);
  214. }
  215. return elements;
  216. }
  217. }
  218. /**
  219. * _F_Strings : String helper functions
  220. */
  221. var _F_Strings =
  222. {
  223. normalize: function(text)
  224. {
  225. if (text == null) {
  226. return null;
  227. }
  228. // remove whitespace at beginning and end of the string and
  229. // replace multiple whitespace characters with a single space
  230. return text.replace(/^\s*|\s*$/g,"").replace(/\s+/g," ");
  231. },
  232. urlEncode: function(text)
  233. {
  234. return encodeURIComponent(text);
  235. },
  236. urlDecode: function(text)
  237. {
  238. return decodeURIComponent(text);
  239. },
  240. htmlEncode: function(text)
  241. {
  242. return text
  243. .replace(/\&/g, "&amp;")
  244. .replace(/</g, "&lt;")
  245. .replace(/>/g, "&gt;");
  246. },
  247. htmlDecode: function(text)
  248. {
  249. return text
  250. .replace(/\&lt;/g, '<')
  251. .replace(/\&gt;/g, '>')
  252. .replace(/\&amp;/g, '&');
  253. },
  254. xmlEncode: function(text)
  255. {
  256. return text
  257. .replace(/\&/g, "&amp;")
  258. .replace(/</g, "&lt;");
  259. },
  260. xmlDecode: function(text)
  261. {
  262. return text
  263. .replace(/\&lt;/g, "<")
  264. .replace(/\&gt;/g, ">")
  265. .replace(/\&apos;/g, "'")
  266. .replace(/\&quot;/g, '"')
  267. .replace(/\&amp;/g, "&");
  268. }
  269. };
  270. /**
  271. * @deprecated: use _F_Strings.urlEncode()
  272. */
  273. function urlEncode(text)
  274. {
  275. _F_log("W", "DEPRECATED FUNCTION: urlEncode --> _F_Strings.urlEncode");
  276. return _F_Strings.urlEncode(text);
  277. }
  278. /**
  279. * @deprecated: use _F_Strings.htmlEncode()
  280. */
  281. function htmlEncode(text)
  282. {
  283. _F_log("W", "DEPRECATED FUNCTION: htmlEncode --> _F_Strings.htmlEncode");
  284. return _F_Strings.htmlEncode(text);
  285. }
  286. /**
  287. * @deprecated: use _F_Strings.xmlEncode()
  288. */
  289. function xmlEncode(text)
  290. {
  291. _F_log("W", "DEPRECATED FUNCTION: xmlEncode --> _F_Strings.xmlEncode");
  292. return _F_Strings.xmlEncode(text);
  293. }
  294. /**
  295. * @deprecated: use _F_Strings.normalize()
  296. */
  297. function _F_strip(str)
  298. {
  299. _F_log("W", "DEPRECATED FUNCTION: _F_strip --> _F_Strings.normalize");
  300. return _F_Strings.normalize(str);
  301. }
  302. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  303. // Additional Array features
  304. var _F_Array =
  305. {
  306. indexOf: function(array, value, begin, strict)
  307. {
  308. for (var i = +begin || 0, l = array.length; i < l; i++) {
  309. if (array[i] === value || strict && array[i] == value) {
  310. return i;
  311. }
  312. }
  313. return -1;
  314. },
  315. unique: function (array, strict)
  316. {
  317. var a = [], i, l = array.length;
  318. for (i = 0; i < l; i++) {
  319. if (this.indexOf(a, array[i], 0, strict) < 0) {
  320. a.push(array[i]);
  321. }
  322. }
  323. return a;
  324. },
  325. forEach: function(array, func, thisArg)
  326. {
  327. if (typeof func == "function") {
  328. var i, v, l = array.length;
  329. if (thisArg === undefined) {
  330. for (i = 0; i < l; i++) {
  331. func(array[i]);
  332. }
  333. } else {
  334. for (i = 0; i < l; i++) {
  335. func.call(thisArg, array[i]);
  336. }
  337. }
  338. }
  339. },
  340. insert: function(array, i, obj)
  341. {
  342. if (i !== undefined && obj !==undefined) {
  343. array.splice(i, 0, obj);
  344. }
  345. },
  346. remove: function(array, obj)
  347. {
  348. if (obj !== undefined)
  349. {
  350. var i = this.indexOf(array, obj);
  351. if (i >= 0)
  352. {
  353. array.splice(i, 1);
  354. return obj;
  355. }
  356. }
  357. return null;
  358. },
  359. removeAt: function(array, i)
  360. {
  361. if (i !== undefined) {
  362. array.splice(i, 1);
  363. }
  364. }
  365. };
  366. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  367. // client-side logging functions
  368. function _F_log(type, msg)
  369. {
  370. if (!_F_Config.enableLog) {
  371. return;
  372. }
  373. // Check for Firefox's Firebug extension
  374. if (window.console !== undefined)
  375. {
  376. //Builing params array without the debug key.
  377. var params = [];
  378. for (var i=1; i < arguments.length; i++)
  379. {
  380. params[i-1] = arguments[i];
  381. }
  382. switch (type)
  383. {
  384. case undefined:
  385. break;
  386. case "W":
  387. console.warn.apply(console, params);
  388. break;
  389. case "E":
  390. console.error.apply(console, params);
  391. break;
  392. case "I":
  393. console.info.apply(console, params);
  394. break;
  395. case "D":
  396. case "L":
  397. default:
  398. console.debug.apply(console, params);
  399. break;
  400. }
  401. }
  402. else
  403. {
  404. // basic status logger:
  405. switch (type)
  406. {
  407. case undefined:
  408. window.status = "";
  409. break;
  410. case "W":
  411. window.status = "WARNING: " + msg;
  412. break;
  413. case "E":
  414. window.status = "ERROR: " + msg;
  415. break;
  416. case "I":
  417. window.status = "INFO: " + msg;
  418. break;
  419. case "D":
  420. default:
  421. window.status = "DEBUG: " + msg;
  422. break;
  423. }
  424. }
  425. }
  426. function _F_alert(msg, title)
  427. {
  428. if (title != null) {
  429. window.alert(title + "\n\n" + msg);
  430. } else {
  431. window.alert(msg);
  432. }
  433. }
  434. /**
  435. * _F_Resource : Resource loading (LINK & SCRIPT)
  436. */
  437. var _F_Resource =
  438. {
  439. loaded: [],
  440. initialize: function()
  441. {
  442. var nodes = document.getElementsByTagName("SCRIPT");
  443. var l = nodes.length;
  444. var i = 0, j=0;
  445. var attrs;
  446. for (i = 0; i < l; i++)
  447. {
  448. attrs = nodes[i].attributes;
  449. for (j = 0; j < attrs.length; j++) {
  450. if (attrs[j].nodeName == "src")
  451. {
  452. this.loaded.push(attrs[j].nodeValue);
  453. break;
  454. }
  455. }
  456. }
  457. nodes = document.getElementsByTagName("LINK");
  458. l = nodes.length;
  459. for (i = 0; i < l; i++)
  460. {
  461. attrs = nodes[i].attributes;
  462. for (j = 0; j < attrs.length; j++) {
  463. if (attrs[j].nodeName == "href")
  464. {
  465. this.loaded.push(attrs[j].nodeValue);
  466. break;
  467. }
  468. }
  469. }
  470. },
  471. loadResource: function(tagName, href, arg1)
  472. {
  473. if (_F_Array.indexOf(this.loaded, href) == -1)
  474. {
  475. tagName = tagName.toUpperCase();
  476. var head = document.getElementsByTagName('HEAD').item(0);
  477. var node = document.createElement(tagName);
  478. var _self = this;
  479. switch (tagName)
  480. {
  481. case "SCRIPT":
  482. node.onload = node.onreadystatechange = function()
  483. {
  484. if (this.readyState && this.readyState != 'loaded' && this.readyState != 'complete') {
  485. return;
  486. }
  487. if (_F_Array.indexOf(_self.loaded, href) != -1) {
  488. return;
  489. }
  490. _self.loaded.push(href);
  491. _F_runQueue.resume();
  492. };
  493. node.type = 'text/javascript';
  494. node.src = href;
  495. head.appendChild(node);
  496. break;
  497. case "LINK":
  498. var cssLoaded = function () {
  499. if (_F_Array.indexOf(_self.loaded, href) != -1) {
  500. // For a CSS file that has import(s), multiple callbacks are possible - which can cause
  501. // synchronization issues when loading script resources - especially in IE.
  502. // This code ensures 'spurious' callbacks are ignored.
  503. return;
  504. }
  505. _self.loaded.push(href);
  506. _F_runQueue.resume();
  507. }
  508. if (xIE4Up) {
  509. // Only IE support the onload event for loading CSS
  510. node.onload = function(){
  511. cssLoaded();
  512. };
  513. }
  514. node.type = 'text/css';
  515. node.rel = "stylesheet";
  516. if (arg1 != null && arg1 != "") {
  517. node.media = arg1;
  518. }
  519. node.href = href;
  520. head.appendChild(node);
  521. if (!xIE4Up) {
  522. // Browser other than IE do not support the onload event for CSS loading.
  523. // In this case, we simply poll and check when it's loaded
  524. var cssId = "css_" +(new Date).getTime();
  525. node.id = cssId;
  526. var count = 0;
  527. var checkCSS = function() {
  528. if (count > 250){
  529. cssLoaded();
  530. return;
  531. }
  532. try {
  533. for(var i = 0; i < document.styleSheets.length; i++) {
  534. if(document.styleSheets[i].ownerNode.id == cssId) {
  535. document.styleSheets[i].cssRules;
  536. cssLoaded();
  537. return;
  538. }
  539. }
  540. } catch(e) {
  541. //swallow any exception and just fall through to trying again
  542. //since firefox throws exception...but safari does not
  543. }
  544. count++;
  545. window.setTimeout(checkCSS, 50);
  546. }
  547. checkCSS();
  548. }
  549. break;
  550. default:
  551. _F_log("E", "unsupported tag named: " + tagName);
  552. break;
  553. }
  554. // indicate to stop the run of the queue
  555. return true;
  556. }
  557. return false;
  558. }
  559. };
  560. /**
  561. * _F_Ajax : Allows AJAX calls back to IBM Cognos gateway or web content.
  562. *
  563. * The url is absolute to the web server. Two macros are supported to ease the url construction:
  564. * - $WEB$ is replaced by the web content root.
  565. * - $CGI$ is replaced by the gateway.
  566. *
  567. * Usage:
  568. * <pre>
  569. * var x = new _F_Ajax.Request( "$CGI$/xts.run",
  570. * {
  571. * method: "get",
  572. * parameters: { m: "/read.xts", path: "/content" },
  573. * onSuccess: function(transport) { jscode },
  574. * onFailure: function() { jscode },
  575. * });
  576. * </pre>
  577. *
  578. * Options are:
  579. * asynchronous(true) : Determines whether XMLHttpRequest is used asynchronously or not.
  580. * contentType("application/x-www-form-urlencoded") : The Content-Type header for the request.
  581. * encoding("UTF-8") : The encoding of the request contents.
  582. * method("post") : The HTTP method to use for the request.
  583. * parameters(hash-object) : The parameters for the request, which will be encoded into the URL for a 'get' method, or into the request body for the other methods.
  584. * postBody(null) : Specific contents for the request body on a 'post' method. If it is not provided, the contents of the parameters option will be used instead.
  585. * requestHeaders(hash-object) : Request headers as an object, with properties representing headers.
  586. * onSuccess(function) : Invoked when a request completes and its status code is undefined or belongs in the 2xy family.
  587. * onFailure(function) : Invoked when a request completes and its status code exists but is not in the 2xy family.
  588. * onException(function) : Triggered whenever an XMLHttpRequest error arises.
  589. */
  590. var _F_Ajax =
  591. {
  592. getTransport: function()
  593. {
  594. if (_F_Config.xmlHttpDefault != null) {
  595. return new ActiveXObject(_F_Config.xmlHttpDefault);
  596. }
  597. // Well if there is no ActiveXObject available it must be firefox, opera, or something else
  598. if (typeof XMLHttpRequest != 'undefined')
  599. {
  600. try
  601. {
  602. return new XMLHttpRequest();
  603. }
  604. catch (e)
  605. {
  606. _F_alert(e);
  607. }
  608. }
  609. throw "No XMLHttpRequest object is available";
  610. }
  611. };
  612. /**
  613. * Creates a request object.
  614. * @param url - (mandatory) target url (may contains macros).
  615. * @param options - (mandatory) request's options.
  616. */
  617. _F_Ajax.Request = function(url, options, caller)
  618. {
  619. try
  620. {
  621. var asynchronous = (options.asynchronous !== undefined) ? options.asynchronous : true;
  622. var contentType = options.contentType || "application/x-www-form-urlencoded";
  623. var encoding = options.encoding;
  624. var method = (options.method || "post").toLowerCase();
  625. var params = "";
  626. var parts = [];
  627. // replace the supported macros
  628. url = _F_Config.expandMacros(url);
  629. if (typeof options.parameters == "object")
  630. {
  631. for (var p in options.parameters)
  632. {
  633. var value = options.parameters[p];
  634. parts.push(encodeURIComponent(p) + '=' + ((value != null) ? encodeURIComponent(value) : ''));
  635. }
  636. params = parts.join('&');
  637. if (params != "")
  638. {
  639. url += ((url.indexOf('?') >= 0) ? '&' : '?') + params;
  640. params = "";
  641. }
  642. }
  643. if ((method == "post" || method == "put") && (options.postBody === undefined))
  644. {
  645. parts = url.split('?');
  646. url = parts[0];
  647. params = parts[1];
  648. }
  649. this.transport = _F_Ajax.getTransport();
  650. this.transport.open(method.toUpperCase(), url, asynchronous);
  651. var headers =
  652. {
  653. "X-Fragment-Version": _F_Config.version,
  654. "X-Controller-Agent": "fragment/" + _F_Config.version,
  655. "Accept": "text/javascript, text/html, application/xml, text/xml, */*"
  656. };
  657. if (method == 'post') {
  658. headers['Content-Type'] = contentType + (encoding ? '; charset=' + encoding : '');
  659. // XSRF-TOKEN cookie is null when disableXSRFCheck=true in bootstrap.properties.
  660. var xsrfTokenCookie = _F_Document.getCookie("XSRF-TOKEN");
  661. if (xsrfTokenCookie) {
  662. headers['X-XSRF-TOKEN'] = xsrfTokenCookie;
  663. }
  664. }
  665. for (var rh in options.requestHeaders) {
  666. headers[rh] = options.requestHeaders[rh];
  667. }
  668. for (var h in headers) {
  669. this.transport.setRequestHeader(h, headers[h]);
  670. }
  671. if (asynchronous)
  672. {
  673. var _self = this;
  674. this.transport.onreadystatechange = function()
  675. {
  676. try
  677. {
  678. if (_self.transport.readyState == 4)
  679. {
  680. if (_self.transport.status >= 200 && _self.transport.status < 300)
  681. {
  682. if (typeof options.onSuccess == "function") {
  683. options.onSuccess.call(_self, _self.transport);
  684. }
  685. }
  686. else
  687. {
  688. if (typeof options.onFailure == "function") {
  689. options.onFailure.call(_self, _self.transport);
  690. }
  691. }
  692. // fix for IE memory leak
  693. _self.transport.onreadystatechange = _F_Config.emptyFunction;
  694. }
  695. }
  696. catch (e)
  697. {
  698. try
  699. {
  700. if (typeof options.onException == "function") {
  701. if (this.status !== 0) {
  702. options.onException.call(this, e);
  703. }
  704. }
  705. }
  706. catch (e1)
  707. {
  708. _F_alert(e1);
  709. }
  710. }
  711. }; // of function
  712. }
  713. this.transport.send(options.postBody || params);
  714. if (!asynchronous)
  715. {
  716. try
  717. {
  718. if (this.transport.status >= 200 && this.transport.status < 300)
  719. {
  720. if (typeof options.onSuccess == "function") {
  721. options.onSuccess.call(this, this.transport);
  722. }
  723. }
  724. else
  725. {
  726. if (typeof options.onFailure == "function") {
  727. options.onFailure.call(this, this.transport);
  728. }
  729. }
  730. }
  731. catch (e)
  732. {
  733. try
  734. {
  735. if (typeof options.onException == "function") {
  736. options.onException.call(this, e);
  737. }
  738. }
  739. catch (e1)
  740. {
  741. _F_alert(e1);
  742. }
  743. }
  744. }
  745. }
  746. catch (e2)
  747. {
  748. try
  749. {
  750. if (typeof options.onException == "function") {
  751. options.onException.call(this, e2);
  752. }
  753. }
  754. catch (e3)
  755. {
  756. _F_alert(e3);
  757. }
  758. this.transport.abort();
  759. }
  760. };
  761. _F_Ajax.Request.prototype =
  762. {
  763. getHeader: function(name)
  764. {
  765. try
  766. {
  767. return this.transport.getResponseHeader(name);
  768. }
  769. catch (e)
  770. {
  771. return null;
  772. }
  773. },
  774. getResponseXml: function () {
  775. var responseXML = null;
  776. if (this.transport.status === 200) {
  777. if ("ActiveXObject" in window) {
  778. responseXML = new ActiveXObject("Microsoft.XMLDOM");
  779. responseXML.async = "false";
  780. responseXML.loadXML(this.transport.responseText);
  781. } else {
  782. var parser = new DOMParser();
  783. responseXML = parser.parseFromString(this.transport.responseText, "text/xml");
  784. }
  785. }
  786. return responseXML;
  787. },
  788. getResponseText: function()
  789. {
  790. return (this.transport.status === 200) ? this.transport.responseText : null;
  791. },
  792. getStatus: function()
  793. {
  794. return this.transport.status;
  795. }
  796. };
  797. /**
  798. * _F_Document : Allows high-level modification of the HTML document.
  799. */
  800. var _F_Document =
  801. {
  802. associate: function (target, obj, methodName)
  803. {
  804. return function(e)
  805. {
  806. e = e||window.event;
  807. return obj[methodName](e, target);
  808. };
  809. },
  810. addEventListener: function (node, type, callback, capture)
  811. {
  812. type = type.toLowerCase();
  813. if (node.addEventListener) {
  814. node.addEventListener(type, callback, capture);
  815. } else if (node.attachEvent) {
  816. node.attachEvent('on' + type, callback);
  817. } else {
  818. node['on' + type] = callback;
  819. }
  820. },
  821. buildHeadTagId: function(id, tagName)
  822. {
  823. return (id + tagName.toLowerCase() + "s");
  824. },
  825. addHeadTag: function(tagName, text, id)
  826. {
  827. try
  828. {
  829. var head = document.getElementsByTagName('HEAD').item(0);
  830. var domTag, domText;
  831. if (id)
  832. {
  833. domTag = $(id);
  834. if (domTag && domTag.parentNode == head) {
  835. head.removeChild(domTag);
  836. }
  837. }
  838. tagName = tagName.toUpperCase();
  839. domTag = document.createElement(tagName);
  840. if (id) {
  841. domTag.id = id;
  842. }
  843. if (tagName == 'SCRIPT')
  844. {
  845. domTag.type = 'text/javascript';
  846. domTag.text = text;
  847. }
  848. else if (tagName == 'STYLE')
  849. {
  850. domTag.type = 'text/css';
  851. if (domTag.styleSheet)
  852. {
  853. domTag.styleSheet.cssText = text;
  854. }
  855. else
  856. {
  857. domText = document.createTextNode(text);
  858. domTag.appendChild(domText);
  859. }
  860. }
  861. else
  862. {
  863. domText = document.createTextNode(text);
  864. domTag.appendChild(domText);
  865. }
  866. head.appendChild(domTag);
  867. }
  868. catch (e)
  869. {
  870. _F_log("E", e);
  871. }
  872. },
  873. removeHeadTag: function(id)
  874. {
  875. if (id)
  876. {
  877. var head = document.getElementsByTagName('HEAD').item(0);
  878. var domTag = $(id);
  879. if (domTag && domTag.parentNode == head) {
  880. head.removeChild(domTag);
  881. }
  882. domtag = null;
  883. }
  884. },
  885. extractTagText: function(text, tagName)
  886. {
  887. var lowerText = text.toLowerCase();
  888. tagName = tagName.toLowerCase();
  889. var fromIndex = lowerText.indexOf("<" + tagName);
  890. if (fromIndex == -1) {
  891. return "";
  892. }
  893. // skip attributes
  894. fromIndex = lowerText.indexOf(">", fromIndex + tagName.length + 1);
  895. if (fromIndex == -1) {
  896. return "";
  897. }
  898. fromIndex++;
  899. var toIndex = lowerText.indexOf("</" + tagName + ">", fromIndex);
  900. if (toIndex == -1) {
  901. return "";
  902. }
  903. return text.substring(fromIndex, toIndex);
  904. },
  905. addHeadUniqueTag: function(parts, id, tagName)
  906. {
  907. if (parts)
  908. {
  909. var combinedParts = "";
  910. var i, l = parts.length;
  911. for (i = 0; i < l; i++) {
  912. combinedParts += this.extractTagText(parts[i], tagName);
  913. }
  914. if (combinedParts != "") {
  915. this.addHeadTag(tagName, combinedParts, this.buildHeadTagId(id, tagName));
  916. }
  917. }
  918. },
  919. getCookie: function(name)
  920. {
  921. var value = null;
  922. if (document.cookie.length > 0)
  923. {
  924. var search = name + "=";
  925. var index = document.cookie.indexOf(search);
  926. if (index != -1)
  927. {
  928. var start = index + search.length;
  929. var end = document.cookie.indexOf(";", start);
  930. if (end == -1) {
  931. end = document.cookie.length;
  932. }
  933. value = unescape(document.cookie.substring(start, end));
  934. }
  935. }
  936. return value;
  937. },
  938. setCookie: function(name, value, expires, path, domain, secure)
  939. {
  940. if (typeof expires == "number")
  941. {
  942. expires = new Date(new Date().getTime() + (1000 * expires));
  943. }
  944. if (!secure) {
  945. secure = _F_Config.getSecure();
  946. }
  947. document.cookie = name + "=" + value +
  948. ((expires) ? "; expires=" + expires.toGMTString() : "") +
  949. ((path) ? "; path=" + path : "") +
  950. ((domain) ? "; domain=" + domain : "") +
  951. ((secure) ? "; secure" : "");
  952. },
  953. getTextContent: function(obj){
  954. if (obj.innerText) {
  955. return obj.innerText;
  956. }
  957. else if (obj.textContent) {
  958. return obj.textContent;
  959. }
  960. else {
  961. return "";
  962. }
  963. },
  964. parseXml: function(xmlString)
  965. {
  966. var xmlDoc = findXMLHttpActiveXVersion();
  967. if (xmlDoc) {
  968. xmlDoc.async="false";
  969. xmlDoc.loadXML(xmlString);
  970. } else {
  971. var parser = new DOMParser();
  972. xmlDoc = parser.parseFromString(xmlString,"text/xml");
  973. }
  974. return xmlDoc;
  975. }
  976. };
  977. /**
  978. * _F_DOM : Helper functions for reading XML document.
  979. */
  980. var _F_DOM =
  981. {
  982. selectNodes: function(node, xpath)
  983. {
  984. var arr = [];
  985. var doc = (node.ownerDocument) ? node.ownerDocument : node;
  986. if(doc.evaluate) {
  987. var results = doc.evaluate(xpath, node, doc.createNSResolver(doc.documentElement), XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
  988. if (results)
  989. {
  990. node = results.iterateNext();
  991. while (node != null)
  992. {
  993. arr.push(node);
  994. node = results.iterateNext();
  995. }
  996. return arr;
  997. }
  998. }
  999. else if('all' in document && 'selectNodes' in node) {
  1000. var nodes = node.selectNodes(xpath);
  1001. var i, l = nodes.length;
  1002. for (i=0; i<l; i++)
  1003. {
  1004. arr.push(nodes.item(i));
  1005. }
  1006. return arr;
  1007. }
  1008. return null;
  1009. },
  1010. selectSingleNode: function (node, xpath)
  1011. {
  1012. var doc = (node.ownerDocument) ? node.ownerDocument : node;
  1013. if (doc.evaluate) {
  1014. var results = doc.evaluate(xpath, node, doc.createNSResolver(doc.documentElement), XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  1015. if (results && results.singleNodeValue) {
  1016. return results.singleNodeValue;
  1017. }
  1018. return null;
  1019. }
  1020. else if ('all' in document && 'selectSingleNode' in node) {
  1021. return node.selectSingleNode(xpath);
  1022. }
  1023. return null;
  1024. },
  1025. getAttribute: function(node, name)
  1026. {
  1027. return node.getAttribute(name);
  1028. },
  1029. text: function(node)
  1030. {
  1031. function deepScanText(node)
  1032. {
  1033. var v = "";
  1034. var n = node.firstChild;
  1035. while (n != null)
  1036. {
  1037. if (n.nodeType == 3) {
  1038. v += n.nodeValue;
  1039. }
  1040. else if (n.nodeType == 4) {
  1041. v += n.data;
  1042. }
  1043. else if (n.nodeType == 1) {
  1044. v += deepScanText(n);
  1045. }
  1046. n = n.nextSibling;
  1047. }
  1048. return v;
  1049. }
  1050. if (node == null || node === undefined) {
  1051. return "";
  1052. }
  1053. if (document.all) {
  1054. return node.text;
  1055. }
  1056. else if (node.nodeValue) {
  1057. return node.nodeValue;
  1058. }
  1059. return deepScanText(node);
  1060. }
  1061. };
  1062. /**
  1063. * @deprecated use _F_DOM.selectNodes()
  1064. */
  1065. function _F_DOM_selectNodes(node, xpath)
  1066. {
  1067. _F_log("W", "DEPRECATED FUNCTION: _F_DOM_selectNodes --> _F_DOM.selectNodes");
  1068. return _F_DOM.selectNodes(node, xpath);
  1069. }
  1070. /**
  1071. * @deprecated use _F_DOM.selectSingleNode()
  1072. */
  1073. function _F_DOM_selectSingleNode(node, xpath)
  1074. {
  1075. _F_log("W", "DEPRECATED FUNCTION: _F_DOM_selectSingleNode --> _F_DOM.selectSingleNode");
  1076. return _F_DOM.selectSingleNode(node, xpath);
  1077. }
  1078. /**
  1079. * @deprecated use _F_DOM.getAttribute()
  1080. */
  1081. function _F_DOM_getAttribute(node, name)
  1082. {
  1083. _F_log("W", "DEPRECATED FUNCTION: _F_DOM_getAttribute --> _F_DOM.getAttribute");
  1084. return _F_DOM.getAttribute(node, name);
  1085. }
  1086. /**
  1087. * @deprecated use _F_DOM.text()
  1088. */
  1089. function _F_DOM_text(node)
  1090. {
  1091. _F_log("W", "DEPRECATED FUNCTION: _F_DOM_text --> _F_DOM.text");
  1092. return _F_DOM.text(node);
  1093. }
  1094. /**
  1095. * _F_Form : Form helper functions
  1096. */
  1097. var _F_Form =
  1098. {
  1099. /**
  1100. * Finds a form based on its unique name (e.g. _THIS_form)
  1101. */
  1102. find: function(name)
  1103. {
  1104. return document.forms[name];
  1105. },
  1106. lookupAction: function(action)
  1107. {
  1108. var forms = document.forms;
  1109. var i, l = forms.length;
  1110. for (i = 0; i < l; i++) {
  1111. if (forms[i].action.indexOf(action) > -1) {
  1112. return forms[i];
  1113. }
  1114. }
  1115. return null;
  1116. },
  1117. getParamForInput: function(form, elem)
  1118. {
  1119. if (elem.disabled) {
  1120. return null;
  1121. }
  1122. switch (elem.type)
  1123. {
  1124. case "select-multiple":
  1125. var s = "";
  1126. var i, l = elem.options.length;
  1127. for (i = 0; i < l; i++) {
  1128. if (elem.options[i].selected)
  1129. {
  1130. if (s != "") {
  1131. s += "&";
  1132. }
  1133. s += this.getParamName(form, elem.name) + "=" + _F_Strings.urlEncode(elem.options[i].value);
  1134. }
  1135. }
  1136. if (s != "") {
  1137. return s;
  1138. }
  1139. break;
  1140. case "select-one":
  1141. if (elem.selectedIndex >= 0) {
  1142. return this.getParamName(form, elem.name) + "=" + _F_Strings.urlEncode(elem.value);
  1143. }
  1144. break;
  1145. case "radio":
  1146. case "checkbox":
  1147. if (!elem.checked) {
  1148. return null;
  1149. }
  1150. case "text":
  1151. case "textarea":
  1152. case "password":
  1153. case "hidden":
  1154. case "submit":
  1155. if (elem.value != null) {
  1156. return this.getParamName(form, elem.name) + "=" + _F_Strings.urlEncode(elem.value);
  1157. }
  1158. // all other cases, return null
  1159. case "button":
  1160. return null;
  1161. default:
  1162. _F_log("W", "unsupported input named: " + elem.name + " (" + elem.type + ")");
  1163. break;
  1164. }
  1165. return null;
  1166. },
  1167. /**
  1168. * Used to override the input names (globally).
  1169. */
  1170. getParamName: function(form, name)
  1171. {
  1172. return name;
  1173. },
  1174. getParams: function(form)
  1175. {
  1176. var s = "";
  1177. if (form != null)
  1178. {
  1179. var i, l = form.elements.length;
  1180. for (i = 0; i < l; i++)
  1181. {
  1182. var elem = form.elements[i];
  1183. if (elem.name != null && elem.name != "")
  1184. {
  1185. var param = this.getParamForInput(form, elem);
  1186. if (param != null) {
  1187. s += "&" + param;
  1188. }
  1189. }
  1190. }
  1191. }
  1192. return s;
  1193. },
  1194. getActionParams: function(action)
  1195. {
  1196. return this.getParams(this.lookupAction(action));
  1197. }
  1198. };
  1199. /**
  1200. * @deprecated use _F_Form.getParams()
  1201. */
  1202. function _F_formScan(form)
  1203. {
  1204. _F_log("W", "DEPRECATED FUNCTION: _F_formScan --> _F_Form.getParams");
  1205. return _F_Form.getParams(form);
  1206. }
  1207. /**
  1208. * @deprecated use _F_Form.getParamsForAction()
  1209. */
  1210. function _F_formParams(action)
  1211. {
  1212. _F_log("W", "DEPRECATED FUNCTION: _F_formParams --> _F_Form.getActionParams");
  1213. return _F_Form.getActionParams(action);
  1214. }
  1215. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1216. // Fragment Functions
  1217. function _F_depth(obj)
  1218. {
  1219. var p = obj.parent;
  1220. var count = 1;
  1221. while (p != null)
  1222. {
  1223. count++;
  1224. p = p.parent;
  1225. }
  1226. return count;
  1227. }
  1228. function _F_descendants(sId, sIdExclude, assoc)
  1229. {
  1230. // descendants all start with sId, excluding sId
  1231. var list = [];
  1232. for (var id in fragments)
  1233. {
  1234. if (fragments[id] != null) {
  1235. if (id.indexOf(sId) == 0 && id != sIdExclude) {
  1236. list.push(id);
  1237. }
  1238. }
  1239. }
  1240. // make sure the list is sorted on ids
  1241. list = list.sort();
  1242. var result = (assoc) ? {} : [];
  1243. var i, l=list.length;
  1244. if (assoc) {
  1245. for (i=0; i<l; i++) {
  1246. result[list[i]] = fragments[list[i]];
  1247. }
  1248. } else {
  1249. for (i=0; i<l; i++) {
  1250. result.push(fragments[list[i]]);
  1251. }
  1252. }
  1253. return result;
  1254. }
  1255. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1256. // Fragment Event Object
  1257. var _F_Event =
  1258. {
  1259. distributedEvents:
  1260. [
  1261. "fragment.load",
  1262. "fragment.unload",
  1263. "fragment.resize",
  1264. "fragment.refresh",
  1265. "fragment.visibility.change"
  1266. ],
  1267. propagatedEvents:
  1268. [
  1269. "fragment.load",
  1270. "fragment.unload",
  1271. "fragment.resize",
  1272. "fragment.refresh",
  1273. "fragment.windowstate.change",
  1274. "fragment.visibility.change"
  1275. ],
  1276. /**
  1277. * helper function that will dispatch an event to other members of a list
  1278. */
  1279. dispatch: function(list, evt, bReflected)
  1280. {
  1281. var targetIndex = _F_Array.indexOf(list, evt.target.id);
  1282. var i, l = list.length;
  1283. for (i = 0; i < l; i++)
  1284. {
  1285. if (i != targetIndex)
  1286. {
  1287. var oEvent = new _F_Event.Event();
  1288. oEvent.initEvent(evt.name, evt.type, evt.payload, evt.bubbles, evt.cancelable);
  1289. oEvent.source = evt.source;
  1290. oEvent.reflected = bReflected;
  1291. fragments[list[i]].dispatchEvent(oEvent);
  1292. oEvent = null;
  1293. }
  1294. }
  1295. },
  1296. /**
  1297. * Distribute event to a list
  1298. */
  1299. distribute: function(list, evt)
  1300. {
  1301. // ignore all reflected events
  1302. if (evt.reflected) {
  1303. return;
  1304. }
  1305. if (window._F_Debug !== undefined && evt.debugEnabled())
  1306. {
  1307. var phase = "";
  1308. switch (evt.eventPhase) { case 1: phase = "CAPTURE"; break; case 2: phase = "TARGET"; break; case 3: phase = "BUBBLE"; }
  1309. var source = evt.source ? evt.source.id : "none";
  1310. _F_Debug.log.group("eventDistributor: " + evt.name + " (" + phase + ") - id: " + evt.currentTarget.id + " src: " + source);
  1311. }
  1312. // pass-down specific fragment events if raised on distributor fragment
  1313. if (evt.eventPhase == evt.AT_TARGET && evt.name.indexOf("fragment.") == 0)
  1314. {
  1315. if (_F_Array.indexOf(this.distributedEvents, evt.name) > -1)
  1316. {
  1317. this.dispatch(list, evt, false);
  1318. }
  1319. }
  1320. else
  1321. {
  1322. // if non-fragment event fired by child of page, distribute event to other children
  1323. if (evt.name.indexOf("fragment.") != 0)
  1324. {
  1325. var targetIndex = _F_Array.indexOf(list, evt.target.id);
  1326. if (targetIndex > -1) {
  1327. this.dispatch(list, evt, true);
  1328. }
  1329. }
  1330. }
  1331. // prevent the default behaviour for fragment.refresh events targetted at an event distributor
  1332. if (evt.eventPhase == evt.AT_TARGET && "fragment.refresh" == evt.name) {
  1333. evt.preventDefault();
  1334. }
  1335. if (window._F_Debug !== undefined && evt.debugEnabled()) {
  1336. _F_Debug.log.groupEnd();
  1337. }
  1338. },
  1339. /**
  1340. * Executes the event's handler function
  1341. */
  1342. execute: function(frag, listener, evt)
  1343. {
  1344. // handle late bound functions
  1345. var func = null;
  1346. if (typeof listener[1] == "string")
  1347. {
  1348. try
  1349. {
  1350. func = eval(listener[1]);
  1351. }
  1352. catch (e)
  1353. {
  1354. }
  1355. }
  1356. else {
  1357. func = listener[1];
  1358. }
  1359. if (typeof func == "function")
  1360. {
  1361. try
  1362. {
  1363. func.call(frag, evt);
  1364. }
  1365. catch (e1)
  1366. {
  1367. _F_log("E", "Error in event handler function: " + e1 + ", function name=" + listener[1]);
  1368. }
  1369. }
  1370. else {
  1371. _F_log("E", "Expecting an event handler function, got: " + listener[1]);
  1372. }
  1373. }
  1374. };
  1375. _F_Event.Event = function()
  1376. {
  1377. this.name = "";
  1378. this.type = "";
  1379. this.payload = null;
  1380. this.source = null;
  1381. this.target = null;
  1382. this.currentTarget = null;
  1383. this.eventPhase = 0;
  1384. this.bubbles = true;
  1385. this.cancelable = true;
  1386. this.cancelled = false;
  1387. this.stopped = false;
  1388. this.timeStamp = new Date();
  1389. this.reflected = false;
  1390. };
  1391. _F_Event.Event.prototype =
  1392. {
  1393. CAPTURING_PHASE: 1,
  1394. AT_TARGET: 2,
  1395. BUBBLING_PHASE: 3,
  1396. initEvent: function(name, type, payload, canBubble, cancelable)
  1397. {
  1398. this.name = name;
  1399. this.type = type;
  1400. this.payload = payload;
  1401. this.bubbles = canBubble;
  1402. this.cancelable = cancelable;
  1403. this.cancelled = false;
  1404. this.stopped = false;
  1405. },
  1406. preventDefault: function()
  1407. {
  1408. if (this.cancelable) {
  1409. this.cancelled = true;
  1410. }
  1411. },
  1412. stopPropagation: function()
  1413. {
  1414. this.stopped = true;
  1415. }
  1416. };
  1417. /**
  1418. * @deprecated: use _F_Event.distribute()
  1419. */
  1420. function _F_eventDistributor(list, evt)
  1421. {
  1422. _F_log("W", "DEPRECATED FUNCTION: _F_eventDistributor --> _F_Event.distribute");
  1423. _F_Event.distribute(list, evt);
  1424. }
  1425. /**
  1426. * @deprecated: use fragment.proxyEvent()
  1427. */
  1428. function _F_eventProxy(evt)
  1429. {
  1430. _F_log("W", "DEPRECATED FUNCTION: _F_eventProxy --> this.proxyEvent");
  1431. this.proxyEvent(evt);
  1432. }
  1433. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1434. // Fragment Object
  1435. // associative array of all active fragments by id
  1436. var fragments = {};
  1437. function fragment(path, id, div)
  1438. {
  1439. this.id = id;
  1440. this.path = path;
  1441. this.parent = findParent(this.id);
  1442. this.div = div ? div : id + "content";
  1443. this.state = null;
  1444. this.custom = null;
  1445. this.mode = "view";
  1446. this.windowState = "normal";
  1447. this.visibility = "visible";
  1448. this.view = "";
  1449. this.transientState = {};
  1450. this.eventListeners = [];
  1451. this.modes = [];
  1452. this.windowStates = [];
  1453. this.loaded = false;
  1454. this.page = false;
  1455. this.validator = null;
  1456. this.internal = {
  1457. requestCount: 0,
  1458. locked: false,
  1459. dirty: false
  1460. };
  1461. this.addEventListener("fragment.visibility.change", this.setVisibilityEvent, false);
  1462. fragments[this.id] = this;
  1463. function findParent(sId)
  1464. {
  1465. // parent has longest subid
  1466. var frag = null;
  1467. var fraglen = 0;
  1468. for (var id in fragments)
  1469. {
  1470. var test = fragments[id];
  1471. if (test != null)
  1472. {
  1473. if (sId != test.id && sId.indexOf(test.id) == 0 && test.id.length > fraglen)
  1474. {
  1475. frag = test;
  1476. fraglen = frag.id.length;
  1477. }
  1478. }
  1479. }
  1480. return frag;
  1481. }
  1482. }
  1483. fragment.prototype =
  1484. {
  1485. getRoot: function()
  1486. {
  1487. var frag = this;
  1488. while (frag.parent) {
  1489. frag = frag.parent;
  1490. }
  1491. return frag;
  1492. },
  1493. getChildren: function()
  1494. {
  1495. var children = [];
  1496. for (var sId in fragments) {
  1497. if (fragments[sId].parent == this) {
  1498. children.push(fragments[sId]);
  1499. }
  1500. }
  1501. return children;
  1502. },
  1503. getAncestors: function()
  1504. {
  1505. var ancestors = [];
  1506. var frag = this.parent;
  1507. while (frag)
  1508. {
  1509. ancestors.push(frag);
  1510. frag = frag.parent;
  1511. }
  1512. return ancestors;
  1513. },
  1514. baseURI: function()
  1515. {
  1516. return "$CGI$" + _F_Config.application + this.path;
  1517. },
  1518. attach: function (obj)
  1519. {
  1520. for (var prop in obj) {
  1521. this[prop] = obj[prop];
  1522. }
  1523. },
  1524. encodedTransients: function()
  1525. {
  1526. var name;
  1527. var transients = {};
  1528. // add any page level trans, if they are not already included
  1529. var p = this.getPageFragment();
  1530. for (name in p.transientState) {
  1531. if (transients[name] === undefined) {
  1532. transients[name] = p.transientState[name];
  1533. }
  1534. }
  1535. // finally, add global transients, if they are not already included
  1536. for (name in this.transientGlobal) {
  1537. if (transients[name] === undefined) {
  1538. transients[name] = this.transientGlobal[name];
  1539. }
  1540. }
  1541. // assemble everything as url
  1542. var s = "";
  1543. for (name in transients) {
  1544. s += "&" + _F_Strings.urlEncode(name) + "=" + _F_Strings.urlEncode(transients[name]);
  1545. }
  1546. return s;
  1547. },
  1548. fragmentURI: function()
  1549. {
  1550. var s = "frag-id=" + this.id +
  1551. "&frag-agent=" + _F_Strings.urlEncode(navigator.userAgent) +
  1552. "&frag-mode=" + this.mode;
  1553. if (_F_config.authToken) {
  1554. s += "&frag-authToken=" + _F_Strings.urlEncode(_F_config.authToken);
  1555. }
  1556. if (this.validator != null && this.validator.remote) {
  1557. s += "&frag-validator=" + this.validator.remote;
  1558. }
  1559. if (this.loaded && this.mode != "view" && _F_Array.indexOf(this.modes, this.mode) == -1) {
  1560. s += "&frag-delegate=" + _F_Strings.urlEncode(this.mode);
  1561. }
  1562. if (this.view != "") {
  1563. s += "&frag-view=" + _F_Strings.urlEncode(this.view);
  1564. }
  1565. if (this.windowState != "") {
  1566. s += "&frag-windowState=" + _F_Strings.urlEncode(this.windowState);
  1567. }
  1568. if (this.channel !== undefined && this.channel != null) {
  1569. s += "&frag-channel=" + _F_Strings.urlEncode(this.channel);
  1570. }
  1571. // state
  1572. if (this.state != null) {
  1573. s += "&frag-state=" + _F_Strings.urlEncode(this.state);
  1574. }
  1575. // custom properties
  1576. if (this.custom != null) {
  1577. s += "&frag-custom=" + _F_Strings.urlEncode(this.custom);
  1578. }
  1579. // transient properties
  1580. s += this.encodedTransients();
  1581. if (this.customProperties != null){
  1582. var customParams = "";
  1583. for (var cp in this.customProperties){
  1584. if (customParams != "") {
  1585. customParams += "&";
  1586. }
  1587. customParams+=cp + "=" + _F_Strings.urlEncode(this.customProperties[cp]);
  1588. }
  1589. s += "&frag-customProperties=" + _F_Strings.urlEncode(customParams);
  1590. }
  1591. return s;
  1592. },
  1593. renderURI: function(excludeDescendantState)
  1594. {
  1595. var s = this.baseURI();
  1596. s += ((s.indexOf('?') >= 0) ? "&" : "?") + this.fragmentURI();
  1597. if (excludeDescendantState === undefined || excludeDescendantState == false)
  1598. {
  1599. var descendants = _F_descendants(this.id, this.id);
  1600. if (descendants)
  1601. {
  1602. for (var i=0; i < descendants.length; i++)
  1603. {
  1604. s += "&frag-sub=" + _F_Strings.urlEncode(descendants[i].fragmentURI());
  1605. }
  1606. }
  1607. }
  1608. return s;
  1609. },
  1610. interactionURI: function(sParams, excludeDescendantState)
  1611. {
  1612. if (sParams && sParams != "")
  1613. {
  1614. if (sParams.indexOf('&') != 0) {
  1615. return (this.renderURI(excludeDescendantState) + "&" + sParams);
  1616. }
  1617. else {
  1618. return (this.renderURI(excludeDescendantState) + sParams);
  1619. }
  1620. }
  1621. return this.renderURI(excludeDescendantState);
  1622. },
  1623. update: function(markup, div)
  1624. {
  1625. div = div ? div : this.div;
  1626. var divTag = $(div);
  1627. var bFullUpdate = divTag == $(this.div);
  1628. var bHasHtml = false;
  1629. if (divTag != null)
  1630. {
  1631. if (bFullUpdate) {
  1632. this.raiseEvent("fragment.unload", null, "", false, false);
  1633. }
  1634. var tempNode = document.createElement("div");
  1635. // to get around IE problem. If markup starts with script tag, no at scripts will be loaded in the DOM
  1636. tempNode.innerHTML = "<span style='display:none'>&nbsp;</span>" + markup;
  1637. tempNode.removeChild(tempNode.firstChild);
  1638. var scriptElements = tempNode.getElementsByTagName("SCRIPT");
  1639. var scripts = [];
  1640. var length = scriptElements.length;
  1641. for (var i = length - 1 ; i >= 0; i--){
  1642. scripts.unshift("<script>"+scriptElements[i].text+"</script>");
  1643. if(scriptElements[i].parentNode){
  1644. scriptElements[i].parentNode.removeChild(scriptElements[i]);
  1645. }
  1646. }
  1647. var styleElements = tempNode.getElementsByTagName("STYLE");
  1648. var styles = [];
  1649. length = styleElements.length;
  1650. for (var j = length - 1 ; j >= 0 ; j--){
  1651. styles.unshift("<style>" + styleElements[j].innerHTML +"</style>");
  1652. if(styleElements[j].parentNode){
  1653. styleElements[j].parentNode.removeChild(styleElements[j]);
  1654. }
  1655. }
  1656. // styles need to be available when html is inserted
  1657. _F_Document.addHeadUniqueTag(styles, div, 'style');
  1658. if (tempNode.childNodes){
  1659. var nodesLength = tempNode.childNodes.length;
  1660. for (var k = nodesLength - 1 ; k >= 0; k--){
  1661. if ((tempNode.childNodes[k].nodeType != 3) ||
  1662. (tempNode.childNodes[k].nodeType == 3 && tempNode.childNodes[k].nodeValue.replace(/^\s*|\s*$/g,"") != "")){
  1663. if (!bHasHtml){
  1664. divTag.innerHTML = "";
  1665. divTag.appendChild(tempNode.childNodes[k]);
  1666. bHasHtml = true;
  1667. }else{
  1668. divTag.insertBefore(tempNode.childNodes[k], divTag.firstChild);
  1669. }
  1670. }
  1671. }
  1672. }
  1673. tempNode = null;
  1674. /*
  1675. This is to get around a FF issue where the script is loaded asynchronously.
  1676. This means that the "fragment.load" event might be raised before the fragment script is evaluated.
  1677. To get around the problem, we add the code that raises the event to the fragment script.
  1678. */
  1679. if (bFullUpdate && !xIE4Up){
  1680. var loadEventScript = "<script>;fragments['"+this.id+"'].raiseEvent(\"fragment.load\", {source: \"retrieve\"}, \"\", false, false);</script>";
  1681. scripts.push(loadEventScript);
  1682. }
  1683. // html needs to be available to javascript once it is inserted
  1684. _F_Document.addHeadUniqueTag(scripts, div, 'script');
  1685. if (window._F_Debug !== undefined && this.debugEnabled())
  1686. {
  1687. _F_Debug.log.logDetails("Update innerHTML for fragment: " + this.id + "\ttitle: " + _F_Strings.normalize(this.title), this);
  1688. }
  1689. if (bFullUpdate && xIE4Up) {
  1690. this.raiseEvent("fragment.load", {source: "retrieve"}, "", false, false);
  1691. }
  1692. }
  1693. else {
  1694. _F_log("W", "target div was not found: "+div);
  1695. }
  1696. return bHasHtml;
  1697. },
  1698. performAction: function(sParams)
  1699. {
  1700. this.retrieve(sParams);
  1701. },
  1702. retrieve: function(sParams, dest, synchronous, excludeDescendantState)
  1703. {
  1704. if (!this.loaded) {
  1705. if (!sParams) {
  1706. sParams = "";
  1707. }
  1708. sParams += "&frag-action=attach";
  1709. }
  1710. if ( _F_depth(this) > 100)
  1711. {
  1712. window[this.id] = this;
  1713. fragments[this.id] = this;
  1714. this.processError("maxnestedlevels", PFM.JS.IDS_JS_ERROR_RETRIEVE, "");
  1715. return;
  1716. }
  1717. // TODO: this function is added in uicommon.js, it should be removed and replaced with events
  1718. if (this.clearerror) {
  1719. this.clearerror();
  1720. }
  1721. this.send(sParams, dest, synchronous, excludeDescendantState);
  1722. },
  1723. send: function(sParams, dest, synchronous, excludeDescendantState)
  1724. {
  1725. if (this.internal.locked > 0)
  1726. {
  1727. // don't process this send, just mark the fragment as dirty
  1728. this.internal.dirty = true;
  1729. return;
  1730. }
  1731. else
  1732. {
  1733. this.internal.dirty = false;
  1734. if (!this.raiseEvent("fragment.retrieve.before", sParams, "xsd:string"))
  1735. {
  1736. // preventDefault() was called, so invoke the "after" event
  1737. // to keep the before/after contract valid.
  1738. this.raiseEvent("fragment.retrieve.after", false, "xsd:boolean");
  1739. return;
  1740. }
  1741. }
  1742. // now we can process the request
  1743. this.setRefreshDelay(0); // cancel any pending delay
  1744. var requestCount = ++this.internal.requestCount;
  1745. var _self = this;
  1746. var requestOptions = {
  1747. requestHeaders:
  1748. {
  1749. "Connection": "keep-alive",
  1750. "Accept": "text/xml,application/xml"
  1751. },
  1752. onSuccess: function(transport)
  1753. {
  1754. // make the _THIS_ variable visible
  1755. window[_self.id] = _self;
  1756. fragments[_self.id] = _self;
  1757. if (dest == null) {
  1758. dest = _self.div;
  1759. }
  1760. if (dest == _self.div) {
  1761. if (requestCount != _self.internal.requestCount)
  1762. {
  1763. _F_log("W", "discarding expired response for fragment: "+_self.id);
  1764. _self.raiseEvent("fragment.retrieve.after", false, "xsd:boolean");
  1765. return; //out of sequence detected - discard this response!
  1766. }
  1767. }
  1768. var responseXML = this.getResponseXml();
  1769. var xmlParseError = false;
  1770. if (responseXML) {
  1771. if ((responseXML.parseError && responseXML.parseError.errorCode != 0) ||
  1772. (responseXML.documentElement && responseXML.documentElement.nodeName == "parsererror")) {
  1773. xmlParseError = true;
  1774. }
  1775. } else {
  1776. xmlParseError = true;
  1777. }
  1778. if (!xmlParseError)
  1779. {
  1780. var fragNode = _F_DOM.selectSingleNode(responseXML, "/fragment");
  1781. if (fragNode != null)
  1782. {
  1783. var list = [];
  1784. var i, l, href;
  1785. var linkNodes = _F_DOM.selectNodes(fragNode, "./css");
  1786. if (linkNodes && linkNodes.length > 0)
  1787. {
  1788. l = linkNodes.length;
  1789. for (i = 0; i < l; i++)
  1790. {
  1791. href = _F_DOM.getAttribute(linkNodes[i], "href");
  1792. var media = _F_DOM.getAttribute(linkNodes[i], "media");
  1793. list.push(["LINK", href, media]);
  1794. }
  1795. }
  1796. var librarieNodes = _F_DOM.selectNodes(fragNode, "./library");
  1797. if (librarieNodes && librarieNodes.length > 0)
  1798. {
  1799. l = librarieNodes.length;
  1800. for (i = 0; i < l; i++)
  1801. {
  1802. href = _F_DOM.getAttribute(librarieNodes[i], "href");
  1803. list.push(["SCRIPT", href]);
  1804. }
  1805. }
  1806. var processFragmentXMLFunction;
  1807. if (xIE4Up && !synchronous) {
  1808. // COGCQ0019952
  1809. processFragmentXMLFunction = function(){
  1810. var _args = arguments;
  1811. setTimeout(function(){
  1812. _self.processFragmentXML.apply(_self, _args);
  1813. }, 1);
  1814. };
  1815. } else {
  1816. processFragmentXMLFunction = _self.processFragmentXML;
  1817. }
  1818. _self.loadFragmentResources(list, processFragmentXMLFunction, fragNode, dest);
  1819. }
  1820. else
  1821. {
  1822. // check if we got an SOAP-Fault
  1823. var fault = _F_DOM.selectSingleNode(responseXML, "/*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='Fault']");
  1824. if (fault != null)
  1825. {
  1826. var code = _F_DOM.text(_F_DOM.selectSingleNode(fault, "./faultcode"));
  1827. var msg = _F_DOM.text(_F_DOM.selectSingleNode(fault, "./faultstring"));
  1828. var details = _F_DOM.text(_F_DOM.selectSingleNode(fault, "./faultdetails"));
  1829. _self.processError(code, msg, details);
  1830. }
  1831. else
  1832. {
  1833. _self.processError("unexpected", PFM.JS.IDS_JS_ERROR_UNEXPECTED_RESPONSE, "");
  1834. }
  1835. _self.raiseEvent("fragment.retrieve.after", false, "xsd:boolean");
  1836. _F_log("W", "expecting <fragment> XML for fragment: "+_self.id);
  1837. }
  1838. }
  1839. else
  1840. {
  1841. //DEBUG: error response most likely html, show it
  1842. var txt = this.getResponseText();
  1843. var ecode = _F_Document.extractTagText(txt, "ERROR_CODE");
  1844. if (ecode == "CAM_PASSPORT_ERROR")
  1845. {
  1846. // substitute the error code to an invalid passport
  1847. _self.processError("invalidCredentials", null, null);
  1848. _self.raiseEvent("fragment.retrieve.after", false, "xsd:boolean");
  1849. _F_log("W", "expecting XML, got HTML for fragment: "+_self.id);
  1850. }
  1851. else
  1852. {
  1853. var bReloadPage = false;
  1854. if (txt != null && _F_Config.responsePattern != null && _F_Config.responsePattern.length > 0)
  1855. {
  1856. var patterns = _F_Config.responsePattern.split(",");
  1857. var i, l;
  1858. var upperTxt = txt.toUpperCase();
  1859. for (i = 0, l = patterns.length; i < l; i++) {
  1860. if (patterns[i] != "" && (upperTxt.indexOf(patterns[i].toUpperCase()) != -1)) {
  1861. // Ignore the HTML response, and reload the page. This will force the same HTML response to be returned
  1862. // to this current page (presumably a 3rd party login page) and hopefully they will then redirect you back to
  1863. // the current location. (pre AJAX/fragment action)
  1864. bReloadPage = true;
  1865. location.reload();
  1866. }
  1867. }
  1868. }
  1869. if (!bReloadPage) {
  1870. // open up that HTML markup and let the end-user deal with it
  1871. var emsg = _F_Document.extractTagText(txt, "ERROR_MSG");
  1872. var edetails = _F_Document.extractTagText(txt, "ERROR_DETAILS");
  1873. _self.processError(ecode, emsg, edetails);
  1874. var w = window.open(_F_Config.webContent + "/common/blank.html", _self.id, "width=700,height=600,resizable,status=no,menubar=no,toolbar=no,location=no");
  1875. w.document.open();
  1876. w.document.write(txt);
  1877. w.document.close();
  1878. w.focus();
  1879. _self.raiseEvent("fragment.retrieve.after", false, "xsd:boolean");
  1880. _F_log("W", "expecting XML, got HTML for fragment: "+_self.id);
  1881. }
  1882. }
  1883. }
  1884. },
  1885. onFailure: function(transport)
  1886. {
  1887. _self.raiseEvent("fragment.retrieve.after", false, "xsd:boolean");
  1888. _F_log("E", "XMLHttp " + transport.status + ", " + transport.statusText);
  1889. _F_alert("#" + transport.status + "\n" + transport.statusText, _self.title);
  1890. },
  1891. onException: function(request, e)
  1892. {
  1893. _self.raiseEvent("fragment.retrieve.after", false, "xsd:boolean");
  1894. _F_alert(e, _self.title);
  1895. }
  1896. };
  1897. if (synchronous != null && synchronous == true)
  1898. {
  1899. requestOptions.asynchronous=false;
  1900. }
  1901. var fragRequest = new _F_Ajax.Request(this.interactionURI(sParams, excludeDescendantState), requestOptions, this);
  1902. },
  1903. processFragmentXML: function(fragNode, dest)
  1904. {
  1905. // respond to delay
  1906. var delayNode = _F_DOM.selectSingleNode(fragNode, "./delay");
  1907. if (delayNode)
  1908. {
  1909. var period = _F_DOM.text(_F_DOM.selectSingleNode(delayNode, "period"));
  1910. this.setRefreshDelay(period);
  1911. }
  1912. var bHasHtml = false;
  1913. if (dest !== undefined)
  1914. {
  1915. var markupNode = _F_DOM.selectSingleNode(fragNode, "./markup/markupString");
  1916. if (markupNode)
  1917. {
  1918. var markup = _F_DOM.text(markupNode);
  1919. if (markup == "" && delayNode)
  1920. {
  1921. markup = _F_DOM.text(_F_DOM.selectSingleNode(delayNode, "message"));
  1922. }
  1923. if (markup != "")
  1924. {
  1925. try
  1926. {
  1927. bHasHtml = this.update(markup, dest);
  1928. if (this.onupdate) {
  1929. this.onupdate();
  1930. }
  1931. }
  1932. catch (e)
  1933. {
  1934. _F_log("E", "execution error when updating markup for fragment: "+this.id);
  1935. }
  1936. }
  1937. else {
  1938. _F_log("W", "no markup text in markupString for fragment: "+this.id);
  1939. }
  1940. markupNode = null;
  1941. }
  1942. }
  1943. // respond to newWindow
  1944. var newWindowStateNode = _F_DOM.selectSingleNode(fragNode, "./newWindowState");
  1945. // and to newMode
  1946. var newModeNode = _F_DOM.selectSingleNode(fragNode, "./newMode");
  1947. if (newWindowStateNode || newModeNode)
  1948. {
  1949. var newWindowState = _F_DOM.text(newWindowStateNode);
  1950. var newMode = _F_DOM.text(newModeNode);
  1951. if (newWindowState != "")
  1952. {
  1953. // this markup is already using the new window state, assign it right away
  1954. this.setWindowState(newWindowState, "internal");
  1955. }
  1956. if (newMode != "")
  1957. {
  1958. // this markup is already using the new mode, assign it right away
  1959. this.setMode(newMode, "internal");
  1960. }
  1961. // check if we must reload the fragment because no html was returned.
  1962. if (!bHasHtml) {
  1963. this.setRefreshDelay(1);
  1964. }
  1965. }
  1966. // respond to validator
  1967. var validatorNode = _F_DOM.selectSingleNode(fragNode, "./validator");
  1968. if (validatorNode)
  1969. {
  1970. if (this.validator == null)
  1971. {
  1972. this.validator = {};
  1973. this.validator.remote = null;
  1974. this.validator.client = null;
  1975. }
  1976. try
  1977. {
  1978. this.validator.remote = _F_DOM.text(_F_DOM.selectSingleNode(validatorNode, "./remote"));
  1979. this.validator.client = eval(_F_DOM.text(_F_DOM.selectSingleNode(validatorNode, "./client")));
  1980. }
  1981. catch (e1)
  1982. {
  1983. this.validator = null;
  1984. _F_log("E", e1);
  1985. }
  1986. }
  1987. var preferredTitleNode = _F_DOM.selectSingleNode(fragNode, "./preferredTitle");
  1988. if (preferredTitleNode) {
  1989. this.setTitle(_F_DOM.text(preferredTitleNode));
  1990. }
  1991. else if (this.info != null) {
  1992. this.setTitle(this.info.title);
  1993. }
  1994. // respond to custom update
  1995. var i, l;
  1996. var customUpdateNode = _F_DOM.selectSingleNode(fragNode, "./customUpdate");
  1997. if (customUpdateNode)
  1998. {
  1999. var customParams = _F_DOM.selectNodes(customUpdateNode, "./param");
  2000. if(customParams && customParams.length > 0){
  2001. this.customProperties = {};
  2002. l = customParams.length;
  2003. for (i = 0; i < l; i++)
  2004. {
  2005. var paramName = _F_DOM.getAttribute(customParams[i], "name");
  2006. this.customProperties[paramName] = _F_DOM.text(customParams[i]);
  2007. }
  2008. }else{
  2009. this.customProperties = {};
  2010. this.custom = _F_DOM.text(customUpdateNode);
  2011. }
  2012. }
  2013. // respond to state update
  2014. var stateNode = _F_DOM.selectSingleNode(fragNode, "./state");
  2015. if (stateNode)
  2016. {
  2017. this.state = _F_DOM.text(stateNode);
  2018. }
  2019. // raise events
  2020. var eventNodes = _F_DOM.selectNodes(fragNode, "./event");
  2021. if (eventNodes)
  2022. {
  2023. l = eventNodes.length;
  2024. for (i = 0; i < l; i++)
  2025. {
  2026. var eventName = _F_DOM.getAttribute(eventNodes[i], "name");
  2027. var eventType = _F_DOM.getAttribute(eventNodes[i], "type");
  2028. var eventPayload = _F_DOM.selectSingleNode(eventNodes[i], "./payload");
  2029. var payload = null;
  2030. if (eventType.indexOf('params') > -1 && _F_DOM.selectSingleNode(eventPayload, "./params"))
  2031. {
  2032. var params = _F_DOM.selectNodes(eventPayload, "./params/param");
  2033. payload = {};
  2034. var j, m = params.length;
  2035. for (j = 0; j < m; j++)
  2036. {
  2037. var name = _F_DOM.getAttribute(params[j], "name");
  2038. var value = _F_DOM.text(params[j]);
  2039. payload[name] = value;
  2040. }
  2041. }
  2042. else
  2043. {
  2044. var payloadRoot = _F_DOM.selectSingleNode(eventPayload, "./*");
  2045. if (payloadRoot) {
  2046. payload = payloadRoot;
  2047. }
  2048. else {
  2049. payload = _F_DOM.text(eventPayload);
  2050. }
  2051. }
  2052. var evt = new _F_Event.Event();
  2053. evt.initEvent(eventName, eventType, payload, true, true);
  2054. evt.source = this;
  2055. this.dispatchEvent(evt);
  2056. }
  2057. }
  2058. var errorNode = _F_DOM.selectSingleNode(fragNode, "./error");
  2059. if (errorNode)
  2060. {
  2061. var code = _F_DOM.text(_F_DOM.selectSingleNode(errorNode, "code"));
  2062. var msg = _F_DOM.text(_F_DOM.selectSingleNode(errorNode, "message"));
  2063. var details = _F_DOM.text(_F_DOM.selectSingleNode(errorNode, "details"));
  2064. this.processError(code, msg, details);
  2065. }
  2066. // respond to transient updates
  2067. var transientUpdateNodes = _F_DOM.selectNodes(fragNode, "./transientUpdate");
  2068. if (transientUpdateNodes && transientUpdateNodes.length > 0)
  2069. {
  2070. var list = [];
  2071. l = transientUpdateNodes.length;
  2072. for (i = 0; i < l; i++)
  2073. {
  2074. var transUpdate = {};
  2075. transUpdate.name = _F_DOM.getAttribute(transientUpdateNodes[i], "name");
  2076. transUpdate.scope = _F_DOM.getAttribute(transientUpdateNodes[i], "scope");
  2077. transUpdate.channel = _F_DOM.getAttribute(transientUpdateNodes[i], "channel");
  2078. transUpdate.value = _F_DOM.text(transientUpdateNodes[i]);
  2079. list[i] = transUpdate;
  2080. }
  2081. this.transientUpdateList(list, true);
  2082. }
  2083. // process subfragments
  2084. var subfragmentNodes = _F_DOM.selectNodes(fragNode, "./subfragment/fragment");
  2085. if (subfragmentNodes && subfragmentNodes.length > 0)
  2086. {
  2087. l = subfragmentNodes.length;
  2088. for (i = 0; i < l; i++)
  2089. {
  2090. var fragID = _F_DOM.text(_F_DOM.selectSingleNode(subfragmentNodes[i], "./id"));
  2091. var subfrag = fragments[fragID];
  2092. if (subfrag !== undefined) {
  2093. subfrag.processFragmentXML(subfragmentNodes[i]);
  2094. }
  2095. else {
  2096. _F_log("E", "expecting fragment object for fragment id: " + fragID);
  2097. }
  2098. }
  2099. }
  2100. this.raiseEvent("fragment.retrieve.after", true, "xsd:boolean", true, false);
  2101. // don't stop the queue processing
  2102. return false;
  2103. },
  2104. loadFragmentResources: function(list, func)
  2105. {
  2106. if (window._F_Debug !== undefined && this.debugEnabled())
  2107. {
  2108. _F_Debug.log.logText("Begin _F_loadFragmentResources for id: " + this.id );
  2109. }
  2110. var args = Array.prototype.slice.call(arguments, 2);
  2111. if (list.length == 0)
  2112. {
  2113. // nothing to load, execute right away
  2114. if (typeof func == "function")
  2115. {
  2116. func.apply(this, args);
  2117. }
  2118. }
  2119. else
  2120. {
  2121. // load external files
  2122. var i, l;
  2123. for (i = 0, l = list.length; i < l; i++)
  2124. {
  2125. _F_runQueue.add(_F_Resource, _F_Resource.loadResource, list[i]);
  2126. }
  2127. if (typeof func == "function")
  2128. {
  2129. _F_runQueue.add(this, func, args);
  2130. }
  2131. // execute first in queue
  2132. _F_runQueue.run();
  2133. }
  2134. if (window._F_Debug !== undefined && this.debugEnabled())
  2135. {
  2136. _F_Debug.log.logText("End _F_loadFragmentResources for id: " + this.id);
  2137. }
  2138. },
  2139. lockUpdates: function(locked)
  2140. {
  2141. //-- Bug Fix: Firefox bug that destroys the PDF document when we hide the iframe.
  2142. // This is a firefox specific fix, referenced in firefox bug https://bugzilla.mozilla.org/show_bug.cgi?id=180802
  2143. var embedFrames = [];
  2144. function isEmbedFrame(iframe)
  2145. {
  2146. var doc = null;
  2147. try
  2148. {
  2149. doc = iframe.contentDocument.firstChild;
  2150. }
  2151. catch (e)
  2152. {
  2153. doc = null;
  2154. }
  2155. return (doc
  2156. && doc.tagName == "HTML"
  2157. && doc.firstChild.tagName == "BODY"
  2158. && doc.firstChild.firstChild.tagName == "EMBED"
  2159. && doc.firstChild.firstChild.type.indexOf("pdf") > -1);
  2160. }
  2161. function addEmbedFrame(iframe)
  2162. {
  2163. if (_F_Array.indexOf(embedFrames, iframe, 0, true) < 0) {
  2164. embedFrames.push(iframe);
  2165. }
  2166. }
  2167. function searchEmbedFrames(frag)
  2168. {
  2169. // detect firefox browser, return if not
  2170. if (_F_config.browser != "firefox") {
  2171. return false;
  2172. }
  2173. // search fragment markup for iframes
  2174. var div = $(frag.div);
  2175. if (div)
  2176. {
  2177. var iframes = div.getElementsByTagName("iframe");
  2178. // for each iframe check for embedded pdf
  2179. if (iframes)
  2180. {
  2181. var i, l = iframes.length;
  2182. for (i = 0; i < l; i++)
  2183. {
  2184. if (isEmbedFrame(iframes[i])) {
  2185. addEmbedFrame(iframes[i]);
  2186. }
  2187. }
  2188. }
  2189. }
  2190. }
  2191. function reloadEmbedFrames()
  2192. {
  2193. var i, l = embedFrames.length;
  2194. for (i = 0; i < l; i++)
  2195. {
  2196. embedFrames[i].setAttribute("src", embedFrames[i].getAttribute("src"));
  2197. }
  2198. }
  2199. //-- /Bug Fix
  2200. var list = _F_descendants(this.id);
  2201. var i, l = list.length;
  2202. if (locked)
  2203. {
  2204. for (i = 0; i < l; i++) {
  2205. list[i].internal.locked++;
  2206. }
  2207. }
  2208. else
  2209. {
  2210. var skipChildren = "";
  2211. for (i = 0; i < l; i++)
  2212. {
  2213. var frag = list[i];
  2214. if (0 <= (--frag.internal.locked))
  2215. {
  2216. frag.internal.locked = 0; // safety net
  2217. if (frag.internal.dirty)
  2218. {
  2219. if (skipChildren != "" && (0 == frag.id.indexOf(skipChildren)))
  2220. {
  2221. // the parent fragment's retrieve is already called,
  2222. // don't retrieve this child.
  2223. frag.internal.dirty = false;
  2224. continue;
  2225. }
  2226. else {
  2227. skipChildren = frag.id;
  2228. }
  2229. frag.retrieve();
  2230. }
  2231. else {
  2232. searchEmbedFrames(frag);
  2233. }
  2234. }
  2235. }
  2236. reloadEmbedFrames();
  2237. }
  2238. },
  2239. /**
  2240. * Callback function used to process logon fault.
  2241. */
  2242. processingLogon: null,
  2243. processErrorHref: function() {
  2244. return window.location.href;
  2245. },
  2246. processError: function(code, message, details)
  2247. {
  2248. if (code == "invalidCredentials")
  2249. {
  2250. if (window.handleLogon != null)
  2251. {
  2252. if (this.processingLogon == null)
  2253. {
  2254. xAddEventListener(window, "beforeunload", _F_config.emptyFunction); // hack: so onload event will be fired on cancel or back action
  2255. var dashboard_login = _F_Document.getCookie("frag_login");
  2256. if (dashboard_login == "true") {
  2257. //Simply display the error
  2258. this.onerror(message, details, code);
  2259. return;
  2260. }
  2261. _F_Document.setCookie("frag_login", "true", 60);
  2262. var _self = this;
  2263. var href = this.processErrorHref();
  2264. var rmidx = href.indexOf("#");
  2265. if (rmidx != -1) {
  2266. href = href.substring(0, rmidx);
  2267. }
  2268. window.location.replace(href + "#frag-logon"); //to mark that we're in a logon process
  2269. this.processingLogon = window.setTimeout(
  2270. function()
  2271. {
  2272. handleLogon(href, _self);
  2273. _self.processingLogon = null;
  2274. },
  2275. 10);
  2276. }
  2277. return;
  2278. }
  2279. }
  2280. this.onerror(message, details, code);
  2281. },
  2282. /**
  2283. * Calls the client validator library for one specific parameter.
  2284. * @param param
  2285. * @param value
  2286. * @return See validator.js for the meaning of the error codes
  2287. * 0 = success
  2288. * less than 0 = execution error of the validator's generated code
  2289. * greater then 0 = validation error code.
  2290. */
  2291. validate: function(param, value)
  2292. {
  2293. if (this.validator != null &&
  2294. this.validator.client != null &&
  2295. typeof this.validator.client.verify == "function")
  2296. {
  2297. return this.validator.client.verify(param, value);
  2298. }
  2299. return 0;
  2300. },
  2301. //- events
  2302. EVENT_NAME: 0,
  2303. EVENT_FUNC: 1,
  2304. EVENT_USECAP: 2,
  2305. /**
  2306. * Returns an array of indexes for matching event listeners, null if no match.
  2307. * @param name: the event's name
  2308. */
  2309. findEventListeners: function(name)
  2310. {
  2311. // note: avoid creating unnecessary array objects
  2312. var result = null;
  2313. var i, l = this.eventListeners.length;
  2314. for (i = 0; i < l; i++)
  2315. {
  2316. var sMatch = this.eventListeners[i][this.EVENT_NAME];
  2317. if (sMatch == "*")
  2318. {
  2319. if (result == null) {
  2320. result = [];
  2321. }
  2322. result.push(this.eventListeners[i]);
  2323. continue;
  2324. }
  2325. if (sMatch.indexOf(".*") == sMatch.length - 2)
  2326. {
  2327. if (name.indexOf(sMatch.substring(0, sMatch.length - 1)) == 0)
  2328. {
  2329. if (result == null) {
  2330. result = [];
  2331. }
  2332. result.push(this.eventListeners[i]);
  2333. }
  2334. }
  2335. else
  2336. if (name == sMatch)
  2337. {
  2338. if (result == null) {
  2339. result = [];
  2340. }
  2341. result.push(this.eventListeners[i]);
  2342. }
  2343. }
  2344. return result;
  2345. },
  2346. addEventListener: function(name, listener, useCapture)
  2347. {
  2348. useCapture = useCapture === undefined ? false : useCapture;
  2349. // make sure listener not already in list
  2350. var i, l = this.eventListeners.length;
  2351. for (i = 0; i < l; i++) {
  2352. if (this.eventListeners[i][this.EVENT_NAME] == name &&
  2353. this.eventListeners[i][this.EVENT_FUNC] == listener &&
  2354. this.eventListeners[i][this.EVENT_USECAP] == useCapture) {
  2355. return;
  2356. }
  2357. }
  2358. this.eventListeners.push([name, listener, useCapture]);
  2359. if (window._F_Debug !== undefined && this.debugEnabled())
  2360. {
  2361. _F_Debug.log.logDetails("Added event listener for fragment: " + this.id + "\ttitle: " + _F_Strings.normalize(this.title) + "\tevent: " + name, this);
  2362. }
  2363. },
  2364. removeEventListener: function(name, listener, useCapture)
  2365. {
  2366. useCapture = useCapture === undefined ? false : useCapture;
  2367. // find listener
  2368. var i, l = this.eventListeners.length;
  2369. for (i = 0; i < l; i++)
  2370. {
  2371. if (this.eventListeners[i][this.EVENT_NAME] == name &&
  2372. this.eventListeners[i][this.EVENT_FUNC] == listener &&
  2373. this.eventListeners[i][this.EVENT_USECAP] == useCapture)
  2374. {
  2375. _F_Array.removeAt(this.eventListeners, i);
  2376. if (window._F_Debug !== undefined && this.debugEnabled())
  2377. {
  2378. _F_Debug.log.logDetails("Removed event listener for fragment: " + this.id + "\ttitle: " + _F_Strings.normalize(this.title) + "\tevent: " + name, this);
  2379. }
  2380. break;
  2381. }
  2382. }
  2383. },
  2384. dispatchEvent: function(evt)
  2385. {
  2386. if (window._F_Debug !== undefined && evt.debugEnabled())
  2387. {
  2388. _F_Debug.log.logText("dispatchEvent: " + evt.name + " - id: " + this.id);
  2389. }
  2390. // prepare event object
  2391. evt.target = this;
  2392. evt.cancelled = false;
  2393. evt.stopped = false;
  2394. // prepare list of ancestor event handlers
  2395. var scope = this.getAncestors();
  2396. var indexes = new Array(scope.length);
  2397. var hasListener = false;
  2398. var i, l = scope.length;
  2399. for (i = 0; i < l; i++)
  2400. {
  2401. indexes[i] = scope[i].findEventListeners(evt.name);
  2402. if (indexes[i]) {
  2403. hasListener = true;
  2404. }
  2405. }
  2406. // capture phase
  2407. if (hasListener)
  2408. {
  2409. evt.eventPhase = evt.CAPTURING_PHASE;
  2410. l = scope.length;
  2411. for (i = l - 1; i >= 0; i--)
  2412. {
  2413. if (indexes[i])
  2414. {
  2415. var j, m = indexes[i].length;
  2416. for (j = 0; j < m; j++)
  2417. {
  2418. var listener = indexes[i][j];
  2419. // useCapture true?
  2420. if (listener[this.EVENT_USECAP])
  2421. {
  2422. evt.currentTarget = scope[i];
  2423. _F_Event.execute(scope[i], listener, evt);
  2424. }
  2425. }
  2426. if (evt.stopped) {
  2427. return !evt.cancelled;
  2428. }
  2429. }
  2430. }
  2431. }
  2432. // list of target event listeners
  2433. var targetListeners = this.findEventListeners(evt.name);
  2434. // at target phase
  2435. if (targetListeners)
  2436. {
  2437. evt.eventPhase = evt.AT_TARGET;
  2438. evt.currentTarget = this;
  2439. l = targetListeners.length;
  2440. for (i = 0; i < l; i++)
  2441. {
  2442. var listener1 = targetListeners[i];
  2443. _F_Event.execute(this, listener1, evt);
  2444. }
  2445. if (evt.stopped) {
  2446. return !evt.cancelled;
  2447. }
  2448. }
  2449. // bubbling phase
  2450. if (evt.bubbles && hasListener)
  2451. {
  2452. evt.eventPhase = evt.BUBBLING_PHASE;
  2453. l = scope.length;
  2454. for (i = 0; i < l; i++)
  2455. {
  2456. if (indexes[i])
  2457. {
  2458. var k, n = indexes[i].length;
  2459. for (k = 0; k < n; k++)
  2460. {
  2461. var listener2 = indexes[i][k];
  2462. // useCapture false?
  2463. if (!listener2[this.EVENT_USECAP])
  2464. {
  2465. evt.currentTarget = scope[i];
  2466. _F_Event.execute(scope[i], listener2, evt);
  2467. }
  2468. }
  2469. if (evt.stopped) {
  2470. return !evt.cancelled;
  2471. }
  2472. }
  2473. }
  2474. }
  2475. // default behaviour for fragment events
  2476. if (!evt.cancelled)
  2477. {
  2478. if ("fragment.refresh" == evt.name)
  2479. {
  2480. this.retrieve("frag-event=" + _F_Strings.urlEncode("name=" + evt.name));
  2481. }
  2482. }
  2483. return !evt.cancelled;
  2484. },
  2485. raiseEvent: function(name, payload, type, bubbles, cancelable)
  2486. {
  2487. // If not initialized, we queue the event
  2488. if (!this.onloadInitialized ){
  2489. _F_eventQueue.add(this, this.raiseEvent, arguments);
  2490. // we return trues so we don't cancel the event. Canceling it will affect the source fragment (e.g. canceling a retrieve event)
  2491. return true;
  2492. }
  2493. bubbles = bubbles === undefined ? true : bubbles;
  2494. cancelable = cancelable === undefined ? true : cancelable;
  2495. var evt = new _F_Event.Event();
  2496. evt.initEvent(name, type, payload, bubbles, cancelable);
  2497. evt.source = this;
  2498. return this.dispatchEvent(evt);
  2499. },
  2500. /**
  2501. * Proxy an event to every children
  2502. */
  2503. proxyEvent: function(evt)
  2504. {
  2505. if (window._F_Debug !== undefined && evt.debugEnabled())
  2506. {
  2507. var phase = "";
  2508. switch (evt.eventPhase) { case 1: phase = "CAPTURE"; break; case 2: phase = "TARGET"; break; case 3: phase = "BUBBLE"; }
  2509. var source = evt.source ? evt.source.id : "none";
  2510. _F_Debug.log.group("eventProxy: " + evt.name + " (" + phase + ") - id: " + this.id + " src: " + source);
  2511. }
  2512. // pass-down specific events if raised on proxy fragment
  2513. var children;
  2514. if (evt.eventPhase == evt.AT_TARGET)
  2515. {
  2516. var bPropagate = false;
  2517. if (evt.name.indexOf("fragment.") == 0)
  2518. {
  2519. bPropagate = _F_Array.indexOf(_F_Event.propagatedEvents, evt.name) > -1;
  2520. }
  2521. else
  2522. {
  2523. // make sure event doesn't come from child
  2524. bPropagate = !(evt.proxy && evt.proxy == this);
  2525. }
  2526. if (bPropagate)
  2527. {
  2528. children = this.getChildren();
  2529. var i, l = children.length;
  2530. for (i = 0; i < l; i++) {
  2531. children[i].dispatchEvent(evt);
  2532. }
  2533. }
  2534. }
  2535. else
  2536. {
  2537. if (evt.name.indexOf("fragment.") != 0)
  2538. {
  2539. // fire event on self if event source is immediate child or from a child event proxy
  2540. children = this.getChildren();
  2541. if (_F_Array.indexOf(children, evt.source) > -1 || _F_Array.indexOf(children, evt.proxy) > -1)
  2542. {
  2543. evt.stopPropagation();
  2544. var oEvent = new _F_Event.Event();
  2545. oEvent.initEvent(evt.name, evt.type, evt.payload, evt.bubbles, evt.cancelable);
  2546. oEvent.source = evt.source;
  2547. oEvent.proxy = this;
  2548. this.dispatchEvent(oEvent);
  2549. }
  2550. }
  2551. }
  2552. // prevent the default behaviour for fragment.refresh events targetted at an event proxy
  2553. if (evt.eventPhase == evt.AT_TARGET && "fragment.refresh" == evt.name) {
  2554. evt.preventDefault();
  2555. }
  2556. if (window._F_Debug !== undefined && evt.debugEnabled()) {
  2557. _F_Debug.log.groupEnd();
  2558. }
  2559. },
  2560. //- onload
  2561. onloadInitialized: false,
  2562. onloadHandlers: [],
  2563. // old code for backwards compatibility (to be removed)
  2564. setOnloadHandler: function(func)
  2565. {
  2566. if (this.onloadInitialized) {
  2567. func();
  2568. }
  2569. else {
  2570. this.onloadHandlers.push(func);
  2571. }
  2572. },
  2573. //- transient properties
  2574. transientGlobal: { },
  2575. transientUpdate: function(sName, sValue, sScope, sChannel)
  2576. {
  2577. var scope;
  2578. sChannel = ((sChannel == null || sChannel === undefined) ? this.channel||"" : sChannel);
  2579. var sKey = sName + "[" + sChannel + "]";
  2580. if (sScope == 'private')
  2581. {
  2582. // private communication
  2583. scope = [this];
  2584. }
  2585. else if (sScope == 'page')
  2586. {
  2587. // set value in page transients
  2588. var p = this.getPageFragment();
  2589. p.transientState[sKey] = sValue;
  2590. scope = _F_descendants(p.id);
  2591. }
  2592. else if (!(sScope) || sScope == "" || sScope == "application")
  2593. {
  2594. // set value in global transients
  2595. scope = [];
  2596. this.transientGlobal[sKey] = sValue;
  2597. for (var id in fragments)
  2598. {
  2599. if (fragments[id] != null)
  2600. {
  2601. scope.push(fragments[id]);
  2602. }
  2603. }
  2604. }
  2605. else
  2606. {
  2607. // unsupported scope, do nothing
  2608. scope = [];
  2609. }
  2610. var i, l;
  2611. var refreshList = (arguments.length > 4) ? arguments[4] : null;
  2612. if (refreshList)
  2613. {
  2614. l = scope.length;
  2615. for (i = 0; i < l; i++)
  2616. {
  2617. try
  2618. {
  2619. if (scope[i].transientUpdateCheck(sName, sValue, sChannel, false)) {
  2620. refreshList.push(scope[i]);
  2621. }
  2622. }
  2623. catch (e)
  2624. {
  2625. _F_log("E", e);
  2626. }
  2627. }
  2628. }
  2629. else
  2630. {
  2631. l = scope.length;
  2632. for (i = 0; i < l; i++)
  2633. {
  2634. try
  2635. {
  2636. scope[i].transientUpdateCheck(sName, sValue, sChannel, true);
  2637. }
  2638. catch (e1)
  2639. {
  2640. _F_log("E", e1);
  2641. }
  2642. }
  2643. }
  2644. },
  2645. transientUpdateList: function(list)
  2646. {
  2647. if (list == null || list.length == 0) {
  2648. return;
  2649. }
  2650. var serverUpdate = (arguments.length > 1) ? arguments[1] : false;
  2651. var refreshList = [];
  2652. var i, l = list.length;
  2653. for (i = 0; i < l; i++) {
  2654. this.transientUpdate(list[i].name, list[i].value, list[i].scope, list[i].channel, refreshList);
  2655. }
  2656. refreshList = _F_Array.unique(refreshList);
  2657. if (serverUpdate) {
  2658. _F_Array.remove(refreshList, this);
  2659. }
  2660. l = refreshList.length;
  2661. for (i = 0; i < l; i++){
  2662. var frag = refreshList[i];
  2663. if (frag.raiseEvent("fragment.transientUpdate", list, "")){
  2664. frag.retrieve();
  2665. }
  2666. }
  2667. },
  2668. /**
  2669. * transientUpdateCheck - checks if this fragment should be refreshed because
  2670. * the value was changed for the specified channel.
  2671. * @param sName transient name
  2672. * @param sValue new value
  2673. * @param sChannel which channel name (string or undefined/null/'' are considered global)
  2674. * @param bRefreshNow allow the call to retrieve
  2675. */
  2676. transientUpdateCheck: function(sName, sValue, sChannel, bRefreshNow)
  2677. {
  2678. if (this.transients)
  2679. {
  2680. var i, l = this.transients.length;
  2681. for (i = 0; i < l; i++) {
  2682. if (this.transients[i] == sName)
  2683. {
  2684. if ((this.transientState[sName] != sValue) && ((this.channel||'') == (sChannel||'')))
  2685. {
  2686. var refresh = this.transientNotify(sName, sValue);
  2687. if (refresh && bRefreshNow){
  2688. if (this.raiseEvent("fragment.transientUpdate", [{name: sName, value:sValue, channel:sChannel}], "")){
  2689. this.retrieve();
  2690. }
  2691. }
  2692. return refresh;
  2693. }
  2694. return false;
  2695. }
  2696. }
  2697. }
  2698. return false;
  2699. },
  2700. /**
  2701. * transientNotify: assign the new value and returns true to do the
  2702. * automatic refresh(), otherwise return false.
  2703. * @param sName transient name
  2704. * @param sValue new value to be set
  2705. */
  2706. transientNotify: function(sName, sValue)
  2707. {
  2708. this.transientState[sName] = sValue;
  2709. if (window._F_Debug !== undefined && this.debugEnabled())
  2710. {
  2711. _F_Debug.log.logDetails("Transient Notify fragment: " + this.id + "\ttitle: " + _F_Strings.normalize(this.title),
  2712. "name = " + sName + " value = " + sValue);
  2713. }
  2714. return true;
  2715. },
  2716. getPageFragment: function()
  2717. {
  2718. var p = this;
  2719. while (p != null)
  2720. {
  2721. if (p.page) {
  2722. return p;
  2723. }
  2724. p = p.parent;
  2725. }
  2726. return (this.parent != null) ? this.parent : this;
  2727. },
  2728. /**
  2729. * Method sets the title of the fragment, the title will be added to the caption of the
  2730. * fragment if the fragment has a caption.
  2731. * When the method is called the fragment.title.change event is fired.
  2732. * The event will have an object payload, containing the currentTitle and the newTitle.
  2733. * If no one in the fragment chain handles the event and calls preventDefault,
  2734. * the default behavior of fragment.retrieve() will occur.
  2735. * @param text: title's text
  2736. */
  2737. setTitle: function(text)
  2738. {
  2739. if (this.raiseEvent("fragment.title.change",
  2740. {
  2741. "currentTitle":this.title,
  2742. "newTitle":text
  2743. },
  2744. "params"))
  2745. {
  2746. this.title = text;
  2747. }
  2748. },
  2749. /**
  2750. * Method sets the mode of the fragment, modes can be any mode defined
  2751. * in the fragment implementation file.
  2752. * When the method is called the fragment.mode.change event is fired.
  2753. * This event has an object payload, containing the currentMode and the newMode.
  2754. * If no one in the fragment chain handles the event and calls preventDefault,
  2755. * the default behavior of fragment.retrieve() will occur.
  2756. * @param mode: new fragment mode
  2757. */
  2758. setMode: function(mode)
  2759. {
  2760. if (mode != "" && mode != this.mode)
  2761. {
  2762. var currentMode = this.mode;
  2763. this.mode = mode;
  2764. var performDefault = this.raiseEvent("fragment.mode.change",
  2765. {
  2766. "currentMode":currentMode,
  2767. "newMode":this.mode
  2768. }
  2769. , "params");
  2770. if (performDefault && (arguments[1] === undefined || arguments[1] != "internal")) {
  2771. this.retrieve();
  2772. }
  2773. }
  2774. },
  2775. /**
  2776. * Method sets the windowState of the fragment, windowState can be normal, maximized or minimized.
  2777. * When the method is called the fragment.windowstate.change event is fired.
  2778. * This event has an object payload, containing the currentWindowState and the newWindowState.
  2779. * If no one in the fragment chain handles the event and calls preventDefault,
  2780. * the default behavior of fragment.retrieve() will occur.
  2781. * @param windowState: new fragment window state
  2782. */
  2783. setWindowState: function(windowState)
  2784. {
  2785. if (windowState != "" && windowState != this.windowState)
  2786. {
  2787. //Raising windowstate changed event
  2788. var performDefault = this.raiseEvent("fragment.windowstate.change",
  2789. {
  2790. "currentWindowState":this.windowState,
  2791. "newWindowState":windowState
  2792. }
  2793. , "params");
  2794. this.windowState = windowState;
  2795. //Raise a visiblility change event with siblings
  2796. var siblings = this.parent.getChildren();
  2797. var visibility = windowState=="maximized" ? "hidden" : "visible";
  2798. for (var i=0; i<siblings.length; i++)
  2799. {
  2800. if (siblings[i].id != this.id)
  2801. {
  2802. siblings[i].raiseEvent("fragment.visibility.change",
  2803. {
  2804. "setVisibility":visibility
  2805. }
  2806. , "params", false, false);
  2807. }
  2808. else
  2809. {
  2810. siblings[i].raiseEvent("fragment.visibility.change",
  2811. {
  2812. "setVisibility":"visible"
  2813. }
  2814. , "params", false, false);
  2815. }
  2816. }
  2817. if (performDefault && (_F_Array.indexOf(this.windowStates, windowState) > -1) && ((arguments[1] === undefined)||(arguments[1] != "internal"))) {
  2818. this.retrieve();
  2819. }
  2820. }
  2821. },
  2822. /**
  2823. * Default event handler for the fragment.visibility.change event. This event handler should be called first as it will
  2824. * calculate and set old/new visibility for the fragment and update both the fragment and event with this data for the
  2825. * use of subsequent window.visibility.change event handlers.
  2826. * @param evt: window.visibility.change event object
  2827. */
  2828. setVisibilityEvent: function(evt)
  2829. {
  2830. if (evt.eventPhase == evt.AT_TARGET)
  2831. {
  2832. evt.payload.currentVisibility = this.visibility;
  2833. var newVisibility;
  2834. if (evt.payload.setVisibility == "hidden")
  2835. {
  2836. newVisibility = "hidden";
  2837. }
  2838. else
  2839. {
  2840. if (this.windowState == "minimized")
  2841. {
  2842. newVisibility = "hidden";
  2843. }
  2844. else
  2845. {
  2846. newVisibility = "visible";
  2847. }
  2848. }
  2849. evt.payload.newVisibility = newVisibility;
  2850. this.visibility = newVisibility;
  2851. }
  2852. },
  2853. /**
  2854. * Instruct this fragment to refresh itself in a number of seconds.
  2855. * Calling this method with a value of 0 will cancel the current pending refresh, however
  2856. * there's no garantee that the refresh would be effectively cancelled.
  2857. * @param sec: number of seconds
  2858. */
  2859. setRefreshDelay: function(sec)
  2860. {
  2861. if (this.refreshTimeout) {
  2862. window.clearInterval(this.refreshTimeout);
  2863. }
  2864. if (sec > 0)
  2865. {
  2866. var _self = this;
  2867. this.refreshTimeout = window.setTimeout(
  2868. function()
  2869. {
  2870. _self.retrieve();
  2871. },
  2872. sec * 1000);
  2873. }
  2874. },
  2875. //- error handling
  2876. onerror: function(msg, details, code)
  2877. {
  2878. _F_alert(code + ":\n" + msg + "\n\n" + details, this.title);
  2879. },
  2880. /**
  2881. * Destroys a fragment and all its children.
  2882. */
  2883. destroy: function()
  2884. {
  2885. // call event handlers and delete this object
  2886. this.raiseEvent("fragment.unload", null, "", true, false);
  2887. // recursively call destroy on children
  2888. var children = this.getChildren();
  2889. var i, l = children.length;
  2890. for (i = 0; i < l; i++) {
  2891. children[i].destroy();
  2892. }
  2893. // remove private scripts and styles
  2894. _F_Document.removeHeadTag(_F_Document.buildHeadTagId(this.id, "SCRIPT"));
  2895. _F_Document.removeHeadTag(_F_Document.buildHeadTagId(this.id, "LINK"));
  2896. if ($(this.div)) {
  2897. $(this.div).innerHTML = "";
  2898. }
  2899. this.raiseEvent("fragment.destroy", null, "", true, false);
  2900. delete fragments[this.id];
  2901. },
  2902. reloadAll: function ()
  2903. {
  2904. var action = _F_Config.gateway + _F_Config.application;
  2905. var formElement = document.createElement("form");
  2906. formElement.setAttribute("name","pageload");
  2907. formElement.setAttribute("method","POST");
  2908. formElement.setAttribute("action",_F_Config.gateway);
  2909. hiddenElement = document.createElement("input");
  2910. hiddenElement.setAttribute("type","hidden");
  2911. hiddenElement.setAttribute("name","b_action");
  2912. hiddenElement.setAttribute("value",_F_Config.application.substring(1));
  2913. formElement.appendChild(hiddenElement);
  2914. for (var id in fragments)
  2915. {
  2916. var frag = fragments[id];
  2917. if (frag.parent == null)
  2918. {
  2919. var path = frag.path;
  2920. if (frag.id == "cm")
  2921. {
  2922. hiddenElement = document.createElement("input");
  2923. hiddenElement.setAttribute("type","hidden");
  2924. hiddenElement.setAttribute("name","pathinfo");
  2925. hiddenElement.setAttribute("value","/cm");
  2926. formElement.appendChild(hiddenElement);
  2927. hiddenElement = document.createElement("input");
  2928. hiddenElement.setAttribute("type","hidden");
  2929. hiddenElement.setAttribute("name","path");
  2930. hiddenElement.setAttribute("value","storeID(\"" + frag.path.substring(frag.path.lastIndexOf("/")+1) + "\")");
  2931. formElement.appendChild(hiddenElement);
  2932. }
  2933. else
  2934. {
  2935. hiddenElement = document.createElement("input");
  2936. hiddenElement.setAttribute("type","hidden");
  2937. hiddenElement.setAttribute("name","pathinfo");
  2938. hiddenElement.setAttribute("value",frag.path);
  2939. formElement.appendChild(hiddenElement);
  2940. }
  2941. }
  2942. //Raise an event before capturing the state of the fragment so that any needed updates can be done
  2943. frag.raiseEvent("fragment.reload", null, "", false, false);
  2944. hiddenElement = document.createElement("input");
  2945. hiddenElement.setAttribute("type","hidden");
  2946. hiddenElement.setAttribute("name","frag-sub");
  2947. hiddenElement.setAttribute("value",frag.fragmentURI());
  2948. formElement.appendChild(hiddenElement);
  2949. }
  2950. //Assume a header is present
  2951. hiddenElement = document.createElement("input");
  2952. hiddenElement.setAttribute("type","hidden");
  2953. hiddenElement.setAttribute("name","frag-header");
  2954. hiddenElement.setAttribute("value","true");
  2955. formElement.appendChild(hiddenElement);
  2956. document.body.appendChild(formElement);
  2957. formElement.submit();
  2958. document.body.removeChild(formElement);
  2959. formElement = null;
  2960. }
  2961. };
  2962. //--------------------------------------------------------------
  2963. // Drag and Drop
  2964. // find the nearest element up the chain that begins with "labelPrefix" in its id
  2965. function _F_findParentObj(obj, labelPrefix)
  2966. {
  2967. while (obj)
  2968. {
  2969. if (obj.id && obj.id.indexOf(labelPrefix) == 0) {
  2970. return obj;
  2971. }
  2972. obj = xParent(obj, true);
  2973. }
  2974. return obj;
  2975. }
  2976. // find the nearest element up the chain that begins with "label" in its id
  2977. function _F_ancestorFragments(obj)
  2978. {
  2979. var list = [];
  2980. while (obj)
  2981. {
  2982. var id = obj.id;
  2983. if (id && id.indexOf('content') == id.length - 7) {
  2984. list.push(obj);
  2985. }
  2986. obj = xParent(obj, true);
  2987. }
  2988. return list;
  2989. }
  2990. //-- dragContext Object
  2991. function dragContext(obj)
  2992. {
  2993. this.obj = obj;
  2994. if (this.obj.getAttributeNode("payload")) {
  2995. this.payload = this.obj.getAttributeNode("payload").nodeValue;
  2996. }
  2997. if (this.obj.getAttributeNode("itemtitle")) {
  2998. this.title = this.obj.getAttributeNode("itemtitle").nodeValue;
  2999. }
  3000. if (this.obj.getAttributeNode("dragtype"))
  3001. {
  3002. this.type = this.obj.getAttributeNode("dragtype").nodeValue;
  3003. }
  3004. else
  3005. {
  3006. // extract object class and any extra info
  3007. var s = obj.id.substring(9);
  3008. s = s.substring(0, s.indexOf("_"));
  3009. var n = s.indexOf(".");
  3010. if (n != -1)
  3011. {
  3012. this.type = s.substring(0, n);
  3013. this.info = s.substring(n+1);
  3014. }
  3015. else {
  3016. this.type = s;
  3017. }
  3018. }
  3019. // drop target handling
  3020. this.xevent = null;
  3021. this.dropType = 0;
  3022. this.dropTarget = null;
  3023. this.dropHandler = null;
  3024. // drag icon display states
  3025. this.imgPath = _F_Config.webContent + "/fragments/dragdrop/images/";
  3026. this.bDragMulti = false; // _multi
  3027. this.bDragDrop = false; // _nodrop
  3028. this.bDragCopy = false; // _copy
  3029. this.init();
  3030. }
  3031. dragContext.prototype =
  3032. {
  3033. div: null,
  3034. img: null,
  3035. icons: [],
  3036. iconNames:
  3037. [
  3038. "drag_cursor",
  3039. "drag_cursor_copy",
  3040. "drag_cursor_nodrop",
  3041. "drag_cursor_multi",
  3042. "drag_cursor_multi_copy",
  3043. "drag_cursor_multi_nodrop",
  3044. "drag_cursor_multi_nodrop_copy"
  3045. ],
  3046. init: function()
  3047. {
  3048. if (!this.div)
  3049. {
  3050. this.div = document.createElement('DIV');
  3051. this.div.setAttribute("id", "F_dragDiv");
  3052. this.div.style.position = "absolute";
  3053. this.div.style.visibility = "hidden";
  3054. this.div.style.zIndex = "100";
  3055. this.img = document.createElement('IMG');
  3056. this.img.setAttribute("name", "F_dragImage");
  3057. this.img.setAttribute("src", this.imgPath + "drag_cursor.gif");
  3058. this.img.setAttribute("width", "22");
  3059. this.img.setAttribute("height", "22");
  3060. this.img.setAttribute("border", "0");
  3061. this.div.appendChild(this.img);
  3062. document.body.appendChild(this.div);
  3063. // load images
  3064. var i, l = this.iconNames.length;
  3065. for (i = 0; i < l; i++)
  3066. {
  3067. var icon = new Image(22, 22);
  3068. icon.src = this.imgPath + this.iconNames[i] + ".gif";
  3069. this.icons[this.iconNames[i]] = icon;
  3070. }
  3071. }
  3072. },
  3073. updateIcon: function()
  3074. {
  3075. var sName = "drag_cursor" +
  3076. (this.bDragMulti ? "_multi" : "") +
  3077. (this.bDragDrop ? "" : "_nodrop") +
  3078. (this.bDragCopy ? "_copy" : "");
  3079. if (this.icons[sName]) {
  3080. this.img.src = this.icons[sName].src;
  3081. }
  3082. },
  3083. canDrop: function(bDrop)
  3084. {
  3085. if (this.bDragDrop != bDrop)
  3086. {
  3087. this.bDragDrop = bDrop;
  3088. this.updateIcon();
  3089. }
  3090. },
  3091. capture: function(e)
  3092. {
  3093. this.xevent = e;
  3094. xMoveTo(this.div, e.pageX + 5, e.pageY + 8);
  3095. xShow(this.div);
  3096. this.updateIcon();
  3097. },
  3098. ENTER: 0,
  3099. MOVE: 1,
  3100. LEAVE: 2,
  3101. DROP: 3,
  3102. move: function(e)
  3103. {
  3104. this.xevent = e;
  3105. xMoveTo(this.div, e.pageX + 5, e.pageY + 8);
  3106. var droplist = _F_ancestorFragments(e.target);
  3107. var drop = null;
  3108. var frag = null;
  3109. var i, l = droplist.length;
  3110. for (i = 0; i < l; i++)
  3111. {
  3112. var id = droplist[i].id.substring(0, droplist[i].id.length - 7);
  3113. frag = fragments[id];
  3114. if (frag && frag.ondrop)
  3115. {
  3116. drop = droplist[i];
  3117. break;
  3118. }
  3119. }
  3120. if (drop != this.dropTarget)
  3121. {
  3122. if (this.dropTarget)
  3123. {
  3124. this.dropType = this.LEAVE;
  3125. this.dropHandler(this);
  3126. this.dropTarget = null;
  3127. this.dropHandler = null;
  3128. this.canDrop(false);
  3129. }
  3130. }
  3131. if (drop)
  3132. {
  3133. this.dropTarget = drop;
  3134. this.dropHandler = frag.ondrop;
  3135. this.dropType = this.ENTER;
  3136. this.dropHandler(this);
  3137. }
  3138. if (this.dropTarget)
  3139. {
  3140. this.dropType = this.MOVE;
  3141. this.dropHandler(this);
  3142. }
  3143. },
  3144. release: function(e)
  3145. {
  3146. this.xevent = e;
  3147. xHide(this.div);
  3148. if (this.dropTarget)
  3149. {
  3150. this.dropType = this.bDragDrop ? this.DROP : this.LEAVE;
  3151. this.dropHandler(this);
  3152. this.dropTarget = null;
  3153. this.dropHandler = null;
  3154. }
  3155. }
  3156. };
  3157. //-- _F_Drag Singleton
  3158. var _F_Drag =
  3159. {
  3160. obj: null,
  3161. startX: 0,
  3162. startY: 0,
  3163. dragging: false,
  3164. context: null,
  3165. pending: function(obj, e)
  3166. {
  3167. this.obj = obj;
  3168. this.startX = e.pageX;
  3169. this.startY = e.pageY;
  3170. this.dragging = false;
  3171. this.context = null;
  3172. },
  3173. start: function(e)
  3174. {
  3175. this.dragging = true;
  3176. this.context = new dragContext(this.obj);
  3177. this.context.capture(e);
  3178. },
  3179. move: function(e)
  3180. {
  3181. if (!this.dragging)
  3182. {
  3183. // check for drag outside the start rect
  3184. if ((e.pageX > (this.startX + 8)) || (e.pageX < (this.startX - 8)) ||
  3185. (e.pageY > (this.startY + 8)) || (e.pageY < (this.startY - 8)))
  3186. {
  3187. this.start(e);
  3188. }
  3189. }
  3190. if (this.context) {
  3191. this.context.move(e);
  3192. }
  3193. },
  3194. stop: function(e)
  3195. {
  3196. if (this.context) {
  3197. this.context.release(e);
  3198. }
  3199. this.obj = null;
  3200. this.dragging = false;
  3201. this.context = null;
  3202. }
  3203. };
  3204. //-- Mouse Event handling
  3205. function _F_dragMD(evt)
  3206. {
  3207. // capture events
  3208. var e = new xEvent(evt);
  3209. var obj = _F_findParentObj(e.target, 'dragitem_');
  3210. if (obj)
  3211. {
  3212. xPreventDefault(evt);
  3213. _F_Drag.pending(obj, e);
  3214. xAddEventListener(document, "mousemove", _F_dragMM, false);
  3215. xAddEventListener(document, "mouseup", _F_dragMU, false);
  3216. }
  3217. }
  3218. function _F_dragMM(evt)
  3219. {
  3220. var e = new xEvent(evt);
  3221. xPreventDefault(evt);
  3222. _F_Drag.move(e);
  3223. }
  3224. function _F_dragMU(evt)
  3225. {
  3226. var e = new xEvent(evt);
  3227. xPreventDefault(evt);
  3228. _F_Drag.stop(e);
  3229. xRemoveEventListener(document, "mousemove", _F_dragMM);
  3230. xRemoveEventListener(document, "mouseup", _F_dragMU);
  3231. }
  3232. //------------------------------------------------------------------------------
  3233. // execute a method on an object with arguments
  3234. var _F_Queue =
  3235. {
  3236. };
  3237. _F_Queue.Runnable = function(obj, func, args)
  3238. {
  3239. this.obj = obj;
  3240. this.func = func;
  3241. this.args = args;
  3242. };
  3243. _F_Queue.Runnable.prototype =
  3244. {
  3245. run: function()
  3246. {
  3247. var stopRun = this.func.apply(this.obj, this.args);
  3248. this.func = null;
  3249. this.obj = null;
  3250. this.args = null;
  3251. return stopRun;
  3252. }
  3253. };
  3254. _F_Queue.Queue = function()
  3255. {
  3256. this.head = null;
  3257. this.tail = null;
  3258. };
  3259. _F_Queue.Queue.prototype =
  3260. {
  3261. add: function(obj)
  3262. {
  3263. var newEntry =
  3264. {
  3265. value: obj,
  3266. next: null
  3267. };
  3268. if (this.tail) {
  3269. this.tail.next = newEntry;
  3270. }
  3271. else {
  3272. this.head = newEntry;
  3273. }
  3274. this.tail = newEntry;
  3275. },
  3276. hasNext: function()
  3277. {
  3278. return (this.head != null);
  3279. },
  3280. next: function()
  3281. {
  3282. var entry = this.head;
  3283. var obj = entry.value;
  3284. this.head = entry.next;
  3285. if (entry.next == null) {
  3286. this.tail = null;
  3287. }
  3288. entry.next = null;
  3289. delete (entry);
  3290. return obj;
  3291. }
  3292. };
  3293. _F_Queue.RunQueue = function()
  3294. {
  3295. this.queue = new _F_Queue.Queue();
  3296. this.isRunning = false;
  3297. };
  3298. _F_Queue.RunQueue.prototype =
  3299. {
  3300. add: function(obj, func, args)
  3301. {
  3302. this.queue.add(new _F_Queue.Runnable(obj, func, args));
  3303. },
  3304. run: function()
  3305. {
  3306. if (!this.isRunning){
  3307. this.isRunning = true;
  3308. this.resume();
  3309. }
  3310. },
  3311. resume: function()
  3312. {
  3313. while (this.queue.hasNext()) {
  3314. if (this.queue.next().run()) {
  3315. break;
  3316. }
  3317. }
  3318. this.isRunning = this.queue.hasNext();
  3319. }
  3320. };
  3321. var _F_runQueue = new _F_Queue.RunQueue();
  3322. var _F_eventQueue = new _F_Queue.RunQueue();
  3323. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3324. // Framework
  3325. function _F_attach(obj)
  3326. {
  3327. var frag = fragments[obj.id];
  3328. if (!frag) {
  3329. frag = new fragment(obj.path, obj.id, obj.div);
  3330. }
  3331. if (!frag.loaded)
  3332. {
  3333. frag.attach(obj);
  3334. if (frag.title) {
  3335. frag.setTitle(frag.title);
  3336. }
  3337. frag.loaded = true;
  3338. if (window._F_Debug !== undefined && frag.debugEnabled())
  3339. {
  3340. _F_Debug.log.logDetails("Attach fragment: " + frag.id + "\ttitle: " + _F_Strings.normalize(frag.title),
  3341. "path: " + obj.path, frag);
  3342. }
  3343. frag.raiseEvent("fragment.create", null, "", true, false);
  3344. }
  3345. else
  3346. {
  3347. frag.channel = obj.channel;
  3348. }
  3349. return frag;
  3350. }
  3351. function _F_resize()
  3352. {
  3353. var skipChildren = null;
  3354. var list = (arguments.length == 1) ? arguments[0] : fragments;
  3355. for (var id in list)
  3356. {
  3357. if (skipChildren != null && id.indexOf(skipChildren) == 0) {
  3358. continue;
  3359. }
  3360. if (fragments[id] != null && fragments[id].onresize && fragments[id].onresize() == true) {
  3361. skipChildren = id;
  3362. }
  3363. else {
  3364. skipChildren = null;
  3365. }
  3366. }
  3367. }
  3368. function _F_onload(){
  3369. if (window.location.href.indexOf("#frag-logon") != -1) {
  3370. document.cookie = "frag_login=";
  3371. }
  3372. fragment.prototype.onloadInitialized = true;
  3373. // old code for backwards compatibility (to be removed)
  3374. var i, l = fragment.prototype.onloadHandlers.length;
  3375. for (i = 0; i < l; i++) {
  3376. fragment.prototype.onloadHandlers[i]();
  3377. }
  3378. // fire "fragment.load" event on all fragments
  3379. var oEvent = new _F_Event.Event();
  3380. var isbrowserBack = false;
  3381. var backJaxForm = $('cps_backjaxform');
  3382. if (typeof backJaxForm != "undefined" && backJaxForm != null)
  3383. {
  3384. if (typeof backJaxForm.visited != "undefined")
  3385. {
  3386. isbrowserBack = ("true" == backJaxForm.visited.value);
  3387. backJaxForm.visited.value = "true";
  3388. }
  3389. }
  3390. oEvent.initEvent("fragment.load", "", {source: isbrowserBack? "cache" : "dom"}, false, false);
  3391. for (var id in fragments)
  3392. {
  3393. if (fragments[id].parent == null)
  3394. {
  3395. oEvent.source = fragments[id];
  3396. fragments[id].dispatchEvent(oEvent);
  3397. }
  3398. }
  3399. _F_eventQueue.run();
  3400. while(_F_eventQueue.queue.hasNext()) {
  3401. _F_eventQueue.resume();
  3402. }
  3403. }
  3404. function _F_onresize()
  3405. {
  3406. _F_resize();
  3407. return true;
  3408. }
  3409. function _F_init()
  3410. {
  3411. _F_Config.initialize();
  3412. _F_Resource.initialize();
  3413. _F_onload();
  3414. _F_Document.addEventListener(window, "resize", _F_onresize, true);
  3415. _F_Document.addEventListener(document, "mousedown", _F_dragMD);
  3416. if (window._F_Debug !== undefined && _F_Debug.enabled)
  3417. {
  3418. _F_Debug.initialize();
  3419. }
  3420. }
  3421. function _F_getFragmentByID(fid)
  3422. {
  3423. return window.fragments[fid];
  3424. }
  3425. _F_Document.addEventListener(window, "load", _F_init);
  3426. /**
  3427. * @deprecated: use _F_Document.getCookie()
  3428. */
  3429. function _F_getCookie(name)
  3430. {
  3431. _F_log("W", "DEPRECATED FUNCTION: _F_getCookie --> _F_Document.getCookie");
  3432. return _F_Document.getCookie(name);
  3433. }
  3434. /**
  3435. * @deprecated: use _F_Document.setCookie()
  3436. */
  3437. function _F_setCookie(name, value, expires, path, domain, secure)
  3438. {
  3439. _F_log("W", "DEPRECATED FUNCTION: _F_setCookie --> _F_Document.setCookie");
  3440. _F_Document.setCookie(name, value, expires, path, domain, secure);
  3441. }