/Trunk/Content_7.0.6/website/js/Debug/dnn.js

# · JavaScript · 1202 lines · 759 code · 106 blank · 337 comment · 259 complexity · ee3401a45053fbed748d16b6fd87680d MD5 · raw file

  1. /// <reference name="MicrosoftAjax.js" />
  2. /// <reference name="dnn.js" assembly="DotNetNuke.WebUtility" />
  3. /*add browser detect for chrome*/
  4. var dnnJscriptVersion = "6.0.0";
  5. if (typeof (Sys.Browser.Chrome) == "undefined") {
  6. Sys.Browser.Chrome = {};
  7. if (navigator.userAgent.indexOf(" Chrome/") > -1) {
  8. Sys.Browser.agent = Sys.Browser.Chrome;
  9. Sys.Browser.version = parseFloat(navigator.userAgent.match(/Chrome\/(\d+\.\d+)/)[1]);
  10. Sys.Browser.name = "Chrome";
  11. Sys.Browser.hasDebuggerStatement = true;
  12. }
  13. }
  14. var DNN_HIGHLIGHT_COLOR = '#9999FF';
  15. var COL_DELIMITER = String.fromCharCode(18);
  16. var ROW_DELIMITER = String.fromCharCode(17);
  17. var QUOTE_REPLACEMENT = String.fromCharCode(19);
  18. var KEY_LEFT_ARROW = 37;
  19. var KEY_UP_ARROW = 38;
  20. var KEY_RIGHT_ARROW = 39;
  21. var KEY_DOWN_ARROW = 40;
  22. var KEY_RETURN = 13;
  23. var KEY_ESCAPE = 27;
  24. Type.registerNamespace('dnn');
  25. dnn.extend = function (dest, src) {
  26. for (s in src)
  27. dest[s] = src[s];
  28. return dest;
  29. }
  30. dnn.extend(dnn, {
  31. apiversion: new Number('04.02'),
  32. pns: '',
  33. ns: 'dnn',
  34. diagnostics: null,
  35. vars: null,
  36. dependencies: new Array(),
  37. isLoaded: false,
  38. delay: [],
  39. _delayedSet: null, //used to delay setting variable until page is loaded - perf
  40. getVars: function () {
  41. /// <summary>
  42. /// Gets array of name value pairs set on the server side by the RegisterClientVariable method.
  43. /// </summary>
  44. /// <value type="String" />
  45. if (this.vars == null) {
  46. //this.vars = new Array();
  47. var ctl = dnn.dom.getById('__dnnVariable');
  48. if (ctl != null) {
  49. if (ctl.value.indexOf('`') == 0)
  50. ctl.value = ctl.value.substring(1).replace( /`/g , '"');
  51. if (ctl.value.indexOf('__scdoff') != -1) //back compat
  52. {
  53. COL_DELIMITER = '~|~';
  54. ROW_DELIMITER = '~`~';
  55. QUOTE_REPLACEMENT = '~!~';
  56. }
  57. }
  58. if (ctl != null && ctl.value.length > 0)
  59. this.vars = Sys.Serialization.JavaScriptSerializer.deserialize(ctl.value);
  60. else
  61. this.vars = [];
  62. }
  63. return this.vars;
  64. },
  65. getVar: function (key, def) {
  66. /// <summary>
  67. /// Gets value for passed in variable name set on the server side by the RegisterClientVariable method.
  68. /// </summary>
  69. /// <param name="key" type="String">
  70. /// Name of parameter to retrieve value for
  71. /// </param>
  72. /// <param name="def" type="String">
  73. /// Default value if key not present
  74. /// </param>
  75. /// <returns type="String" />
  76. if (this.getVars()[key] != null) {
  77. var re = eval('/' + QUOTE_REPLACEMENT + '/g');
  78. return this.getVars()[key].replace(re, '"');
  79. }
  80. return def;
  81. },
  82. setVar: function (key, val) {
  83. /// <summary>
  84. /// Sets value for variable to be sent to the server
  85. /// </summary>
  86. /// <param name="key" type="String">
  87. /// Name of parameter to set value for
  88. /// </param>
  89. /// <param name="val" type="String">
  90. /// value
  91. /// </param>
  92. /// <returns type="Boolean" />
  93. if (this.vars == null)
  94. this.getVars();
  95. this.vars[key] = val;
  96. var ctl = dnn.dom.getById('__dnnVariable');
  97. if (ctl == null) {
  98. ctl = dnn.dom.createElement('INPUT');
  99. ctl.type = 'hidden';
  100. ctl.id = '__dnnVariable';
  101. dnn.dom.appendChild(dnn.dom.getByTagName("body")[0], ctl);
  102. }
  103. if (dnn.isLoaded)
  104. ctl.value = Sys.Serialization.JavaScriptSerializer.serialize(this.vars);
  105. else
  106. dnn._delayedSet = { key: key, val: val }; //doesn't matter how many times this gets overwritten, we just want one value to set after load so serialize is called
  107. return true;
  108. },
  109. callPostBack: function (action) {
  110. /// <summary>
  111. /// Initiates a postback call for the passed in action. In order to work the action will need to be registered on the server side.
  112. /// </summary>
  113. /// <param name="action" type="String">
  114. /// Action name to be raised
  115. /// </param>
  116. /// <param name="N Params" type="Array">
  117. /// Pass in any number of parameters the postback requires. Parameters should be in the form of 'paramname=paramvalue', 'paramname=paramvalue', 'paramname=paramvalue'
  118. /// </param>
  119. /// <returns type="Boolean" />
  120. var postBack = dnn.getVar('__dnn_postBack');
  121. var data = '';
  122. if (postBack.length > 0) {
  123. data += action;
  124. for (var i = 1; i < arguments.length; i++) {
  125. var aryParam = arguments[i].split('=');
  126. data += COL_DELIMITER + aryParam[0] + COL_DELIMITER + aryParam[1];
  127. }
  128. eval(postBack.replace('[DATA]', data));
  129. return true;
  130. }
  131. return false;
  132. },
  133. //atlas
  134. createDelegate: function (oThis, ptr) {
  135. /// <summary>
  136. /// Creates delegate (closure)
  137. /// </summary>
  138. /// <param name="oThis" type="Object">
  139. /// Object to create delegate on
  140. /// </param>
  141. /// <param name="ptr" type="Function">
  142. /// Function to invoke
  143. /// </param>
  144. /// <returns type="Function" />
  145. return Function.createDelegate(oThis, ptr);
  146. },
  147. doDelay: function (key, time, ptr, ctx) {
  148. /// <summary>
  149. /// Allows for a setTimeout to occur that will also pass a context object.
  150. /// </summary>
  151. /// <param name="key" type="String">
  152. /// Key to identify the particular delay. If you wish to cancel this delay you need to call cancelDelay passing this key.
  153. /// </param>
  154. /// <param name="time" type="Number">
  155. /// Number of milliseconds to wait before firing timer. This value is simply passed into the second parameter in setTimeout.
  156. /// </param>
  157. /// <param name="ptr" type="Function">
  158. /// Pointer to the function to invoke after time has elapsed
  159. /// </param>
  160. /// <param name="ctx" type="Object">
  161. /// Context to be passed to the function
  162. /// </param>
  163. /// <returns />
  164. if (this.delay[key] == null) {
  165. this.delay[key] = new dnn.delayObject(ptr, ctx, key);
  166. this.delay[key].num = window.setTimeout(dnn.createDelegate(this.delay[key], this.delay[key].complete), time);
  167. }
  168. },
  169. cancelDelay: function (key) {
  170. /// <summary>
  171. /// Allows for delay to be canceled.
  172. /// </summary>
  173. /// <param name="key" type="String">
  174. /// Key to identify the particular delay.
  175. /// </param>
  176. /// <returns />
  177. if (this.delay[key] != null) {
  178. window.clearTimeout(this.delay[key].num);
  179. this.delay[key] = null;
  180. }
  181. },
  182. decodeHTML: function (html) {
  183. /// <summary>
  184. /// Unencodes html string
  185. /// </summary>
  186. /// <param name="html" type="String">
  187. /// encoded html
  188. /// </param>
  189. /// <returns type="String" />
  190. return html.toString().replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"');
  191. },
  192. encode: function (arg, doubleEncode) {
  193. /// <summary>
  194. /// Encodes string using either encodeURIComponent or escape
  195. /// </summary>
  196. /// <param name="arg" type="String">
  197. /// string to encode
  198. /// </param>
  199. /// <returns type="String" />
  200. var ret = arg;
  201. if (encodeURIComponent)
  202. ret = encodeURIComponent(ret);
  203. else
  204. ret = escape(ret);
  205. if (doubleEncode == false)
  206. return ret;
  207. //handle double encoding for encoded value "+" encode-> "%2B" replace-> "%252B"
  208. return ret.replace(/%/g, "%25");
  209. },
  210. encodeHTML: function (html) {
  211. /// <summary>
  212. /// Encodes html string
  213. /// </summary>
  214. /// <param name="html" type="String">
  215. /// html to encode
  216. /// </param>
  217. /// <returns type="String" />
  218. return html.toString().replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/'/g, "&apos;").replace(/\"/g, "&quot;");
  219. },
  220. encodeJSON: function (json) {
  221. /// <summary>
  222. /// Encodes json string
  223. /// </summary>
  224. /// <param name="json" type="String">
  225. /// json to encode
  226. /// </param>
  227. /// <returns type="String" />
  228. //todo: does Atlas provide method for this?
  229. return json.toString().replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/'/g, "\u0027").replace(/\"/g, "&quot;").replace(/\\/g, "\\\\");
  230. },
  231. //atlas
  232. evalJSON: function (data) {
  233. /// <summary>
  234. /// dencodes data
  235. /// </summary>
  236. /// <param name="data" type="String">
  237. /// json to dencode
  238. /// </param>
  239. /// <returns type="Object" />
  240. return Sys.Serialization.JavaScriptSerializer.deserialize(data);
  241. },
  242. escapeForEval: function (s) //needs work...
  243. {
  244. /// <summary>
  245. /// Allows a string to be evaluated successfully without worry of inappropriate characters. For example ' will be replaced with \' so when evaluated it is equal to
  246. /// </summary>
  247. /// <param name="s" type="String">
  248. /// string to escape
  249. /// </param>
  250. /// <returns type="String" />
  251. return s.replace(/\\/g, '\\\\').replace(/\'/g, "\\'").replace(/\r/g, '').replace(/\n/g, '\\n').replace(/\./, '\\.');
  252. },
  253. getEnumByValue: function (enumType, val) {
  254. /// <summary>
  255. /// Obtains enum from value passed in
  256. /// </summary>
  257. /// <param name="enumType" type="Object">
  258. /// Enumeration type
  259. /// </param>
  260. /// <param name="val" type="Number">
  261. /// Value of enumerator
  262. /// </param>
  263. /// <returns type="Object" />
  264. for (var prop in enumType) {
  265. if (typeof (enumType[prop]) == 'number' && enumType[prop] == val)
  266. return prop;
  267. }
  268. },
  269. _onload: function () {
  270. dnn.isLoaded = true;
  271. if (dnn._delayedSet)
  272. dnn.setVar(dnn._delayedSet.key, dnn._delayedSet.val);
  273. }
  274. });
  275. //delayObject
  276. dnn.delayObject = function (ptr, ctx, type) {
  277. /// <summary>
  278. /// Object used to hold context for the doDelay functionality
  279. /// </summary>
  280. this.num = null;
  281. this.pfunc = ptr;
  282. this.context = ctx;
  283. this.type = type;
  284. }
  285. dnn.delayObject.prototype =
  286. {
  287. complete: function () {
  288. /// <summary>
  289. /// This function is invoked internally by the setTimout of the doDelay. It in turn will invoke the function referenced by the pfunc property, passing the context
  290. /// </summary>
  291. /// <returns />
  292. dnn.delay[this.type] = null;
  293. this.pfunc(this.context);
  294. }
  295. }
  296. dnn.delayObject.registerClass('dnn.delayObject');
  297. dnn.ScriptRequest = function (src, text, fCallBack) {
  298. /// <summary>
  299. /// The ScriptRequest object allows the loading of external script files from script
  300. /// </summary>
  301. this.ctl = null;
  302. this.xmlhttp = null;
  303. this.src = null;
  304. this.text = null;
  305. if (src != null && src.length > 0) {
  306. var file = dnn.dom.scriptFile(src);
  307. var embedSrc = dnn.getVar(file + '.resx', '');
  308. if (embedSrc.length > 0)
  309. this.src = embedSrc;
  310. else
  311. this.src = src;
  312. }
  313. if (text != null && text.length > 0)
  314. this.text = text;
  315. this.callBack = fCallBack;
  316. this.status = 'init';
  317. this.timeOut = 5000;
  318. this._xmlhttpStatusChangeDelegate = dnn.createDelegate(this, this.xmlhttpStatusChange);
  319. this._statusChangeDelegate = dnn.createDelegate(this, this.statusChange);
  320. this._completeDelegate = dnn.createDelegate(this, this.complete);
  321. this._reloadDelegate = dnn.createDelegate(this, this.reload);
  322. //this.alreadyLoaded = false;
  323. }
  324. dnn.ScriptRequest.prototype =
  325. {
  326. load: function () {
  327. /// <summary>
  328. /// Loads script
  329. /// </summary>
  330. this.status = 'loading';
  331. this.ctl = document.createElement('script');
  332. this.ctl.type = 'text/javascript';
  333. if (this.src != null) {
  334. if (dnn.dom.browser.isType(dnn.dom.browser.Safari)) {
  335. this.xmlhttp = new XMLHttpRequest();
  336. this.xmlhttp.open('GET', this.src, true);
  337. this.xmlhttp.onreadystatechange = this._xmlhttpStatusChangeDelegate;
  338. this.xmlhttp.send(null);
  339. return;
  340. }
  341. else {
  342. if (dnn.dom.browser.isType(dnn.dom.browser.InternetExplorer))
  343. this.ctl.onreadystatechange = this._statusChangeDelegate;
  344. else if (dnn.dom.browser.isType(dnn.dom.browser.Opera) == false) //opera loads synchronously
  345. this.ctl.onload = this._completeDelegate;
  346. this.ctl.src = this.src;
  347. }
  348. dnn.dom.scriptElements[this.src] = this.ctl; //JON VERIFY THIS!!!
  349. }
  350. else {
  351. if (dnn.dom.browser.isType(dnn.dom.browser.Safari))
  352. this.ctl.innerHTML = dnn.encodeHTML(this.text);
  353. else
  354. this.ctl.text = this.text;
  355. }
  356. var oHeads = dnn.dom.getByTagName('HEAD');
  357. if (oHeads) {
  358. //opera will load script twice if inline and appended to page
  359. if (dnn.dom.browser.isType(dnn.dom.browser.Opera) == false || this.src != null)
  360. oHeads[0].appendChild(this.ctl);
  361. }
  362. else
  363. alert('Cannot load dynamic script, no HEAD tag present.');
  364. if (this.src == null || dnn.dom.browser.isType(dnn.dom.browser.Opera)) //opera loads script synchronously
  365. this.complete();
  366. else if (this.timeOut)
  367. dnn.doDelay('loadScript_' + this.src, this.timeOut, this._reloadDelegate, null);
  368. },
  369. xmlhttpStatusChange: function () {
  370. /// <summary>
  371. /// Event fires when script request status changes
  372. /// </summary>
  373. if (this.xmlhttp.readyState != 4)
  374. return;
  375. this.src = null;
  376. this.text = this.xmlhttp.responseText;
  377. this.load(); //load as inline script
  378. },
  379. statusChange: function () {
  380. /// <summary>
  381. /// Event fires when script request status changes
  382. /// </summary>
  383. if ((this.ctl.readyState == 'loaded' || this.ctl.readyState == 'complete') && this.status != 'complete')
  384. this.complete();
  385. },
  386. reload: function () {
  387. /// <summary>
  388. /// Reloads a script reference
  389. /// </summary>
  390. if (dnn.dom.scriptStatus(this.src) == 'complete') {
  391. this.complete();
  392. }
  393. else {
  394. this.load();
  395. }
  396. },
  397. complete: function () {
  398. /// <summary>
  399. /// Event fires when script request loaded
  400. /// </summary>
  401. dnn.cancelDelay('loadScript_' + this.src);
  402. this.status = 'complete';
  403. if (typeof (this.callBack) != 'undefined')
  404. this.callBack(this);
  405. this.dispose();
  406. },
  407. dispose: function () {
  408. /// <summary>
  409. /// Cleans up memory
  410. /// </summary>
  411. this.callBack = null;
  412. if (this.ctl) {
  413. if (this.ctl.onreadystatechange)
  414. this.ctl.onreadystatechange = new function () { }; //stop IE memory leak. Not sure why can't set to null;
  415. else if (this.ctl.onload)
  416. this.ctl.onload = null;
  417. this.ctl = null;
  418. }
  419. this.xmlhttp = null;
  420. this._xmlhttpStatusChangeDelegate = null;
  421. this._statusChangeDelegate = null;
  422. this._completeDelegate = null;
  423. this._reloadDelegate = null;
  424. }
  425. }
  426. dnn.ScriptRequest.registerClass('dnn.ScriptRequest');
  427. //--- dnn.dom
  428. Type.registerNamespace('dnn.dom');
  429. dnn.extend(dnn.dom, {
  430. pns: 'dnn',
  431. ns: 'dom',
  432. browser: null,
  433. __leakEvts: [],
  434. scripts: [],
  435. scriptElements: [],
  436. tweens: [],
  437. attachEvent: function (ctl, type, fHandler) {
  438. /// <summary>
  439. /// Attatches an event to an element. - you are encouraged to use the $addHandler method instead - kept only for backwards compatibility
  440. /// </summary>
  441. /// <param name="ctl" type="Object">
  442. /// Control
  443. /// </param>
  444. /// <param name="type" type="String">
  445. /// Event name to attach
  446. /// </param>
  447. /// <param name="fHandler" type="Function">
  448. /// Reference to the function that will react to event
  449. /// </param>
  450. /// <returns type="Boolean" />
  451. if (dnn.dom.browser.isType(dnn.dom.browser.InternetExplorer) == false) {
  452. var name = type.substring(2);
  453. ctl.addEventListener(name, function (evt) { dnn.dom.event = new dnn.dom.eventObject(evt, evt.target); return fHandler(); }, false);
  454. }
  455. else
  456. ctl.attachEvent(type, function () { dnn.dom.event = new dnn.dom.eventObject(window.event, window.event.srcElement); return fHandler(); });
  457. return true;
  458. },
  459. cursorPos: function (ctl) {
  460. /// <summary>
  461. /// Obtains the current cursor position within a textbox
  462. /// </summary>
  463. /// <param name="ctl" type="Object">
  464. /// Control
  465. /// </param>
  466. /// <returns type="Number" />
  467. // empty control means the cursor is at 0
  468. if (ctl.value.length == 0)
  469. return 0;
  470. // -1 for unknown
  471. var pos = -1;
  472. if (ctl.selectionStart) // Moz - Opera
  473. pos = ctl.selectionStart;
  474. else if (ctl.createTextRange)// IE
  475. {
  476. var sel = window.document.selection.createRange();
  477. var range = ctl.createTextRange();
  478. // if the current selection is within the edit control
  479. if (range == null || sel == null || ((sel.text != "") && range.inRange(sel) == false))
  480. return -1;
  481. if (sel.text == "") {
  482. if (range.boundingLeft == sel.boundingLeft)
  483. pos = 0;
  484. else {
  485. var tagName = ctl.tagName.toLowerCase();
  486. // Handle inputs.
  487. if (tagName == "input") {
  488. var text = range.text;
  489. var i = 1;
  490. while (i < text.length) {
  491. range.findText(text.substring(i));
  492. if (range.boundingLeft == sel.boundingLeft)
  493. break;
  494. i++;
  495. }
  496. }
  497. // Handle text areas.
  498. else if (tagName == "textarea") {
  499. var i = ctl.value.length + 1;
  500. var oCaret = document.selection.createRange().duplicate();
  501. while (oCaret.parentElement() == ctl && oCaret.move("character", 1) == 1)
  502. --i;
  503. if (i == ctl.value.length + 1)
  504. i = -1;
  505. }
  506. pos = i;
  507. }
  508. }
  509. else
  510. pos = range.text.indexOf(sel.text);
  511. }
  512. return pos;
  513. },
  514. cancelCollapseElement: function (ctl) {
  515. /// <summary>
  516. /// Allows animation for the collapsing of an element to be canceled
  517. /// </summary>
  518. /// <param name="ctl" type="Object">
  519. /// Control
  520. /// </param>
  521. dnn.cancelDelay(ctl.id + 'col');
  522. ctl.style.display = 'none';
  523. },
  524. collapseElement: function (ctl, num, pCallBack) {
  525. /// <summary>
  526. /// Animates the collapsing of an element
  527. /// </summary>
  528. /// <param name="ctl" type="Object">
  529. /// Control
  530. /// </param>
  531. /// <param name="num" type="Number">
  532. /// Number of animations to perform the collapse. The more you specify, the longer it will take
  533. /// </param>
  534. /// <param name="pCallback" type="Function">
  535. /// Function to call when complete
  536. /// </param>
  537. if (num == null)
  538. num = 10;
  539. ctl.style.overflow = 'hidden';
  540. var ctx = new Object();
  541. ctx.num = num;
  542. ctx.ctl = ctl;
  543. ctx.pfunc = pCallBack;
  544. ctl.origHeight = ctl.offsetHeight;
  545. dnn.dom.__collapseElement(ctx);
  546. },
  547. __collapseElement: function (ctx) {
  548. var num = ctx.num;
  549. var ctl = ctx.ctl;
  550. var step = ctl.origHeight / num;
  551. if (ctl.offsetHeight - (step * 2) > 0) {
  552. ctl.style.height = (ctl.offsetHeight - step).toString() + 'px';
  553. dnn.doDelay(ctl.id + 'col', 10, dnn.dom.__collapseElement, ctx);
  554. }
  555. else {
  556. ctl.style.display = 'none';
  557. if (ctx.pfunc != null)
  558. ctx.pfunc();
  559. }
  560. },
  561. cancelExpandElement: function (ctl) {
  562. /// <summary>
  563. /// Allows animation for the expanding of an element to be canceled
  564. /// </summary>
  565. /// <param name="ctl" type="Object">
  566. /// Control
  567. /// </param>
  568. dnn.cancelDelay(ctl.id + 'exp');
  569. ctl.style.overflow = '';
  570. ctl.style.height = '';
  571. },
  572. disableTextSelect: function (ctl) {
  573. if (typeof ctl.onselectstart != "undefined") //ie
  574. ctl.onselectstart = function () { return false }
  575. else if (typeof ctl.style.MozUserSelect != "undefined") //ff
  576. ctl.style.MozUserSelect = "none"
  577. else //others
  578. ctl.onmousedown = function () { return false }
  579. },
  580. expandElement: function (ctl, num, pCallBack) {
  581. /// <summary>
  582. /// Animates the expanding of an element
  583. /// </summary>
  584. /// <param name="ctl" type="Object">
  585. /// Control
  586. /// </param>
  587. /// <param name="num" type="Number">
  588. /// Number of animations to perform the collapse. The more you specify, the longer it will take
  589. /// </param>
  590. /// <param name="pCallback" type="Function">
  591. /// Function to call when complete
  592. /// </param>
  593. if (num == null)
  594. num = 10;
  595. if (ctl.style.display == 'none' && ctl.origHeight == null) {
  596. ctl.style.display = '';
  597. ctl.style.overflow = '';
  598. ctl.origHeight = ctl.offsetHeight;
  599. ctl.style.overflow = 'hidden';
  600. ctl.style.height = '1px';
  601. }
  602. ctl.style.display = '';
  603. var ctx = new Object();
  604. ctx.num = num;
  605. ctx.ctl = ctl;
  606. ctx.pfunc = pCallBack;
  607. dnn.dom.__expandElement(ctx);
  608. },
  609. __expandElement: function (ctx) {
  610. var num = ctx.num;
  611. var ctl = ctx.ctl;
  612. var step = ctl.origHeight / num;
  613. if (ctl.offsetHeight + step < ctl.origHeight) {
  614. ctl.style.height = (ctl.offsetHeight + step).toString() + 'px';
  615. dnn.doDelay(ctl.id + 'exp', 10, dnn.dom.__expandElement, ctx);
  616. }
  617. else {
  618. ctl.style.overflow = '';
  619. ctl.style.height = '';
  620. if (ctx.pfunc != null)
  621. ctx.pfunc();
  622. }
  623. },
  624. deleteCookie: function (name, path, domain) {
  625. /// <summary>
  626. /// Deletes a cookie
  627. /// </summary>
  628. /// <param name="name" type="String">
  629. /// Name of the desired cookie to delete
  630. /// </param>
  631. /// <param name="path" type="String">
  632. /// Path for which the cookie is valid
  633. /// </param>
  634. /// <param name="domain" type="String">
  635. /// Domain for which the cookie is valid
  636. /// </param>
  637. /// <returns type="Boolean" />
  638. if (this.getCookie(name)) {
  639. this.setCookie(name, '', -1, path, domain);
  640. return true;
  641. }
  642. return false;
  643. },
  644. getAttr: function (node, attr, def) {
  645. /// <summary>
  646. /// Utility funcion used to retrieve the attribute value of an object. Allows for a default value to be returned if null.
  647. /// </summary>
  648. /// <param name="node" type="Object">
  649. /// Object to obtain attribute from
  650. /// </param>
  651. /// <param name="attr" type="String">
  652. /// Name of attribute to retrieve
  653. /// </param>
  654. /// <param name="def" type="String">
  655. /// Default value to retrieve if attribute is null or zero-length
  656. /// </param>
  657. /// <returns type="String" />
  658. if (node.getAttribute == null)
  659. return def;
  660. var val = node.getAttribute(attr);
  661. if (val == null || val == '')
  662. return def;
  663. else
  664. return val;
  665. },
  666. //Atlas
  667. getById: function (id, ctl) {
  668. /// <summary>
  669. /// Retrieves element on page based off of passed in id. - use $get instead - backwards compat only
  670. /// </summary>
  671. /// <param name="id" type="String">
  672. /// Control's id to retrieve
  673. /// </param>
  674. /// <param name="ctl" type="Object" optional="true">
  675. /// If you wish to narrow down the search, pass in the control whose children you wish to search.
  676. /// </param>
  677. /// <returns type="Object" />
  678. return $get(id, ctl);
  679. },
  680. getByTagName: function (tag, ctl) {
  681. /// <summary>
  682. /// Retrieves element on page based off of passed in id. - use $get instead - backwards compat only
  683. /// </summary>
  684. /// <param name="tag" type="String">
  685. /// TagName to retrieve
  686. /// </param>
  687. /// <param name="ctl" type="Object" optional="true">
  688. /// If you wish to narrow down the search, pass in the control whose children you wish to search.
  689. /// </param>
  690. /// <returns type="Array" />
  691. if (ctl == null)
  692. ctl = document;
  693. if (ctl.getElementsByTagName)
  694. return ctl.getElementsByTagName(tag);
  695. else if (ctl.all && ctl.all.tags)
  696. return ctl.all.tags(tag);
  697. else
  698. return null;
  699. },
  700. getParentByTagName: function (ctl, tag) {
  701. /// <summary>
  702. /// Retrieves parent element of a particular tag. This function walks up the control's parent references until it locates control of particular tag or parent no longer exists.
  703. /// </summary>
  704. /// <param name="ctl" type="Object">
  705. /// Control you wish to start the lookup at
  706. /// </param>
  707. /// <param name="tag" type="String">
  708. /// TagName to of parent control retrieve
  709. /// </param>
  710. /// <returns type="Object" />
  711. var parent = ctl.parentNode;
  712. tag = tag.toLowerCase();
  713. while (parent != null) {
  714. if (parent.tagName && parent.tagName.toLowerCase() == tag)
  715. return parent;
  716. parent = parent.parentNode;
  717. }
  718. return null;
  719. },
  720. getCookie: function (name) {
  721. /// <summary>
  722. /// Retrieves a cookie
  723. /// </summary>
  724. /// <param name="name" type="String">
  725. /// Name of the desired cookie
  726. /// </param>
  727. /// <returns type="String" />
  728. var cookie = " " + document.cookie;
  729. var search = " " + name + "=";
  730. var ret = null;
  731. var offset = 0;
  732. var end = 0;
  733. if (cookie.length > 0) {
  734. offset = cookie.indexOf(search);
  735. if (offset != -1) {
  736. offset += search.length;
  737. end = cookie.indexOf(";", offset)
  738. if (end == -1)
  739. end = cookie.length;
  740. ret = unescape(cookie.substring(offset, end));
  741. }
  742. }
  743. return (ret);
  744. },
  745. getNonTextNode: function (node) {
  746. /// <summary>
  747. /// Retrieves first non-text node. If passed in node is textnode, it looks at each sibling
  748. /// </summary>
  749. /// <param name="node" type="Object">
  750. /// Node to start looking at
  751. /// </param>
  752. /// <returns type="Object" />
  753. if (this.isNonTextNode(node))
  754. return node;
  755. while (node != null && this.isNonTextNode(node)) {
  756. node = this.getSibling(node, 1);
  757. }
  758. return node;
  759. },
  760. addSafeHandler: function (ctl, evt, obj, method) {
  761. /// <summary>
  762. /// Creates memory safe event handler (closure) over element - use createDelegate instead with dispose - kept for backwards compatibility
  763. /// </summary>
  764. /// <param name="ctl" type="Object">
  765. /// Control to attach event on
  766. /// </param>
  767. /// <param name="evt" type="String">
  768. /// Event to attach
  769. /// </param>
  770. /// <param name="obj" type="Object">
  771. /// Instance of object to invoke method on
  772. /// </param>
  773. /// <param name="method" type="String">
  774. /// Method to invoke on object for event
  775. /// </param>
  776. ctl[evt] = this.getObjMethRef(obj, method);
  777. if (dnn.dom.browser.isType(dnn.dom.browser.InternetExplorer)) //handle IE memory leaks with closures
  778. {
  779. if (this.__leakEvts.length == 0)
  780. dnn.dom.attachEvent(window, 'onunload', dnn.dom.destroyHandlers);
  781. this.__leakEvts[this.__leakEvts.length] = new dnn.dom.leakEvt(evt, ctl, ctl[evt]);
  782. }
  783. },
  784. destroyHandlers: function () {
  785. /// <summary>
  786. /// Automatically called (internal) - handles IE memory leaks with closures
  787. /// </summary>
  788. var iCount = dnn.dom.__leakEvts.length - 1;
  789. for (var i = iCount; i >= 0; i--) {
  790. var oEvt = dnn.dom.__leakEvts[i];
  791. oEvt.ctl.detachEvent(oEvt.name, oEvt.ptr);
  792. oEvt.ctl[oEvt.name] = null;
  793. dnn.dom.__leakEvts.length = dnn.dom.__leakEvts.length - 1;
  794. }
  795. },
  796. getObjMethRef: function (obj, methodName) {
  797. /// <summary>
  798. /// Creates event delegate (closure) - use createDelegate instead with dispose - kept for backwards compatibility
  799. /// adapted from http://jibbering.com/faq/faq_notes/closures.html (associateObjWithEvent)
  800. /// </summary>
  801. /// <param name="obj" type="Object">
  802. /// Instance of object to invoke method on
  803. /// </param>
  804. /// <param name="methodName" type="String">
  805. /// Method to invoke on object for event
  806. /// </param>
  807. return (function (e) { e = e || window.event; return obj[methodName](e, this); });
  808. },
  809. getSibling: function (ctl, offset) {
  810. /// <summary>
  811. /// Starts at the passed in control and retrieves the sibling that is at the desired offset
  812. /// </summary>
  813. /// <param name="ctl" type="Object">
  814. /// Control in which to find the sibling related to it
  815. /// </param>
  816. /// <param name="offset" type="Number">
  817. /// How many positions removed from the passed in control to look for the sibling. For example if you wanted your immediate sibling below you would pass in 1
  818. /// </param>
  819. /// <returns type="Object" />
  820. if (ctl != null && ctl.parentNode != null) {
  821. for (var i = 0; i < ctl.parentNode.childNodes.length; i++) {
  822. if (ctl.parentNode.childNodes[i].id == ctl.id) {
  823. if (ctl.parentNode.childNodes[i + offset] != null)
  824. return ctl.parentNode.childNodes[i + offset];
  825. }
  826. }
  827. }
  828. return null;
  829. },
  830. isNonTextNode: function (node) {
  831. /// <summary>
  832. /// Determines if passed in control is a text node (i.e. nodeType = 3 or 8)
  833. /// </summary>
  834. /// <param name="node" type="Object">
  835. /// Node object to verify
  836. /// </param>
  837. /// <returns type="Boolean" />
  838. return (node.nodeType != 3 && node.nodeType != 8); //exclude nodeType of Text (Netscape/Mozilla) issue!
  839. },
  840. getScript: function (src) {
  841. if (this.scriptElements[src]) //perf
  842. return this.scriptElements[src];
  843. var oScripts = dnn.dom.getByTagName('SCRIPT'); //safari has document.scripts
  844. for (var s = 0; s < oScripts.length; s++) //safari
  845. {
  846. if (oScripts[s].src != null && oScripts[s].src.indexOf(src) > -1) {
  847. this.scriptElements[src] = oScripts[s]; //cache for perf
  848. return oScripts[s];
  849. }
  850. }
  851. },
  852. getScriptSrc: function (src) {
  853. var resx = dnn.getVar(src + '.resx', '');
  854. if (resx.length > 0)
  855. return resx;
  856. return src;
  857. },
  858. getScriptPath: function () {
  859. var oThisScript = dnn.dom.getScript('dnn.js');
  860. if (oThisScript)
  861. return oThisScript.src.replace('dnn.js', '');
  862. var sSP = dnn.getVar('__sp'); //try and get from var
  863. if (sSP)
  864. return sSP;
  865. return '';
  866. },
  867. scriptFile: function (src) //trims off path
  868. {
  869. var ary = src.split('/');
  870. return ary[ary.length - 1];
  871. },
  872. loadScript: function (src, text, callBack) {
  873. var sFile;
  874. if (src != null && src.length > 0) {
  875. sFile = this.scriptFile(src);
  876. if (this.scripts[sFile] != null) //already loaded
  877. return;
  878. }
  879. var oSR = new dnn.ScriptRequest(src, text, callBack);
  880. if (sFile)
  881. this.scripts[sFile] = oSR;
  882. oSR.load();
  883. return oSR;
  884. },
  885. loadScripts: function (aSrc, aText, callBack) {
  886. if (dnn.scripts == null) {
  887. var oRef = function (aSrc, aText, callBack) //closure to invoke self with same params when done
  888. { return (function () { dnn.dom.loadScripts(aSrc, aText, callBack); }); };
  889. dnn.dom.loadScript(dnn.dom.getScriptPath() + 'dnn.scripts.js', null, oRef(aSrc, aText, callBack));
  890. //dnn.dom.loadScript(dnn.dom.getScriptPath() + 'dnn.scripts.js', null);
  891. return;
  892. }
  893. var oBatch = new dnn.scripts.ScriptBatchRequest(aSrc, aText, callBack);
  894. oBatch.load();
  895. },
  896. scriptStatus: function (src) {
  897. var sFile = this.scriptFile(src);
  898. if (this.scripts[sFile])
  899. return this.scripts[sFile].status; //dynamic load
  900. var oScript = this.getScript(src);
  901. if (oScript != null) //not a dynamic load, must be complete if found
  902. return 'complete';
  903. else
  904. return '';
  905. },
  906. setScriptLoaded: function (src) //called by pages js that is dynamically loaded. Needed since Safari doesn't support onload for script elements
  907. {
  908. var sFile = this.scriptFile(src);
  909. if (this.scripts[sFile] && dnn.dom.scripts[sFile].status != 'complete')
  910. dnn.dom.scripts[sFile].complete();
  911. },
  912. navigate: function (sURL, sTarget) {
  913. if (sTarget != null && sTarget.length > 0) {
  914. if (sTarget == '_blank' || sTarget == '_new') //todo: handle more
  915. window.open(sURL);
  916. else
  917. document.frames[sTarget].location.href = sURL;
  918. }
  919. else {
  920. if (Sys.Browser.agent === Sys.Browser.InternetExplorer)
  921. window.navigate(sURL); //include referrer (WCT-8821)
  922. else
  923. window.location.href = sURL;
  924. }
  925. return false;
  926. },
  927. setCookie: function (name, val, days, path, domain, isSecure) {
  928. /// <summary>
  929. /// Sets a cookie
  930. /// </summary>
  931. /// <param name="name" type="String">
  932. /// Name of the desired cookie to delete
  933. /// </param>
  934. /// <param name="val" type="String">
  935. /// value
  936. /// </param>
  937. /// <param name="days" type="Number">
  938. /// days cookie is valid for
  939. /// </param>
  940. /// <param name="path" type="String">
  941. /// Path for which the cookie is valid
  942. /// </param>
  943. /// <param name="domain" type="String">
  944. /// Domain for which the cookie is valid
  945. /// </param>
  946. /// <param name="isSecure" type="Boolean">
  947. /// determines if cookie is secure
  948. /// </param>
  949. /// <returns type="Boolean" />
  950. var sExpires;
  951. if (days) {
  952. sExpires = new Date();
  953. sExpires.setTime(sExpires.getTime() + (days * 24 * 60 * 60 * 1000));
  954. }
  955. document.cookie = name + "=" + escape(val) + ((sExpires) ? "; expires=" + sExpires.toGMTString() : "") +
  956. ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((isSecure) ? "; secure" : "");
  957. if (document.cookie.length > 0)
  958. return true;
  959. },
  960. //Atlas
  961. getCurrentStyle: function (node, prop) {
  962. var style = Sys.UI.DomElement._getCurrentStyle(node);
  963. if (style)
  964. return style[prop];
  965. return '';
  966. },
  967. getFormPostString: function (ctl) {
  968. var sRet = '';
  969. if (ctl != null) {
  970. if (ctl.tagName && ctl.tagName.toLowerCase() == 'form') //if form, faster to loop elements collection
  971. {
  972. for (var i = 0; i < ctl.elements.length; i++)
  973. sRet += this.getElementPostString(ctl.elements[i]);
  974. }
  975. else {
  976. sRet = this.getElementPostString(ctl);
  977. for (var i = 0; i < ctl.childNodes.length; i++)
  978. sRet += this.getFormPostString(ctl.childNodes[i]); //1.3 fix (calling self recursive insead of elementpoststring)
  979. }
  980. }
  981. return sRet;
  982. },
  983. getElementPostString: function (ctl) {
  984. var tagName;
  985. if (ctl.tagName)
  986. tagName = ctl.tagName.toLowerCase();
  987. if (tagName == 'input') {
  988. var type = ctl.type.toLowerCase();
  989. if (type == 'text' || type == 'password' || type == 'hidden' || ((type == 'checkbox' || type == 'radio') && ctl.checked))
  990. return ctl.name + '=' + dnn.encode(ctl.value, false) + '&';
  991. }
  992. else if (tagName == 'select') {
  993. for (var i = 0; i < ctl.options.length; i++) {
  994. if (ctl.options[i].selected)
  995. return ctl.name + '=' + dnn.encode(ctl.options[i].value, false) + '&';
  996. }
  997. }
  998. else if (tagName == 'textarea')
  999. return ctl.name + '=' + dnn.encode(ctl.value, false) + '&';
  1000. return '';
  1001. },
  1002. //OBSOLETE METHODS
  1003. //devreplace
  1004. //this method is obsolete, call nodeElement.appendChild directly
  1005. appendChild: function (oParent, oChild) {
  1006. return oParent.appendChild(oChild);
  1007. },
  1008. //this method is obsolete, call nodeElement.parentNode.removeChild directly
  1009. removeChild: function (oChild) {
  1010. return oChild.parentNode.removeChild(oChild);
  1011. },
  1012. //devreplace
  1013. //this method is obsolete, call document.createElement directly
  1014. createElement: function (tagName) {
  1015. return document.createElement(tagName.toLowerCase());
  1016. }
  1017. }); //dnn.dom end
  1018. dnn.dom.leakEvt = function (name, ctl, oPtr) {
  1019. this.name = name;
  1020. this.ctl = ctl;
  1021. this.ptr = oPtr;
  1022. }
  1023. dnn.dom.leakEvt.registerClass('dnn.dom.leakEvt');
  1024. dnn.dom.eventObject = function (e, srcElement) {
  1025. this.object = e;
  1026. this.srcElement = srcElement;
  1027. }
  1028. dnn.dom.eventObject.registerClass('dnn.dom.eventObject');
  1029. //--- dnn.dom.browser
  1030. //Kept as is, Atlas detects smaller number of browsers
  1031. dnn.dom.browserObject = function () {
  1032. this.InternetExplorer = 'ie';
  1033. this.Netscape = 'ns';
  1034. this.Mozilla = 'mo';
  1035. this.Opera = 'op';
  1036. this.Safari = 'safari';
  1037. this.Konqueror = 'kq';
  1038. this.MacIE = 'macie';
  1039. var type;
  1040. var agt = navigator.userAgent.toLowerCase();
  1041. if (agt.indexOf('konqueror') != -1)
  1042. type = this.Konqueror;
  1043. else if (agt.indexOf('msie') != -1 && agt.indexOf('mac') != -1)
  1044. type = this.MacIE;
  1045. else if (Sys.Browser.agent === Sys.Browser.InternetExplorer)
  1046. type = this.InternetExplorer;
  1047. else if (Sys.Browser.agent === Sys.Browser.FireFox)
  1048. type = this.Mozilla; //this.FireFox;
  1049. else if (Sys.Browser.agent === Sys.Browser.Safari)
  1050. type = this.Safari;
  1051. else if (Sys.Browser.agent === Sys.Browser.Opera)
  1052. type = this.Opera;
  1053. else
  1054. type = this.Mozilla;
  1055. this.type = type;
  1056. this.version = Sys.Browser.version;
  1057. var sAgent = navigator.userAgent.toLowerCase();
  1058. if (this.type == this.InternetExplorer) {
  1059. var temp = navigator.appVersion.split("MSIE");
  1060. this.version = parseFloat(temp[1]);
  1061. }
  1062. if (this.type == this.Netscape) {
  1063. var temp = sAgent.split("netscape");
  1064. this.version = parseFloat(temp[1].split("/")[1]);
  1065. }
  1066. }
  1067. dnn.dom.browserObject.prototype =
  1068. {
  1069. toString: function () {
  1070. return this.type + ' ' + this.version;
  1071. },
  1072. isType: function () {
  1073. for (var i = 0; i < arguments.length; i++) {
  1074. if (dnn.dom.browser.type == arguments[i])
  1075. return true;
  1076. }
  1077. return false;
  1078. }
  1079. }
  1080. dnn.dom.browserObject.registerClass('dnn.dom.browserObject');
  1081. dnn.dom.browser = new dnn.dom.browserObject();
  1082. //-- shorthand functions. Only define if not already present
  1083. if (typeof ($) == 'undefined') {
  1084. eval("function $() {var ary = new Array(); for (var i=0; i<arguments.length; i++) {var arg = arguments[i]; var ctl; if (typeof arg == 'string') ctl = dnn.dom.getById(arg); else ctl = arg; if (ctl != null && typeof(Element) != 'undefined' && typeof(Element.extend) != 'undefined') Element.extend(ctl); if (arguments.length == 1) return ctl; ary[ary.length] = ctl;} return ary;}");
  1085. }
  1086. //image flickering
  1087. try { document.execCommand("BackgroundImageCache", false, true); } catch (err) { }
  1088. Sys.Application.add_load(dnn._onload);