Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Revised the events again and fixed regression on the dialogs.
Browse files Browse the repository at this point in the history
  • Loading branch information
cheeaun committed Mar 9, 2009
1 parent cf264d1 commit bf169fb
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions Source/MooEditable/MooEditable.js
Expand Up @@ -64,7 +64,14 @@ var MooEditable = new Class({
var key = act.options.shortcut;
if (key) this.keys[key] = action;
}
if (act.dialogs) this.dialogs[action] = act.dialogs;
if (act.dialogs){
$each(act.dialogs, function(dialog, name){
if ($type(dialog) == 'function') dialog = dialog.attempt(this);
dialog.name = action + ':' + name;
if ($type(this.dialogs[action]) != 'object') this.dialogs[action] = {};
this.dialogs[action][name] = dialog;
}, this);
}
if (act.events){
$each(act.events, function(fn, event){
this.addEvent(event, fn);
Expand Down Expand Up @@ -158,12 +165,14 @@ var MooEditable = new Class({
range = self.selection.getRange();
self.editorDisabled = true;
self.toolbar.disable(name);
self.fireEvent('dialogOpen', this);
},
close: function(){
self.toolbar.enable();
self.editorDisabled = false;
self.focus();
if (range) self.selection.setRange(range);
self.fireEvent('dialogClose', this);
}
});
});
Expand Down Expand Up @@ -933,9 +942,8 @@ MooEditable.UI.Dialog = new Class({
return this;
},

open: function(fn){
open: function(){
this.el.setStyle('display', '');
if (fn) fn.attempt(null, this);
this.fireEvent('open', this);
return this;
},
Expand Down Expand Up @@ -967,7 +975,7 @@ MooEditable.UI.AlertDialog = function(alertText){
});
};

MooEditable.UI.PromptDialog = function(questionText, answerText){
MooEditable.UI.PromptDialog = function(questionText, answerText, fn){
var html = '<label class="mooeditable-dialog-label">' + questionText
+ ' <input type="text" class="text mooeditable-dialog-input" value="' + answerText + '">'
+ '</label> <button class="dialog-ok-button">OK</button>'
Expand All @@ -994,7 +1002,7 @@ MooEditable.UI.PromptDialog = function(questionText, answerText){
var answer = input.get('value');
input.set('value', answerText);
this.close();
this.fireEvent('clickOK', answer);
if (fn) fn.attempt(answer, this);
}
},
});
Expand Down Expand Up @@ -1099,19 +1107,21 @@ MooEditable.Actions = new Hash({
},
dialogs: {
alert: MooEditable.UI.AlertDialog('Please select the text you wish to hyperlink.'),
prompt: MooEditable.UI.PromptDialog('Enter URL', 'http://', function(url){
this.execute('createlink', false, url.trim());
})
prompt: function(editor){
return MooEditable.UI.PromptDialog('Enter URL', 'http://', function(url){
editor.execute('createlink', false, url.trim());
});
}
},
command: function(){
if (this.selection.isCollapsed()){
this.dialogs.createlink.alert.open();
} else {
var text = this.selection.getText();
var url = /^(https?|ftp|rmtp|mms):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i;
this.dialogs.createlink.prompt.open(function(){
if (url.test(text)) this.el.getElement('.mooeditable-dialog-input').set('value', text);
});
var prompt = this.dialogs.createlink.prompt;
if (url.test(text)) prompt.el.getElement('.mooeditable-dialog-input').set('value', text);
prompt.open();
}
}
},
Expand All @@ -1122,12 +1132,14 @@ MooEditable.Actions = new Hash({
shortcut: 'm'
},
dialogs: {
prompt: MooEditable.UI.PromptDialog('Enter image URL', 'http://')
prompt: function(editor){
return MooEditable.UI.PromptDialog('Enter image URL', 'http://', function(url){
editor.execute("insertimage", false, url.trim());
});
}
},
command: function(){
this.dialogs.urlimage.prompt.addEvent('clickOK', function(url){
this.execute("insertimage", false, url.trim());
}.bind(this)).open();
this.dialogs.urlimage.prompt.open();
}
},

Expand Down

0 comments on commit bf169fb

Please sign in to comment.