window.js 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876
  1. // Copyright (c) 2006 Sébastien Gruhier (http://xilinus.com, http://itseb.com)
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining
  4. // a copy of this software and associated documentation files (the
  5. // "Software"), to deal in the Software without restriction, including
  6. // without limitation the rights to use, copy, modify, merge, publish,
  7. // distribute, sublicense, and/or sell copies of the Software, and to
  8. // permit persons to whom the Software is furnished to do so, subject to
  9. // the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be
  12. // included in all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  18. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  19. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  20. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. //
  22. // VERSION 1.3
  23. var Window = Class.create();
  24. Window.keepMultiModalWindow = false;
  25. Window.hasEffectLib = (typeof Effect != 'undefined');
  26. Window.resizeEffectDuration = 0.4;
  27. Window.prototype = {
  28. // Constructor
  29. // Available parameters : className, blurClassName, title, minWidth, minHeight, maxWidth, maxHeight, width, height, top, left, bottom, right, resizable, zIndex, opacity, recenterAuto, wiredDrag
  30. // hideEffect, showEffect, showEffectOptions, hideEffectOptions, effectOptions, url, draggable, closable, minimizable, maximizable, parent, onload
  31. // add all callbacks (if you do not use an observer)
  32. // onDestroy onStartResize onStartMove onResize onMove onEndResize onEndMove onFocus onBlur onBeforeShow onShow onHide onMinimize onMaximize onClose
  33. initialize: function() {
  34. var id;
  35. var optionIndex = 0;
  36. // For backward compatibility like win= new Window("id", {...}) instead of win = new Window({id: "id", ...})
  37. if (arguments.length > 0) {
  38. if (typeof arguments[0] == "string" ) {
  39. id = arguments[0];
  40. optionIndex = 1;
  41. }
  42. else
  43. id = arguments[0] ? arguments[0].id : null;
  44. }
  45. // Generate unique ID if not specified
  46. if (!id)
  47. id = "window_" + new Date().getTime();
  48. if ($(id))
  49. alert("Window " + id + " is already registered in the DOM! Make sure you use setDestroyOnClose() or destroyOnClose: true in the constructor");
  50. this.options = Object.extend({
  51. className: "dialog",
  52. windowClassName: null,
  53. blurClassName: null,
  54. minWidth: 100,
  55. minHeight: 20,
  56. resizable: true,
  57. closable: true,
  58. minimizable: true,
  59. maximizable: true,
  60. draggable: true,
  61. userData: null,
  62. showEffect: (Window.hasEffectLib ? Effect.Appear : Element.show),
  63. hideEffect: (Window.hasEffectLib ? Effect.Fade : Element.hide),
  64. showEffectOptions: {},
  65. hideEffectOptions: {},
  66. effectOptions: null,
  67. parent: document.body,
  68. title: " ",
  69. url: null,
  70. onload: Prototype.emptyFunction,
  71. width: 200,
  72. height: 300,
  73. opacity: 1,
  74. recenterAuto: true,
  75. wiredDrag: false,
  76. closeOnEsc: true,
  77. closeCallback: null,
  78. destroyOnClose: false,
  79. gridX: 1,
  80. gridY: 1
  81. }, arguments[optionIndex] || {});
  82. if (this.options.blurClassName)
  83. this.options.focusClassName = this.options.className;
  84. if (typeof this.options.top == "undefined" && typeof this.options.bottom == "undefined")
  85. this.options.top = this._round(Math.random()*500, this.options.gridY);
  86. if (typeof this.options.left == "undefined" && typeof this.options.right == "undefined")
  87. this.options.left = this._round(Math.random()*500, this.options.gridX);
  88. if (this.options.effectOptions) {
  89. Object.extend(this.options.hideEffectOptions, this.options.effectOptions);
  90. Object.extend(this.options.showEffectOptions, this.options.effectOptions);
  91. if (this.options.showEffect == Element.Appear)
  92. this.options.showEffectOptions.to = this.options.opacity;
  93. }
  94. if (Window.hasEffectLib) {
  95. if (this.options.showEffect == Effect.Appear)
  96. this.options.showEffectOptions.to = this.options.opacity;
  97. if (this.options.hideEffect == Effect.Fade)
  98. this.options.hideEffectOptions.from = this.options.opacity;
  99. }
  100. if (this.options.hideEffect == Element.hide)
  101. this.options.hideEffect = function(){ Element.hide(this.element); if (this.options.destroyOnClose) this.destroy(); }.bind(this)
  102. if (this.options.parent != document.body)
  103. this.options.parent = $(this.options.parent);
  104. this.element = this._createWindow(id);
  105. this.element.win = this;
  106. // Bind event listener
  107. this.eventMouseDown = this._initDrag.bindAsEventListener(this);
  108. this.eventMouseUp = this._endDrag.bindAsEventListener(this);
  109. this.eventMouseMove = this._updateDrag.bindAsEventListener(this);
  110. this.eventOnLoad = this._getWindowBorderSize.bindAsEventListener(this);
  111. this.eventMouseDownContent = this.toFront.bindAsEventListener(this);
  112. this.eventResize = this._recenter.bindAsEventListener(this);
  113. this.eventKeyUp = this._keyUp.bindAsEventListener(this);
  114. this.topbar = $(this.element.id + "_top");
  115. this.bottombar = $(this.element.id + "_bottom");
  116. this.content = $(this.element.id + "_content");
  117. Event.observe(this.topbar, "mousedown", this.eventMouseDown);
  118. Event.observe(this.bottombar, "mousedown", this.eventMouseDown);
  119. Event.observe(this.content, "mousedown", this.eventMouseDownContent);
  120. Event.observe(window, "load", this.eventOnLoad);
  121. Event.observe(window, "resize", this.eventResize);
  122. Event.observe(window, "scroll", this.eventResize);
  123. Event.observe(document, "keyup", this.eventKeyUp);
  124. Event.observe(this.options.parent, "scroll", this.eventResize);
  125. if (this.options.draggable) {
  126. var that = this;
  127. [this.topbar, this.topbar.up().previous(), this.topbar.up().next()].each(function(element) {
  128. element.observe("mousedown", that.eventMouseDown);
  129. element.addClassName("top_draggable");
  130. });
  131. [this.bottombar.up(), this.bottombar.up().previous(), this.bottombar.up().next()].each(function(element) {
  132. element.observe("mousedown", that.eventMouseDown);
  133. element.addClassName("bottom_draggable");
  134. });
  135. }
  136. if (this.options.resizable) {
  137. this.sizer = $(this.element.id + "_sizer");
  138. Event.observe(this.sizer, "mousedown", this.eventMouseDown);
  139. }
  140. this.useLeft = null;
  141. this.useTop = null;
  142. if (typeof this.options.left != "undefined") {
  143. this.element.setStyle({left: parseFloat(this.options.left) + 'px'});
  144. this.useLeft = true;
  145. }
  146. else {
  147. this.element.setStyle({right: parseFloat(this.options.right) + 'px'});
  148. this.useLeft = false;
  149. }
  150. if (typeof this.options.top != "undefined") {
  151. this.element.setStyle({top: parseFloat(this.options.top) + 'px'});
  152. this.useTop = true;
  153. }
  154. else {
  155. this.element.setStyle({bottom: parseFloat(this.options.bottom) + 'px'});
  156. this.useTop = false;
  157. }
  158. this.storedLocation = null;
  159. this.setOpacity(this.options.opacity);
  160. if (this.options.zIndex) {
  161. this.setZIndex(this.options.zIndex)
  162. } else {
  163. this.setZIndex(this.getMaxZIndex());
  164. }
  165. if (this.options.destroyOnClose)
  166. this.setDestroyOnClose(true);
  167. this._getWindowBorderSize();
  168. this.width = this.options.width;
  169. this.height = this.options.height;
  170. this.visible = false;
  171. this.constraint = false;
  172. this.constraintPad = {top: 0, left:0, bottom:0, right:0};
  173. if (this.width && this.height)
  174. this.setSize(this.options.width, this.options.height);
  175. this.setTitle(this.options.title)
  176. Windows.register(this);
  177. },
  178. getMaxZIndex: function() {
  179. var max = 0, i;
  180. var cn = document.body.childNodes;
  181. for (i = 0; i < cn.length; i++) {
  182. var el = cn[i];
  183. var zIndex = el.nodeType == 1 ? parseInt(el.style.zIndex, 10) || 0 : 0;
  184. if (zIndex < 10000) {
  185. max = Math.max(max, zIndex);
  186. }
  187. }
  188. return max + 10;
  189. },
  190. // Destructor
  191. destroy: function() {
  192. this._notify("onDestroy");
  193. Event.stopObserving(this.topbar, "mousedown", this.eventMouseDown);
  194. Event.stopObserving(this.bottombar, "mousedown", this.eventMouseDown);
  195. Event.stopObserving(this.content, "mousedown", this.eventMouseDownContent);
  196. Event.stopObserving(window, "load", this.eventOnLoad);
  197. Event.stopObserving(window, "resize", this.eventResize);
  198. Event.stopObserving(window, "scroll", this.eventResize);
  199. Event.stopObserving(this.content, "load", this.options.onload);
  200. Event.stopObserving(document, "keyup", this.eventKeyUp);
  201. if (this._oldParent) {
  202. var content = this.getContent();
  203. var originalContent = null;
  204. for(var i = 0; i < content.childNodes.length; i++) {
  205. originalContent = content.childNodes[i];
  206. if (originalContent.nodeType == 1)
  207. break;
  208. originalContent = null;
  209. }
  210. if (originalContent)
  211. this._oldParent.appendChild(originalContent);
  212. this._oldParent = null;
  213. }
  214. if (this.sizer)
  215. Event.stopObserving(this.sizer, "mousedown", this.eventMouseDown);
  216. if (this.options.url)
  217. this.content.src = null
  218. if(this.iefix)
  219. Element.remove(this.iefix);
  220. Element.remove(this.element);
  221. Windows.unregister(this);
  222. },
  223. // Sets close callback, if it sets, it should return true to be able to close the window.
  224. setCloseCallback: function(callback) {
  225. this.options.closeCallback = callback;
  226. },
  227. // Gets window content
  228. getContent: function () {
  229. return this.content;
  230. },
  231. // Sets the content with an element id
  232. setContent: function(id, autoresize, autoposition) {
  233. var element = $(id);
  234. if (null == element) throw "Unable to find element '" + id + "' in DOM";
  235. this._oldParent = element.parentNode;
  236. var d = null;
  237. var p = null;
  238. if (autoresize)
  239. d = Element.getDimensions(element);
  240. if (autoposition)
  241. p = Position.cumulativeOffset(element);
  242. var content = this.getContent();
  243. // Clear HTML (and even iframe)
  244. this.setHTMLContent("");
  245. content = this.getContent();
  246. content.appendChild(element);
  247. element.show();
  248. if (autoresize)
  249. this.setSize(d.width, d.height);
  250. if (autoposition)
  251. this.setLocation(p[1] - this.heightN, p[0] - this.widthW);
  252. },
  253. setHTMLContent: function(html) {
  254. // It was an url (iframe), recreate a div content instead of iframe content
  255. if (this.options.url) {
  256. this.content.src = null;
  257. this.options.url = null;
  258. var content ="<div id=\"" + this.getId() + "_content\" class=\"" + this.options.className + "_content\"> </div>";
  259. $(this.getId() +"_table_content").innerHTML = content;
  260. this.content = $(this.element.id + "_content");
  261. }
  262. this.getContent().innerHTML = html;
  263. },
  264. setAjaxContent: function(url, options, showCentered, showModal) {
  265. this.showFunction = showCentered ? "showCenter" : "show";
  266. this.showModal = showModal || false;
  267. options = options || {};
  268. // Clear HTML (and even iframe)
  269. this.setHTMLContent("");
  270. this.onComplete = options.onComplete;
  271. if (! this._onCompleteHandler)
  272. this._onCompleteHandler = this._setAjaxContent.bind(this);
  273. options.onComplete = this._onCompleteHandler;
  274. new Ajax.Request(url, options);
  275. options.onComplete = this.onComplete;
  276. },
  277. _setAjaxContent: function(originalRequest) {
  278. Element.update(this.getContent(), originalRequest.responseText);
  279. if (this.onComplete)
  280. this.onComplete(originalRequest);
  281. this.onComplete = null;
  282. this[this.showFunction](this.showModal)
  283. },
  284. setURL: function(url) {
  285. // Not an url content, change div to iframe
  286. if (this.options.url)
  287. this.content.src = null;
  288. this.options.url = url;
  289. var content= "<iframe frameborder='0' name='" + this.getId() + "_content' id='" + this.getId() + "_content' src='" + url + "' width='" + this.width + "' height='" + this.height + "'> </iframe>";
  290. $(this.getId() +"_table_content").innerHTML = content;
  291. this.content = $(this.element.id + "_content");
  292. },
  293. getURL: function() {
  294. return this.options.url ? this.options.url : null;
  295. },
  296. refresh: function() {
  297. if (this.options.url)
  298. $(this.element.getAttribute('id') + '_content').src = this.options.url;
  299. },
  300. // Stores position/size in a cookie, by default named with window id
  301. setCookie: function(name, expires, path, domain, secure) {
  302. name = name || this.element.id;
  303. this.cookie = [name, expires, path, domain, secure];
  304. // Get cookie
  305. var value = WindowUtilities.getCookie(name)
  306. // If exists
  307. if (value) {
  308. var values = value.split(',');
  309. var x = values[0].split(':');
  310. var y = values[1].split(':');
  311. var w = parseFloat(values[2]), h = parseFloat(values[3]);
  312. var mini = values[4];
  313. var maxi = values[5];
  314. this.setSize(w, h);
  315. if (mini == "true")
  316. this.doMinimize = true; // Minimize will be done at onload window event
  317. else if (maxi == "true")
  318. this.doMaximize = true; // Maximize will be done at onload window event
  319. this.useLeft = x[0] == "l";
  320. this.useTop = y[0] == "t";
  321. this.element.setStyle(this.useLeft ? {left: x[1]} : {right: x[1]});
  322. this.element.setStyle(this.useTop ? {top: y[1]} : {bottom: y[1]});
  323. }
  324. },
  325. // Gets window ID
  326. getId: function() {
  327. return this.element.id;
  328. },
  329. // Detroys itself when closing
  330. setDestroyOnClose: function() {
  331. this.options.destroyOnClose = true;
  332. },
  333. setConstraint: function(bool, padding) {
  334. this.constraint = bool;
  335. this.constraintPad = Object.extend(this.constraintPad, padding || {});
  336. // Reset location to apply constraint
  337. if (this.useTop && this.useLeft)
  338. this.setLocation(parseFloat(this.element.style.top), parseFloat(this.element.style.left));
  339. },
  340. // initDrag event
  341. _initDrag: function(event) {
  342. // No resize on minimized window
  343. if (Event.element(event) == this.sizer && this.isMinimized())
  344. return;
  345. // No move on maximzed window
  346. if (Event.element(event) != this.sizer && this.isMaximized())
  347. return;
  348. if (Prototype.Browser.IE && this.heightN == 0)
  349. this._getWindowBorderSize();
  350. // Get pointer X,Y
  351. this.pointer = [this._round(Event.pointerX(event), this.options.gridX), this._round(Event.pointerY(event), this.options.gridY)];
  352. if (this.options.wiredDrag)
  353. this.currentDrag = this._createWiredElement();
  354. else
  355. this.currentDrag = this.element;
  356. // Resize
  357. if (Event.element(event) == this.sizer) {
  358. this.doResize = true;
  359. this.widthOrg = this.width;
  360. this.heightOrg = this.height;
  361. this.bottomOrg = parseFloat(this.element.getStyle('bottom'));
  362. this.rightOrg = parseFloat(this.element.getStyle('right'));
  363. this._notify("onStartResize");
  364. }
  365. else {
  366. this.doResize = false;
  367. // Check if click on close button,
  368. var closeButton = $(this.getId() + '_close');
  369. if (closeButton && Position.within(closeButton, this.pointer[0], this.pointer[1])) {
  370. this.currentDrag = null;
  371. return;
  372. }
  373. this.toFront();
  374. if (! this.options.draggable)
  375. return;
  376. this._notify("onStartMove");
  377. }
  378. // Register global event to capture mouseUp and mouseMove
  379. Event.observe(document, "mouseup", this.eventMouseUp, false);
  380. Event.observe(document, "mousemove", this.eventMouseMove, false);
  381. // Add an invisible div to keep catching mouse event over iframes
  382. WindowUtilities.disableScreen('__invisible__', '__invisible__', this.overlayOpacity);
  383. // Stop selection while dragging
  384. document.body.ondrag = function () { return false; };
  385. document.body.onselectstart = function () { return false; };
  386. this.currentDrag.show();
  387. Event.stop(event);
  388. },
  389. _round: function(val, round) {
  390. return round == 1 ? val : val = Math.floor(val / round) * round;
  391. },
  392. // updateDrag event
  393. _updateDrag: function(event) {
  394. var pointer = [this._round(Event.pointerX(event), this.options.gridX), this._round(Event.pointerY(event), this.options.gridY)];
  395. var dx = pointer[0] - this.pointer[0];
  396. var dy = pointer[1] - this.pointer[1];
  397. // Resize case, update width/height
  398. if (this.doResize) {
  399. var w = this.widthOrg + dx;
  400. var h = this.heightOrg + dy;
  401. dx = this.width - this.widthOrg
  402. dy = this.height - this.heightOrg
  403. // Check if it's a right position, update it to keep upper-left corner at the same position
  404. if (this.useLeft)
  405. w = this._updateWidthConstraint(w)
  406. else
  407. this.currentDrag.setStyle({right: (this.rightOrg -dx) + 'px'});
  408. // Check if it's a bottom position, update it to keep upper-left corner at the same position
  409. if (this.useTop)
  410. h = this._updateHeightConstraint(h)
  411. else
  412. this.currentDrag.setStyle({bottom: (this.bottomOrg -dy) + 'px'});
  413. this.setSize(w , h);
  414. this._notify("onResize");
  415. }
  416. // Move case, update top/left
  417. else {
  418. this.pointer = pointer;
  419. if (this.useLeft) {
  420. var left = parseFloat(this.currentDrag.getStyle('left')) + dx;
  421. var newLeft = this._updateLeftConstraint(left);
  422. // Keep mouse pointer correct
  423. this.pointer[0] += newLeft-left;
  424. this.currentDrag.setStyle({left: newLeft + 'px'});
  425. }
  426. else
  427. this.currentDrag.setStyle({right: parseFloat(this.currentDrag.getStyle('right')) - dx + 'px'});
  428. if (this.useTop) {
  429. var top = parseFloat(this.currentDrag.getStyle('top')) + dy;
  430. var newTop = this._updateTopConstraint(top);
  431. // Keep mouse pointer correct
  432. this.pointer[1] += newTop - top;
  433. this.currentDrag.setStyle({top: newTop + 'px'});
  434. }
  435. else
  436. this.currentDrag.setStyle({bottom: parseFloat(this.currentDrag.getStyle('bottom')) - dy + 'px'});
  437. this._notify("onMove");
  438. }
  439. if (this.iefix)
  440. this._fixIEOverlapping();
  441. this._removeStoreLocation();
  442. Event.stop(event);
  443. },
  444. // endDrag callback
  445. _endDrag: function(event) {
  446. // Remove temporary div over iframes
  447. WindowUtilities.enableScreen('__invisible__');
  448. if (this.doResize)
  449. this._notify("onEndResize");
  450. else
  451. this._notify("onEndMove");
  452. // Release event observing
  453. Event.stopObserving(document, "mouseup", this.eventMouseUp,false);
  454. Event.stopObserving(document, "mousemove", this.eventMouseMove, false);
  455. Event.stop(event);
  456. this._hideWiredElement();
  457. // Store new location/size if need be
  458. this._saveCookie()
  459. // Restore selection
  460. document.body.ondrag = null;
  461. document.body.onselectstart = null;
  462. },
  463. _updateLeftConstraint: function(left) {
  464. if (this.constraint && this.useLeft && this.useTop) {
  465. var width = this.options.parent == document.body ? WindowUtilities.getPageSize().windowWidth : this.options.parent.getDimensions().width;
  466. if (left < this.constraintPad.left)
  467. left = this.constraintPad.left;
  468. if (left + this.width + this.widthE + this.widthW > width - this.constraintPad.right)
  469. left = width - this.constraintPad.right - this.width - this.widthE - this.widthW;
  470. }
  471. return left;
  472. },
  473. _updateTopConstraint: function(top) {
  474. if (this.constraint && this.useLeft && this.useTop) {
  475. var height = this.options.parent == document.body ? WindowUtilities.getPageSize().windowHeight : this.options.parent.getDimensions().height;
  476. var h = this.height + this.heightN + this.heightS;
  477. if (top < this.constraintPad.top)
  478. top = this.constraintPad.top;
  479. if (top + h > height - this.constraintPad.bottom)
  480. top = height - this.constraintPad.bottom - h;
  481. }
  482. return top;
  483. },
  484. _updateWidthConstraint: function(w) {
  485. if (this.constraint && this.useLeft && this.useTop) {
  486. var width = this.options.parent == document.body ? WindowUtilities.getPageSize().windowWidth : this.options.parent.getDimensions().width;
  487. var left = parseFloat(this.element.getStyle("left"));
  488. if (left + w + this.widthE + this.widthW > width - this.constraintPad.right)
  489. w = width - this.constraintPad.right - left - this.widthE - this.widthW;
  490. }
  491. return w;
  492. },
  493. _updateHeightConstraint: function(h) {
  494. if (this.constraint && this.useLeft && this.useTop) {
  495. var height = this.options.parent == document.body ? WindowUtilities.getPageSize().windowHeight : this.options.parent.getDimensions().height;
  496. var top = parseFloat(this.element.getStyle("top"));
  497. if (top + h + this.heightN + this.heightS > height - this.constraintPad.bottom)
  498. h = height - this.constraintPad.bottom - top - this.heightN - this.heightS;
  499. }
  500. return h;
  501. },
  502. // Creates HTML window code
  503. _createWindow: function(id) {
  504. var className = this.options.className;
  505. var win = document.createElement("div");
  506. win.setAttribute('id', id);
  507. win.className = "dialog";
  508. if (this.options.windowClassName) {
  509. win.className += ' ' + this.options.windowClassName;
  510. }
  511. var content;
  512. if (this.options.url)
  513. content= "<iframe frameborder=\"0\" name=\"" + id + "_content\" id=\"" + id + "_content\" src=\"" + this.options.url + "\"> </iframe>";
  514. else
  515. content ="<div id=\"" + id + "_content\" class=\"" +className + "_content\"> </div>";
  516. var closeDiv = this.options.closable ? "<div class='"+ className +"_close' id='"+ id +"_close' onclick='Windows.close(\""+ id +"\", event)'> </div>" : "";
  517. var minDiv = this.options.minimizable ? "<div class='"+ className + "_minimize' id='"+ id +"_minimize' onclick='Windows.minimize(\""+ id +"\", event)'> </div>" : "";
  518. var maxDiv = this.options.maximizable ? "<div class='"+ className + "_maximize' id='"+ id +"_maximize' onclick='Windows.maximize(\""+ id +"\", event)'> </div>" : "";
  519. var seAttributes = this.options.resizable ? "class='" + className + "_sizer' id='" + id + "_sizer'" : "class='" + className + "_se'";
  520. var blank = "../themes/default/blank.gif";
  521. win.innerHTML = closeDiv + minDiv + maxDiv + "\
  522. <a href='#' id='"+ id +"_focus_anchor'><!-- --></a>\
  523. <table id='"+ id +"_row1' class=\"top table_window\">\
  524. <tr>\
  525. <td class='"+ className +"_nw'></td>\
  526. <td class='"+ className +"_n'><div id='"+ id +"_top' class='"+ className +"_title title_window'>"+ this.options.title +"</div></td>\
  527. <td class='"+ className +"_ne'></td>\
  528. </tr>\
  529. </table>\
  530. <table id='"+ id +"_row2' class=\"mid table_window\">\
  531. <tr>\
  532. <td class='"+ className +"_w'></td>\
  533. <td id='"+ id +"_table_content' class='"+ className +"_content' valign='top'>" + content + "</td>\
  534. <td class='"+ className +"_e'></td>\
  535. </tr>\
  536. </table>\
  537. <table id='"+ id +"_row3' class=\"bot table_window\">\
  538. <tr>\
  539. <td class='"+ className +"_sw'></td>\
  540. <td class='"+ className +"_s'><div id='"+ id +"_bottom' class='status_bar'><span style='float:left; width:1px; height:1px'></span></div></td>\
  541. <td " + seAttributes + "></td>\
  542. </tr>\
  543. </table>\
  544. ";
  545. Element.hide(win);
  546. this.options.parent.insertBefore(win, this.options.parent.firstChild);
  547. Event.observe($(id + "_content"), "load", this.options.onload);
  548. return win;
  549. },
  550. changeClassName: function(newClassName) {
  551. var className = this.options.className;
  552. var id = this.getId();
  553. $A(["_close", "_minimize", "_maximize", "_sizer", "_content"]).each(function(value) { this._toggleClassName($(id + value), className + value, newClassName + value) }.bind(this));
  554. this._toggleClassName($(id + "_top"), className + "_title", newClassName + "_title");
  555. $$("#" + id + " td").each(function(td) {td.className = td.className.sub(className,newClassName); });
  556. this.options.className = newClassName;
  557. },
  558. _toggleClassName: function(element, oldClassName, newClassName) {
  559. if (element) {
  560. element.removeClassName(oldClassName);
  561. element.addClassName(newClassName);
  562. }
  563. },
  564. // Sets window location
  565. setLocation: function(top, left) {
  566. top = this._updateTopConstraint(top);
  567. left = this._updateLeftConstraint(left);
  568. var e = this.currentDrag || this.element;
  569. e.setStyle({top: top + 'px'});
  570. e.setStyle({left: left + 'px'});
  571. this.useLeft = true;
  572. this.useTop = true;
  573. },
  574. getLocation: function() {
  575. var location = {};
  576. if (this.useTop)
  577. location = Object.extend(location, {top: this.element.getStyle("top")});
  578. else
  579. location = Object.extend(location, {bottom: this.element.getStyle("bottom")});
  580. if (this.useLeft)
  581. location = Object.extend(location, {left: this.element.getStyle("left")});
  582. else
  583. location = Object.extend(location, {right: this.element.getStyle("right")});
  584. return location;
  585. },
  586. // Gets window size
  587. getSize: function() {
  588. return {width: this.width, height: this.height};
  589. },
  590. // Sets window size
  591. setSize: function(width, height, useEffect) {
  592. width = parseFloat(width);
  593. height = parseFloat(height);
  594. // Check min and max size
  595. if (!this.minimized && width < this.options.minWidth)
  596. width = this.options.minWidth;
  597. if (!this.minimized && height < this.options.minHeight)
  598. height = this.options.minHeight;
  599. if (this.options. maxHeight && height > this.options. maxHeight)
  600. height = this.options. maxHeight;
  601. if (this.options. maxWidth && width > this.options. maxWidth)
  602. width = this.options. maxWidth;
  603. if (this.useTop && this.useLeft && Window.hasEffectLib && Effect.ResizeWindow && useEffect) {
  604. new Effect.ResizeWindow(this, null, null, width, height, {duration: Window.resizeEffectDuration});
  605. } else {
  606. this.width = width;
  607. this.height = height;
  608. var e = this.currentDrag ? this.currentDrag : this.element;
  609. e.setStyle({width: width + this.widthW + this.widthE + "px"})
  610. e.setStyle({height: height + this.heightN + this.heightS + "px"})
  611. // Update content size
  612. if (!this.currentDrag || this.currentDrag == this.element) {
  613. var content = $(this.element.id + '_content');
  614. content.setStyle({height: height + 'px'});
  615. content.setStyle({width: width + 'px'});
  616. }
  617. }
  618. },
  619. updateHeight: function() {
  620. this.setSize(this.width, this.content.scrollHeight, true);
  621. },
  622. updateWidth: function() {
  623. this.setSize(this.content.scrollWidth, this.height, true);
  624. },
  625. // Brings window to front
  626. toFront: function() {
  627. if (this.element.style.zIndex < Windows.maxZIndex)
  628. this.setZIndex(Windows.maxZIndex + 1);
  629. if (this.iefix)
  630. this._fixIEOverlapping();
  631. },
  632. getBounds: function(insideOnly) {
  633. if (! this.width || !this.height || !this.visible)
  634. this.computeBounds();
  635. var w = this.width;
  636. var h = this.height;
  637. if (!insideOnly) {
  638. w += this.widthW + this.widthE;
  639. h += this.heightN + this.heightS;
  640. }
  641. var bounds = Object.extend(this.getLocation(), {width: w + "px", height: h + "px"});
  642. return bounds;
  643. },
  644. computeBounds: function() {
  645. if (! this.width || !this.height) {
  646. var size = WindowUtilities._computeSize(this.content.innerHTML, this.content.id, this.width, this.height, 0, this.options.className)
  647. if (this.height)
  648. this.width = size + 5
  649. else
  650. this.height = size + 5
  651. }
  652. this.setSize(this.width, this.height);
  653. if (this.centered)
  654. this._center(this.centerTop, this.centerLeft);
  655. },
  656. // Displays window modal state or not
  657. show: function(modal) {
  658. this.visible = true;
  659. if (modal) {
  660. // Hack for Safari !!
  661. if (typeof this.overlayOpacity == "undefined") {
  662. var that = this;
  663. setTimeout(function() {that.show(modal)}, 10);
  664. return;
  665. }
  666. Windows.addModalWindow(this);
  667. this.modal = true;
  668. this.setZIndex(Windows.maxZIndex + 1);
  669. Windows.unsetOverflow(this);
  670. }
  671. else
  672. if (!this.element.style.zIndex)
  673. this.setZIndex(Windows.maxZIndex + 1);
  674. // To restore overflow if need be
  675. if (this.oldStyle)
  676. this.getContent().setStyle({overflow: this.oldStyle});
  677. this.computeBounds();
  678. this._notify("onBeforeShow");
  679. if (this.options.showEffect != Element.show && this.options.showEffectOptions)
  680. this.options.showEffect(this.element, this.options.showEffectOptions);
  681. else
  682. this.options.showEffect(this.element);
  683. this._checkIEOverlapping();
  684. WindowUtilities.focusedWindow = this
  685. this._notify("onShow");
  686. $(this.element.id + '_focus_anchor').focus();
  687. },
  688. // Displays window modal state or not at the center of the page
  689. showCenter: function(modal, top, left) {
  690. this.centered = true;
  691. this.centerTop = top;
  692. this.centerLeft = left;
  693. this.show(modal);
  694. },
  695. isVisible: function() {
  696. return this.visible;
  697. },
  698. _center: function(top, left) {
  699. var windowScroll = WindowUtilities.getWindowScroll(this.options.parent);
  700. var pageSize = WindowUtilities.getPageSize(this.options.parent);
  701. if (typeof top == "undefined")
  702. top = (pageSize.windowHeight - (this.height + this.heightN + this.heightS))/2;
  703. top += windowScroll.top
  704. if (typeof left == "undefined")
  705. left = (pageSize.windowWidth - (this.width + this.widthW + this.widthE))/2;
  706. left += windowScroll.left
  707. this.setLocation(top, left);
  708. this.toFront();
  709. },
  710. _recenter: function(event) {
  711. if (this.centered) {
  712. var pageSize = WindowUtilities.getPageSize(this.options.parent);
  713. var windowScroll = WindowUtilities.getWindowScroll(this.options.parent);
  714. // Check for this stupid IE that sends dumb events
  715. if (this.pageSize && this.pageSize.windowWidth == pageSize.windowWidth && this.pageSize.windowHeight == pageSize.windowHeight &&
  716. this.windowScroll.left == windowScroll.left && this.windowScroll.top == windowScroll.top)
  717. return;
  718. this.pageSize = pageSize;
  719. this.windowScroll = windowScroll;
  720. // set height of Overlay to take up whole page and show
  721. if ($('overlay_modal'))
  722. $('overlay_modal').setStyle({height: (pageSize.pageHeight + 'px')});
  723. if (this.options.recenterAuto)
  724. this._center(this.centerTop, this.centerLeft);
  725. }
  726. },
  727. // Hides window
  728. hide: function() {
  729. this.visible = false;
  730. if (this.modal) {
  731. Windows.removeModalWindow(this);
  732. Windows.resetOverflow();
  733. }
  734. // To avoid bug on scrolling bar
  735. this.oldStyle = this.getContent().getStyle('overflow') || "auto"
  736. this.getContent().setStyle({overflow: "hidden"});
  737. this.options.hideEffect(this.element, this.options.hideEffectOptions);
  738. if(this.iefix)
  739. this.iefix.hide();
  740. if (!this.doNotNotifyHide)
  741. this._notify("onHide");
  742. },
  743. close: function() {
  744. // Asks closeCallback if exists
  745. if (this.visible) {
  746. if (this.options.closeCallback && ! this.options.closeCallback(this))
  747. return;
  748. if (this.options.destroyOnClose) {
  749. var destroyFunc = this.destroy.bind(this);
  750. if (this.options.hideEffectOptions.afterFinish) {
  751. var func = this.options.hideEffectOptions.afterFinish;
  752. this.options.hideEffectOptions.afterFinish = function() {func();destroyFunc() }
  753. }
  754. else
  755. this.options.hideEffectOptions.afterFinish = function() {destroyFunc() }
  756. }
  757. Windows.updateFocusedWindow();
  758. this.doNotNotifyHide = true;
  759. this.hide();
  760. this.doNotNotifyHide = false;
  761. this._notify("onClose");
  762. }
  763. },
  764. minimize: function() {
  765. if (this.resizing)
  766. return;
  767. var r2 = $(this.getId() + "_row2");
  768. if (!this.minimized) {
  769. this.minimized = true;
  770. var dh = r2.getDimensions().height;
  771. this.r2Height = dh;
  772. var h = this.element.getHeight() - dh;
  773. if (this.useLeft && this.useTop && Window.hasEffectLib && Effect.ResizeWindow) {
  774. new Effect.ResizeWindow(this, null, null, null, this.height -dh, {duration: Window.resizeEffectDuration});
  775. } else {
  776. this.height -= dh;
  777. this.element.setStyle({height: h + "px"});
  778. r2.hide();
  779. }
  780. if (! this.useTop) {
  781. var bottom = parseFloat(this.element.getStyle('bottom'));
  782. this.element.setStyle({bottom: (bottom + dh) + 'px'});
  783. }
  784. }
  785. else {
  786. this.minimized = false;
  787. var dh = this.r2Height;
  788. this.r2Height = null;
  789. if (this.useLeft && this.useTop && Window.hasEffectLib && Effect.ResizeWindow) {
  790. new Effect.ResizeWindow(this, null, null, null, this.height + dh, {duration: Window.resizeEffectDuration});
  791. }
  792. else {
  793. var h = this.element.getHeight() + dh;
  794. this.height += dh;
  795. this.element.setStyle({height: h + "px"})
  796. r2.show();
  797. }
  798. if (! this.useTop) {
  799. var bottom = parseFloat(this.element.getStyle('bottom'));
  800. this.element.setStyle({bottom: (bottom - dh) + 'px'});
  801. }
  802. this.toFront();
  803. }
  804. this._notify("onMinimize");
  805. // Store new location/size if need be
  806. this._saveCookie()
  807. },
  808. maximize: function() {
  809. if (this.isMinimized() || this.resizing)
  810. return;
  811. if (Prototype.Browser.IE && this.heightN == 0)
  812. this._getWindowBorderSize();
  813. if (this.storedLocation != null) {
  814. this._restoreLocation();
  815. if(this.iefix)
  816. this.iefix.hide();
  817. }
  818. else {
  819. this._storeLocation();
  820. Windows.unsetOverflow(this);
  821. var windowScroll = WindowUtilities.getWindowScroll(this.options.parent);
  822. var pageSize = WindowUtilities.getPageSize(this.options.parent);
  823. var left = windowScroll.left;
  824. var top = windowScroll.top;
  825. if (this.options.parent != document.body) {
  826. windowScroll = {top:0, left:0, bottom:0, right:0};
  827. var dim = this.options.parent.getDimensions();
  828. pageSize.windowWidth = dim.width;
  829. pageSize.windowHeight = dim.height;
  830. top = 0;
  831. left = 0;
  832. }
  833. if (this.constraint) {
  834. pageSize.windowWidth -= Math.max(0, this.constraintPad.left) + Math.max(0, this.constraintPad.right);
  835. pageSize.windowHeight -= Math.max(0, this.constraintPad.top) + Math.max(0, this.constraintPad.bottom);
  836. left += Math.max(0, this.constraintPad.left);
  837. top += Math.max(0, this.constraintPad.top);
  838. }
  839. var width = pageSize.windowWidth - this.widthW - this.widthE;
  840. var height= pageSize.windowHeight - this.heightN - this.heightS;
  841. if (this.useLeft && this.useTop && Window.hasEffectLib && Effect.ResizeWindow) {
  842. new Effect.ResizeWindow(this, top, left, width, height, {duration: Window.resizeEffectDuration});
  843. }
  844. else {
  845. this.setSize(width, height);
  846. this.element.setStyle(this.useLeft ? {left: left} : {right: left});
  847. this.element.setStyle(this.useTop ? {top: top} : {bottom: top});
  848. }
  849. this.toFront();
  850. if (this.iefix)
  851. this._fixIEOverlapping();
  852. }
  853. this._notify("onMaximize");
  854. // Store new location/size if need be
  855. this._saveCookie()
  856. },
  857. isMinimized: function() {
  858. return this.minimized;
  859. },
  860. isMaximized: function() {
  861. return (this.storedLocation != null);
  862. },
  863. setOpacity: function(opacity) {
  864. if (Element.setOpacity)
  865. Element.setOpacity(this.element, opacity);
  866. },
  867. setZIndex: function(zindex) {
  868. this.element.setStyle({zIndex: zindex});
  869. Windows.updateZindex(zindex, this);
  870. },
  871. setTitle: function(newTitle) {
  872. if (!newTitle || newTitle == "")
  873. newTitle = "&nbsp;";
  874. Element.update(this.element.id + '_top', newTitle);
  875. },
  876. getTitle: function() {
  877. return $(this.element.id + '_top').innerHTML;
  878. },
  879. setStatusBar: function(element) {
  880. var statusBar = $(this.getId() + "_bottom");
  881. if (typeof(element) == "object") {
  882. if (this.bottombar.firstChild)
  883. this.bottombar.replaceChild(element, this.bottombar.firstChild);
  884. else
  885. this.bottombar.appendChild(element);
  886. }
  887. else
  888. this.bottombar.innerHTML = element;
  889. },
  890. _checkIEOverlapping: function() {
  891. if(!this.iefix && (navigator.appVersion.indexOf('MSIE')>0) && (navigator.userAgent.indexOf('Opera')<0) && (this.element.getStyle('position')=='absolute')) {
  892. new Insertion.After(this.element.id, '<iframe id="' + this.element.id + '_iefix" '+ 'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' + 'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
  893. this.iefix = $(this.element.id+'_iefix');
  894. }
  895. if(this.iefix)
  896. setTimeout(this._fixIEOverlapping.bind(this), 50);
  897. },
  898. _fixIEOverlapping: function() {
  899. Position.clone(this.element, this.iefix);
  900. this.iefix.style.zIndex = this.element.style.zIndex - 1;
  901. this.iefix.show();
  902. },
  903. _keyUp: function(event) {
  904. if (27 == event.keyCode && this.options.closeOnEsc) {
  905. this.close();
  906. }
  907. },
  908. _getWindowBorderSize: function(event) {
  909. // Hack to get real window border size!!
  910. var div = this._createHiddenDiv(this.options.className + "_n")
  911. this.heightN = Element.getDimensions(div).height;
  912. div.parentNode.removeChild(div)
  913. var div = this._createHiddenDiv(this.options.className + "_s")
  914. this.heightS = Element.getDimensions(div).height;
  915. div.parentNode.removeChild(div)
  916. var div = this._createHiddenDiv(this.options.className + "_e")
  917. this.widthE = Element.getDimensions(div).width;
  918. div.parentNode.removeChild(div)
  919. var div = this._createHiddenDiv(this.options.className + "_w")
  920. this.widthW = Element.getDimensions(div).width;
  921. div.parentNode.removeChild(div);
  922. var div = document.createElement("div");
  923. div.className = "overlay_" + this.options.className ;
  924. document.body.appendChild(div);
  925. //alert("no timeout:\nopacity: " + div.getStyle("opacity") + "\nwidth: " + document.defaultView.getComputedStyle(div, null).width);
  926. var that = this;
  927. // Workaround for Safari!!
  928. setTimeout(function() {that.overlayOpacity = ($(div).getStyle("opacity")); div.parentNode.removeChild(div);}, 10);
  929. // Workaround for IE!!
  930. if (Prototype.Browser.IE) {
  931. this.heightS = $(this.getId() +"_row3").getDimensions().height;
  932. this.heightN = $(this.getId() +"_row1").getDimensions().height;
  933. }
  934. // Safari size fix
  935. if (Prototype.Browser.WebKit && Prototype.Browser.WebKitVersion < 420)
  936. this.setSize(this.width, this.height);
  937. if (this.doMaximize)
  938. this.maximize();
  939. if (this.doMinimize)
  940. this.minimize();
  941. },
  942. _createHiddenDiv: function(className) {
  943. var objBody = document.body;
  944. var win = document.createElement("div");
  945. win.setAttribute('id', this.element.id+ "_tmp");
  946. win.className = className;
  947. win.style.display = 'none';
  948. win.innerHTML = '';
  949. objBody.insertBefore(win, objBody.firstChild);
  950. return win;
  951. },
  952. _storeLocation: function() {
  953. if (this.storedLocation == null) {
  954. this.storedLocation = {useTop: this.useTop, useLeft: this.useLeft,
  955. top: this.element.getStyle('top'), bottom: this.element.getStyle('bottom'),
  956. left: this.element.getStyle('left'), right: this.element.getStyle('right'),
  957. width: this.width, height: this.height };
  958. }
  959. },
  960. _restoreLocation: function() {
  961. if (this.storedLocation != null) {
  962. this.useLeft = this.storedLocation.useLeft;
  963. this.useTop = this.storedLocation.useTop;
  964. if (this.useLeft && this.useTop && Window.hasEffectLib && Effect.ResizeWindow)
  965. new Effect.ResizeWindow(this, this.storedLocation.top, this.storedLocation.left, this.storedLocation.width, this.storedLocation.height, {duration: Window.resizeEffectDuration});
  966. else {
  967. this.element.setStyle(this.useLeft ? {left: this.storedLocation.left} : {right: this.storedLocation.right});
  968. this.element.setStyle(this.useTop ? {top: this.storedLocation.top} : {bottom: this.storedLocation.bottom});
  969. this.setSize(this.storedLocation.width, this.storedLocation.height);
  970. }
  971. Windows.resetOverflow();
  972. this._removeStoreLocation();
  973. }
  974. },
  975. _removeStoreLocation: function() {
  976. this.storedLocation = null;
  977. },
  978. _saveCookie: function() {
  979. if (this.cookie) {
  980. var value = "";
  981. if (this.useLeft)
  982. value += "l:" + (this.storedLocation ? this.storedLocation.left : this.element.getStyle('left'))
  983. else
  984. value += "r:" + (this.storedLocation ? this.storedLocation.right : this.element.getStyle('right'))
  985. if (this.useTop)
  986. value += ",t:" + (this.storedLocation ? this.storedLocation.top : this.element.getStyle('top'))
  987. else
  988. value += ",b:" + (this.storedLocation ? this.storedLocation.bottom :this.element.getStyle('bottom'))
  989. value += "," + (this.storedLocation ? this.storedLocation.width : this.width);
  990. value += "," + (this.storedLocation ? this.storedLocation.height : this.height);
  991. value += "," + this.isMinimized();
  992. value += "," + this.isMaximized();
  993. WindowUtilities.setCookie(value, this.cookie)
  994. }
  995. },
  996. _createWiredElement: function() {
  997. if (! this.wiredElement) {
  998. if (Prototype.Browser.IE)
  999. this._getWindowBorderSize();
  1000. var div = document.createElement("div");
  1001. div.className = "wired_frame " + this.options.className + "_wired_frame";
  1002. div.style.position = 'absolute';
  1003. this.options.parent.insertBefore(div, this.options.parent.firstChild);
  1004. this.wiredElement = $(div);
  1005. }
  1006. if (this.useLeft)
  1007. this.wiredElement.setStyle({left: this.element.getStyle('left')});
  1008. else
  1009. this.wiredElement.setStyle({right: this.element.getStyle('right')});
  1010. if (this.useTop)
  1011. this.wiredElement.setStyle({top: this.element.getStyle('top')});
  1012. else
  1013. this.wiredElement.setStyle({bottom: this.element.getStyle('bottom')});
  1014. var dim = this.element.getDimensions();
  1015. this.wiredElement.setStyle({width: dim.width + "px", height: dim.height +"px"});
  1016. this.wiredElement.setStyle({zIndex: Windows.maxZIndex+30});
  1017. return this.wiredElement;
  1018. },
  1019. _hideWiredElement: function() {
  1020. if (! this.wiredElement || ! this.currentDrag)
  1021. return;
  1022. if (this.currentDrag == this.element)
  1023. this.currentDrag = null;
  1024. else {
  1025. if (this.useLeft)
  1026. this.element.setStyle({left: this.currentDrag.getStyle('left')});
  1027. else
  1028. this.element.setStyle({right: this.currentDrag.getStyle('right')});
  1029. if (this.useTop)
  1030. this.element.setStyle({top: this.currentDrag.getStyle('top')});
  1031. else
  1032. this.element.setStyle({bottom: this.currentDrag.getStyle('bottom')});
  1033. this.currentDrag.hide();
  1034. this.currentDrag = null;
  1035. if (this.doResize)
  1036. this.setSize(this.width, this.height);
  1037. }
  1038. },
  1039. _notify: function(eventName) {
  1040. if (this.options[eventName])
  1041. this.options[eventName](this);
  1042. else
  1043. Windows.notify(eventName, this);
  1044. }
  1045. };
  1046. // Windows containers, register all page windows
  1047. var Windows = {
  1048. windows: [],
  1049. modalWindows: [],
  1050. observers: [],
  1051. focusedWindow: null,
  1052. maxZIndex: 0,
  1053. overlayShowEffectOptions: {duration: 0.5},
  1054. overlayHideEffectOptions: {duration: 0.5},
  1055. addObserver: function(observer) {
  1056. this.removeObserver(observer);
  1057. this.observers.push(observer);
  1058. },
  1059. removeObserver: function(observer) {
  1060. this.observers = this.observers.reject( function(o) { return o==observer });
  1061. },
  1062. // onDestroy onStartResize onStartMove onResize onMove onEndResize onEndMove onFocus onBlur onBeforeShow onShow onHide onMinimize onMaximize onClose
  1063. notify: function(eventName, win) {
  1064. this.observers.each( function(o) {if(o[eventName]) o[eventName](eventName, win);});
  1065. },
  1066. // Gets window from its id
  1067. getWindow: function(id) {
  1068. return this.windows.detect(function(d) { return d.getId() ==id });
  1069. },
  1070. // Gets the last focused window
  1071. getFocusedWindow: function() {
  1072. return this.focusedWindow;
  1073. },
  1074. updateFocusedWindow: function() {
  1075. this.focusedWindow = this.windows.length >=2 ? this.windows[this.windows.length-2] : null;
  1076. },
  1077. // Registers a new window (called by Windows constructor)
  1078. register: function(win) {
  1079. this.windows.push(win);
  1080. },
  1081. // Add a modal window in the stack
  1082. addModalWindow: function(win) {
  1083. // Disable screen if first modal window
  1084. if (this.modalWindows.length == 0) {
  1085. WindowUtilities.disableScreen(win.options.className, 'overlay_modal', win.overlayOpacity, win.getId(), win.options.parent);
  1086. }
  1087. else {
  1088. // Move overlay over all windows
  1089. if (Window.keepMultiModalWindow) {
  1090. $('overlay_modal').style.zIndex = Windows.maxZIndex + 1;
  1091. Windows.maxZIndex += 1;
  1092. WindowUtilities._hideSelect(this.modalWindows.last().getId());
  1093. }
  1094. // Hide current modal window
  1095. else
  1096. this.modalWindows.last().element.hide();
  1097. // Fucking IE select issue
  1098. WindowUtilities._showSelect(win.getId());
  1099. }
  1100. this.modalWindows.push(win);
  1101. },
  1102. removeModalWindow: function(win) {
  1103. this.modalWindows.pop();
  1104. // No more modal windows
  1105. if (this.modalWindows.length == 0)
  1106. WindowUtilities.enableScreen();
  1107. else {
  1108. if (Window.keepMultiModalWindow) {
  1109. this.modalWindows.last().toFront();
  1110. WindowUtilities._showSelect(this.modalWindows.last().getId());
  1111. }
  1112. else
  1113. this.modalWindows.last().element.show();
  1114. }
  1115. },
  1116. // Registers a new window (called by Windows constructor)
  1117. register: function(win) {
  1118. this.windows.push(win);
  1119. },
  1120. // Unregisters a window (called by Windows destructor)
  1121. unregister: function(win) {
  1122. this.windows = this.windows.reject(function(d) { return d==win });
  1123. },
  1124. // Closes all windows
  1125. closeAll: function() {
  1126. this.windows.each( function(w) {Windows.close(w.getId())} );
  1127. },
  1128. closeAllModalWindows: function() {
  1129. WindowUtilities.enableScreen();
  1130. this.modalWindows.each( function(win) {if (win) win.close()});
  1131. },
  1132. // Minimizes a window with its id
  1133. minimize: function(id, event) {
  1134. var win = this.getWindow(id)
  1135. if (win && win.visible)
  1136. win.minimize();
  1137. Event.stop(event);
  1138. },
  1139. // Maximizes a window with its id
  1140. maximize: function(id, event) {
  1141. var win = this.getWindow(id)
  1142. if (win && win.visible)
  1143. win.maximize();
  1144. Event.stop(event);
  1145. },
  1146. // Closes a window with its id
  1147. close: function(id, event) {
  1148. var win = this.getWindow(id);
  1149. if (win)
  1150. win.close();
  1151. if (event)
  1152. Event.stop(event);
  1153. },
  1154. blur: function(id) {
  1155. var win = this.getWindow(id);
  1156. if (!win)
  1157. return;
  1158. if (win.options.blurClassName)
  1159. win.changeClassName(win.options.blurClassName);
  1160. if (this.focusedWindow == win)
  1161. this.focusedWindow = null;
  1162. win._notify("onBlur");
  1163. },
  1164. focus: function(id) {
  1165. var win = this.getWindow(id);
  1166. if (!win)
  1167. return;
  1168. if (this.focusedWindow)
  1169. this.blur(this.focusedWindow.getId())
  1170. if (win.options.focusClassName)
  1171. win.changeClassName(win.options.focusClassName);
  1172. this.focusedWindow = win;
  1173. win._notify("onFocus");
  1174. },
  1175. unsetOverflow: function(except) {
  1176. this.windows.each(function(d) { d.oldOverflow = d.getContent().getStyle("overflow") || "auto" ; d.getContent().setStyle({overflow: "hidden"}) });
  1177. if (except && except.oldOverflow)
  1178. except.getContent().setStyle({overflow: except.oldOverflow});
  1179. },
  1180. resetOverflow: function() {
  1181. this.windows.each(function(d) { if (d.oldOverflow) d.getContent().setStyle({overflow: d.oldOverflow}) });
  1182. },
  1183. updateZindex: function(zindex, win) {
  1184. if (zindex > this.maxZIndex) {
  1185. this.maxZIndex = zindex;
  1186. if (this.focusedWindow)
  1187. this.blur(this.focusedWindow.getId())
  1188. }
  1189. this.focusedWindow = win;
  1190. if (this.focusedWindow)
  1191. this.focus(this.focusedWindow.getId())
  1192. }
  1193. };
  1194. var Dialog = {
  1195. dialogId: null,
  1196. onCompleteFunc: null,
  1197. callFunc: null,
  1198. parameters: null,
  1199. confirm: function(content, parameters) {
  1200. // Get Ajax return before
  1201. if (content && typeof content != "string") {
  1202. Dialog._runAjaxRequest(content, parameters, Dialog.confirm);
  1203. return
  1204. }
  1205. content = content || "";
  1206. parameters = parameters || {};
  1207. var okLabel = parameters.okLabel ? parameters.okLabel : "Ok";
  1208. var cancelLabel = parameters.cancelLabel ? parameters.cancelLabel : "Cancel";
  1209. // Backward compatibility
  1210. parameters = Object.extend(parameters, parameters.windowParameters || {});
  1211. parameters.windowParameters = parameters.windowParameters || {};
  1212. parameters.className = parameters.className || "alert";
  1213. var okButtonClass = "class ='" + (parameters.buttonClass ? parameters.buttonClass + " " : "") + " ok_button'";
  1214. var cancelButtonClass = "class ='" + (parameters.buttonClass ? parameters.buttonClass + " " : "") + " cancel_button'";
  1215. var content = "\
  1216. <div class='" + parameters.className + "_message'>" + content + "</div>\
  1217. <div class='" + parameters.className + "_buttons'>\
  1218. <button type='button' title='" + okLabel + "' onclick='Dialog.okCallback()' " + okButtonClass + "><span><span><span>" + okLabel + "</span></span></span></button>\
  1219. <button type='button' title='" + cancelLabel + "' onclick='Dialog.cancelCallback()' " + cancelButtonClass + "><span><span><span>" + cancelLabel + "</span></span></span></button>\
  1220. </div>\
  1221. ";
  1222. return this._openDialog(content, parameters)
  1223. },
  1224. alert: function(content, parameters) {
  1225. // Get Ajax return before
  1226. if (content && typeof content != "string") {
  1227. Dialog._runAjaxRequest(content, parameters, Dialog.alert);
  1228. return
  1229. }
  1230. content = content || "";
  1231. parameters = parameters || {};
  1232. var okLabel = parameters.okLabel ? parameters.okLabel : "Ok";
  1233. // Backward compatibility
  1234. parameters = Object.extend(parameters, parameters.windowParameters || {});
  1235. parameters.windowParameters = parameters.windowParameters || {};
  1236. parameters.className = parameters.className || "alert";
  1237. var okButtonClass = "class ='" + (parameters.buttonClass ? parameters.buttonClass + " " : "") + " ok_button'";
  1238. var content = "\
  1239. <div class='" + parameters.className + "_message'>" + content + "</div>\
  1240. <div class='" + parameters.className + "_buttons'>\
  1241. <button type='button' title='" + okLabel + "' onclick='Dialog.okCallback()' " + okButtonClass + "><span><span><span>" + okLabel + "</span></span></span></button>\
  1242. </div>";
  1243. return this._openDialog(content, parameters)
  1244. },
  1245. info: function(content, parameters) {
  1246. // Get Ajax return before
  1247. if (content && typeof content != "string") {
  1248. Dialog._runAjaxRequest(content, parameters, Dialog.info);
  1249. return
  1250. }
  1251. content = content || "";
  1252. // Backward compatibility
  1253. parameters = parameters || {};
  1254. parameters = Object.extend(parameters, parameters.windowParameters || {});
  1255. parameters.windowParameters = parameters.windowParameters || {};
  1256. parameters.className = parameters.className || "alert";
  1257. var content = "<div id='modal_dialog_message' class='" + parameters.className + "_message'>" + content + "</div>";
  1258. if (parameters.showProgress)
  1259. content += "<div id='modal_dialog_progress' class='" + parameters.className + "_progress'> </div>";
  1260. parameters.ok = null;
  1261. parameters.cancel = null;
  1262. return this._openDialog(content, parameters)
  1263. },
  1264. setInfoMessage: function(message) {
  1265. $('modal_dialog_message').update(message);
  1266. },
  1267. closeInfo: function() {
  1268. Windows.close(this.dialogId);
  1269. },
  1270. _openDialog: function(content, parameters) {
  1271. var className = parameters.className;
  1272. if (! parameters.height && ! parameters.width) {
  1273. parameters.width = WindowUtilities.getPageSize(parameters.options.parent || document.body).pageWidth / 2;
  1274. }
  1275. if (parameters.id)
  1276. this.dialogId = parameters.id;
  1277. else {
  1278. var t = new Date();
  1279. this.dialogId = 'modal_dialog_' + t.getTime();
  1280. parameters.id = this.dialogId;
  1281. }
  1282. // compute height or width if need be
  1283. if (! parameters.height || ! parameters.width) {
  1284. var size = WindowUtilities._computeSize(content, this.dialogId, parameters.width, parameters.height, 5, className)
  1285. if (parameters.height)
  1286. parameters.width = size + 5
  1287. else
  1288. parameters.height = size + 5
  1289. }
  1290. parameters.effectOptions = parameters.effectOptions ;
  1291. parameters.resizable = parameters.resizable || false;
  1292. parameters.minimizable = parameters.minimizable || false;
  1293. parameters.maximizable = parameters.maximizable || false;
  1294. parameters.draggable = parameters.draggable || false;
  1295. parameters.closable = parameters.closable || false;
  1296. var win = new Window(parameters);
  1297. win.getContent().innerHTML = content;
  1298. win.showCenter(true, parameters.top, parameters.left);
  1299. win.setDestroyOnClose();
  1300. win.cancelCallback = parameters.onCancel || parameters.cancel;
  1301. win.okCallback = parameters.onOk || parameters.ok;
  1302. return win;
  1303. },
  1304. _getAjaxContent: function(originalRequest) {
  1305. Dialog.callFunc(originalRequest.responseText, Dialog.parameters)
  1306. },
  1307. _runAjaxRequest: function(message, parameters, callFunc) {
  1308. if (message.options == null)
  1309. message.options = {}
  1310. Dialog.onCompleteFunc = message.options.onComplete;
  1311. Dialog.parameters = parameters;
  1312. Dialog.callFunc = callFunc;
  1313. message.options.onComplete = Dialog._getAjaxContent;
  1314. new Ajax.Request(message.url, message.options);
  1315. },
  1316. okCallback: function() {
  1317. var win = Windows.focusedWindow;
  1318. if (!win.okCallback || win.okCallback(win)) {
  1319. // Remove onclick on button
  1320. $$("#" + win.getId()+" input").each(function(element) {element.onclick=null;})
  1321. win.close();
  1322. }
  1323. },
  1324. cancelCallback: function() {
  1325. var win = Windows.focusedWindow;
  1326. // Remove onclick on button
  1327. $$("#" + win.getId()+" input").each(function(element) {element.onclick=null})
  1328. win.close();
  1329. if (win.cancelCallback)
  1330. win.cancelCallback(win);
  1331. }
  1332. }
  1333. /*
  1334. Based on Lightbox JS: Fullsize Image Overlays
  1335. by Lokesh Dhakar - http://www.huddletogether.com
  1336. For more information on this script, visit:
  1337. http://huddletogether.com/projects/lightbox/
  1338. Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
  1339. (basically, do anything you want, just leave my name and link)
  1340. */
  1341. if (Prototype.Browser.WebKit) {
  1342. var array = navigator.userAgent.match(new RegExp(/AppleWebKit\/([\d\.\+]*)/));
  1343. Prototype.Browser.WebKitVersion = parseFloat(array[1]);
  1344. }
  1345. var WindowUtilities = {
  1346. // From dragdrop.js
  1347. getWindowScroll: function(parent) {
  1348. var T, L, W, H;
  1349. parent = parent || document.body;
  1350. if (parent != document.body) {
  1351. T = parent.scrollTop;
  1352. L = parent.scrollLeft;
  1353. W = parent.scrollWidth;
  1354. H = parent.scrollHeight;
  1355. }
  1356. else {
  1357. var w = window;
  1358. with (w.document) {
  1359. if (w.document.documentElement && documentElement.scrollTop) {
  1360. T = documentElement.scrollTop;
  1361. L = documentElement.scrollLeft;
  1362. } else if (w.document.body) {
  1363. T = body.scrollTop;
  1364. L = body.scrollLeft;
  1365. }
  1366. if (w.innerWidth) {
  1367. W = w.innerWidth;
  1368. H = w.innerHeight;
  1369. } else if (w.document.documentElement && documentElement.clientWidth) {
  1370. W = documentElement.clientWidth;
  1371. H = documentElement.clientHeight;
  1372. } else {
  1373. W = body.offsetWidth;
  1374. H = body.offsetHeight
  1375. }
  1376. }
  1377. }
  1378. return { top: T, left: L, width: W, height: H };
  1379. },
  1380. //
  1381. // getPageSize()
  1382. // Returns array with page width, height and window width, height
  1383. // Core code from - quirksmode.org
  1384. // Edit for Firefox by pHaez
  1385. //
  1386. getPageSize: function(parent){
  1387. parent = parent || document.body;
  1388. var windowWidth, windowHeight;
  1389. var pageHeight, pageWidth;
  1390. if (parent != document.body) {
  1391. windowWidth = parent.getWidth();
  1392. windowHeight = parent.getHeight();
  1393. pageWidth = parent.scrollWidth;
  1394. pageHeight = parent.scrollHeight;
  1395. }
  1396. else {
  1397. var xScroll, yScroll;
  1398. if (window.innerHeight && window.scrollMaxY) {
  1399. xScroll = document.body.scrollWidth;
  1400. yScroll = window.innerHeight + window.scrollMaxY;
  1401. } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
  1402. xScroll = document.body.scrollWidth;
  1403. yScroll = document.body.scrollHeight;
  1404. } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
  1405. xScroll = document.body.offsetWidth;
  1406. yScroll = document.body.offsetHeight;
  1407. }
  1408. if (self.innerHeight) { // all except Explorer
  1409. windowWidth = document.documentElement.clientWidth;//self.innerWidth;
  1410. windowHeight = self.innerHeight;
  1411. } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
  1412. windowWidth = document.documentElement.clientWidth;
  1413. windowHeight = document.documentElement.clientHeight;
  1414. } else if (document.body) { // other Explorers
  1415. windowWidth = document.body.clientWidth;
  1416. windowHeight = document.body.clientHeight;
  1417. }
  1418. // for small pages with total height less then height of the viewport
  1419. if(yScroll < windowHeight){
  1420. pageHeight = windowHeight;
  1421. } else {
  1422. pageHeight = yScroll;
  1423. }
  1424. // for small pages with total width less then width of the viewport
  1425. if(xScroll < windowWidth){
  1426. pageWidth = windowWidth;
  1427. } else {
  1428. pageWidth = xScroll;
  1429. }
  1430. }
  1431. return {pageWidth: pageWidth ,pageHeight: pageHeight , windowWidth: windowWidth, windowHeight: windowHeight};
  1432. },
  1433. disableScreen: function(className, overlayId, overlayOpacity, contentId, parent) {
  1434. WindowUtilities.initLightbox(overlayId, className, function() {this._disableScreen(className, overlayId, overlayOpacity, contentId)}.bind(this), parent || document.body);
  1435. },
  1436. _disableScreen: function(className, overlayId, overlayOpacity, contentId) {
  1437. // prep objects
  1438. var objOverlay = $(overlayId);
  1439. var pageSize = WindowUtilities.getPageSize(objOverlay.parentNode);
  1440. // Hide select boxes as they will 'peek' through the image in IE, store old value
  1441. if (contentId && Prototype.Browser.IE) {
  1442. WindowUtilities._hideSelect();
  1443. WindowUtilities._showSelect(contentId);
  1444. }
  1445. // set height of Overlay to take up whole page and show
  1446. objOverlay.style.height = (pageSize.pageHeight + 'px');
  1447. objOverlay.style.display = 'none';
  1448. if (overlayId == "overlay_modal" && Window.hasEffectLib && Windows.overlayShowEffectOptions) {
  1449. objOverlay.overlayOpacity = overlayOpacity;
  1450. new Effect.Appear(objOverlay, Object.extend({from: 0, to: overlayOpacity}, Windows.overlayShowEffectOptions));
  1451. }
  1452. else
  1453. objOverlay.style.display = "block";
  1454. },
  1455. enableScreen: function(id) {
  1456. id = id || 'overlay_modal';
  1457. var objOverlay = $(id);
  1458. if (objOverlay) {
  1459. // hide lightbox and overlay
  1460. if (id == "overlay_modal" && Window.hasEffectLib && Windows.overlayHideEffectOptions)
  1461. new Effect.Fade(objOverlay, Object.extend({from: objOverlay.overlayOpacity, to:0}, Windows.overlayHideEffectOptions));
  1462. else {
  1463. objOverlay.style.display = 'none';
  1464. objOverlay.parentNode.removeChild(objOverlay);
  1465. }
  1466. // make select boxes visible using old value
  1467. if (id != "__invisible__")
  1468. WindowUtilities._showSelect();
  1469. }
  1470. },
  1471. _hideSelect: function(id) {
  1472. if (Prototype.Browser.IE) {
  1473. id = id == null ? "" : "#" + id + " ";
  1474. $$(id + 'select').each(function(element) {
  1475. if (! WindowUtilities.isDefined(element.oldVisibility)) {
  1476. element.oldVisibility = element.style.visibility ? element.style.visibility : "visible";
  1477. element.style.visibility = "hidden";
  1478. }
  1479. });
  1480. }
  1481. },
  1482. _showSelect: function(id) {
  1483. if (Prototype.Browser.IE) {
  1484. id = id == null ? "" : "#" + id + " ";
  1485. $$(id + 'select').each(function(element) {
  1486. if (WindowUtilities.isDefined(element.oldVisibility)) {
  1487. // Why?? Ask IE
  1488. try {
  1489. element.style.visibility = element.oldVisibility;
  1490. } catch(e) {
  1491. element.style.visibility = "visible";
  1492. }
  1493. element.oldVisibility = null;
  1494. }
  1495. else {
  1496. if (element.style.visibility)
  1497. element.style.visibility = "visible";
  1498. }
  1499. });
  1500. }
  1501. },
  1502. isDefined: function(object) {
  1503. return typeof(object) != "undefined" && object != null;
  1504. },
  1505. // initLightbox()
  1506. // Function runs on window load, going through link tags looking for rel="lightbox".
  1507. // These links receive onclick events that enable the lightbox display for their targets.
  1508. // The function also inserts html markup at the top of the page which will be used as a
  1509. // container for the overlay pattern and the inline image.
  1510. initLightbox: function(id, className, doneHandler, parent) {
  1511. // Already done, just update zIndex
  1512. if ($(id)) {
  1513. Element.setStyle(id, {zIndex: Windows.maxZIndex + 1});
  1514. Windows.maxZIndex++;
  1515. doneHandler();
  1516. }
  1517. // create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
  1518. else {
  1519. var objOverlay = document.createElement("div");
  1520. objOverlay.setAttribute('id', id);
  1521. objOverlay.className = "overlay_" + className
  1522. objOverlay.style.display = 'none';
  1523. objOverlay.style.position = 'absolute';
  1524. objOverlay.style.top = '0';
  1525. objOverlay.style.left = '0';
  1526. objOverlay.style.zIndex = Windows.maxZIndex + 1;
  1527. Windows.maxZIndex++;
  1528. objOverlay.style.width = '100%';
  1529. parent.insertBefore(objOverlay, parent.firstChild);
  1530. if (Prototype.Browser.WebKit && id == "overlay_modal") {
  1531. setTimeout(function() {doneHandler()}, 10);
  1532. }
  1533. else
  1534. doneHandler();
  1535. }
  1536. },
  1537. setCookie: function(value, parameters) {
  1538. document.cookie= parameters[0] + "=" + escape(value) +
  1539. ((parameters[1]) ? "; expires=" + parameters[1].toUTCString() : "") +
  1540. ((parameters[2]) ? "; path=" + parameters[2] : "") +
  1541. ((parameters[3]) ? "; domain=" + parameters[3] : "") +
  1542. ((parameters[4]) ? "; secure" : "");
  1543. },
  1544. getCookie: function(name) {
  1545. var dc = document.cookie;
  1546. var prefix = name + "=";
  1547. var begin = dc.indexOf("; " + prefix);
  1548. if (begin == -1) {
  1549. begin = dc.indexOf(prefix);
  1550. if (begin != 0) return null;
  1551. } else {
  1552. begin += 2;
  1553. }
  1554. var end = document.cookie.indexOf(";", begin);
  1555. if (end == -1) {
  1556. end = dc.length;
  1557. }
  1558. return unescape(dc.substring(begin + prefix.length, end));
  1559. },
  1560. _computeSize: function(content, id, width, height, margin, className) {
  1561. var objBody = document.body;
  1562. var tmpObj = document.createElement("div");
  1563. tmpObj.setAttribute('id', id);
  1564. tmpObj.className = className + "_content";
  1565. if (height)
  1566. tmpObj.style.height = height + "px"
  1567. else
  1568. tmpObj.style.width = width + "px"
  1569. tmpObj.style.position = 'absolute';
  1570. tmpObj.style.top = '0';
  1571. tmpObj.style.left = '0';
  1572. tmpObj.style.display = 'none';
  1573. tmpObj.innerHTML = content;
  1574. objBody.insertBefore(tmpObj, objBody.firstChild);
  1575. var size;
  1576. if (height)
  1577. size = $(tmpObj).getDimensions().width + margin;
  1578. else
  1579. size = $(tmpObj).getDimensions().height + margin;
  1580. objBody.removeChild(tmpObj);
  1581. return size;
  1582. }
  1583. }