PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/editors/tiny_mce_3_4_3_1/utils/form_utils.js

#
JavaScript | 210 lines | 146 code | 52 blank | 12 comment | 51 complexity | 579b2803ffca7953c50f53dcbef5df7e MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. /**
  2. * form_utils.js
  3. *
  4. * Copyright 2009, Moxiecode Systems AB
  5. * Released under LGPL License.
  6. *
  7. * License: http://tinymce.moxiecode.com/license
  8. * Contributing: http://tinymce.moxiecode.com/contributing
  9. */
  10. var themeBaseURL = tinyMCEPopup.editor.baseURI.toAbsolute('themes/' + tinyMCEPopup.getParam("theme"));
  11. function getColorPickerHTML(id, target_form_element) {
  12. var h = "", dom = tinyMCEPopup.dom;
  13. if (label = dom.select('label[for=' + target_form_element + ']')[0]) {
  14. label.id = label.id || dom.uniqueId();
  15. }
  16. h += '<a role="button" aria-labelledby="' + id + '_label" id="' + id + '_link" href="javascript:;" onclick="tinyMCEPopup.pickColor(event,\'' + target_form_element +'\');" onmousedown="return false;" class="pickcolor">';
  17. h += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '">&nbsp;<span id="' + id + '_label" class="mceVoiceLabel mceIconOnly" style="display:none;">' + tinyMCEPopup.getLang('browse') + '</span></span></a>';
  18. return h;
  19. }
  20. function updateColor(img_id, form_element_id) {
  21. document.getElementById(img_id).style.backgroundColor = document.forms[0].elements[form_element_id].value;
  22. }
  23. function setBrowserDisabled(id, state) {
  24. var img = document.getElementById(id);
  25. var lnk = document.getElementById(id + "_link");
  26. if (lnk) {
  27. if (state) {
  28. lnk.setAttribute("realhref", lnk.getAttribute("href"));
  29. lnk.removeAttribute("href");
  30. tinyMCEPopup.dom.addClass(img, 'disabled');
  31. } else {
  32. if (lnk.getAttribute("realhref"))
  33. lnk.setAttribute("href", lnk.getAttribute("realhref"));
  34. tinyMCEPopup.dom.removeClass(img, 'disabled');
  35. }
  36. }
  37. }
  38. function getBrowserHTML(id, target_form_element, type, prefix) {
  39. var option = prefix + "_" + type + "_browser_callback", cb, html;
  40. cb = tinyMCEPopup.getParam(option, tinyMCEPopup.getParam("file_browser_callback"));
  41. if (!cb)
  42. return "";
  43. html = "";
  44. html += '<a id="' + id + '_link" href="javascript:openBrowser(\'' + id + '\',\'' + target_form_element + '\', \'' + type + '\',\'' + option + '\');" onmousedown="return false;" class="browse">';
  45. html += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '">&nbsp;</span></a>';
  46. return html;
  47. }
  48. function openBrowser(img_id, target_form_element, type, option) {
  49. var img = document.getElementById(img_id);
  50. if (img.className != "mceButtonDisabled")
  51. tinyMCEPopup.openBrowser(target_form_element, type, option);
  52. }
  53. function selectByValue(form_obj, field_name, value, add_custom, ignore_case) {
  54. if (!form_obj || !form_obj.elements[field_name])
  55. return;
  56. if (!value)
  57. value = "";
  58. var sel = form_obj.elements[field_name];
  59. var found = false;
  60. for (var i=0; i<sel.options.length; i++) {
  61. var option = sel.options[i];
  62. if (option.value == value || (ignore_case && option.value.toLowerCase() == value.toLowerCase())) {
  63. option.selected = true;
  64. found = true;
  65. } else
  66. option.selected = false;
  67. }
  68. if (!found && add_custom && value != '') {
  69. var option = new Option(value, value);
  70. option.selected = true;
  71. sel.options[sel.options.length] = option;
  72. sel.selectedIndex = sel.options.length - 1;
  73. }
  74. return found;
  75. }
  76. function getSelectValue(form_obj, field_name) {
  77. var elm = form_obj.elements[field_name];
  78. if (elm == null || elm.options == null || elm.selectedIndex === -1)
  79. return "";
  80. return elm.options[elm.selectedIndex].value;
  81. }
  82. function addSelectValue(form_obj, field_name, name, value) {
  83. var s = form_obj.elements[field_name];
  84. var o = new Option(name, value);
  85. s.options[s.options.length] = o;
  86. }
  87. function addClassesToList(list_id, specific_option) {
  88. // Setup class droplist
  89. var styleSelectElm = document.getElementById(list_id);
  90. var styles = tinyMCEPopup.getParam('theme_advanced_styles', false);
  91. styles = tinyMCEPopup.getParam(specific_option, styles);
  92. if (styles) {
  93. var stylesAr = styles.split(';');
  94. for (var i=0; i<stylesAr.length; i++) {
  95. if (stylesAr != "") {
  96. var key, value;
  97. key = stylesAr[i].split('=')[0];
  98. value = stylesAr[i].split('=')[1];
  99. styleSelectElm.options[styleSelectElm.length] = new Option(key, value);
  100. }
  101. }
  102. } else {
  103. tinymce.each(tinyMCEPopup.editor.dom.getClasses(), function(o) {
  104. styleSelectElm.options[styleSelectElm.length] = new Option(o.title || o['class'], o['class']);
  105. });
  106. }
  107. }
  108. function isVisible(element_id) {
  109. var elm = document.getElementById(element_id);
  110. return elm && elm.style.display != "none";
  111. }
  112. function convertRGBToHex(col) {
  113. var re = new RegExp("rgb\\s*\\(\\s*([0-9]+).*,\\s*([0-9]+).*,\\s*([0-9]+).*\\)", "gi");
  114. var rgb = col.replace(re, "$1,$2,$3").split(',');
  115. if (rgb.length == 3) {
  116. r = parseInt(rgb[0]).toString(16);
  117. g = parseInt(rgb[1]).toString(16);
  118. b = parseInt(rgb[2]).toString(16);
  119. r = r.length == 1 ? '0' + r : r;
  120. g = g.length == 1 ? '0' + g : g;
  121. b = b.length == 1 ? '0' + b : b;
  122. return "#" + r + g + b;
  123. }
  124. return col;
  125. }
  126. function convertHexToRGB(col) {
  127. if (col.indexOf('#') != -1) {
  128. col = col.replace(new RegExp('[^0-9A-F]', 'gi'), '');
  129. r = parseInt(col.substring(0, 2), 16);
  130. g = parseInt(col.substring(2, 4), 16);
  131. b = parseInt(col.substring(4, 6), 16);
  132. return "rgb(" + r + "," + g + "," + b + ")";
  133. }
  134. return col;
  135. }
  136. function trimSize(size) {
  137. return size.replace(/([0-9\.]+)(px|%|in|cm|mm|em|ex|pt|pc)/i, '$1$2');
  138. }
  139. function getCSSSize(size) {
  140. size = trimSize(size);
  141. if (size == "")
  142. return "";
  143. // Add px
  144. if (/^[0-9]+$/.test(size))
  145. size += 'px';
  146. // Sanity check, IE doesn't like broken values
  147. else if (!(/^[0-9\.]+(px|%|in|cm|mm|em|ex|pt|pc)$/i.test(size)))
  148. return "";
  149. return size;
  150. }
  151. function getStyle(elm, attrib, style) {
  152. var val = tinyMCEPopup.dom.getAttrib(elm, attrib);
  153. if (val != '')
  154. return '' + val;
  155. if (typeof(style) == 'undefined')
  156. style = attrib;
  157. return tinyMCEPopup.dom.getStyle(elm, style);
  158. }