You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

201 rivejä
5.4 KiB

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