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:
parent
4915b0cb9e
commit
662ad0f7bb
|
@ -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) {
|
||||||
var tCleaner = new RegExp('@[^ ]+|![^ ]+|#[^ ]+|^RT[: ]{1}| RT | RT: |^RD[: ]{1}| RD | RD: |[♺♻:]+', 'g')
|
origInit(form);
|
||||||
tArea.keyup(function(){
|
var tArea = form.find(".notice_data-text:first");
|
||||||
var cleaned = tArea.val().replace(tCleaner, '').replace(/^[ ]+/, '');
|
if (tArea.length > 0) {
|
||||||
if($().isRTL(cleaned))
|
var tCleaner = new RegExp('@[^ ]+|![^ ]+|#[^ ]+|^RT[: ]{1}| RT | RT: |^RD[: ]{1}| RD | RD: |[♺♻:]+', 'g')
|
||||||
tArea.css('direction', 'rtl');
|
var ping = function(){
|
||||||
else
|
var cleaned = tArea.val().replace(tCleaner, '').replace(/^[ ]+/, '');
|
||||||
tArea.css('direction', 'ltr');
|
if($().isRTL(cleaned))
|
||||||
});
|
tArea.css('direction', 'rtl');
|
||||||
});
|
else
|
||||||
|
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);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user