File "table.js"

Full Path: /home/asmplong/www/ancien-site-2019/site/components/com_jce/editor/tiny_mce/plugins/table/js/table.js
File size: 18.97 KB
MIME-type: text/plain
Charset: utf-8

tinyMCEPopup.requireLangPack();var TableDialog={settings:{},init:function(){tinyMCEPopup.resizeToInnerSize();if(!this.settings.file_browser){$('input.browser').removeClass('browser')}$.Plugin.init();if(this.settings.context=='merge'){return this.initMerge()}addClassesToList('class',"table_styles");switch(this.settings.context){case'table':this.initTable();break;case'cell':this.initCell();break;case'row':this.initRow();break}$('body').addClass(this.settings.context)},insert:function(){switch(this.settings.context){case'table':this.insertTable();break;case'cell':this.updateCells();break;case'row':this.updateRows();break;case'merge':this.merge();break}},initMerge:function(){$('#numcols').val(tinyMCEPopup.getWindowArg('cols',1));$('#numrows').val(tinyMCEPopup.getWindowArg('rows',1));$('#insert').button('option','label',tinyMCEPopup.getLang('update','Update',true))},initTable:function(){var ed=tinyMCEPopup.editor,dom=tinyMCEPopup.dom;var cols=tinyMCEPopup.getParam('table_default_cols',2),rows=tinyMCEPopup.getParam('table_default_rows',2);var border=tinyMCEPopup.getParam('table_default_border','0'),cellpadding=tinyMCEPopup.getParam('table_default_cellpadding',''),cellspacing=tinyMCEPopup.getParam('table_default_cellspacing','');var align="",width=tinyMCEPopup.getParam('table_default_width'),height=tinyMCEPopup.getParam('table_default_height'),bordercolor="",bgcolor="",className="";var id="",summary="",style="",dir="",lang="",background="",bgcolor="",bordercolor="",rules="",frame="";var elm=dom.getParent(ed.selection.getNode(),"table");action=tinyMCEPopup.getWindowArg('action');if(!action){action=elm?"update":"insert"}if(elm&&action!="insert"){var rowsAr=elm.rows;var cols=0;for(var i=0;i<rowsAr.length;i++){if(rowsAr[i].cells.length>cols){cols=rowsAr[i].cells.length}}cols=cols;rows=rowsAr.length;st=dom.parseStyle(dom.getAttrib(elm,"style"));border=trimSize(getStyle(elm,'border','borderWidth'));cellpadding=dom.getAttrib(elm,'cellpadding',"");cellspacing=dom.getAttrib(elm,'cellspacing',"");width=trimSize(getStyle(elm,'width','width'));height=trimSize(getStyle(elm,'height','height'));bordercolor=convertRGBToHex(getStyle(elm,'bordercolor','borderLeftColor'));bgcolor=convertRGBToHex(getStyle(elm,'bgcolor','backgroundColor'));align=dom.getAttrib(elm,'align',align);frame=dom.getAttrib(elm,'frame');rules=dom.getAttrib(elm,'rules');className=tinymce.trim(dom.getAttrib(elm,'class').replace(/mceItem.+/g,''));id=dom.getAttrib(elm,'id');summary=dom.getAttrib(elm,'summary');style=dom.serializeStyle(st);dir=dom.getAttrib(elm,'dir');lang=dom.getAttrib(elm,'lang');background=getStyle(elm,'background','backgroundImage').replace(new RegExp("url\\(['\"]?([^'\"]*)['\"]?\\)",'gi'),"$1");$('#caption').prop('checked',elm.getElementsByTagName('caption').length>0);this.orgTableWidth=width;this.orgTableHeight=height;$('#insert').button('option','label',tinyMCEPopup.getLang('update','Update',true))}$('#align').val(align);$('#tframe').val(frame);$('#rules').val(rules);$('#class').val(function(){if($('option[value="'+className+'"]',this).length==0){$(this).append(new Option(className,className))}return className});$('#cols').val(cols);$('#rows').val(rows);$('#border').val(border);$('#cellpadding').val(cellpadding);$('#cellspacing').val(cellspacing);$('#width').val(width);$('#height').val(height);$('#bordercolor').val(bordercolor).change();$('#bgcolor').val(bgcolor).change();$('#id').val(id);$('#summary').val(summary);$('#style').val(style);$('#dir').val(dir);$('#lang').val(lang);$('#backgroundimage').val(background);if($('#backgroundimagebrowser').is(':visible')){$('#backgroundimage').width(180)}if(action=="update"){$('#cols, #rows').prop('disabled',true)}},initRow:function(){var ed=tinyMCEPopup.editor,dom=tinyMCEPopup.dom;var trElm=dom.getParent(ed.selection.getStart(),"tr");var st=dom.parseStyle(dom.getAttrib(trElm,"style"));var rowtype=trElm.parentNode.nodeName.toLowerCase();var align=dom.getAttrib(trElm,'align');var valign=dom.getAttrib(trElm,'valign');var height=trimSize(getStyle(trElm,'height','height'));var className=dom.getAttrib(trElm,'class');var bgcolor=convertRGBToHex(getStyle(trElm,'bgcolor','backgroundColor'));var backgroundimage=getStyle(trElm,'background','backgroundImage').replace(new RegExp("url\\(['\"]?([^'\"]*)['\"]?\\)",'gi'),"$1");var id=dom.getAttrib(trElm,'id');var lang=dom.getAttrib(trElm,'lang');var dir=dom.getAttrib(trElm,'dir');$('#rowtype').val(rowtype);if(dom.select('td.mceSelected,th.mceSelected',trElm).length==0){$('#bgcolor').val(bgcolor).change();$('#backgroundimage').val(backgroundimage);$('#height').val(height);$('#id').val(id);$('#lang').val(lang);$('#style').val(dom.serializeStyle(st));$('#align').val(align);$('#valign').val(valign);$('#class').val(function(){if($('option[value="'+className+'"]',this).length==0){$(this).append(new Option(className,className))}return className});$('#dir').val(dir);if($('#backgroundimagebrowser').is(':visible')){$('#backgroundimage').width(180)}$('#insert').button('option','label',tinyMCEPopup.getLang('update','Update',true))}else{$('#action').hide()}},initCell:function(){var ed=tinyMCEPopup.editor,dom=ed.dom;var tdElm=dom.getParent(ed.selection.getStart(),"td,th");var st=dom.parseStyle(dom.getAttrib(tdElm,"style"));var celltype=tdElm.nodeName.toLowerCase();var align=dom.getAttrib(tdElm,'align');var valign=dom.getAttrib(tdElm,'valign');var width=trimSize(getStyle(tdElm,'width','width'));var height=trimSize(getStyle(tdElm,'height','height'));var bordercolor=convertRGBToHex(getStyle(tdElm,'bordercolor','borderLeftColor'));var bgcolor=convertRGBToHex(getStyle(tdElm,'bgcolor','backgroundColor'));var className=dom.getAttrib(tdElm,'class');var backgroundimage=getStyle(tdElm,'background','backgroundImage').replace(new RegExp("url\\(['\"]?([^'\"]*)['\"]?\\)",'gi'),"$1");var id=dom.getAttrib(tdElm,'id');var lang=dom.getAttrib(tdElm,'lang');var dir=dom.getAttrib(tdElm,'dir');var scope=dom.getAttrib(tdElm,'scope');if(!dom.hasClass(tdElm,'mceSelected')){$('#bordercolor').val(bordercolor);$('#bgcolor').val(bgcolor);$('#backgroundimage').val(backgroundimage);$('#width').val(width);$('#height').val(height);$('#id').val(id);$('#lang').val(lang);$('#style').val(dom.serializeStyle(st));$('#align').val(align);$('#valign').val(valign);$('#class').val(function(){if($('option[value="'+className+'"]',this).length==0){$(this).append(new Option(className,className))}return className});$('#dir').val(dir);$('#celltype').val(celltype);$('#scope').val(scope);if($('#backgroundimagebrowser').is(':visible')){$('#backgroundimage').width(180)}$('#insert').button('option','label',tinyMCEPopup.getLang('update','Update',true))}else{$('#action').hide()}},merge:function(){var func;tinyMCEPopup.restoreSelection();func=tinyMCEPopup.getWindowArg('onaction');func({cols:$('#numcols').val(),rows:$('#numrows').val()});tinyMCEPopup.close()},insertTable:function(){var ed=tinyMCEPopup.editor,dom=ed.dom;var cols=2,rows=2,border=0,cellpadding=-1,cellspacing=-1,align,width,height,className,caption,frame,rules;var html='',capEl,elm;var cellLimit,rowLimit,colLimit;tinyMCEPopup.restoreSelection();if(!AutoValidator.validate($('form').get(0))){tinyMCEPopup.alert(ed.getLang('invalid_data'));return false}elm=dom.getParent(ed.selection.getNode(),'table');cols=$('#cols').val();rows=$('#rows').val();border=$('#border').val()!=""?$('#border').val():0;cellpadding=$('#cellpadding').val()!=""?$('#cellpadding').val():"";cellspacing=$('#cellspacing').val()!=""?$('#cellspacing').val():"";align=$("#align").val();frame=$("#tframe").val();rules=$("#rules").val();width=$('#width').val();height=$('#height').val();bordercolor=$('#bordercolor').val();bgcolor=$('#bgcolor').val();className=$("#class").val();id=$('#id').val();summary=$('#summary').val();style=$('#style').val();dir=$('#dir').val();lang=$('#lang').val();background=$('#backgroundimage').val();caption=$('#caption').is(':checked');cellLimit=tinyMCEPopup.getParam('table_cell_limit',false);rowLimit=tinyMCEPopup.getParam('table_row_limit',false);colLimit=tinyMCEPopup.getParam('table_col_limit',false);if(colLimit&&cols>colLimit){tinyMCEPopup.alert(ed.getLang('table_dlg.col_limit').replace(/\{\$cols\}/g,colLimit));return false}else if(rowLimit&&rows>rowLimit){tinyMCEPopup.alert(ed.getLang('table_dlg.row_limit').replace(/\{\$rows\}/g,rowLimit));return false}else if(cellLimit&&cols*rows>cellLimit){tinyMCEPopup.alert(ed.getLang('table_dlg.cell_limit').replace(/\{\$cells\}/g,cellLimit));return false}if(action=="update"){ed.execCommand('mceBeginUndoLevel');dom.setAttrib(elm,'cellPadding',cellpadding,true);dom.setAttrib(elm,'cellSpacing',cellspacing,true);dom.setAttrib(elm,'border',border);dom.setAttrib(elm,'align',align);dom.setAttrib(elm,'frame',frame);dom.setAttrib(elm,'rules',rules);dom.setAttrib(elm,'class',className);dom.setAttrib(elm,'style',style);dom.setAttrib(elm,'id',id);dom.setAttrib(elm,'summary',summary);dom.setAttrib(elm,'dir',dir);dom.setAttrib(elm,'lang',lang);capEl=ed.dom.select('caption',elm)[0];if(capEl&&!caption){capEl.parentNode.removeChild(capEl)}if(!capEl&&caption){capEl=elm.ownerDocument.createElement('caption');if(!tinymce.isIE){capEl.innerHTML='<br _mce_bogus="1"/>'}elm.insertBefore(capEl,elm.firstChild)}if(width&&ed.settings.inline_styles){dom.setStyle(elm,'width',width);dom.setAttrib(elm,'width','')}else{dom.setAttrib(elm,'width',width,true);dom.setStyle(elm,'width','')}dom.setAttrib(elm,'borderColor','');dom.setAttrib(elm,'bgColor','');dom.setAttrib(elm,'background','');if(height&&ed.settings.inline_styles){dom.setStyle(elm,'height',height);dom.setAttrib(elm,'height','')}else{dom.setAttrib(elm,'height',height,true);dom.setStyle(elm,'height','')}if(background!=''){elm.style.backgroundImage="url('"+background+"')"}else{elm.style.backgroundImage=''}if(bordercolor!=""){elm.style.borderColor=bordercolor;elm.style.borderStyle=elm.style.borderStyle==""?"solid":elm.style.borderStyle;elm.style.borderWidth=border==""?"1px":border}else{elm.style.borderColor=''}elm.style.backgroundColor=bgcolor;elm.style.height=getCSSSize(height);ed.addVisual();ed.nodeChanged();ed.execCommand('mceEndUndoLevel');if($('#width').val()!=this.orgTableWidth||$('#height').val()!=this.orgTableHeight){ed.execCommand('mceRepaint')}tinyMCEPopup.close();return true}html+='<table';html+=this.makeAttrib('id',id);html+=this.makeAttrib('border',border);html+=this.makeAttrib('cellpadding',cellpadding);html+=this.makeAttrib('cellspacing',cellspacing);html+=this.makeAttrib('_mce_new','1');if(width&&ed.settings.inline_styles){if(style){style+='; '}if(/^[0-9\.]+$/.test(width)){width+='px'}style+='width: '+width}else{html+=this.makeAttrib('width',width)}html+=this.makeAttrib('align',align);html+=this.makeAttrib('frame',frame);html+=this.makeAttrib('rules',rules);html+=this.makeAttrib('class',className);html+=this.makeAttrib('style',style);html+=this.makeAttrib('summary',summary);html+=this.makeAttrib('dir',dir);html+=this.makeAttrib('lang',lang);html+='>';if(caption){if(!tinymce.isIE){html+='<caption><br _mce_bogus="1"/></caption>'}else{html+='<caption></caption>'}}for(var y=0;y<rows;y++){html+="<tr>";for(var x=0;x<cols;x++){if(!tinymce.isIE){html+='<td><br _mce_bogus="1"/></td>'}else{html+='<td></td>'}}html+="</tr>"}html+="</table>";ed.execCommand('mceBeginUndoLevel');if(ed.settings.fix_table_elements){var patt='';ed.focus();ed.selection.setContent('<br class="_mce_marker" />');tinymce.each('h1,h2,h3,h4,h5,h6,p'.split(','),function(n){if(patt){patt+=','}patt+=n+' ._mce_marker'});tinymce.each(ed.dom.select(patt),function(n){ed.dom.split(ed.dom.getParent(n,'h1,h2,h3,h4,h5,h6,p'),n)});dom.setOuterHTML(dom.select('br._mce_marker')[0],html)}else{ed.execCommand('mceInsertContent',false,html)}tinymce.each(dom.select('table[_mce_new]'),function(node){var td=dom.select('td',node);ed.selection.select(td[0],true);ed.selection.collapse();dom.setAttrib(node,'_mce_new','')});ed.addVisual();ed.execCommand('mceEndUndoLevel');tinyMCEPopup.close()},updateCells:function(){var self=this,el,ed=tinyMCEPopup.editor,inst=ed,tdElm,trElm,tableElm;tinyMCEPopup.restoreSelection();el=ed.selection.getStart();tdElm=ed.dom.getParent(el,"td,th");trElm=ed.dom.getParent(el,"tr");tableElm=ed.dom.getParent(el,"table");if(ed.dom.hasClass(tdElm,'mceSelected')){tinymce.each(ed.dom.select('td.mceSelected,th.mceSelected'),function(td){self.updateCell(td)});ed.addVisual();ed.nodeChanged();inst.execCommand('mceEndUndoLevel');tinyMCEPopup.close();return}ed.execCommand('mceBeginUndoLevel');switch($('#action').val()){case"cell":var celltype=$('#celltype').val();var scope=$('#scope').val();function doUpdate(s){if(s){self.updateCell(tdElm);ed.addVisual();ed.nodeChanged();inst.execCommand('mceEndUndoLevel');tinyMCEPopup.close()}};if(ed.getParam("accessibility_warnings",1)){if(celltype=="th"&&scope==""){tinyMCEPopup.confirm(ed.getLang('table_dlg.missing_scope','',true),doUpdate)}else{doUpdate(1)}return}this.updateCell(tdElm);break;case"row":var cell=trElm.firstChild;if(cell.nodeName!="TD"&&cell.nodeName!="TH"){cell=this.nextCell(cell)}do{cell=this.updateCell(cell,true)}while((cell=this.nextCell(cell))!=null);break;case"all":var rows=tableElm.getElementsByTagName("tr");for(var i=0;i<rows.length;i++){var cell=rows[i].firstChild;if(cell.nodeName!="TD"&&cell.nodeName!="TH"){cell=this.nextCell(cell)}do{cell=this.updateCell(cell,true)}while((cell=this.nextCell(cell))!=null)}break}ed.addVisual();ed.nodeChanged();inst.execCommand('mceEndUndoLevel');tinyMCEPopup.close()},updateRow:function(tr_elm,skip_id,skip_parent){var ed=tinyMCEPopup.editor,dom=ed.dom,doc=ed.getDoc();var curRowType=tr_elm.parentNode.nodeName.toLowerCase();var rowtype=$('#rowtype').val();$.each(['id','align','valign','lang','dir','class'],function(i,k){v=$('#'+k).val();if(k=='id'&&skip_id){return}if(k=='style'){v=dom.serializeStyle(dom.parseStyle(v))}dom.setAttrib(tr_elm,k,v)});$.each(['height','bgColor','background'],function(i,k){ed.dom.setAttrib(tr_elm,k,null)});tr_elm.style.height=getCSSSize($('#height').val());tr_elm.style.backgroundColor=$('#bgcolor').val();if($('#backgroundimage').val()!=""){tr_elm.style.backgroundImage="url('"+$('#backgroundimage').val()+"')"}else{tr_elm.style.backgroundImage=''}if(curRowType!=rowtype&&!skip_parent){var newRow=tr_elm.cloneNode(1);var theTable=dom.getParent(tr_elm,"table");var dest=rowtype;var newParent=null;for(var i=0;i<theTable.childNodes.length;i++){if(theTable.childNodes[i].nodeName.toLowerCase()==dest){newParent=theTable.childNodes[i]}}if(newParent==null){newParent=doc.createElement(dest);if(dest=="thead"){if(theTable.firstChild.nodeName=='CAPTION'){ed.dom.insertAfter(newParent,theTable.firstChild)}else{theTable.insertBefore(newParent,theTable.firstChild)}}else{theTable.appendChild(newParent)}}newParent.appendChild(newRow);tr_elm.parentNode.removeChild(tr_elm);tr_elm=newRow}dom.setAttrib(tr_elm,'style',dom.serializeStyle(dom.parseStyle(tr_elm.style.cssText)))},makeAttrib:function(attrib,value){if(typeof(value)=="undefined"||value==null){value=$('#'+attrib).val()}if(value==""){return""}value=value.replace(/&/g,'&amp;');value=value.replace(/\"/g,'&quot;');value=value.replace(/</g,'&lt;');value=value.replace(/>/g,'&gt;');return' '+attrib+'="'+value+'"'},updateRows:function(){var self=this,ed=tinyMCEPopup.editor,dom=ed.dom,trElm,tableElm;var action=$('#action').val();tinyMCEPopup.restoreSelection();trElm=dom.getParent(ed.selection.getStart(),"tr");tableElm=dom.getParent(ed.selection.getStart(),"table");if(dom.select('td.mceSelected,th.mceSelected',trElm).length>0){tinymce.each(tableElm.rows,function(tr){var i;for(i=0;i<tr.cells.length;i++){if(dom.hasClass(tr.cells[i],'mceSelected')){self.updateRow(tr,true);return}}});ed.addVisual();ed.nodeChanged();ed.execCommand('mceEndUndoLevel');tinyMCEPopup.close();return}ed.execCommand('mceBeginUndoLevel');switch(action){case"row":this.updateRow(trElm);break;case"all":var rows=tableElm.getElementsByTagName("tr");for(var i=0;i<rows.length;i++){this.updateRow(rows[i],true)}break;case"odd":case"even":var rows=tableElm.getElementsByTagName("tr");for(var i=0;i<rows.length;i++){if((i%2==0&&action=="odd")||(i%2!=0&&action=="even"))this.updateRow(rows[i],true,true)}break}ed.addVisual();ed.nodeChanged();ed.execCommand('mceEndUndoLevel');tinyMCEPopup.close()},updateCell:function(td,skip_id){var ed=tinyMCEPopup.editor,dom=ed.dom,doc=ed.getDoc(),v;var curCellType=td.nodeName.toLowerCase();var celltype=$('#celltype').val();$.each(['id','align','valign','lang','dir','class','scope'],function(i,k){v=$('#'+k).val();if(k=='id'&&skip_id){return}if(k=='style'){v=dom.serializeStyle(dom.parseStyle(v))}if(v===''){td.removeAttribute(k)}else{dom.setAttrib(td,k,v)}});$.each(['width','height','bgColor','borderColor','background'],function(i,k){ed.dom.setAttrib(td,k,null)});td.style.width=getCSSSize($('#width').val());td.style.height=getCSSSize($('#height').val());if($('#bordercolor').val()!=""){td.style.borderColor=$('#bordercolor').val();td.style.borderStyle=td.style.borderStyle==""?"solid":td.style.borderStyle;td.style.borderWidth=td.style.borderWidth==""?"1px":td.style.borderWidth}else{td.style.borderColor=''}td.style.backgroundColor=$('#bgcolor').val();if($('#backgroundimage').val()!=""){td.style.backgroundImage="url('"+$('#backgroundimage').val()+"')"}else{td.style.backgroundImage=''}if(curCellType!=celltype){var newCell=doc.createElement(celltype);for(var c=0;c<td.childNodes.length;c++)newCell.appendChild(td.childNodes[c].cloneNode(1));for(var a=0;a<td.attributes.length;a++)ed.dom.setAttrib(newCell,td.attributes[a].name,ed.dom.getAttrib(td,td.attributes[a].name));td.parentNode.replaceChild(newCell,td);td=newCell}dom.setAttrib(td,'style',dom.serializeStyle(dom.parseStyle(td.style.cssText)));return td},nextCell:function(elm){while((elm=elm.nextSibling)!=null){if(elm.nodeName=="TD"||elm.nodeName=="TH"){return elm}}return null},changedSize:function(){var st=tinyMCEPopup.dom.parseStyle($('#style').val());var height=$('#height').val();if(height!=""){st['height']=getCSSSize(height)}else{st['height']=""}$('#style').val(tinyMCEPopup.dom.serializeStyle(st))},changedBackgroundImage:function(){var st=tinyMCEPopup.dom.parseStyle($('#style').val());st['background-image']="url('"+$('#backgroundimage').val()+"')";$('#style').val(tinyMCEPopup.dom.serializeStyle(st))},changedBorder:function(){var st=tinyMCEPopup.dom.parseStyle($('#style').val());if($('#border').val()!=""&&$('#bordercolor').val()!=""){st['border-width']=$('#border').val()+"px"}$('#style').val(tinyMCEPopup.dom.serializeStyle(st))},changedColor:function(){var dom=tinyMCEPopup.dom;var st=dom.parseStyle($('#style').val());st['background-color']=$('#bgcolor').val();if($('#bordercolor').val()!=""){st['border-color']=$('#bordercolor').val();if(!st['border-width']){st['border-width']=$('#border').val()==""?"1px":$('#border').val()+"px"}}$('#style').val(dom.serializeStyle(st))},changedStyle:function(){var dom=tinyMCEPopup.dom;var st=dom.parseStyle($('#style').val());if(st['background-image']){$('#backgroundimage').val(st['background-image'].replace(new RegExp("url\\(['\"]?([^'\"]*)['\"]?\\)",'gi'),"$1"))}else{$('#backgroundimage').val('')}if(st['width']){$('#width').val(trimSize(st['width']))}if(st['height']){$('#height').val(trimSize(st['height']))}if(st['background-color']){$('#bgcolor').val(st['background-color']).change()}if(st['border-color']){$('#bordercolor').val(st['border-color']).change()}}};tinyMCEPopup.onInit.add(TableDialog.init,TableDialog);