balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

form_utils.js (6071B)


      1 /**
      2  * form_utils.js
      3  *
      4  * Released under LGPL License.
      5  * Copyright (c) 1999-2017 Ephox Corp. All rights reserved
      6  *
      7  * License: http://www.tinymce.com/license
      8  * Contributing: http://www.tinymce.com/contributing
      9  */
     10 
     11 var themeBaseURL = tinyMCEPopup.editor.baseURI.toAbsolute('themes/' + tinyMCEPopup.getParam("theme"));
     12 
     13 function getColorPickerHTML(id, target_form_element) {
     14   var h = "", dom = tinyMCEPopup.dom;
     15 
     16   if (label = dom.select('label[for=' + target_form_element + ']')[0]) {
     17     label.id = label.id || dom.uniqueId();
     18   }
     19 
     20   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">';
     21   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>';
     22 
     23   return h;
     24 }
     25 
     26 function updateColor(img_id, form_element_id) {
     27   document.getElementById(img_id).style.backgroundColor = document.forms[0].elements[form_element_id].value;
     28 }
     29 
     30 function setBrowserDisabled(id, state) {
     31   var img = document.getElementById(id);
     32   var lnk = document.getElementById(id + "_link");
     33 
     34   if (lnk) {
     35     if (state) {
     36       lnk.setAttribute("realhref", lnk.getAttribute("href"));
     37       lnk.removeAttribute("href");
     38       tinyMCEPopup.dom.addClass(img, 'disabled');
     39     } else {
     40       if (lnk.getAttribute("realhref")) {
     41         lnk.setAttribute("href", lnk.getAttribute("realhref"));
     42       }
     43 
     44       tinyMCEPopup.dom.removeClass(img, 'disabled');
     45     }
     46   }
     47 }
     48 
     49 function getBrowserHTML(id, target_form_element, type, prefix) {
     50   var option = prefix + "_" + type + "_browser_callback", cb, html;
     51 
     52   cb = tinyMCEPopup.getParam(option, tinyMCEPopup.getParam("file_browser_callback"));
     53 
     54   if (!cb) {
     55     return "";
     56   }
     57 
     58   html = "";
     59   html += '<a id="' + id + '_link" href="javascript:openBrowser(\'' + id + '\',\'' + target_form_element + '\', \'' + type + '\',\'' + option + '\');" onmousedown="return false;" class="browse">';
     60   html += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '">&nbsp;</span></a>';
     61 
     62   return html;
     63 }
     64 
     65 function openBrowser(img_id, target_form_element, type, option) {
     66   var img = document.getElementById(img_id);
     67 
     68   if (img.className != "mceButtonDisabled") {
     69     tinyMCEPopup.openBrowser(target_form_element, type, option);
     70   }
     71 }
     72 
     73 function selectByValue(form_obj, field_name, value, add_custom, ignore_case) {
     74   if (!form_obj || !form_obj.elements[field_name]) {
     75     return;
     76   }
     77 
     78   if (!value) {
     79     value = "";
     80   }
     81 
     82   var sel = form_obj.elements[field_name];
     83 
     84   var found = false;
     85   for (var i = 0; i < sel.options.length; i++) {
     86     var option = sel.options[i];
     87 
     88     if (option.value == value || (ignore_case && option.value.toLowerCase() == value.toLowerCase())) {
     89       option.selected = true;
     90       found = true;
     91     } else {
     92       option.selected = false;
     93     }
     94   }
     95 
     96   if (!found && add_custom && value != '') {
     97     var option = new Option(value, value);
     98     option.selected = true;
     99     sel.options[sel.options.length] = option;
    100     sel.selectedIndex = sel.options.length - 1;
    101   }
    102 
    103   return found;
    104 }
    105 
    106 function getSelectValue(form_obj, field_name) {
    107   var elm = form_obj.elements[field_name];
    108 
    109   if (elm == null || elm.options == null || elm.selectedIndex === -1) {
    110     return "";
    111   }
    112 
    113   return elm.options[elm.selectedIndex].value;
    114 }
    115 
    116 function addSelectValue(form_obj, field_name, name, value) {
    117   var s = form_obj.elements[field_name];
    118   var o = new Option(name, value);
    119   s.options[s.options.length] = o;
    120 }
    121 
    122 function addClassesToList(list_id, specific_option) {
    123   // Setup class droplist
    124   var styleSelectElm = document.getElementById(list_id);
    125   var styles = tinyMCEPopup.getParam('theme_advanced_styles', false);
    126   styles = tinyMCEPopup.getParam(specific_option, styles);
    127 
    128   if (styles) {
    129     var stylesAr = styles.split(';');
    130 
    131     for (var i = 0; i < stylesAr.length; i++) {
    132       if (stylesAr != "") {
    133         var key, value;
    134 
    135         key = stylesAr[i].split('=')[0];
    136         value = stylesAr[i].split('=')[1];
    137 
    138         styleSelectElm.options[styleSelectElm.length] = new Option(key, value);
    139       }
    140     }
    141   } else {
    142     /*tinymce.each(tinyMCEPopup.editor.dom.getClasses(), function(o) {
    143     styleSelectElm.options[styleSelectElm.length] = new Option(o.title || o['class'], o['class']);
    144     });*/
    145   }
    146 }
    147 
    148 function isVisible(element_id) {
    149   var elm = document.getElementById(element_id);
    150 
    151   return elm && elm.style.display != "none";
    152 }
    153 
    154 function convertRGBToHex(col) {
    155   var re = new RegExp("rgb\\s*\\(\\s*([0-9]+).*,\\s*([0-9]+).*,\\s*([0-9]+).*\\)", "gi");
    156 
    157   var rgb = col.replace(re, "$1,$2,$3").split(',');
    158   if (rgb.length == 3) {
    159     r = parseInt(rgb[0]).toString(16);
    160     g = parseInt(rgb[1]).toString(16);
    161     b = parseInt(rgb[2]).toString(16);
    162 
    163     r = r.length == 1 ? '0' + r : r;
    164     g = g.length == 1 ? '0' + g : g;
    165     b = b.length == 1 ? '0' + b : b;
    166 
    167     return "#" + r + g + b;
    168   }
    169 
    170   return col;
    171 }
    172 
    173 function convertHexToRGB(col) {
    174   if (col.indexOf('#') != -1) {
    175     col = col.replace(new RegExp('[^0-9A-F]', 'gi'), '');
    176 
    177     r = parseInt(col.substring(0, 2), 16);
    178     g = parseInt(col.substring(2, 4), 16);
    179     b = parseInt(col.substring(4, 6), 16);
    180 
    181     return "rgb(" + r + "," + g + "," + b + ")";
    182   }
    183 
    184   return col;
    185 }
    186 
    187 function trimSize(size) {
    188   return size.replace(/([0-9\.]+)(px|%|in|cm|mm|em|ex|pt|pc)/i, '$1$2');
    189 }
    190 
    191 function getCSSSize(size) {
    192   size = trimSize(size);
    193 
    194   if (size == "") {
    195     return "";
    196   }
    197 
    198   // Add px
    199   if (/^[0-9]+$/.test(size)) {
    200     size += 'px';
    201   }
    202   // Sanity check, IE doesn't like broken values
    203   else if (!(/^[0-9\.]+(px|%|in|cm|mm|em|ex|pt|pc)$/i.test(size))) {
    204     return "";
    205   }
    206 
    207   return size;
    208 }
    209 
    210 function getStyle(elm, attrib, style) {
    211   var val = tinyMCEPopup.dom.getAttrib(elm, attrib);
    212 
    213   if (val != '') {
    214     return '' + val;
    215   }
    216 
    217   if (typeof (style) == 'undefined') {
    218     style = attrib;
    219   }
    220 
    221   return tinyMCEPopup.dom.getStyle(elm, style);
    222 }