bgneal@312: /** bgneal@312: * element_common.js bgneal@312: * bgneal@312: * Copyright 2009, Moxiecode Systems AB bgneal@312: * Released under LGPL License. bgneal@312: * bgneal@312: * License: http://tinymce.moxiecode.com/license bgneal@312: * Contributing: http://tinymce.moxiecode.com/contributing bgneal@312: */ bgneal@312: bgneal@312: tinyMCEPopup.requireLangPack(); bgneal@312: bgneal@312: function initCommonAttributes(elm) { bgneal@312: var formObj = document.forms[0], dom = tinyMCEPopup.editor.dom; bgneal@312: bgneal@312: // Setup form data for common element attributes bgneal@312: setFormValue('title', dom.getAttrib(elm, 'title')); bgneal@312: setFormValue('id', dom.getAttrib(elm, 'id')); bgneal@312: selectByValue(formObj, 'class', dom.getAttrib(elm, 'class'), true); bgneal@312: setFormValue('style', dom.getAttrib(elm, 'style')); bgneal@312: selectByValue(formObj, 'dir', dom.getAttrib(elm, 'dir')); bgneal@312: setFormValue('lang', dom.getAttrib(elm, 'lang')); bgneal@312: setFormValue('onfocus', dom.getAttrib(elm, 'onfocus')); bgneal@312: setFormValue('onblur', dom.getAttrib(elm, 'onblur')); bgneal@312: setFormValue('onclick', dom.getAttrib(elm, 'onclick')); bgneal@312: setFormValue('ondblclick', dom.getAttrib(elm, 'ondblclick')); bgneal@312: setFormValue('onmousedown', dom.getAttrib(elm, 'onmousedown')); bgneal@312: setFormValue('onmouseup', dom.getAttrib(elm, 'onmouseup')); bgneal@312: setFormValue('onmouseover', dom.getAttrib(elm, 'onmouseover')); bgneal@312: setFormValue('onmousemove', dom.getAttrib(elm, 'onmousemove')); bgneal@312: setFormValue('onmouseout', dom.getAttrib(elm, 'onmouseout')); bgneal@312: setFormValue('onkeypress', dom.getAttrib(elm, 'onkeypress')); bgneal@312: setFormValue('onkeydown', dom.getAttrib(elm, 'onkeydown')); bgneal@312: setFormValue('onkeyup', dom.getAttrib(elm, 'onkeyup')); bgneal@312: } bgneal@312: bgneal@312: function setFormValue(name, value) { bgneal@312: if(document.forms[0].elements[name]) document.forms[0].elements[name].value = value; bgneal@312: } bgneal@312: bgneal@312: function insertDateTime(id) { bgneal@312: document.getElementById(id).value = getDateTime(new Date(), "%Y-%m-%dT%H:%M:%S"); bgneal@312: } bgneal@312: bgneal@312: function getDateTime(d, fmt) { bgneal@312: fmt = fmt.replace("%D", "%m/%d/%y"); bgneal@312: fmt = fmt.replace("%r", "%I:%M:%S %p"); bgneal@312: fmt = fmt.replace("%Y", "" + d.getFullYear()); bgneal@312: fmt = fmt.replace("%y", "" + d.getYear()); bgneal@312: fmt = fmt.replace("%m", addZeros(d.getMonth()+1, 2)); bgneal@312: fmt = fmt.replace("%d", addZeros(d.getDate(), 2)); bgneal@312: fmt = fmt.replace("%H", "" + addZeros(d.getHours(), 2)); bgneal@312: fmt = fmt.replace("%M", "" + addZeros(d.getMinutes(), 2)); bgneal@312: fmt = fmt.replace("%S", "" + addZeros(d.getSeconds(), 2)); bgneal@312: fmt = fmt.replace("%I", "" + ((d.getHours() + 11) % 12 + 1)); bgneal@312: fmt = fmt.replace("%p", "" + (d.getHours() < 12 ? "AM" : "PM")); bgneal@312: fmt = fmt.replace("%%", "%"); bgneal@312: bgneal@312: return fmt; bgneal@312: } bgneal@312: bgneal@312: function addZeros(value, len) { bgneal@312: var i; bgneal@312: bgneal@312: value = "" + value; bgneal@312: bgneal@312: if (value.length < len) { bgneal@312: for (i=0; i<(len-value.length); i++) bgneal@312: value = "0" + value; bgneal@312: } bgneal@312: bgneal@312: return value; bgneal@312: } bgneal@312: bgneal@312: function selectByValue(form_obj, field_name, value, add_custom, ignore_case) { bgneal@312: if (!form_obj || !form_obj.elements[field_name]) bgneal@312: return; bgneal@312: bgneal@312: var sel = form_obj.elements[field_name]; bgneal@312: bgneal@312: var found = false; bgneal@312: for (var i=0; i 0) { bgneal@312: tagName = element_name; bgneal@312: bgneal@312: insertInlineElement(element_name); bgneal@312: var elementArray = tinymce.grep(SXE.inst.dom.select(element_name)); bgneal@312: for (var i=0; i -1) ? true : false; bgneal@312: } bgneal@312: bgneal@312: SXE.removeClass = function(elm,cl) { bgneal@312: if(elm.className == null || elm.className == "" || !SXE.containsClass(elm,cl)) { bgneal@312: return true; bgneal@312: } bgneal@312: var classNames = elm.className.split(" "); bgneal@312: var newClassNames = ""; bgneal@312: for (var x = 0, cnl = classNames.length; x < cnl; x++) { bgneal@312: if (classNames[x] != cl) { bgneal@312: newClassNames += (classNames[x] + " "); bgneal@312: } bgneal@312: } bgneal@312: elm.className = newClassNames.substring(0,newClassNames.length-1); //removes extra space at the end bgneal@312: } bgneal@312: bgneal@312: SXE.addClass = function(elm,cl) { bgneal@312: if(!SXE.containsClass(elm,cl)) elm.className ? elm.className += " " + cl : elm.className = cl; bgneal@312: return true; bgneal@312: } bgneal@312: bgneal@312: function insertInlineElement(en) { bgneal@312: var ed = tinyMCEPopup.editor, dom = ed.dom; bgneal@312: bgneal@312: ed.getDoc().execCommand('FontName', false, 'mceinline'); bgneal@312: tinymce.each(dom.select('span,font'), function(n) { bgneal@312: if (n.style.fontFamily == 'mceinline' || n.face == 'mceinline') bgneal@442: dom.replace(dom.create(en, {'data-mce-new' : 1}), n, 1); bgneal@312: }); bgneal@312: }