b2evolution PHP Cross Reference Blogging Systems

Source: /plugins/tinymce_plugin/tiny_mce/utils/form_utils.js - 212 lines - 5859 bytes - Summary - Text - Print

Description: Various form utilitiy functions.

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

title

Description

title

Description

title

Description

title

title

Body