Skip to content

Commit

Permalink
RTE formatting tools update and IE fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kaievns committed Dec 22, 2010
1 parent af10e76 commit 3fdbce9
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 85 deletions.
6 changes: 3 additions & 3 deletions src/rte/__init__.js
Expand Up @@ -10,8 +10,9 @@ var R = RightJS,
$w = RightJS.$w,
$E = RightJS.$E,
$A = RightJS.$A,
RegExp = RightJS.RegExp,
Class = RightJS.Class;
RegExp = RightJS.RegExp,
Class = RightJS.Class,
Element = RightJS.Element;


include_module_files(
Expand Down Expand Up @@ -75,7 +76,6 @@ include_module_files(
'tools/fontsize',
'tools/subscript',
'tools/superscript',
'tools/symbol',

'document',
'input'
Expand Down
10 changes: 1 addition & 9 deletions src/rte/rte/editor.js
Expand Up @@ -37,15 +37,7 @@ Rte.Editor = new Class(Element, {
* @return Rte.Editor this
*/
update: function(text) {
for (var key in Rte.Convert) {
text = text.replace(
new RegExp('<(\/)?'+ key +'>', 'ig'),
'<$1'+ Rte.Convert[key] + '>'
);
}

this._.innerHTML = text;

this.$super(text);
return this;
},

Expand Down
6 changes: 5 additions & 1 deletion src/rte/rte/tool/command.js
Expand Up @@ -22,7 +22,11 @@ Rte.Tool.Command = new Class(Rte.Tool, {
* @return boolean check result
*/
enabled: function() {
return document.queryCommandEnabled(this.command);
try {
return document.queryCommandEnabled(this.command);
} catch(e) {
return false;
}
},

/**
Expand Down
6 changes: 4 additions & 2 deletions src/rte/rte/tool/options.js
Expand Up @@ -94,8 +94,10 @@ Rte.Tool.Options = {

// updates the display
updateDisplay: function(value) {
this.display._.innerHTML = value !== null && value in this.items ?
this.items[value].text() : this._.title;
this.display.update(
value !== null && value in this.items ?
this.items[value].text() : this._.title
);
}

};
39 changes: 23 additions & 16 deletions src/rte/rte/tool/style.js
Expand Up @@ -27,6 +27,28 @@ Rte.Tool.Style = new Class(Rte.Tool.Format, {
return this;
},

/**
* Triggers the action
*
* @return void
*/
exec: function() {
// unformatting if there is a value
if (this.active()) {
this.attrs = {style: this.style + ":" + this._value};
this.unformat();
}

// formatting if some value was asked
if (this.value) {
this.attrs = {style: this.style + ":" + this.value};
this.format();
}

// getting back the RE checker
this.attrs = {style: this.re};
},

/**
* Overloading the original method so that we could do some additional
* features with the actual current value
Expand All @@ -37,7 +59,7 @@ Rte.Tool.Style = new Class(Rte.Tool.Format, {
var element = this.element(), active = false, value = null;

if (element !== null) {
value = this.getStyleValue();
this._value = value = this.getStyleValue();
active = true;
}

Expand All @@ -48,21 +70,6 @@ Rte.Tool.Style = new Class(Rte.Tool.Format, {

// protected

// calling format all over again because there might be nested styles
unformat: function() { this.format(); },

// reformatting the selection using the `style` property
format: function() {
if (this.value) {
this.attrs = {style: this.style + ":" + this.value};
this.$super();
this.attrs = {style: this.re};
} else if (this.element()) {
// removing the formatting element if there is no style value
Rte.Tool.Format.prototype.unformat.call(this);
}
},

/**
* Finds the current style value (if any)
*
Expand Down
13 changes: 9 additions & 4 deletions src/rte/tools/format.js
Expand Up @@ -46,13 +46,18 @@ Rte.Tools.Format = new Class(Rte.Tool.Format, {
* @return void
*/
exec: function() {
if (this.formats[this.value]) {
// removing the formatting first
if (this.active() && this.rule) {
this.tag = this.formats[this.rule].tag;
this.attrs = this.formats[this.rule].attrs;
this.unformat();
}

// applying a new formatting if needed
if (this.value && this.formats[this.value]) {
this.tag = this.formats[this.value].tag;
this.attrs = this.formats[this.value].attrs;

this.format();
} else {
this.unformat();
}
},

Expand Down
50 changes: 0 additions & 50 deletions src/rte/tools/symbol.js

This file was deleted.

0 comments on commit 3fdbce9

Please sign in to comment.