123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254 |
- define("dojox/editor/plugins/TablePlugins", [
- "dojo",
- "dijit",
- "dojox",
- "dijit/_base/popup",
- "dijit/_Widget",
- "dijit/_TemplatedMixin",
- "dijit/_WidgetsInTemplateMixin",
- "dijit/Menu",
- "dijit/MenuItem",
- "dijit/MenuSeparator",
- "dijit/TooltipDialog",
- "dijit/form/Button",
- "dijit/form/DropDownButton",
- "dijit/Dialog",
- "dijit/form/TextBox",
- "dijit/form/FilteringSelect",
- "dijit/popup",
- "dijit/_editor/_Plugin",
- "dijit/_editor/range",
- "dijit/_editor/selection",
- "dijit/ColorPalette",
- "dojox/widget/ColorPicker",
- "dojo/_base/connect",
- "dojo/_base/declare",
- "dojo/i18n",
- "dojo/i18n!dojox/editor/plugins/nls/TableDialog"
- ], function(dojo, dijit, dojox) {
- dojo.experimental("dojox.editor.plugins.TablePlugins");
- dojo.declare("dojox.editor.plugins._TableHandler", dijit._editor._Plugin,{
-
-
-
-
-
-
- tablesConnected:false,
- currentlyAvailable: false,
- alwaysAvailable:false,
- availableCurrentlySet:false,
- initialized:false,
- tableData: null,
- shiftKeyDown:false,
- editorDomNode: null,
- undoEnabled: true,
- refCount: 0,
-
- doMixins: function(){
-
- dojo.mixin(this.editor,{
- getAncestorElement: function(tagName){
- return dojo.withGlobal(this.window, "getAncestorElement",dijit._editor.selection, [tagName]);
- },
- hasAncestorElement: function(tagName){
- return dojo.withGlobal(this.window, "hasAncestorElement",dijit._editor.selection, [tagName]);
- },
- selectElement: function(elem){
- dojo.withGlobal(this.window, "selectElement",dijit._editor.selection, [elem]);
- },
- byId: function(id){
- return dojo.withGlobal(this.window, "byId", dojo, [id]);
- },
- query: function(arg, scope, returnFirstOnly){
-
- var ar = dojo.withGlobal(this.window, "query", dojo, [arg, scope]);
- return (returnFirstOnly) ? ar[0] : ar;
- }
- });
- },
- initialize: function(editor){
-
-
-
-
-
-
-
- this.refCount++;
-
-
- editor.customUndo = true;
- if(this.initialized){ return; }
-
- this.initialized = true;
- this.editor = editor;
- this.editor._tablePluginHandler = this;
-
-
-
- editor.onLoadDeferred.addCallback(dojo.hitch(this, function(){
- this.editorDomNode = this.editor.editNode || this.editor.iframe.document.body.firstChild;
-
-
-
- this._myListeners = [
- dojo.connect(this.editorDomNode , "mouseup", this.editor, "onClick"),
- dojo.connect(this.editor, "onDisplayChanged", this, "checkAvailable"),
- dojo.connect(this.editor, "onBlur", this, "checkAvailable"),
- dojo.connect(this.editor, "_saveSelection", this, function(){
-
- this._savedTableInfo = this.getTableInfo();
- }),
- dojo.connect(this.editor, "_restoreSelection", this, function(){
- delete this._savedTableInfo;
- })
- ];
- this.doMixins();
- this.connectDraggable();
- }));
- },
-
- getTableInfo: function(forceNewData){
-
-
-
-
- if(this._savedTableInfo){
-
- return this._savedTableInfo;
- }
- if(forceNewData){ this._tempStoreTableData(false); }
- if(this.tableData){
-
-
-
- return this.tableData;
- }
- var tr, trs, td, tds, tbl, cols, tdIndex, trIndex, o;
- td = this.editor.getAncestorElement("td");
- if(td){ tr = td.parentNode; }
-
- tbl = this.editor.getAncestorElement("table");
-
-
- if(tbl){
- tds = dojo.query("td", tbl);
- tds.forEach(function(d, i){
- if(td==d){tdIndex = i;}
- });
- trs = dojo.query("tr", tbl);
- trs.forEach(function(r, i){
- if(tr==r){trIndex = i;}
- });
- cols = tds.length/trs.length;
- o = {
- tbl:tbl,
- td:td,
- tr:tr,
- trs:trs,
- tds:tds,
- rows:trs.length,
- cols:cols,
- tdIndex:tdIndex,
- trIndex:trIndex,
- colIndex:tdIndex%cols
- };
- }else{
-
- o = {};
- }
-
- this.tableData = o;
- this._tempStoreTableData(500);
- return this.tableData;
- },
-
- connectDraggable: function(){
-
-
-
-
-
- if(!dojo.isIE){
-
- return;
- }
-
-
- this.editorDomNode.ondragstart = dojo.hitch(this, "onDragStart");
- this.editorDomNode.ondragend = dojo.hitch(this, "onDragEnd");
-
-
-
-
-
-
-
-
-
- },
- onDragStart: function(){
- var e = window.event;
- if(!e.srcElement.id){
- e.srcElement.id = "tbl_"+(new Date().getTime());
- }
-
- },
- onDragEnd: function(){
-
-
-
-
-
-
-
-
-
-
-
- var e = window.event;
- var node = e.srcElement;
- var id = node.id;
- var win = this.editor.window;
-
-
-
-
-
- if(node.tagName.toLowerCase()=="table"){
- setTimeout(function(){
- var node = dojo.withGlobal(win, "byId", dojo, [id]);
- dojo.removeAttr(node, "align");
-
- }, 100);
- }
- },
- checkAvailable: function(){
-
-
-
-
-
- if(this.availableCurrentlySet){
-
-
-
- return this.currentlyAvailable;
- }
-
-
- if(!this.editor) {
-
- return false;
- }
- if(this.alwaysAvailable) {
-
- return true;
- }
-
-
- this.currentlyAvailable = this.editor.focused && (this._savedTableInfo ? this._savedTableInfo.tbl :
- this.editor.hasAncestorElement("table"));
-
- if(this.currentlyAvailable){
- this.connectTableKeys();
- }else{
- this.disconnectTableKeys();
- }
-
- this._tempAvailability(500);
-
- dojo.publish(this.editor.id + "_tablePlugins", [ this.currentlyAvailable ]);
- return this.currentlyAvailable;
- },
-
- _prepareTable: function(tbl){
-
-
-
- var tds = this.editor.query("td", tbl);
- console.log("prep:", tds, tbl);
- if(!tds[0].id){
- tds.forEach(function(td, i){
- if(!td.id){
- td.id = "tdid"+i+this.getTimeStamp();
- }
- }, this);
- }
- return tds;
- },
-
- getTimeStamp: function(){
- return new Date().getTime();
- },
-
- _tempStoreTableData: function(type){
-
-
- if(type===true){
-
- }else if(type===false){
-
- this.tableData = null;
- }else if(type===undefined){
- console.warn("_tempStoreTableData must be passed an argument");
- }else{
-
- setTimeout(dojo.hitch(this, function(){
- this.tableData = null;
- }), type);
- }
- },
-
- _tempAvailability: function(type){
-
- if(type===true){
-
- this.availableCurrentlySet = true;
- }else if(type===false){
-
- this.availableCurrentlySet = false;
- }else if(type===undefined){
- console.warn("_tempAvailability must be passed an argument");
- }else{
-
- this.availableCurrentlySet = true;
- setTimeout(dojo.hitch(this, function(){
- this.availableCurrentlySet = false;
- }), type);
- }
-
- },
-
- connectTableKeys: function(){
-
-
-
-
-
- if(this.tablesConnected){ return; }
- this.tablesConnected = true;
- var node = (this.editor.iframe) ? this.editor.document : this.editor.editNode;
- this.cnKeyDn = dojo.connect(node, "onkeydown", this, "onKeyDown");
- this.cnKeyUp = dojo.connect(node, "onkeyup", this, "onKeyUp");
- this._myListeners.push(dojo.connect(node, "onkeypress", this, "onKeyUp"));
- },
-
- disconnectTableKeys: function(){
-
- dojo.disconnect(this.cnKeyDn);
- dojo.disconnect(this.cnKeyUp);
- this.tablesConnected = false;
- },
-
- onKeyDown: function(evt){
- var key = evt.keyCode;
-
- if(key == 16){ this.shiftKeyDown = true;}
- if(key == 9) {
- var o = this.getTableInfo();
-
-
-
- o.tdIndex = (this.shiftKeyDown) ? o.tdIndex-1 : tabTo = o.tdIndex+1;
- if(o.tdIndex>=0 && o.tdIndex<o.tds.length){
-
- this.editor.selectElement(o.tds[o.tdIndex]);
-
-
-
- this.currentlyAvailable = true;
- this._tempAvailability(true);
-
- this._tempStoreTableData(true);
- this.stopEvent = true;
- }else{
-
- this.stopEvent = false;
- this.onDisplayChanged();
- }
- if(this.stopEvent) {
- dojo.stopEvent(evt);
- }
- }
- },
-
- onKeyUp: function(evt){
- var key = evt.keyCode;
-
- if(key == 16){ this.shiftKeyDown = false;}
- if(key == 37 || key == 38 || key == 39 || key == 40 ){
-
- this.onDisplayChanged();
- }
- if(key == 9 && this.stopEvent){ dojo.stopEvent(evt);}
- },
-
- onDisplayChanged: function(){
-
- this.currentlyAvailable = false;
- this._tempStoreTableData(false);
- this._tempAvailability(false);
- this.checkAvailable();
- },
- uninitialize: function(editor){
-
-
-
-
-
-
-
-
- if(this.editor == editor){
- this.refCount--;
- if(!this.refCount && this.initialized){
- if(this.tablesConnected){
- this.disconnectTableKeys();
- }
- this.initialized = false;
- dojo.forEach(this._myListeners, function(l){
- dojo.disconnect(l);
- });
- delete this._myListeners;
- delete this.editor._tablePluginHandler;
- delete this.editor;
- }
- this.inherited(arguments);
- }
- }
- });
- dojo.declare("dojox.editor.plugins.TablePlugins",
- dijit._editor._Plugin,
- {
-
-
-
-
-
-
-
-
- iconClassPrefix: "editorIcon",
- useDefaultCommand: false,
- buttonClass: dijit.form.Button,
- commandName:"",
- label:"",
- alwaysAvailable:false,
- undoEnabled:true,
-
- onDisplayChanged: function(withinTable){
-
-
-
- if(!this.alwaysAvailable){
- this.available = withinTable;
- this.button.set('disabled', !this.available);
- }
- },
-
- setEditor: function(editor){
- this.editor = editor;
- this.editor.customUndo = true;
- this.inherited(arguments);
- this._availableTopic = dojo.subscribe(this.editor.id + "_tablePlugins", this, "onDisplayChanged");
- this.onEditorLoaded();
- },
- onEditorLoaded: function(){
- if(!this.editor._tablePluginHandler){
-
-
-
- var tablePluginHandler = new dojox.editor.plugins._TableHandler();
- tablePluginHandler.initialize(this.editor);
- }else{
- this.editor._tablePluginHandler.initialize(this.editor);
- }
- },
-
- selectTable: function(){
-
- var o = this.getTableInfo();
- if(o && o.tbl){
- dojo.withGlobal(this.editor.window, "selectElement",dijit._editor.selection, [o.tbl]);
- }
- },
-
- _initButton: function(){
- this.command = this.commandName;
-
- this.label = this.editor.commands[this.command] = this._makeTitle(this.command);
- this.inherited(arguments);
- delete this.command;
-
- this.connect(this.button, "onClick", "modTable");
-
- this.onDisplayChanged(false);
- },
-
- modTable: function(cmd, args){
-
-
-
-
-
-
- if(dojo.isIE){
-
-
- this.editor.focus();
- }
- this.begEdit();
- var o = this.getTableInfo();
- var sw = (dojo.isString(cmd))?cmd : this.commandName;
- var r, c, i;
- var adjustColWidth = false;
-
- switch(sw){
- case "insertTableRowBefore":
- r = o.tbl.insertRow(o.trIndex);
- for(i=0;i<o.cols;i++){
- c = r.insertCell(-1);
- c.innerHTML = " ";
- }
- break;
- case "insertTableRowAfter":
- r = o.tbl.insertRow(o.trIndex+1);
- for(i=0;i<o.cols;i++){
- c = r.insertCell(-1);
- c.innerHTML = " ";
- }
- break;
- case "insertTableColumnBefore":
- o.trs.forEach(function(r){
- c = r.insertCell(o.colIndex);
- c.innerHTML = " ";
- });
- adjustColWidth = true;
- break;
- case "insertTableColumnAfter":
- o.trs.forEach(function(r){
- c = r.insertCell(o.colIndex+1);
- c.innerHTML = " ";
- });
- adjustColWidth = true;
- break;
- case "deleteTableRow":
- o.tbl.deleteRow(o.trIndex);
- console.log("TableInfo:", this.getTableInfo());
- break;
- case "deleteTableColumn":
- o.trs.forEach(function(tr){
- tr.deleteCell(o.colIndex);
- });
- adjustColWidth = true;
- break;
- case "modifyTable":
- break;
- case "insertTable":
- break;
-
- }
- if(adjustColWidth){
- this.makeColumnsEven();
- }
- this.endEdit();
- },
-
- begEdit: function(){
- if(this.editor._tablePluginHandler.undoEnabled){
-
- if(this.editor.customUndo){
- this.editor.beginEditing();
- }else{
- this.valBeforeUndo = this.editor.getValue();
-
-
- }
- }
- },
- endEdit: function(){
- if(this.editor._tablePluginHandler.undoEnabled){
- if(this.editor.customUndo){
- this.editor.endEditing();
- }else{
-
-
-
- var afterUndo = this.editor.getValue();
-
- this.editor.setValue(this.valBeforeUndo);
- this.editor.replaceValue(afterUndo);
- }
-
- this.editor.onDisplayChanged();
- }
- },
-
- makeColumnsEven: function(){
-
-
-
-
-
- setTimeout(dojo.hitch(this, function(){
- var o = this.getTableInfo(true);
- var w = Math.floor(100/o.cols);
- o.tds.forEach(function(d){
- dojo.attr(d, "width", w+"%");
- });
- }), 10);
- },
-
- getTableInfo: function(forceNewData){
-
-
-
-
- return this.editor._tablePluginHandler.getTableInfo(forceNewData);
- },
- _makeTitle: function(str){
-
-
- this._strings = dojo.i18n.getLocalization("dojox.editor.plugins", "TableDialog");
- var title = this._strings[str+"Title"] || this._strings[str+"Label"];
- if(!title){
- if(str == "colorTableCell"){
- title = this._strings["backgroundColor"].slice(0, - 1);
- }else{
- var ns = [];
- dojo.forEach(str, function(c, i){
- if(c.charCodeAt(0)<91 && i>0 && ns[i-1].charCodeAt(0)!=32){
- ns.push(" ");
- }
- if(i===0){ c = c.toUpperCase();}
- ns.push(c);
- });
- title = ns.join("");
- }
- }
- return title;
- },
-
-
-
- getSelectedCells: function(){
-
-
-
- var cells = [];
- var tbl = this.getTableInfo().tbl;
- this.editor._tablePluginHandler._prepareTable(tbl);
- var e = this.editor;
-
-
- var text = dojo.withGlobal(e.window, "getSelectedHtml",dijit._editor.selection, [null]);
- var str = text.match(/id="*\w*"*/g);
- dojo.forEach(str, function(a){
- var id = a.substring(3, a.length);
- if(id.charAt(0) == "\"" && id.charAt(id.length - 1) == "\""){
- id = id.substring(1, id.length - 1);
- }
- var node = e.byId(id);
- if(node && node.tagName.toLowerCase() == "td"){
- cells.push(node);
- }
- }, this);
- if(!cells.length){
-
-
- var sel = dijit.range.getSelection(e.window);
- if(sel.rangeCount){
- var r = sel.getRangeAt(0);
- var node = r.startContainer;
- while(node && node != e.editNode && node != e.document){
- if(node.nodeType === 1){
- var tg = node.tagName ? node.tagName.toLowerCase() : "";
- if(tg === "td"){
- return [node];
- }
- }
- node = node.parentNode;
- }
- }
- }
- return cells;
- },
-
- updateState: function(){
-
-
- if(this.button){
- if((this.available || this.alwaysAvailable) && !this.get("disabled")){
- this.button.set("disabled",false);
- }else{
- this.button.set("disabled",true);
- }
- }
- },
- destroy: function(){
-
-
- this.inherited(arguments);
- dojo.unsubscribe(this._availableTopic);
-
-
-
- this.editor._tablePluginHandler.uninitialize(this.editor);
- }
-
- }
- );
- dojo.declare("dojox.editor.plugins.TableContextMenu",
- dojox.editor.plugins.TablePlugins,
- {
- constructor: function(){
-
-
-
- this.connect(this, "setEditor", function(editor){
- editor.onLoadDeferred.addCallback(dojo.hitch(this, function() {
- this._createContextMenu();
- }));
- this.button.domNode.style.display = "none";
- });
- },
- destroy: function(){
-
-
- if(this.menu){
- this.menu.destroyRecursive();
- delete this.menu;
- }
- this.inherited(arguments);
- },
-
-
- _initButton: function(){
- this.inherited(arguments);
- if(this.commandName=="tableContextMenu"){ this.button.domNode.display = "none";}
- },
-
- _createContextMenu: function(){
-
-
-
-
- var pMenu = new dijit.Menu({targetNodeIds:[this.editor.iframe]});
- var messages = dojo.i18n.getLocalization("dojox.editor.plugins", "TableDialog", this.lang);
- pMenu.addChild(new dijit.MenuItem({label: messages.selectTableLabel, onClick: dojo.hitch(this, "selectTable")}));
- pMenu.addChild(new dijit.MenuSeparator());
-
- pMenu.addChild(new dijit.MenuItem({label: messages.insertTableRowBeforeLabel, onClick: dojo.hitch(this, "modTable", "insertTableRowBefore" )}));
- pMenu.addChild(new dijit.MenuItem({label: messages.insertTableRowAfterLabel, onClick: dojo.hitch(this, "modTable", "insertTableRowAfter" )}));
- pMenu.addChild(new dijit.MenuItem({label: messages.insertTableColumnBeforeLabel, onClick: dojo.hitch(this, "modTable", "insertTableColumnBefore" )}));
- pMenu.addChild(new dijit.MenuItem({label: messages.insertTableColumnAfterLabel, onClick: dojo.hitch(this, "modTable", "insertTableColumnAfter" )}));
- pMenu.addChild(new dijit.MenuSeparator());
- pMenu.addChild(new dijit.MenuItem({label: messages.deleteTableRowLabel, onClick: dojo.hitch(this, "modTable", "deleteTableRow" )}));
- pMenu.addChild(new dijit.MenuItem({label: messages.deleteTableColumnLabel, onClick: dojo.hitch(this, "modTable", "deleteTableColumn" )}));
- this.menu = pMenu;
- }
- });
- dojo.declare("dojox.editor.plugins.InsertTable",
- dojox.editor.plugins.TablePlugins,
- {
- alwaysAvailable: true,
-
- modTable: function(){
- var w = new dojox.editor.plugins.EditorTableDialog({});
- w.show();
- var c = dojo.connect(w, "onBuildTable", this, function(obj){
- dojo.disconnect(c);
-
- var res = this.editor.execCommand('inserthtml', obj.htmlText);
-
-
-
-
-
-
- });
- }
- });
- dojo.declare("dojox.editor.plugins.ModifyTable",
- dojox.editor.plugins.TablePlugins,
- {
- modTable: function(){
- if (!this.editor._tablePluginHandler.checkAvailable()) {return;}
- var o = this.getTableInfo();
-
- var w = new dojox.editor.plugins.EditorModifyTableDialog({table:o.tbl});
- w.show();
- this.connect(w, "onSetTable", function(color){
-
- var o = this.getTableInfo();
-
- dojo.attr(o.td, "bgcolor", color);
- });
- }
- });
- dojo.declare("dojox.editor.plugins._CellColorDropDown", [dijit._Widget, dijit._TemplatedMixin, dijit._WidgetsInTemplateMixin], {
-
-
-
-
-
-
-
- templateString:
- "<div style='display: none; position: absolute; top: -10000; z-index: -10000'>" +
- "<div dojoType='dijit.TooltipDialog' dojoAttachPoint='dialog' class='dojoxEditorColorPicker'>" +
- "<div dojoType='dojox.widget.ColorPicker' dojoAttachPoint='_colorPicker'></div>" +
- "<div style='margin: 0.5em 0em 0em 0em'>" +
- "<button dojoType='dijit.form.Button' type='submit' dojoAttachPoint='_setButton'>${buttonSet}</button>" +
- " " +
- "<button dojoType='dijit.form.Button' type='button' dojoAttachPoint='_cancelButton'>${buttonCancel}</button>" +
- "</div>" +
- "</div>" +
- "</div>",
-
-
- widgetsInTemplate: true,
- constructor: function(){
-
-
-
- var strings = dojo.i18n.getLocalization("dojox.editor.plugins", "TableDialog");
- dojo.mixin(this, strings);
- },
- startup: function(){
-
-
- if(!this._started){
- this.inherited(arguments);
- this.connect(this.dialog, "execute", function(){
- this.onChange(this.get("value"));
- });
- this.connect(this._cancelButton, "onClick", function(){
- dijit.popup.close(this.dialog);
- });
- this.connect(this.dialog, "onCancel", "onCancel");
-
- dojo.style(this.domNode, "display", "block");
- }
- },
- _setValueAttr: function(value, priorityChange){
-
-
-
-
-
-
- this._colorPicker.set("value", value, priorityChange);
- },
- _getValueAttr: function(){
-
-
- return this._colorPicker.get("value");
- },
- setColor: function(/*String*/ color){
- this._colorPicker.setColor(color, false);
- },
-
- onChange: function(value){
-
-
-
-
- },
- onCancel: function(){
-
-
- }
- });
- dojo.declare("dojox.editor.plugins.ColorTableCell", dojox.editor.plugins.TablePlugins, {
- constructor: function(){
-
-
- this.closable = true;
- this.buttonClass = dijit.form.DropDownButton;
- var picker = new dojox.editor.plugins._CellColorDropDown();
- dojo.body().appendChild(picker.domNode);
- picker.startup();
- this.dropDown = picker.dialog;
- this.connect(picker, "onChange", function(color){
- this.editor.focus();
- this.modTable(null, color);
- });
- this.connect(picker, "onCancel", function(){
- this.editor.focus();
- });
- this.connect(picker.dialog, "onOpen", function(){
- var o = this.getTableInfo(),
- tds = this.getSelectedCells(o.tbl);
- if(tds && tds.length > 0){
- var t = tds[0] == this.lastObject ? tds[0] : tds[tds.length - 1],
- color;
- while(t && t !== this.editor.document && ((color = dojo.style(t, "backgroundColor")) == "transparent" || color.indexOf("rgba") == 0)){
- t = t.parentNode;
- }
- if(color != "transparent" && color.indexOf("rgba") != 0){
- picker.setColor(color);
- }
- }
- });
- this.connect(this, "setEditor", function(editor){
- editor.onLoadDeferred.addCallback(dojo.hitch(this, function(){
- this.connect(this.editor.editNode, "onmouseup", function(evt){
- this.lastObject = evt.target;
- });
- }));
- });
- },
-
- _initButton: function(){
- this.command = this.commandName;
-
- this.label = this.editor.commands[this.command] = this._makeTitle(this.command);
- this.inherited(arguments);
- delete this.command;
- this.onDisplayChanged(false);
- },
-
- modTable: function(cmd, args){
-
-
-
-
-
-
-
- this.begEdit();
- var o = this.getTableInfo();
-
-
- var tds = this.getSelectedCells(o.tbl);
-
- dojo.forEach(tds, function(td){
- dojo.style(td, "backgroundColor", args);
- });
- this.endEdit();
- }
- });
- dojo.declare("dojox.editor.plugins.EditorTableDialog", [dijit.Dialog, dijit._TemplatedMixin, dijit._WidgetsInTemplateMixin], {
-
-
- baseClass:"EditorTableDialog",
-
- templateString: dojo.cache("dojox.editor.plugins", "resources/insertTable.html"),
- postMixInProperties: function(){
- var messages = dojo.i18n.getLocalization("dojox.editor.plugins", "TableDialog", this.lang);
- dojo.mixin(this, messages);
- this.inherited(arguments);
- },
- postCreate: function(){
- dojo.addClass(this.domNode, this.baseClass);
- this.inherited(arguments);
- },
- onInsert: function(){
- console.log("insert");
-
- var rows = this.selectRow.get("value") || 1,
- cols = this.selectCol.get("value") || 1,
- width = this.selectWidth.get("value"),
- widthType = this.selectWidthType.get("value"),
- border = this.selectBorder.get("value"),
- pad = this.selectPad.get("value"),
- space = this.selectSpace.get("value"),
- _id = "tbl_"+(new Date().getTime()),
- t = '<table id="'+_id+'"width="'+width+((widthType=="percent")?'%':'')+'" border="'+border+'" cellspacing="'+space+'" cellpadding="'+pad+'">\n';
-
- for(var r=0;r<rows;r++){
- t += '\t<tr>\n';
- for(var c=0;c<cols;c++){
- t += '\t\t<td width="'+(Math.floor(100/cols))+'%"> </td>\n';
- }
- t += '\t</tr>\n';
- }
- t += '</table><br />';
-
-
- this.onBuildTable({htmlText:t, id:_id});
- var cl = dojo.connect(this, "onHide", function(){
- dojo.disconnect(cl);
- var self = this;
- setTimeout(function(){
- self.destroyRecursive();
- }, 10);
- });
- this.hide();
- },
- onCancel: function(){
-
-
-
- var c = dojo.connect(this, "onHide", function(){
- dojo.disconnect(c);
- var self = this;
- setTimeout(function(){
- self.destroyRecursive();
- }, 10);
- });
- },
- onBuildTable: function(tableText){
-
- }
- });
- dojo.declare("dojox.editor.plugins.EditorModifyTableDialog", [dijit.Dialog, dijit._TemplatedMixin, dijit._WidgetsInTemplateMixin], {
-
-
-
-
-
- baseClass:"EditorTableDialog",
- table:null,
- tableAtts:{},
- templateString: dojo.cache("dojox.editor.plugins", "resources/modifyTable.html"),
- postMixInProperties: function(){
- var messages = dojo.i18n.getLocalization("dojox.editor.plugins", "TableDialog", this.lang);
- dojo.mixin(this, messages);
- this.inherited(arguments);
- },
- postCreate: function(){
- dojo.addClass(this.domNode, this.baseClass);
- this.inherited(arguments);
- this._cleanupWidgets = [];
- var w1 = new dijit.ColorPalette({});
- this.connect(w1, "onChange", function(color){
- dijit.popup.close(w1);
- this.setBrdColor(color);
- });
- this.connect(w1, "onBlur", function(){
- dijit.popup.close(w1);
- });
- this.connect(this.borderCol, "click", function(){
- dijit.popup.open({popup:w1, around:this.borderCol});
- w1.focus();
- });
- var w2 = new dijit.ColorPalette({});
- this.connect(w2, "onChange", function(color){
- dijit.popup.close(w2);
- this.setBkColor(color);
- });
- this.connect(w2, "onBlur", function(){
- dijit.popup.close(w2);
- });
- this.connect(this.backgroundCol, "click", function(){
- dijit.popup.open({popup:w2, around:this.backgroundCol});
- w2.focus();
- });
- this._cleanupWidgets.push(w1);
- this._cleanupWidgets.push(w2);
-
- this.setBrdColor(dojo.attr(this.table, "bordercolor"));
- this.setBkColor(dojo.attr(this.table, "bgcolor"));
- var w = dojo.attr(this.table, "width");
- if(!w){
- w = this.table.style.width;
- }
- var p = "pixels";
- if(dojo.isString(w) && w.indexOf("%")>-1){
- p = "percent";
- w = w.replace(/%/, "");
- }
-
- if(w){
- this.selectWidth.set("value", w);
- this.selectWidthType.set("value", p);
- }else{
- this.selectWidth.set("value", "");
- this.selectWidthType.set("value", "percent");
- }
-
- this.selectBorder.set("value", dojo.attr(this.table, "border"));
- this.selectPad.set("value", dojo.attr(this.table, "cellPadding"));
- this.selectSpace.set("value", dojo.attr(this.table, "cellSpacing"));
- this.selectAlign.set("value", dojo.attr(this.table, "align"));
- },
-
- setBrdColor: function(color){
- this.brdColor = color;
- dojo.style(this.borderCol, "backgroundColor", color);
- },
-
- setBkColor: function(color){
- this.bkColor = color;
- dojo.style(this.backgroundCol, "backgroundColor", color);
- },
- onSet: function(){
- dojo.attr(this.table, "borderColor", this.brdColor);
- dojo.attr(this.table, "bgColor", this.bkColor);
- if(this.selectWidth.get("value")){
-
- dojo.style(this.table, "width", "");
- dojo.attr(this.table, "width", (this.selectWidth.get("value") + ((this.selectWidthType.get("value")=="pixels")?"":"%") ));
- }
- dojo.attr(this.table, "border", this.selectBorder.get("value"));
- dojo.attr(this.table, "cellPadding", this.selectPad.get("value"));
- dojo.attr(this.table, "cellSpacing", this.selectSpace.get("value"));
- dojo.attr(this.table, "align", this.selectAlign.get("value"));
- var c = dojo.connect(this, "onHide", function(){
- dojo.disconnect(c);
- var self = this;
- setTimeout(function(){
- self.destroyRecursive();
- }, 10);
- });
- this.hide();
- },
- onCancel: function(){
-
-
-
- var c = dojo.connect(this, "onHide", function(){
- dojo.disconnect(c);
- var self = this;
- setTimeout(function(){
- self.destroyRecursive();
- }, 10);
- });
- },
- onSetTable: function(tableText){
-
- },
- destroy: function(){
-
-
- this.inherited(arguments);
- dojo.forEach(this._cleanupWidgets, function(w){
- if(w && w.destroy){
- w.destroy();
- }
- });
- delete this._cleanupWidgets;
- }
- });
- dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o){
- if(o.plugin){ return; }
-
- if(o.args && o.args.command){
- var cmd = o.args.command.charAt(0).toLowerCase()+o.args.command.substring(1,o.args.command.length);
-
- switch(cmd){
- case "insertTableRowBefore":
- case "insertTableRowAfter":
- case "insertTableColumnBefore":
- case "insertTableColumnAfter":
- case "deleteTableRow":
- case "deleteTableColumn":
- o.plugin = new dojox.editor.plugins.TablePlugins({commandName: cmd});
- break;
- case "colorTableCell":
- o.plugin = new dojox.editor.plugins.ColorTableCell({commandName: cmd});
- break;
- case "modifyTable":
- o.plugin = new dojox.editor.plugins.ModifyTable({commandName: cmd});
- break;
- case "insertTable":
- o.plugin = new dojox.editor.plugins.InsertTable({commandName: cmd});
- break;
- case "tableContextMenu":
- o.plugin = new dojox.editor.plugins.TableContextMenu({commandName: cmd});
- break;
- }
- }
- });
- return dojox.editor.plugins.TablePlugins;
- });
|