PageRenderTime 41ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/Typps/Resources/ClientScripts/startup.js

#
JavaScript | 772 lines | 730 code | 9 blank | 33 comment | 212 complexity | 4063ab908209103a6e0ba03b33bb1d6f MD5 | raw file
  1. /*
  2. Typps HTML Editor for ASP.NET
  3. FULL EDITION
  4. Copyright (c) 2009 Alessandro Zifiglio, http://www.Typps.com
  5. EMail: alessandro@Typps.com
  6. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. Sys.Browser.WebKit = {}; //Safari 3 is considered WebKit
  18. if (navigator.userAgent.indexOf('WebKit/') > -1) {
  19. Sys.Browser.agent = Sys.Browser.WebKit;
  20. Sys.Browser.version = parseFloat(navigator.userAgent.match(/WebKit\/(\d+(\.\d+)?)/)[1]);
  21. Sys.Browser.name = 'WebKit';
  22. }
  23. Type.registerNamespace("Typps");
  24. Typps.EventArgs = function () {
  25. Typps.EventArgs.initializeBase(this);
  26. this._commandName = null;
  27. this._commandArgument = null;
  28. this._innerArgs = null;
  29. }
  30. Typps.EventArgs.prototype = {
  31. get_commandName: function () { return this._commandName; },
  32. set_commandName: function (value) { this._commandName = value; },
  33. get_commandArgument: function () { return this._commandArgument; },
  34. set_commandArgument: function (value) { this._commandArgument = value; },
  35. get_innerArgs: function () { return this._innerArgs; },
  36. set_innerArgs: function (value) { this._innerArgs = value; }
  37. }
  38. Typps.EventArgs.registerClass('Typps.EventArgs', Sys.EventArgs);
  39. Typps.MediaItemEventArgs = function () {
  40. Typps.MediaItemEventArgs.initializeBase(this);
  41. this._sender = null;
  42. this._element = null;
  43. this._header = null;
  44. this._footer = null;
  45. this._oldWidth = null;
  46. this._oldHeight = null;
  47. }
  48. Typps.MediaItemEventArgs.prototype = {
  49. get_sender: function () { return this._sender; },
  50. set_sender: function (value) { this._sender = value; },
  51. get_element: function () { return this._element; },
  52. set_element: function (value) { this._element = value; },
  53. get_header: function () { return this._header; },
  54. set_header: function (value) { this._header = value; },
  55. get_footer: function () { return this._footer; },
  56. set_footer: function (value) { this._footer = value; },
  57. get_oldWidth: function () { return this._oldWidth; },
  58. set_oldWidth: function (value) { this._oldWidth = value; },
  59. get_oldHeight: function () { return this._oldHeight; },
  60. set_oldHeight: function (value) { this._oldHeight = value; }
  61. }
  62. Typps.MediaItemEventArgs.registerClass('Typps.MediaItemEventArgs', Sys.EventArgs);
  63. Typps.Perform = function () { };
  64. Typps.Perform.prototype =
  65. {
  66. Add: 0,
  67. Remove: 1,
  68. Toggle: 2
  69. }
  70. Typps.Perform.registerEnum('Typps.Perform');
  71. Typps.Utility = function () {
  72. //hr,br cannot contain child elements, so keep them in the list.
  73. this._blockElements = ['ol', 'p', 'pre', 'table', 'td', 'ul', 'blockquote', 'div', 'dl', 'fieldset', 'address', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'noscript', 'hr'];
  74. this._blockContentNodes = ['p', 'div', 'li', 'tr', 'td', 'pre', 'dl', 'dt', 'dd'];
  75. }
  76. Typps.Utility.getInstance = function Typps$Utility$getInstance() {
  77. var instance = Typps.Utility._instance;
  78. if (!instance) {
  79. instance = Typps.Utility._instance = new Typps.Utility();
  80. }
  81. return instance;
  82. }
  83. Typps.Utility.getBlockLevelElements = function Typps$Utility$getBlockLevelElements() {
  84. return Typps.Utility.getInstance()._blockElements;
  85. }
  86. Typps.Utility.getHighestZIndex = function Typps$Utility$getHighestZIndex() {
  87. var zIndex = Typps.Utility._zIndex;
  88. if (!zIndex) {
  89. zIndex = Typps.Utility._zIndex = Typps.Utility.getInstance()._getNextHighestZindex(null);
  90. }
  91. return zIndex;
  92. }
  93. Typps.Utility.isAlphaNumericValidate = function Typps$Utility$isAlphaNumericValidate(alphanumeric) {
  94. return Typps.Utility.getInstance()._isAlphaNumericValidate(alphanumeric);
  95. }
  96. Typps.Utility.regExpEscape = function Typps$Utility$regExpEscape(text) {
  97. return Typps.Utility.getInstance()._regExpEscape(text);
  98. }
  99. Typps.Utility.incrementZIndex = function Typps$Utility$incrementZIndex(i) {
  100. if (i == null || i < 0) i = 1;
  101. var zIndex = Typps.Utility._zIndex;
  102. if (zIndex)
  103. zIndex = Typps.Utility._zIndex = Typps.Utility._zIndex + i;
  104. else
  105. zIndex = Typps.Utility.getHighestZIndex(null);
  106. return zIndex;
  107. }
  108. Typps.Utility.paragraphWrap = function Typps$Utility$paragraphWrap(node, doc) {
  109. return Typps.Utility.getInstance()._paragraphWrap(node, doc);
  110. }
  111. Typps.Utility.isNbsp = function Typps$Utility$isNbsp(textNode) {
  112. return Typps.Utility.getInstance()._isNbsp(textNode);
  113. }
  114. Typps.Utility.getFormKeyValuePair = function Typps$Utility$(id, formKeyValuePair, form, includeAll) {
  115. return Typps.Utility.getInstance()._getFormKeyValuePair(id, formKeyValuePair, form, includeAll);
  116. }
  117. Typps.Utility.splitText = function Typps$Utility$(doc, node, offset) {
  118. return Typps.Utility.getInstance()._splitText(doc, node, offset);
  119. }
  120. Typps.Utility.getCommandArgument = function Typps$Utility$getCommandArgument(command, ae) {
  121. return Typps.Utility.getInstance()._getCommandArgument(command, ae);
  122. }
  123. Typps.Utility.windowBounds = function Typps$Utility$windowBounds() {
  124. return Typps.Utility.getInstance()._windowBounds();
  125. }
  126. Typps.Utility.scrollDistance = function Typps$Utility$scrollDistance(w) {
  127. return Typps.Utility.getInstance()._scrollDistance(w);
  128. }
  129. Typps.Utility.getScrollBarWidth = function Typps$Utility$getScrollBarWidth() {
  130. return Typps.Utility.getInstance()._getScrollBarWidth();
  131. }
  132. Typps.Utility.getParentOffset = function Typps$Utility$getParentOffset(elem) {
  133. return Typps.Utility.getInstance()._getParentOffset(elem);
  134. }
  135. Typps.Utility.getAdjacentHTML = function Typps$Utility$getAdjacentHTML(markup, container) {
  136. return Typps.Utility.getInstance()._getAdjacentHTML(markup, container);
  137. }
  138. Typps.Utility.getIndexByNameFromOptions = function Typps$Utility$getIndexByNameFromOptions(value, option) {
  139. return Typps.Utility.getInstance()._getIndexByNameFromOptions(value, option);
  140. }
  141. Typps.Utility.applyShade = function Typps$Utility$applyShade(element, shaderColor, transparency, zIndex) {
  142. return Typps.Utility.getInstance()._applyShade(element, shaderColor, transparency, zIndex);
  143. }
  144. Typps.Utility.setFloat = function Typps$Utility$setFloat(element, direction) {
  145. return Typps.Utility.getInstance()._setFloat(element, direction);
  146. }
  147. Typps.Utility.setTransparency = function Typps$Utility$setTransparency(element, val1) {
  148. return Typps.Utility.getInstance()._setTransparency(element, val1);
  149. }
  150. Typps.Utility.setBackGroundImage = function Typps$Utility$setBackGroundImage(element, imageUrl, repeat, position) {
  151. return Typps.Utility.getInstance()._setBackGroundImage(element, imageUrl, repeat, position);
  152. }
  153. Typps.Utility.isDesignMode = function Typps$Utility$isDesignMode(doc) {
  154. return Typps.Utility.getInstance()._isDesignMode(doc);
  155. }
  156. Typps.Utility.addScriptBlocks = function Typps$Utility$addScriptBlocks(id, evt, code) {
  157. return Typps.Utility.getInstance()._addScriptBlocks(id, evt, code);
  158. }
  159. Typps.Utility.setDesignMode = function Typps$Utility$setDesignMode(doc, value) {
  160. return Typps.Utility.getInstance()._setDesignMode(doc, value);
  161. }
  162. Typps.Utility.createBlockScreen = function Typps$Utility$createBlockScreen(id, shaderColor, shaderOpacity) {
  163. return Typps.Utility.getInstance()._createBlockScreen(id, shaderColor, shaderOpacity);
  164. }
  165. Typps.Utility.toggleBlockScreen = function Typps$Utility$toggleBlockScreen(elem, zIndex) {
  166. return Typps.Utility.getInstance()._toggleBlockScreen(elem, zIndex);
  167. }
  168. Typps.Utility.applyBlockScreenBounds = function Typps$Utility$applyBlockScreenBounds(id) {
  169. return Typps.Utility.getInstance()._applyBlockScreenBounds(id);
  170. }
  171. Typps.Utility.setLocation = function Typps$Utility$setLocation(elem) {
  172. return Typps.Utility.getInstance()._setLocation(elem);
  173. }
  174. Typps.Utility.getLocationByElement = function Typps$Utility$getLocationByElement(elem) {
  175. return Typps.Utility.getInstance()._getLocationByElement(elem);
  176. }
  177. Typps.Utility.getLocationBySize = function Typps$Utility$getLocationBySize(width, height) {
  178. return Typps.Utility.getInstance()._getLocationBySize(width, height);
  179. }
  180. Typps.Utility.toggleSelectElement = function Typps$Utility$toggleSelectElement(elem, selectCache) {
  181. return Typps.Utility.getInstance()._toggleSelectElement(elem, selectCache);
  182. }
  183. Typps.Utility.isNullOrEmpty = function Typps$Utility$isNullOrEmpty(value) {
  184. return Typps.Utility.getInstance()._isNullOrEmpty(value);
  185. }
  186. Typps.Utility.addRemoveClassName = function Typps$Utility$addRemoveClassName(elem, className, operation) {
  187. return Typps.Utility.getInstance()._addRemoveClassName(elem, className, operation);
  188. }
  189. Typps.Utility.containsCssClass = function Typps$Utility$addRemoveClassName(elem, className) {
  190. return Typps.Utility.getInstance()._containsCssClass(elem, className);
  191. }
  192. Typps.Utility.requiresParagraph = function Typps$Utility$requiresParagraph(node) {
  193. return Typps.Utility.getInstance()._requiresParagraph(node);
  194. }
  195. Typps.Utility.getTokenId = function Typps$Utility$getTokenId(doc) {
  196. return Typps.Utility.getInstance()._getTokenId(doc);
  197. }
  198. Typps.Utility.isEmptyTextNode = function Typps$Utility$isEmptyTextNode(node) {
  199. return Typps.Utility.getInstance()._isEmptyTextNode(node);
  200. }
  201. Typps.Utility.isBr = function Typps$Utility$isBr(node) {
  202. return Typps.Utility.getInstance()._isBr(node);
  203. }
  204. Typps.Utility.isElementNode = function Typps$Utility$isElementNode(node) {
  205. return Typps.Utility.getInstance()._isElementNode(node);
  206. }
  207. Typps.Utility.insertAfter = function Typps$Utility$insertAfter(newNode, node) {
  208. return Typps.Utility.getInstance()._insertAfter(newNode, node);
  209. }
  210. Typps.Utility.getForm = function Typps$Utility$getForm(id) {
  211. return Typps.Utility.getInstance()._getForm(id);
  212. }
  213. Typps.Utility.prototype = {
  214. _requiresParagraph: function (node) {
  215. //nodeType 1 = Element node
  216. if (node.nodeType != 1 || this._isEmptyTextNode(node) ||
  217. this._isNbsp(node))
  218. return true;
  219. var nodeName = node.nodeName.toLowerCase();
  220. switch (nodeName) {
  221. case 'br':
  222. case 'hr':
  223. return false;
  224. }
  225. for (var num1 = 0; num1 < this._blockContentNodes.length; num1++) {
  226. var match = this._blockContentNodes[num1];
  227. if (match == nodeName)
  228. return false;
  229. }
  230. return true;
  231. },
  232. _insertAfter: function (parent, node, referenceNode) {
  233. parent.insertBefore(node, referenceNode.nextSibling);
  234. },
  235. _paragraphWrap: function (node, doc) {
  236. if (this._isNestedInBlockElement(node) ||
  237. !this._requiresParagraph(node))
  238. return null;
  239. var container = doc.createElement('p');
  240. var newParagraph = doc.createElement('p');
  241. this._insertAfter(node.parentNode, container, node);
  242. while (node != null) {
  243. var currentNode = node;
  244. node = node.previousSibling;
  245. if (this._requiresParagraph(currentNode))
  246. container.insertBefore(currentNode.parentNode.removeChild(currentNode), container.firstChild);
  247. else
  248. break;
  249. }
  250. this._insertAfter(container.parentNode, newParagraph, container);
  251. var br = doc.createElement('br');
  252. newParagraph.appendChild(br);
  253. return br;
  254. },
  255. _isPreWrapped: function (textNode) {
  256. var parentNode = textNode.parentNode;
  257. while (parentNode) {
  258. if (parentNode.nodeName.toLowerCase() == 'pre')
  259. return true;
  260. parentNode = parentNode.parentNode;
  261. }
  262. return false;
  263. },
  264. _isNbsp: function (textNode) {
  265. if (textNode.nodeType != 3)
  266. return false;
  267. var pat = /\u00A0/;
  268. return textNode.nodeValue.match(pat);
  269. },
  270. _isNestedInBlockElement: function (element) {
  271. for (var num1 = 0; num1 < this._blockContentNodes.length; num1++) {
  272. var tagName = this._blockContentNodes[num1];
  273. while (element.nodeName.toLowerCase() != tagName) {
  274. element = element.parentNode;
  275. if (element == null || element.nodeName.toLowerCase() == 'body')
  276. return false;
  277. }
  278. if (element.nodeName.toLowerCase() == tagName)
  279. break;
  280. }
  281. return true;
  282. },
  283. _getFormKeyValuePair: function (id, formKeyValuePair, form, includeAll) {
  284. var formBody = new Sys.StringBuilder();
  285. for (var s in formKeyValuePair) {
  286. if (s != 'formdata')
  287. formBody.append(String.format('{0}={1}&', s, encodeURIComponent(formKeyValuePair[s])));
  288. else
  289. formBody.append(String.format('{0}${1}={2}&', s, id, encodeURIComponent(formKeyValuePair[s])));
  290. }
  291. formBody.append(String.format('iscallback${0}=true&', id));
  292. formBody.append('iscallback$Typps=true&');
  293. if (includeAll) {
  294. var count = form.elements.length;
  295. for (var i = 0; i < count; i++) {
  296. var element = form.elements[i];
  297. var name = element.name;
  298. if (typeof (name) === "undefined" || (name === null) || (name.length === 0)) {
  299. continue;
  300. }
  301. var tagName = element.tagName;
  302. if (tagName === 'INPUT') {
  303. var type = element.type;
  304. if ((type === 'text') ||
  305. (type === 'password') ||
  306. (type === 'hidden') ||
  307. (((type === 'checkbox') || (type === 'radio')) && element.checked)) {
  308. formBody.append(encodeURIComponent(name));
  309. formBody.append('=');
  310. formBody.append(encodeURIComponent(element.value));
  311. formBody.append('&');
  312. }
  313. }
  314. else if (tagName === 'SELECT') {
  315. var optionCount = element.options.length;
  316. for (var j = 0; j < optionCount; j++) {
  317. var option = element.options[j];
  318. if (option.selected) {
  319. formBody.append(encodeURIComponent(name));
  320. formBody.append('=');
  321. formBody.append(encodeURIComponent(option.value));
  322. formBody.append('&');
  323. }
  324. }
  325. }
  326. else if (tagName === 'TEXTAREA') {
  327. formBody.append(encodeURIComponent(name));
  328. formBody.append('=');
  329. formBody.append(encodeURIComponent(element.value));
  330. formBody.append('&');
  331. }
  332. }
  333. }
  334. return formBody.toString();
  335. },
  336. _getCommandArgument: function (commandName, callbacks) {
  337. for (var index in callbacks) {
  338. var c = callbacks[index];
  339. if (c.commandName == commandName)
  340. return c;
  341. }
  342. return { message: null, commandArgument: null };
  343. },
  344. _windowBounds: function (w) {
  345. if (w == null)
  346. w = window;
  347. var inner = { x: 0, y: 0 };
  348. var outer = { x: 0, y: 0 };
  349. var doc = w.document;
  350. if (w.innerHeight) {
  351. inner.x = w.innerWidth;
  352. inner.y = w.innerHeight;
  353. outer.x = w.outerWidth;
  354. outer.y = w.outerHeight;
  355. }
  356. else if (doc.documentElement && doc.documentElement.clientHeight) {
  357. // Explorer 6 Strict Mode
  358. inner.x = doc.documentElement.clientWidth;
  359. inner.y = doc.documentElement.clientHeight;
  360. outer.x = doc.documentElement.scrollWidth;
  361. outer.y = doc.documentElement.scrollHeight;
  362. }
  363. else if (doc.body) {
  364. // other Explorers
  365. inner.x = doc.body.clientWidth;
  366. inner.y = doc.body.clientHeight;
  367. outer.x = doc.body.scrollWidth;
  368. outer.y = doc.body.scrollHeight;
  369. }
  370. return { ix: inner.x, iy: inner.y, ox: outer.x, oy: outer.y };
  371. },
  372. _scrollDistance: function (w) {
  373. if (w == null)
  374. w = window;
  375. var scroll = { x: 0, y: 0 };
  376. var doc = w.document;
  377. // all except Explorer
  378. if (w.pageYOffset ||
  379. w.pageXOffset) {
  380. scroll.x = w.scrollX;
  381. scroll.y = w.scrollY;
  382. }
  383. else if (doc.documentElement && (doc.documentElement.scrollTop ||
  384. doc.documentElement.scrollLeft)) {
  385. // Explorer 6 Strict
  386. scroll.x = doc.documentElement.scrollLeft;
  387. scroll.y = doc.documentElement.scrollTop;
  388. }
  389. // all other Explorers
  390. else if (doc.body) {
  391. scroll.x = doc.body.scrollLeft;
  392. scroll.y = doc.body.scrollTop;
  393. }
  394. return scroll;
  395. },
  396. _getScrollBarWidth: function () {
  397. var container = document.createElement('div');
  398. container.style.position = 'absolute';
  399. container.style.top = '-1000px';
  400. container.style.left = '-1000px';
  401. container.style.width = '100px';
  402. container.style.height = '50px';
  403. container.style.overflow = 'hidden';
  404. var content = document.createElement('div');
  405. content.style.width = '100%';
  406. content.style.height = '200px';
  407. container.appendChild(content);
  408. document.body.appendChild(container);
  409. var contentWidth = content.offsetWidth;
  410. container.style.overflow = 'auto';
  411. var containerWidth = content.offsetWidth;
  412. container.parentNode.removeChild(container);
  413. return (contentWidth - containerWidth);
  414. },
  415. _getParentOffset: function (elem) {
  416. var position = { x: 0, y: 0 }, offsetParent;
  417. do {
  418. position.x += elem.offsetLeft;
  419. position.y += elem.offsetTop;
  420. offsetParent = elem.offsetParent;
  421. if (offsetParent && (offsetParent.style.left != 0 || offsetParent.style.top != 0)) {
  422. break;
  423. }
  424. } while (elem = offsetParent);
  425. return position;
  426. },
  427. _getAdjacentHTML: function (markup, container) {
  428. if (container.insertAdjacentHTML) { // IE and opera
  429. container.insertAdjacentHTML('beforeEnd', markup);
  430. }
  431. else if (container.ownerDocument.createRange) { // all others, opera included.
  432. var range = container.ownerDocument.createRange();
  433. range.selectNodeContents(container);
  434. range.deleteContents();
  435. if (range.createContextualFragment) { // exclude opera, since it does not support it :-)
  436. var documentFragment = range.createContextualFragment(markup);
  437. container.appendChild(documentFragment);
  438. }
  439. }
  440. return container;
  441. },
  442. _getIndexByNameFromOptions: function (value, options) {
  443. for (var num1 = 0; num1 < options.length; num1++) {
  444. var option = options[num1];
  445. if (option.value.toLowerCase() == value.toLowerCase())
  446. return num1;
  447. }
  448. return -1;
  449. },
  450. _applyShade: function (element, shaderColor, transparency, zIndex) {
  451. var bounds = this.windowBounds();
  452. element.style.width = bounds.ix + 'px';
  453. element.style.height = bounds.iy + 'px';
  454. element.style.zIndex = zIndex; // pick a random high zindex
  455. Sys.UI.DomElement.setLocation(element, 0, 0);
  456. element.style.backgroundColor = shaderColor;
  457. this.setTransparency(element, transparency);
  458. },
  459. _setFloat: function (element, direction) {
  460. if (element == null) return;
  461. if (Sys.Browser.agent == Sys.Browser.InternetExplorer)
  462. element.style.styleFloat = direction;
  463. else
  464. element.style.cssFloat = direction;
  465. },
  466. _setTransparency: function (element, val1) {
  467. ///val1 is transparency value as supported by IE, for non IE divide by 100
  468. var val2 = val1 / 100;
  469. if (Sys.Browser.agent == Sys.Browser.InternetExplorer) {
  470. if (val1 == 100)
  471. element.style.filter = '';
  472. else
  473. element.style.filter += String.format('progid:DXImageTransform.Microsoft.Alpha(Opacity={0})', val1);
  474. }
  475. else {
  476. element.style.opacity = val2;
  477. }
  478. },
  479. _setBackGroundImage: function (element, imageUrl, repeat, position) {
  480. element.style.backgroundRepeat = repeat;
  481. element.style.backgroundPosition = position;
  482. element.style.backgroundImage = String.format("url({0})", imageUrl);
  483. },
  484. _isDesignMode: function (doc) {
  485. var returnValue = false;
  486. var designMode = doc.designMode.toLowerCase();
  487. if (designMode == 'on')
  488. returnValue = true;
  489. if (Sys.Browser.agent == Sys.Browser.InternetExplorer) {
  490. if (doc.body != null && doc.body.contentEditable == 'true')
  491. returnValue = true;
  492. }
  493. return returnValue;
  494. },
  495. _setDesignMode: function (doc, value) {/*use contentEditable for ie, works better with dynamic css contained in the object tag*/
  496. if (Sys.Browser.agent == Sys.Browser.InternetExplorer)
  497. doc.body.contentEditable = value;
  498. else
  499. doc.designMode = (value == true) ? 'on' : 'off';
  500. },
  501. _addScriptBlocks: function (id, evt, code) {
  502. var scriptclick = document.createElement('script');
  503. scriptclick.htmlFor = id;
  504. scriptclick.setAttribute('type', 'text/javascript');
  505. scriptclick.event = 'on' + evt;
  506. scriptclick.text = code;
  507. document.getElementsByTagName('head')[0].appendChild(scriptclick);
  508. },
  509. _getNextHighestZindex: function (obj) {
  510. var highestIndex = 0;
  511. var currentIndex = 0;
  512. var elArray = Array();
  513. if (obj) { elArray = obj.getElementsByTagName('*'); } else { elArray = document.getElementsByTagName('*'); }
  514. for (var i = 0; i < elArray.length; i++) {
  515. if (elArray[i].currentStyle) {
  516. currentIndex = parseFloat(elArray[i].currentStyle['zIndex']);
  517. } else if (window.getComputedStyle) {
  518. currentIndex = parseFloat(document.defaultView.getComputedStyle(elArray[i], null).getPropertyValue('z-index'));
  519. }
  520. if (!isNaN(currentIndex) && currentIndex > highestIndex) { highestIndex = currentIndex; }
  521. }
  522. return (highestIndex + 1);
  523. },
  524. _isAlphaNumericValidate: function (alphanumeric) {
  525. var regex = /^[0-9a-zA-Z\s]+$/;
  526. return regex.test(alphanumeric);
  527. },
  528. _regExpEscape: function (text) {
  529. return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
  530. },
  531. _createBlockScreen: function (id, shaderColor, shaderOpacity) {
  532. var shadeElement = $get(id);
  533. if (shadeElement == null) {
  534. shadeElement = document.createElement('div');
  535. shadeElement.id = id;
  536. shadeElement.style.backgroundColor = shaderColor;
  537. shadeElement.style.position = 'absolute';
  538. shadeElement.style.left = '0px';
  539. shadeElement.style.top = '0px';
  540. this._setTransparency(shadeElement, shaderOpacity);
  541. var container = document.body;
  542. if ((Sys.Browser.agent == Sys.Browser.InternetExplorer &&
  543. Sys.Browser.version == 6) && document.forms.length > 0)
  544. container = document.forms[0];
  545. container.appendChild(shadeElement);
  546. shadeElement.style.display = 'none';
  547. }
  548. this._applyBlockScreenBounds(id);
  549. return shadeElement;
  550. },
  551. _toggleBlockScreen: function (elem, zIndex) {
  552. if (elem == null) return;
  553. elem.style.zIndex = zIndex;
  554. if (elem.style.display == '')
  555. elem.style.display = 'none';
  556. else
  557. elem.style.display = '';
  558. },
  559. _applyBlockScreenBounds: function (id) {
  560. var elem = $get(id);
  561. if (elem == null) return;
  562. var bounds = this._windowBounds();
  563. var distance = this._scrollDistance();
  564. var x = bounds.ix;
  565. var y = bounds.iy;
  566. var barWidth = 0;
  567. if (Sys.Browser.agent != Sys.Browser.InternetExplorer)
  568. barWidth = this._getScrollBarWidth();
  569. var html = document.getElementsByTagName('html')[0];
  570. if (html.scrollHeight > y && barWidth > 0)
  571. x -= barWidth;
  572. elem.style.width = x + distance.x + 'px';
  573. elem.style.height = y + distance.y + 'px';
  574. },
  575. _setLocation: function (elem) {
  576. if (elem == null) return;
  577. var location = Typps.Utility.getLocationByElement(elem);
  578. elem.style.left = location.x + 'px';
  579. elem.style.top = location.y + 'px';
  580. },
  581. _getLocationByElement: function (elem) {
  582. if (elem == null) return;
  583. return this._getLocationBySize(elem.offsetWidth, elem.offsetHeight);
  584. },
  585. _getLocationBySize: function (width, height) {
  586. var bounds = this._windowBounds();
  587. var distance = this._scrollDistance();
  588. var barWidth = 0;
  589. if (Sys.Browser.agent != Sys.Browser.InternetExplorer)
  590. barWidth = this._getScrollBarWidth();
  591. var x = bounds.ix;
  592. var y = bounds.iy;
  593. var html = document.getElementsByTagName('html')[0];
  594. if (html.scrollHeight > y && barWidth > 0)
  595. x -= barWidth;
  596. x = Math.round((x - width) / 2);
  597. y = Math.round((y - height) / 2);
  598. return { x: (x + distance.x), y: (y + distance.y) };
  599. },
  600. _toggleSelectElement: function (elem, selectsCache) {
  601. if (Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version <= 7) {
  602. var selects = document.getElementsByTagName('SELECT');
  603. //not all the selects! We want to ignore the ones in this popup
  604. var selectsToIgnore = elem.getElementsByTagName('SELECT');
  605. var sel = null;
  606. if (selectsCache == null) {
  607. for (var num1 = 0; num1 < selects.length; num1++) {
  608. sel = selects[num1];
  609. var skip = false;
  610. if (selectsToIgnore.length > 0) {
  611. for (var num2 = 0; num2 < selectsToIgnore.length; num2++) {
  612. if (sel == selectsToIgnore[num2]) {
  613. skip = true;
  614. break;
  615. }
  616. }
  617. }
  618. if (skip == true) continue;
  619. if (sel.style.display != 'none') {
  620. sel.style.display = 'none';
  621. if (selectsCache == null)
  622. selectsCache = new Array();
  623. selectsCache[selectsCache.length] = sel;
  624. }
  625. }
  626. }
  627. else {
  628. var length = selectsCache.length;
  629. for (var num3 = 0; num3 < length; num3++) {
  630. sel = selectsCache.pop();
  631. sel.style.display = '';
  632. }
  633. selectsCache = null;
  634. }
  635. }
  636. return selectsCache;
  637. },
  638. _isNullOrEmpty: function (value) {
  639. var isNullOrEmpty = true;
  640. if (value) {
  641. if (typeof (value) == 'string') {
  642. if (value.length > 0)
  643. isNullOrEmpty = false;
  644. }
  645. }
  646. return isNullOrEmpty;
  647. },
  648. _addRemoveClassName: function (elem, className, operation) {
  649. var add = operation == Typps.Perform.Add;
  650. var remove = operation == Typps.Perform.Remove;
  651. var toggle = operation == Typps.Perform.Toggle;
  652. var containsCssClass = this._containsCssClass(elem, className);
  653. if (!containsCssClass && remove) return;
  654. if (containsCssClass && add) return;
  655. var namesList = className.split(' ');
  656. if (namesList.length > 0) {
  657. for (var index in namesList) {
  658. var cn = namesList[index];
  659. if (cn != '') {
  660. var containsClass = Sys.UI.DomElement.containsCssClass(elem, cn);
  661. if (add) {
  662. if (!containsClass)
  663. Sys.UI.DomElement.addCssClass(elem, cn);
  664. } else if (remove) {
  665. if (containsClass)
  666. Sys.UI.DomElement.removeCssClass(elem, cn);
  667. } else if (toggle) {
  668. if (containsCssClass)
  669. Sys.UI.DomElement.removeCssClass(elem, cn);
  670. else
  671. Sys.UI.DomElement.addCssClass(elem, cn);
  672. }
  673. }
  674. }
  675. }
  676. if (elem.className == '') {
  677. if (this._isIE)
  678. elem.removeAttribute('className');
  679. else
  680. elem.removeAttribute('class');
  681. }
  682. },
  683. _containsCssClass: function (elem, className) {
  684. var namesList = className.split(' ');
  685. var returnValue = false;
  686. if (namesList.length > 0) {
  687. for (var index in namesList) {
  688. var cn = namesList[index];
  689. if (cn != '') {
  690. var containsClass = Sys.UI.DomElement.containsCssClass(elem, cn);
  691. //match all classes in list
  692. if (containsClass)
  693. returnValue = true;
  694. else
  695. returnValue = false;
  696. }
  697. }
  698. }
  699. return returnValue;
  700. },
  701. _getTokenId: function (doc) {
  702. var tokenId = 'token';
  703. var tokenIndex = 0;
  704. while ($get(String.format('{0}{1}', tokenId, tokenIndex), doc)) {
  705. tokenIndex++;
  706. }
  707. return tokenId += tokenIndex;
  708. },
  709. _isEmptyTextNode: function (node) {
  710. if (node != null && (node.nodeType == 3 && node.data.trim() == ''))
  711. return true;
  712. return false;
  713. },
  714. _isBr: function (node) {
  715. if (node != null && (node.nodeType == 1 && node.nodeName.toLowerCase() == 'br'))
  716. return true;
  717. return false;
  718. },
  719. _isElementNode: function (node) {
  720. if (node != null && (node.nodeType == 1)) return true;
  721. return false;
  722. },
  723. _insertAfter: function (newNode, node) {
  724. if (!node.nextSibling)
  725. node.parentNode.appendChild(newNode);
  726. else
  727. node.parentNode.insertBefore(newNode, node.nextSibling);
  728. },
  729. _getForm: function (id) {
  730. var form = null;
  731. if (!Typps.Utility.isNullOrEmpty(id))
  732. form = $get(id);
  733. if (!form)
  734. form = document.forms[0];
  735. return form;
  736. },
  737. _splitText: function (doc, node, offset) {
  738. if (node.nodeType != 3) return;
  739. var nextSibling, newTextNode;
  740. if (node.length == offset) {
  741. nextSibling = node.nextSibling;
  742. newTextNode = doc.createTextNode('');
  743. if (nextSibling == null) {
  744. node.parentNode.appendChild(newTextNode);
  745. } else {
  746. node.parentNode.insertBefore(newTextNode, nextSibling);
  747. }
  748. }
  749. else {
  750. return node.splitText(offset);
  751. }
  752. return newTextNode;
  753. }
  754. }
  755. Typps.Utility.registerClass('Typps.Utility');
  756. // Since this script is not loaded by System.Web.Handlers.ScriptResourceHandler
  757. // invoke Sys.Application.notifyScriptLoaded to notify ScriptManager
  758. // that this is the end of the script.
  759. if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();