Update DirectionDetector for reusable notice forms.

Also tweaked it to trigger on cut/paste, and to reset when the form resets.
This commit is contained in:
Brion Vibber 2011-03-09 18:11:08 -08:00
parent 4915b0cb9e
commit 662ad0f7bb

View File

@ -47,15 +47,26 @@
return true; return true;
return false; return false;
}; };
$(document).ready(function(){ var origInit = SN.Init.NoticeFormSetup;
var tArea = $("#notice_data-text"); SN.Init.NoticeFormSetup = function(form) {
origInit(form);
var tArea = form.find(".notice_data-text:first");
if (tArea.length > 0) {
var tCleaner = new RegExp('@[^ ]+|![^ ]+|#[^ ]+|^RT[: ]{1}| RT | RT: |^RD[: ]{1}| RD | RD: |[♺♻:]+', 'g') var tCleaner = new RegExp('@[^ ]+|![^ ]+|#[^ ]+|^RT[: ]{1}| RT | RT: |^RD[: ]{1}| RD | RD: |[♺♻:]+', 'g')
tArea.keyup(function(){ var ping = function(){
var cleaned = tArea.val().replace(tCleaner, '').replace(/^[ ]+/, ''); var cleaned = tArea.val().replace(tCleaner, '').replace(/^[ ]+/, '');
if($().isRTL(cleaned)) if($().isRTL(cleaned))
tArea.css('direction', 'rtl'); tArea.css('direction', 'rtl');
else else
tArea.css('direction', 'ltr'); tArea.css('direction', 'ltr');
};
tArea.bind('keyup cut paste', function() {
// cut/paste trigger before the change
window.setTimeout(ping, 0);
}); });
form.bind('reset', function() {
tArea.css('direction', 'ltr');
}); });
}
};
})(jQuery); })(jQuery);