bgneal@312: tinyMCEPopup.requireLangPack(); bgneal@312: bgneal@312: var ed; bgneal@312: bgneal@312: function init() { bgneal@312: ed = tinyMCEPopup.editor; bgneal@312: tinyMCEPopup.resizeToInnerSize(); bgneal@312: bgneal@312: document.getElementById('backgroundimagebrowsercontainer').innerHTML = getBrowserHTML('backgroundimagebrowser','backgroundimage','image','table'); bgneal@312: document.getElementById('bordercolor_pickcontainer').innerHTML = getColorPickerHTML('bordercolor_pick','bordercolor'); bgneal@312: document.getElementById('bgcolor_pickcontainer').innerHTML = getColorPickerHTML('bgcolor_pick','bgcolor') bgneal@312: bgneal@312: var inst = ed; bgneal@312: var tdElm = ed.dom.getParent(ed.selection.getStart(), "td,th"); bgneal@312: var formObj = document.forms[0]; bgneal@312: var st = ed.dom.parseStyle(ed.dom.getAttrib(tdElm, "style")); bgneal@312: bgneal@312: // Get table cell data bgneal@312: var celltype = tdElm.nodeName.toLowerCase(); bgneal@312: var align = ed.dom.getAttrib(tdElm, 'align'); bgneal@312: var valign = ed.dom.getAttrib(tdElm, 'valign'); bgneal@312: var width = trimSize(getStyle(tdElm, 'width', 'width')); bgneal@312: var height = trimSize(getStyle(tdElm, 'height', 'height')); bgneal@312: var bordercolor = convertRGBToHex(getStyle(tdElm, 'bordercolor', 'borderLeftColor')); bgneal@312: var bgcolor = convertRGBToHex(getStyle(tdElm, 'bgcolor', 'backgroundColor')); bgneal@312: var className = ed.dom.getAttrib(tdElm, 'class'); bgneal@312: var backgroundimage = getStyle(tdElm, 'background', 'backgroundImage').replace(new RegExp("url\\(['\"]?([^'\"]*)['\"]?\\)", 'gi'), "$1"); bgneal@312: var id = ed.dom.getAttrib(tdElm, 'id'); bgneal@312: var lang = ed.dom.getAttrib(tdElm, 'lang'); bgneal@312: var dir = ed.dom.getAttrib(tdElm, 'dir'); bgneal@312: var scope = ed.dom.getAttrib(tdElm, 'scope'); bgneal@312: bgneal@312: // Setup form bgneal@312: addClassesToList('class', 'table_cell_styles'); bgneal@312: TinyMCE_EditableSelects.init(); bgneal@312: bgneal@312: if (!ed.dom.hasClass(tdElm, 'mceSelected')) { bgneal@312: formObj.bordercolor.value = bordercolor; bgneal@312: formObj.bgcolor.value = bgcolor; bgneal@312: formObj.backgroundimage.value = backgroundimage; bgneal@312: formObj.width.value = width; bgneal@312: formObj.height.value = height; bgneal@312: formObj.id.value = id; bgneal@312: formObj.lang.value = lang; bgneal@312: formObj.style.value = ed.dom.serializeStyle(st); bgneal@312: selectByValue(formObj, 'align', align); bgneal@312: selectByValue(formObj, 'valign', valign); bgneal@312: selectByValue(formObj, 'class', className, true, true); bgneal@312: selectByValue(formObj, 'celltype', celltype); bgneal@312: selectByValue(formObj, 'dir', dir); bgneal@312: selectByValue(formObj, 'scope', scope); bgneal@312: bgneal@312: // Resize some elements bgneal@312: if (isVisible('backgroundimagebrowser')) bgneal@312: document.getElementById('backgroundimage').style.width = '180px'; bgneal@312: bgneal@312: updateColor('bordercolor_pick', 'bordercolor'); bgneal@312: updateColor('bgcolor_pick', 'bgcolor'); bgneal@312: } else bgneal@312: tinyMCEPopup.dom.hide('action'); bgneal@312: } bgneal@312: bgneal@312: function updateAction() { bgneal@312: var el, inst = ed, tdElm, trElm, tableElm, formObj = document.forms[0]; bgneal@312: bgneal@312: tinyMCEPopup.restoreSelection(); bgneal@312: el = ed.selection.getStart(); bgneal@312: tdElm = ed.dom.getParent(el, "td,th"); bgneal@312: trElm = ed.dom.getParent(el, "tr"); bgneal@312: tableElm = ed.dom.getParent(el, "table"); bgneal@312: bgneal@312: // Cell is selected bgneal@312: if (ed.dom.hasClass(tdElm, 'mceSelected')) { bgneal@312: // Update all selected sells bgneal@312: tinymce.each(ed.dom.select('td.mceSelected,th.mceSelected'), function(td) { bgneal@312: updateCell(td); bgneal@312: }); bgneal@312: bgneal@312: ed.addVisual(); bgneal@312: ed.nodeChanged(); bgneal@312: inst.execCommand('mceEndUndoLevel'); bgneal@312: tinyMCEPopup.close(); bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: switch (getSelectValue(formObj, 'action')) { bgneal@312: case "cell": bgneal@312: var celltype = getSelectValue(formObj, 'celltype'); bgneal@312: var scope = getSelectValue(formObj, 'scope'); bgneal@312: bgneal@312: function doUpdate(s) { bgneal@312: if (s) { bgneal@312: updateCell(tdElm); bgneal@312: bgneal@312: ed.addVisual(); bgneal@312: ed.nodeChanged(); bgneal@312: inst.execCommand('mceEndUndoLevel'); bgneal@312: tinyMCEPopup.close(); bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: if (ed.getParam("accessibility_warnings", 1)) { bgneal@312: if (celltype == "th" && scope == "") bgneal@312: tinyMCEPopup.confirm(ed.getLang('table_dlg.missing_scope', '', true), doUpdate); bgneal@312: else bgneal@312: doUpdate(1); bgneal@312: bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: updateCell(tdElm); bgneal@312: break; bgneal@312: bgneal@312: case "row": bgneal@312: var cell = trElm.firstChild; bgneal@312: bgneal@312: if (cell.nodeName != "TD" && cell.nodeName != "TH") bgneal@312: cell = nextCell(cell); bgneal@312: bgneal@312: do { bgneal@312: cell = updateCell(cell, true); bgneal@312: } while ((cell = nextCell(cell)) != null); bgneal@312: bgneal@312: break; bgneal@312: bgneal@312: case "all": bgneal@312: var rows = tableElm.getElementsByTagName("tr"); bgneal@312: bgneal@312: for (var i=0; i<rows.length; i++) { bgneal@312: var cell = rows[i].firstChild; bgneal@312: bgneal@312: if (cell.nodeName != "TD" && cell.nodeName != "TH") bgneal@312: cell = nextCell(cell); bgneal@312: bgneal@312: do { bgneal@312: cell = updateCell(cell, true); bgneal@312: } while ((cell = nextCell(cell)) != null); bgneal@312: } bgneal@312: bgneal@312: break; bgneal@312: } bgneal@312: bgneal@312: ed.addVisual(); bgneal@312: ed.nodeChanged(); bgneal@312: inst.execCommand('mceEndUndoLevel'); bgneal@312: tinyMCEPopup.close(); bgneal@312: } bgneal@312: bgneal@312: function nextCell(elm) { bgneal@312: while ((elm = elm.nextSibling) != null) { bgneal@312: if (elm.nodeName == "TD" || elm.nodeName == "TH") bgneal@312: return elm; bgneal@312: } bgneal@312: bgneal@312: return null; bgneal@312: } bgneal@312: bgneal@312: function updateCell(td, skip_id) { bgneal@312: var inst = ed; bgneal@312: var formObj = document.forms[0]; bgneal@312: var curCellType = td.nodeName.toLowerCase(); bgneal@312: var celltype = getSelectValue(formObj, 'celltype'); bgneal@312: var doc = inst.getDoc(); bgneal@312: var dom = ed.dom; bgneal@312: bgneal@312: if (!skip_id) bgneal@442: dom.setAttrib(td, 'id', formObj.id.value); bgneal@312: bgneal@442: dom.setAttrib(td, 'align', formObj.align.value); bgneal@442: dom.setAttrib(td, 'vAlign', formObj.valign.value); bgneal@442: dom.setAttrib(td, 'lang', formObj.lang.value); bgneal@442: dom.setAttrib(td, 'dir', getSelectValue(formObj, 'dir')); bgneal@442: dom.setAttrib(td, 'style', ed.dom.serializeStyle(ed.dom.parseStyle(formObj.style.value))); bgneal@442: dom.setAttrib(td, 'scope', formObj.scope.value); bgneal@442: dom.setAttrib(td, 'class', getSelectValue(formObj, 'class')); bgneal@312: bgneal@312: // Clear deprecated attributes bgneal@312: ed.dom.setAttrib(td, 'width', ''); bgneal@312: ed.dom.setAttrib(td, 'height', ''); bgneal@312: ed.dom.setAttrib(td, 'bgColor', ''); bgneal@312: ed.dom.setAttrib(td, 'borderColor', ''); bgneal@312: ed.dom.setAttrib(td, 'background', ''); bgneal@312: bgneal@312: // Set styles bgneal@312: td.style.width = getCSSSize(formObj.width.value); bgneal@312: td.style.height = getCSSSize(formObj.height.value); bgneal@312: if (formObj.bordercolor.value != "") { bgneal@312: td.style.borderColor = formObj.bordercolor.value; bgneal@312: td.style.borderStyle = td.style.borderStyle == "" ? "solid" : td.style.borderStyle; bgneal@312: td.style.borderWidth = td.style.borderWidth == "" ? "1px" : td.style.borderWidth; bgneal@312: } else bgneal@312: td.style.borderColor = ''; bgneal@312: bgneal@312: td.style.backgroundColor = formObj.bgcolor.value; bgneal@312: bgneal@312: if (formObj.backgroundimage.value != "") bgneal@312: td.style.backgroundImage = "url('" + formObj.backgroundimage.value + "')"; bgneal@312: else bgneal@312: td.style.backgroundImage = ''; bgneal@312: bgneal@312: if (curCellType != celltype) { bgneal@312: // changing to a different node type bgneal@312: var newCell = doc.createElement(celltype); bgneal@312: bgneal@312: for (var c=0; c<td.childNodes.length; c++) bgneal@312: newCell.appendChild(td.childNodes[c].cloneNode(1)); bgneal@312: bgneal@312: for (var a=0; a<td.attributes.length; a++) bgneal@312: ed.dom.setAttrib(newCell, td.attributes[a].name, ed.dom.getAttrib(td, td.attributes[a].name)); bgneal@312: bgneal@312: td.parentNode.replaceChild(newCell, td); bgneal@312: td = newCell; bgneal@312: } bgneal@312: bgneal@312: dom.setAttrib(td, 'style', dom.serializeStyle(dom.parseStyle(td.style.cssText))); bgneal@312: bgneal@312: return td; bgneal@312: } bgneal@312: bgneal@312: function changedBackgroundImage() { bgneal@312: var formObj = document.forms[0]; bgneal@312: var st = ed.dom.parseStyle(formObj.style.value); bgneal@312: bgneal@312: st['background-image'] = "url('" + formObj.backgroundimage.value + "')"; bgneal@312: bgneal@312: formObj.style.value = ed.dom.serializeStyle(st); bgneal@312: } bgneal@312: bgneal@312: function changedSize() { bgneal@312: var formObj = document.forms[0]; bgneal@312: var st = ed.dom.parseStyle(formObj.style.value); bgneal@312: bgneal@312: var width = formObj.width.value; bgneal@312: if (width != "") bgneal@312: st['width'] = getCSSSize(width); bgneal@312: else bgneal@312: st['width'] = ""; bgneal@312: bgneal@312: var height = formObj.height.value; bgneal@312: if (height != "") bgneal@312: st['height'] = getCSSSize(height); bgneal@312: else bgneal@312: st['height'] = ""; bgneal@312: bgneal@312: formObj.style.value = ed.dom.serializeStyle(st); bgneal@312: } bgneal@312: bgneal@312: function changedColor() { bgneal@312: var formObj = document.forms[0]; bgneal@312: var st = ed.dom.parseStyle(formObj.style.value); bgneal@312: bgneal@312: st['background-color'] = formObj.bgcolor.value; bgneal@312: st['border-color'] = formObj.bordercolor.value; bgneal@312: bgneal@312: formObj.style.value = ed.dom.serializeStyle(st); bgneal@312: } bgneal@312: bgneal@312: function changedStyle() { bgneal@312: var formObj = document.forms[0]; bgneal@312: var st = ed.dom.parseStyle(formObj.style.value); bgneal@312: bgneal@312: if (st['background-image']) bgneal@312: formObj.backgroundimage.value = st['background-image'].replace(new RegExp("url\\('?([^']*)'?\\)", 'gi'), "$1"); bgneal@312: else bgneal@312: formObj.backgroundimage.value = ''; bgneal@312: bgneal@312: if (st['width']) bgneal@312: formObj.width.value = trimSize(st['width']); bgneal@312: bgneal@312: if (st['height']) bgneal@312: formObj.height.value = trimSize(st['height']); bgneal@312: bgneal@312: if (st['background-color']) { bgneal@312: formObj.bgcolor.value = st['background-color']; bgneal@312: updateColor('bgcolor_pick','bgcolor'); bgneal@312: } bgneal@312: bgneal@312: if (st['border-color']) { bgneal@312: formObj.bordercolor.value = st['border-color']; bgneal@312: updateColor('bordercolor_pick','bordercolor'); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: tinyMCEPopup.onInit.add(init);