Permalink
Browse files

- use "bue" namespace in events.

  • Loading branch information...
1 parent 74f091f commit ec8d3d09d8e3297ad14a181befe82e1aa5a0cc02 ufku committed Nov 8, 2010
View
@@ -17,8 +17,8 @@ BUE.behavior = function(context, settings) {
$.each(pset, function (tid, tplid) {
BUE.processTextarea($('#'+ tid, context).get(0), tplid);
});
- //fix enter key on textfields triggering button click.
- $('input:text', context).keydown(function(e) {e.keyCode == 13 && (BUE.enterKeyTime = new Date())});
+ // Fix enter key on textfields triggering button click.
+ $('input:text', context).bind('keydown.bue', BUE.eFixEnter);
};
//integrate editor template into textarea T
@@ -47,11 +47,9 @@ BUE.instance = function (T, tplid) {
E.UI = BUE.$html(BUE.theme(tplid).replace(/\%n/g, i)).insertBefore(T);
E.buttons = $('.bue-button', E.UI).each(function(i, B) {
var arr = B.id.split('-');
- $($.extend(B, {eindex: arr[1], bid: arr[3], bindex: i})).click(function() {
- return !(BUE.enterKeyTime && new Date() - BUE.enterKeyTime < 500) && BUE.buttonClick(B.eindex, B.bindex);
- });
+ $($.extend(B, {eindex: arr[1], bid: arr[3], bindex: i})).bind('click.bue', BUE.eButtonClick);
}).get();
- $(T).focus(function() {!T.bue.dialog.esp && T.bue.activate()});
+ $(T).bind('focus.bue', BUE.eTextareaFocus);
};
//execute button's click event
@@ -172,9 +170,27 @@ function (T) {
return {start: T.selectionStart || 0, end: T.selectionEnd || 0}
};
-//html 2 jquery. way faster than $(html)
-BUE.$html = function(s){return $(document.createElement('div')).html(s).children()};
-//not to break old button scripts.
+// Enter key fixer for text fields
+BUE.eFixEnter = function(e) {
+ e.keyCode == 13 && (BUE.enterKeyTime = new Date());
+};
+
+// Button click handler
+BUE.eButtonClick = function(e) {
+ return !(BUE.enterKeyTime && new Date() - BUE.enterKeyTime < 500) && BUE.buttonClick(this.eindex, this.bindex);
+}
+
+// Textarea focus handler
+BUE.eTextareaFocus = function(e) {
+ this.bue && !this.bue.dialog.esp && this.bue.activate();
+}
+
+// Html 2 jquery. Faster than $(html)
+BUE.$html = function(s){
+ return $(document.createElement('div')).html(s).children();
+};
+
+// Backward compatibility.
window.editor = window.editor || BUE;
//initiate bueditor
$(document).ready(function () {
@@ -22,7 +22,7 @@ BUE.preprocess.autocomplete = function(E, $) {
E.ACAdd({'<!--': '-->', '<?php': '?>', '>': BUE.ACTag, ']': BUE.ACTag});
//register keypress
- $(E.textArea).keypress(function(e) {
+ $(E.textArea).bind('keypress.bue', function(e) {
var code = e.charCode === undefined ? e.keyCode : e.charCode;
//disable keycodes that have multi-meaning in opera. 39: hypen-right, 40: parenthesis-down.
//extend 37:percentage-left, 38:ampersand-up, 33:exclamation-pageup, 34:double quote-pagedown...
View
@@ -18,7 +18,7 @@ BUE.preprocess.ctrl = function(E, $) {
});
//register ctrl shortcuts for the editor.
- $(E.textArea).keydown(function(e) {
+ $(E.textArea).bind('keydown.bue', function(e) {
if (e.ctrlKey && !e.shiftKey && !e.originalEvent.altKey && E.ctrlKeys[e.keyCode]) {
E.ctrlKeys[e.keyCode].click();
//Opera needs supression of keypress.
@@ -16,7 +16,7 @@ BUE.history = function(E) {
H.writable= true; //dynamic allowance of state saving.
//attach textarea events triggering history operations.
- $(E.textArea).one('focus', function(){H.save()}).keyup(function(e) {
+ $(E.textArea).one('focus.bue', function(){H.save()}).bind('keyup.bue', function(e) {
H.writable && (!H.keys || H.keys[e.keyCode]) && H.save();
});
View
@@ -4,7 +4,7 @@
//Requires: none
BUE.preprocess.li = function(E, $) {
- $(E.textArea).keyup(function(e) {
+ $(E.textArea).bind('keyup.bue', function(e) {
if (!e.ctrlKey && !e.shiftKey && !e.originalEvent.altKey && e.keyCode == 13) {
var prefix = E.getContent().substr(0, E.posSelection().start);
/<\/li>\s*$/.test(prefix) && E.tagSelection('<li>', '</li>');
Oops, something went wrong.
Oops, something went wrong.
@@ -116,14 +116,14 @@ BUE.preprocess = $.extend({popup: function(Ed, $) {
var E = BUE.active;
E.buttonsDisabled(true).stayClicked(true);
D.esp = E.posSelection();
- $(E.textArea).focus(foc);
+ $(E.textArea).bind('focus.bue', foc);
return Do(title, content, opt);
};
//close
D.close = function(effect) {
if (!D.esp) return D;
var E = D.bue;
- $(E.textArea).unbind('focus', foc);
+ $(E.textArea).unbind('focus.bue', foc);
E.buttonsDisabled(false).stayClicked(false);
E == BUE.active && E.makeSelection(D.esp.start, D.esp.end);
D.esp = null;
View
@@ -11,7 +11,7 @@ BUE.preprocess.tab = function(E, $) {
blocks: true //indent/unindent selected text blocks without overwriting.
};
- $(E.textArea).keydown(function(e) {
+ $(E.textArea).bind('keydown.bue', function(e) {
if (e.keyCode == 9) {
if (e.ctrlKey && e.originalEvent.altKey) {//enable-disable
E.tabs.on = !E.tabs.on;

0 comments on commit ec8d3d0

Please sign in to comment.