summaryrefslogtreecommitdiff
path: root/program/js/tiny_mce/utils
diff options
context:
space:
mode:
authorsvncommit <devs@roundcube.net>2006-09-14 03:49:28 +0000
committersvncommit <devs@roundcube.net>2006-09-14 03:49:28 +0000
commita0109c4933e0bfb5ed9dbcf94f932991ca689542 (patch)
tree955246969bf9da5d5335d1d7c483025fdbd50407 /program/js/tiny_mce/utils
parentbb5ddfa0ade5fbd2ed9be16e51d4ce695252eece (diff)
Initial TinyMCE editor support (still need to work on spellcheck and skins)
Diffstat (limited to 'program/js/tiny_mce/utils')
-rw-r--r--program/js/tiny_mce/utils/editable_selects.js63
-rw-r--r--program/js/tiny_mce/utils/form_utils.js210
-rw-r--r--program/js/tiny_mce/utils/mclayer.js212
-rw-r--r--program/js/tiny_mce/utils/mctabs.js76
-rw-r--r--program/js/tiny_mce/utils/validate.js50
5 files changed, 611 insertions, 0 deletions
diff --git a/program/js/tiny_mce/utils/editable_selects.js b/program/js/tiny_mce/utils/editable_selects.js
new file mode 100644
index 000000000..81c99eb5c
--- /dev/null
+++ b/program/js/tiny_mce/utils/editable_selects.js
@@ -0,0 +1,63 @@
+/**
+ * $RCSfile: editable_selects.js,v $
+ * $Revision: 1.1 $
+ * $Date: 2006/04/10 09:30:19 $
+ *
+ * Makes select boxes editable.
+ *
+ * @author Moxiecode
+ * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
+ */
+
+var TinyMCE_EditableSelects = {
+ editSelectElm : null,
+
+ init : function() {
+ var nl = document.getElementsByTagName("select"), i, d = document, o;
+
+ for (i=0; i<nl.length; i++) {
+ if (nl[i].className.indexOf('mceEditableSelect') != -1) {
+ o = new Option('(value)', '__mce_add_custom__');
+
+ o.className = 'mceAddSelectValue';
+
+ nl[i].options[nl[i].options.length] = o;
+ nl[i].setAttribute('onchange', 'TinyMCE_EditableSelects.onChangeEditableSelect(this);');
+ }
+ }
+ },
+
+ onChangeEditableSelect : function(se) {
+ var d = document, ne;
+
+ if (se.options[se.selectedIndex].value == '__mce_add_custom__') {
+ ne = d.createElement("input");
+ ne.id = se.id + "_custom";
+ ne.name = se.name + "_custom";
+ ne.type = "text";
+
+ ne.style.width = se.clientWidth;
+ se.parentNode.insertBefore(ne, se);
+ se.style.display = 'none';
+ ne.focus();
+ ne.onblur = TinyMCE_EditableSelects.onBlurEditableSelectInput;
+ TinyMCE_EditableSelects.editSelectElm = se;
+ }
+ },
+
+ onBlurEditableSelectInput : function() {
+ var se = TinyMCE_EditableSelects.editSelectElm;
+
+ if (se) {
+ if (se.previousSibling.value != '') {
+ addSelectValue(document.forms[0], se.id, se.previousSibling.value, se.previousSibling.value);
+ selectByValue(document.forms[0], se.id, se.previousSibling.value);
+ } else
+ selectByValue(document.forms[0], se.id, '');
+
+ se.style.display = 'inline';
+ se.parentNode.removeChild(se.previousSibling);
+ TinyMCE_EditableSelects.editSelectElm = null;
+ }
+ }
+};
diff --git a/program/js/tiny_mce/utils/form_utils.js b/program/js/tiny_mce/utils/form_utils.js
new file mode 100644
index 000000000..f1e935809
--- /dev/null
+++ b/program/js/tiny_mce/utils/form_utils.js
@@ -0,0 +1,210 @@
+/**
+ * $RCSfile: form_utils.js,v $
+ * $Revision: 1.11 $
+ * $Date: 2006/04/07 15:53:12 $
+ *
+ * Various form utilitiy functions.
+ *
+ * @author Moxiecode
+ * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
+ */
+
+function getColorPickerHTML(id, target_form_element) {
+ var html = "";
+
+ html += '<a id="' + id + '_link" href="javascript:void(0);" onkeydown="pickColor(event,\'' + target_form_element +'\');" onmousedown="pickColor(event,\'' + target_form_element +'\');return false;">';
+ html += '<img id="' + id + '" src="../../themes/' + tinyMCE.getParam("theme") + '/images/color.gif"';
+ html += ' onmouseover="this.className=\'mceButtonOver\'"';
+ html += ' onmouseout="this.className=\'mceButtonNormal\'"';
+ html += ' onmousedown="this.className=\'mceButtonDown\'"';
+ html += ' width="20" height="16" border="0" title="' + tinyMCE.getLang('lang_browse') + '"';
+ html += ' class="mceButtonNormal" alt="' + tinyMCE.getLang('lang_browse') + '" /></a>';
+
+ return html;
+}
+
+function pickColor(e, target_form_element) {
+ if ((e.keyCode == 32 || e.keyCode == 13) || e.type == "mousedown")
+ tinyMCEPopup.pickColor(e, target_form_element);
+}
+
+function updateColor(img_id, form_element_id) {
+ document.getElementById(img_id).style.backgroundColor = document.forms[0].elements[form_element_id].value;
+}
+
+function setBrowserDisabled(id, state) {
+ var img = document.getElementById(id);
+ var lnk = document.getElementById(id + "_link");
+
+ if (lnk) {
+ if (state) {
+ lnk.setAttribute("realhref", lnk.getAttribute("href"));
+ lnk.removeAttribute("href");
+ tinyMCE.switchClass(img, 'mceButtonDisabled', true);
+ } else {
+ lnk.setAttribute("href", lnk.getAttribute("realhref"));
+ tinyMCE.switchClass(img, 'mceButtonNormal', false);
+ }
+ }
+}
+
+function getBrowserHTML(id, target_form_element, type, prefix) {
+ var option = prefix + "_" + type + "_browser_callback";
+ var cb = tinyMCE.getParam(option, tinyMCE.getParam("file_browser_callback"));
+ if (cb == null)
+ return "";
+
+ var html = "";
+
+ html += '<a id="' + id + '_link" href="javascript:openBrower(\'' + id + '\',\'' + target_form_element + '\', \'' + type + '\',\'' + option + '\');" onmousedown="return false;">';
+ html += '<img id="' + id + '" src="../../themes/' + tinyMCE.getParam("theme") + '/images/browse.gif"';
+ html += ' onmouseover="this.className=\'mceButtonOver\';"';
+ html += ' onmouseout="this.className=\'mceButtonNormal\';"';
+ html += ' onmousedown="this.className=\'mceButtonDown\';"';
+ html += ' width="20" height="18" border="0" title="' + tinyMCE.getLang('lang_browse') + '"';
+ html += ' class="mceButtonNormal" alt="' + tinyMCE.getLang('lang_browse') + '" /></a>';
+
+ return html;
+}
+
+function openBrower(img_id, target_form_element, type, option) {
+ var img = document.getElementById(img_id);
+
+ if (img.className != "mceButtonDisabled")
+ tinyMCEPopup.openBrowser(target_form_element, type, option);
+}
+
+function selectByValue(form_obj, field_name, value, add_custom, ignore_case) {
+ if (!form_obj || !form_obj.elements[field_name])
+ return;
+
+ var sel = form_obj.elements[field_name];
+
+ var found = false;
+ for (var i=0; i<sel.options.length; i++) {
+ var option = sel.options[i];
+
+ if (option.value == value || (ignore_case && option.value.toLowerCase() == value.toLowerCase())) {
+ option.selected = true;
+ found = true;
+ } else
+ option.selected = false;
+ }
+
+ if (!found && add_custom && value != '') {
+ var option = new Option(value, value);
+ option.selected = true;
+ sel.options[sel.options.length] = option;
+ sel.selectedIndex = sel.options.length - 1;
+ }
+
+ return found;
+}
+
+function getSelectValue(form_obj, field_name) {
+ var elm = form_obj.elements[field_name];
+
+ if (elm == null || elm.options == null)
+ return "";
+
+ return elm.options[elm.selectedIndex].value;
+}
+
+function addSelectValue(form_obj, field_name, name, value) {
+ var s = form_obj.elements[field_name];
+ var o = new Option(name, value);
+ s.options[s.options.length] = o;
+}
+
+function addClassesToList(list_id, specific_option) {
+ // Setup class droplist
+ var styleSelectElm = document.getElementById(list_id);
+ var styles = tinyMCE.getParam('theme_advanced_styles', false);
+ styles = tinyMCE.getParam(specific_option, styles);
+
+ if (styles) {
+ var stylesAr = styles.split(';');
+
+ for (var i=0; i<stylesAr.length; i++) {
+ if (stylesAr != "") {
+ var key, value;
+
+ key = stylesAr[i].split('=')[0];
+ value = stylesAr[i].split('=')[1];
+
+ styleSelectElm.options[styleSelectElm.length] = new Option(key, value);
+ }
+ }
+ } else {
+ // Use auto impored classes
+ var csses = tinyMCE.getCSSClasses(tinyMCE.getWindowArg('editor_id'));
+ for (var i=0; i<csses.length; i++)
+ styleSelectElm.options[styleSelectElm.length] = new Option(csses[i], csses[i]);
+ }
+}
+
+function isVisible(element_id) {
+ var elm = document.getElementById(element_id);
+
+ return elm && elm.style.display != "none";
+}
+
+function convertRGBToHex(col) {
+ var re = new RegExp("rgb\\s*\\(\\s*([0-9]+).*,\\s*([0-9]+).*,\\s*([0-9]+).*\\)", "gi");
+
+ var rgb = col.replace(re, "$1,$2,$3").split(',');
+ if (rgb.length == 3) {
+ r = parseInt(rgb[0]).toString(16);
+ g = parseInt(rgb[1]).toString(16);
+ b = parseInt(rgb[2]).toString(16);
+
+ r = r.length == 1 ? '0' + r : r;
+ g = g.length == 1 ? '0' + g : g;
+ b = b.length == 1 ? '0' + b : b;
+
+ return "#" + r + g + b;
+ }
+
+ return col;
+}
+
+function convertHexToRGB(col) {
+ if (col.indexOf('#') != -1) {
+ col = col.replace(new RegExp('[^0-9A-F]', 'gi'), '');
+
+ r = parseInt(col.substring(0, 2), 16);
+ g = parseInt(col.substring(2, 4), 16);
+ b = parseInt(col.substring(4, 6), 16);
+
+ return "rgb(" + r + "," + g + "," + b + ")";
+ }
+
+ return col;
+}
+
+function trimSize(size) {
+ return size.replace(new RegExp('[^0-9%]', 'gi'), '');
+}
+
+function getCSSSize(size) {
+ size = trimSize(size);
+
+ if (size == "")
+ return "";
+
+ return size.indexOf('%') != -1 ? size : size + "px";
+}
+
+function getStyle(elm, attrib, style) {
+ var val = tinyMCE.getAttrib(elm, attrib);
+
+ if (val != '')
+ return '' + val;
+
+ if (typeof(style) == 'undefined')
+ style = attrib;
+
+ val = eval('elm.style.' + style);
+
+ return val == null ? '' : '' + val;
+}
diff --git a/program/js/tiny_mce/utils/mclayer.js b/program/js/tiny_mce/utils/mclayer.js
new file mode 100644
index 000000000..0a7837b28
--- /dev/null
+++ b/program/js/tiny_mce/utils/mclayer.js
@@ -0,0 +1,212 @@
+/**
+ * $RCSfile: mclayer.js,v $
+ * $Revision: 1.2 $
+ * $Date: 2006/02/06 20:11:09 $
+ *
+ * Moxiecode floating layer script.
+ *
+ * @author Moxiecode
+ * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
+ */
+
+function MCLayer(id) {
+ this.id = id;
+ this.settings = new Array();
+ this.blockerElement = null;
+ this.isMSIE = navigator.appName == "Microsoft Internet Explorer";
+ this.events = false;
+ this.autoHideCallback = null;
+}
+
+MCLayer.prototype = {
+ moveRelativeTo : function(re, p, a) {
+ var rep = this.getAbsPosition(re);
+ var w = parseInt(re.offsetWidth);
+ var h = parseInt(re.offsetHeight);
+ var x, y;
+
+ switch (p) {
+ case "tl":
+ break;
+
+ case "tr":
+ x = rep.absLeft + w;
+ y = rep.absTop;
+ break;
+
+ case "bl":
+ break;
+
+ case "br":
+ break;
+ }
+
+ this.moveTo(x, y);
+ },
+
+ moveBy : function(dx, dy) {
+ var e = this.getElement();
+ var x = parseInt(e.style.left);
+ var y = parseInt(e.style.top);
+
+ e.style.left = (x + dx) + "px";
+ e.style.top = (y + dy) + "px";
+
+ this.updateBlocker();
+ },
+
+ moveTo : function(x, y) {
+ var e = this.getElement();
+
+ e.style.left = x + "px";
+ e.style.top = y + "px";
+
+ this.updateBlocker();
+ },
+
+ show : function() {
+ MCLayer.visibleLayer = this;
+
+ this.getElement().style.display = 'block';
+ this.updateBlocker();
+ },
+
+ hide : function() {
+ this.getElement().style.display = 'none';
+ this.updateBlocker();
+ },
+
+ setAutoHide : function(s, cb) {
+ this.autoHideCallback = cb;
+ this.registerEventHandlers();
+ },
+
+ getElement : function() {
+ return document.getElementById(this.id);
+ },
+
+ updateBlocker : function() {
+ if (!this.isMSIE)
+ return;
+
+ var e = this.getElement();
+ var b = this.getBlocker();
+ var x = this.parseInt(e.style.left);
+ var y = this.parseInt(e.style.top);
+ var w = this.parseInt(e.offsetWidth);
+ var h = this.parseInt(e.offsetHeight);
+
+ b.style.left = x + 'px';
+ b.style.top = y + 'px';
+ b.style.width = w + 'px';
+ b.style.height = h + 'px';
+ b.style.display = e.style.display;
+ },
+
+ getBlocker : function() {
+ if (!this.blockerElement) {
+ var d = document, b = d.createElement("iframe");
+
+ b.style.cssText = 'display: none; left: 0px; position: absolute; top: 0';
+ b.src = 'javascript:false;';
+ b.frameBorder = '0';
+ b.scrolling = 'no';
+
+ d.body.appendChild(b);
+ this.blockerElement = b;
+ }
+
+ return this.blockerElement;
+ },
+
+ getAbsPosition : function(n) {
+ var p = {absLeft : 0, absTop : 0};
+
+ while (n) {
+ p.absLeft += n.offsetLeft;
+ p.absTop += n.offsetTop;
+ n = n.offsetParent;
+ }
+
+ return p;
+ },
+
+ registerEventHandlers : function() {
+ if (!this.events) {
+ var d = document;
+
+ this.addEvent(d, 'mousedown', MCLayer.prototype.onMouseDown);
+
+ this.events = true;
+ }
+ },
+
+ addEvent : function(o, n, h) {
+ if (o.attachEvent)
+ o.attachEvent("on" + n, h);
+ else
+ o.addEventListener(n, h, false);
+ },
+
+ onMouseDown : function(e) {
+ e = typeof(e) == "undefined" ? window.event : e;
+ var b = document.body;
+ var l = MCLayer.visibleLayer;
+
+ if (l) {
+ var mx = l.isMSIE ? e.clientX + b.scrollLeft : e.pageX;
+ var my = l.isMSIE ? e.clientY + b.scrollTop : e.pageY;
+ var el = l.getElement();
+ var x = parseInt(el.style.left);
+ var y = parseInt(el.style.top);
+ var w = parseInt(el.offsetWidth);
+ var h = parseInt(el.offsetHeight);
+
+ if (!(mx > x && mx < x + w && my > y && my < y + h)) {
+ MCLayer.visibleLayer = null;
+
+ if (l.autoHideCallback && l.autoHideCallback(l, e, mx, my))
+ return true;
+
+ l.hide();
+ }
+ }
+ },
+
+ addCSSClass : function(e, c) {
+ this.removeCSSClass(e, c);
+ var a = this.explode(' ', e.className);
+ a[a.length] = c;
+ e.className = a.join(' ');
+ },
+
+ removeCSSClass : function(e, c) {
+ var a = this.explode(' ', e.className), i;
+
+ for (i=0; i<a.length; i++) {
+ if (a[i] == c)
+ a[i] = '';
+ }
+
+ e.className = a.join(' ');
+ },
+
+ explode : function(d, s) {
+ var ar = s.split(d);
+ var oar = new Array();
+
+ for (var i = 0; i<ar.length; i++) {
+ if (ar[i] != "")
+ oar[oar.length] = ar[i];
+ }
+
+ return oar;
+ },
+
+ parseInt : function(s) {
+ if (s == null || s == '')
+ return 0;
+
+ return parseInt(s);
+ }
+} \ No newline at end of file
diff --git a/program/js/tiny_mce/utils/mctabs.js b/program/js/tiny_mce/utils/mctabs.js
new file mode 100644
index 000000000..c159360c0
--- /dev/null
+++ b/program/js/tiny_mce/utils/mctabs.js
@@ -0,0 +1,76 @@
+/**
+ * $RCSfile: mctabs.js,v $
+ * $Revision: 1.2 $
+ * $Date: 2006/02/06 20:11:09 $
+ *
+ * Moxiecode DHTML Tabs script.
+ *
+ * @author Moxiecode
+ * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
+ */
+
+function MCTabs() {
+ this.settings = new Array();
+};
+
+MCTabs.prototype.init = function(settings) {
+ this.settings = settings;
+};
+
+MCTabs.prototype.getParam = function(name, default_value) {
+ var value = null;
+
+ value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];
+
+ // Fix bool values
+ if (value == "true" || value == "false")
+ return (value == "true");
+
+ return value;
+};
+
+MCTabs.prototype.displayTab = function(tab_id, panel_id) {
+ var panelElm = document.getElementById(panel_id);
+ var panelContainerElm = panelElm ? panelElm.parentNode : null;
+ var tabElm = document.getElementById(tab_id);
+ var tabContainerElm = tabElm ? tabElm.parentNode : null;
+ var selectionClass = this.getParam('selection_class', 'current');
+
+ if (tabElm && tabContainerElm) {
+ var nodes = tabContainerElm.childNodes;
+
+ // Hide all other tabs
+ for (var i=0; i<nodes.length; i++) {
+ if (nodes[i].nodeName == "LI")
+ nodes[i].className = '';
+ }
+
+ // Show selected tab
+ tabElm.className = 'current';
+ }
+
+ if (panelElm && panelContainerElm) {
+ var nodes = panelContainerElm.childNodes;
+
+ // Hide all other panels
+ for (var i=0; i<nodes.length; i++) {
+ if (nodes[i].nodeName == "DIV")
+ nodes[i].className = 'panel';
+ }
+
+ // Show selected panel
+ panelElm.className = 'current';
+ }
+};
+
+MCTabs.prototype.getAnchor = function() {
+ var pos, url = document.location.href;
+
+ if ((pos = url.lastIndexOf('#')) != -1)
+ return url.substring(pos + 1);
+
+ return "";
+};
+
+// Global instance
+var mcTabs = new MCTabs();
diff --git a/program/js/tiny_mce/utils/validate.js b/program/js/tiny_mce/utils/validate.js
new file mode 100644
index 000000000..747b62bb6
--- /dev/null
+++ b/program/js/tiny_mce/utils/validate.js
@@ -0,0 +1,50 @@
+/**
+ * $RCSfile: validate.js,v $
+ * $Revision: 1.3 $
+ * $Date: 2006/02/06 20:11:09 $
+ *
+ * Various form validation methods.
+ *
+ * @author Moxiecode
+ * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
+ */
+
+function testRegExp(form_name, element_name, re) {
+ return new RegExp(re).test(document.forms[form_name].elements[element_name].value);
+}
+
+function validateString(form_name, element_name) {
+ return (document.forms[form_name].elements[element_name].value.length > 0);
+}
+
+function validateSelection(form_name, element_name) {
+ return (document.forms[form_name].elements[element_name].selectedIndex > 0);
+}
+
+function validateCheckBox(form_name, element_name) {
+ return document.forms[form_name].elements[element_name].checked;
+}
+
+function validateCleanString(form_name, element_name) {
+ return testRegExp(form_name, element_name, '^[A-Za-z0-9_]+$');
+}
+
+function validateEmail(form_name, element_name) {
+ return testRegExp(form_name, element_name, '^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$');
+}
+
+function validateAbsUrl(form_name, element_name) {
+ return testRegExp(form_name, element_name, '^(news|telnet|nttp|file|http|ftp|https)://[-A-Za-z0-9\\.]+$');
+}
+
+function validateNumber(form_name, element_name, allow_blank) {
+ return (!allow_blank && value == '') ? false : testRegExp(form_name, element_name, '^-?[0-9]*\\.?[0-9]*$');
+}
+
+function validateSize(form_name, element_name,) {
+ return testRegExp(form_name, element_name, '^[0-9]+(px|%)?$');
+}
+
+function validateID(form_name, element_name,) {
+ return testRegExp(form_name, element_name, '^[A-Za-z_]([A-Za-z0-9_])*$');
+}