12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- // Licensed Materials - Property of IBM
- //
- // IBM Cognos Products: cclcore
- //
- // (C) Copyright IBM Corp. 2012, 2013
- //
- // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- dojo.provide("bidi.dojo.editor.plugins.BidiSupport");
- dojo.require("dijit._editor._Plugin");
- dojo.declare("bidi.dojo.editor.plugins.BidiSupport",dijit._editor._Plugin,{
- // summary:
- // This plugin provides 2 toolbar buttons making possible to switch RTE text direction
- // between LTR and RTL mode
- command: "bidiSupport",
- _LTR: 'ltr',
- _RTL: 'rtl',
- _transText: {},
- setEditor: function(/*dijit.Editor*/ editor){
- // summary:
- // Tell the plugin which Editor it is associated with.
- this.editor = editor;
- this._initButton();
- },
- _initButton: function(){
- // summary:
- // Override _Plugin._initButton(). Creates two buttons, used for
- // setting text direction to left-to-right and right-to-left.
- this._transText[this._LTR] = this._LTR;
- this._transText[this._RTL] = this._RTL;
- var bMenu = new dijit.Menu({});
- bMenu.addChild(new dijit.MenuItem({label:this._transText[this._LTR], iconClass:this.iconClassPrefix+" "+this.iconClassPrefix + "LeftToRight", onClick:dojo.hitch(this, "_changeDir", this._LTR)}));
- bMenu.addChild(new dijit.MenuItem({label:this._transText[this._RTL], iconClass:this.iconClassPrefix+" "+this.iconClassPrefix + "RightToLeft", onClick:dojo.hitch(this, "_changeDir", this._RTL)}));
- var direction = dojo.getComputedStyle(this.editor.domNode).direction;
- this.button = new dijit.form.DropDownButton(dojo.mixin({
- label: this._transText[direction],
- lang: this.editor.lang,
- dropDown: bMenu,
- showLabel: false,
- iconClass: this.iconClassPrefix+" "+this.iconClassPrefix + ((direction === this._LTR) ? "LeftToRight" : "RightToLeft")
- }, this.params || {}));
- this.editor.onLoadDeferred.addCallback(dojo.hitch(this, function(){
- var h = dojo.hitch(this,this._toggleDir);
- this.editor.addKeyHandler('d', true, false, h);
- }));
- },
- _toggleDir: function(){
- // summary:
- // Called in result of using Ctrl+Shift+X shortcut.
- // Toggles the Editor direction
- var dir = this.editor.editorObject.contentWindow.document.documentElement.getElementsByTagName("body")[0].dir;
- dir = (dir === this._LTR) ? this._RTL : this._LTR;
- this._changeDir(dir);
- },
- _changeDir: function(dir){
- // summary:
- // Handler for button click events, to switch the text direction of the editor
- if(dir){
- var editDoc = this.editor.editorObject.contentWindow.document.documentElement.getElementsByTagName("body")[0];
- editDoc.dir = dir;
- if(dojo.isIE && editDoc.firstChild) {
- editDoc.firstChild.dir = "";
- }
- var updatedClass = this.iconClassPrefix+" "+this.iconClassPrefix + ((dir === this._LTR)? "LeftToRight" : "RightToLeft");
- dojo.attr(this.button,"iconClass",updatedClass);
- dojo.attr(this.button,"label",this._transText[dir]);
- }
- }
- });
- dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o){
- if(o.plugin){ return; }
- if (o.args.name === "bidiSupport") {
- o.plugin = new bidi.dojo.editor.plugins.BidiSupport({command: o.args.name});
- }
- });
|