Skip to content

Node.js based forum software built for the modern web

no need to set var, just use rjs

Julian Lamff8fb0e9abf7
diff --git a/public/src/overrides.js b/public/src/overrides.js
index 1d16328b6b..62eca1d568 100644
--- a/public/src/overrides.js
+++ b/public/src/overrides.js
@@ -1,86 +1,82 @@
'use strict';
-/* global bootbox, translator */
+/* global bootbox */
var overrides = overrides || {};
if ('undefined' !== typeof window) {
(function ($, undefined) {
- var translator;
- require(['translator'], function(_translator) {
- translator = _translator;
- });
-
- $.fn.getCursorPosition = function() {
- var el = $(this).get(0);
- var pos = 0;
- if('selectionStart' in el) {
- pos = el.selectionStart;
- } else if('selection' in document) {
- el.focus();
- var Sel = document.selection.createRange();
- var SelLength = document.selection.createRange().text.length;
- Sel.moveStart('character', -el.value.length);
- pos = Sel.text.length - SelLength;
- }
- return pos;
- };
-
- $.fn.selectRange = function(start, end) {
- if(!end) {
- end = start;
- }
- return this.each(function() {
- if (this.setSelectionRange) {
- this.focus();
- this.setSelectionRange(start, end);
- } else if (this.createTextRange) {
- var range = this.createTextRange();
- range.collapse(true);
- range.moveEnd('character', end);
- range.moveStart('character', start);
- range.select();
+ require(['translator'], function(translator) {
+ $.fn.getCursorPosition = function() {
+ var el = $(this).get(0);
+ var pos = 0;
+ if('selectionStart' in el) {
+ pos = el.selectionStart;
+ } else if('selection' in document) {
+ el.focus();
+ var Sel = document.selection.createRange();
+ var SelLength = document.selection.createRange().text.length;
+ Sel.moveStart('character', -el.value.length);
+ pos = Sel.text.length - SelLength;
}
- });
- };
+ return pos;
+ };
- //http://stackoverflow.com/questions/511088/use-javascript-to-place-cursor-at-end-of-text-in-text-input-element
- $.fn.putCursorAtEnd = function() {
- return this.each(function() {
- $(this).focus();
-
- if (this.setSelectionRange) {
- var len = $(this).val().length * 2;
- this.setSelectionRange(len, len);
- } else {
- $(this).val($(this).val());
+ $.fn.selectRange = function(start, end) {
+ if(!end) {
+ end = start;
}
- this.scrollTop = 999999;
- });
- };
-
- $.fn.translateHtml = function(str) {
- return translate(this, 'html', str);
- };
-
- $.fn.translateText = function(str) {
- return translate(this, 'text', str);
- };
-
- $.fn.translateVal = function(str) {
- return translate(this, 'val', str);
- };
-
- function translate(elements, type, str) {
- return elements.each(function() {
- var el = $(this);
- translator.translate(str, function(translated) {
- el[type](translated);
+ return this.each(function() {
+ if (this.setSelectionRange) {
+ this.focus();
+ this.setSelectionRange(start, end);
+ } else if (this.createTextRange) {
+ var range = this.createTextRange();
+ range.collapse(true);
+ range.moveEnd('character', end);
+ range.moveStart('character', start);
+ range.select();
+ }
});
- });
- }
-
+ };
+
+ //http://stackoverflow.com/questions/511088/use-javascript-to-place-cursor-at-end-of-text-in-text-input-element
+ $.fn.putCursorAtEnd = function() {
+ return this.each(function() {
+ $(this).focus();
+
+ if (this.setSelectionRange) {
+ var len = $(this).val().length * 2;
+ this.setSelectionRange(len, len);
+ } else {
+ $(this).val($(this).val());
+ }
+ this.scrollTop = 999999;
+ });
+ };
+
+ $.fn.translateHtml = function(str) {
+ return translate(this, 'html', str);
+ };
+
+ $.fn.translateText = function(str) {
+ return translate(this, 'text', str);
+ };
+
+ $.fn.translateVal = function(str) {
+ return translate(this, 'val', str);
+ };
+
+ function translate(elements, type, str) {
+ return elements.each(function() {
+ var el = $(this);
+ translator.translate(str, function(translated) {
+ el[type](translated);
+ });
+ });
+ }
+ });
})(jQuery || {fn:{}});
(function(){
@@ -107,43 +103,40 @@ if ('undefined' !== typeof window) {
})();
overrides.overrideBootbox = function () {
- var dialog = bootbox.dialog,
- prompt = bootbox.prompt,
- confirm = bootbox.confirm;
-
- var translator;
- require(['translator'], function(_translator) {
- translator = _translator;
- });
-
- function translate(modal) {
- var header = modal.find('.modal-header'),
- footer = modal.find('.modal-footer');
- translator.translate(header.html(), function(html) {
- header.html(html);
- });
- translator.translate(footer.html(), function(html) {
- footer.html(html);
- });
- }
-
- bootbox.dialog = function() {
- var modal = $(dialog.apply(this, arguments)[0]);
- translate(modal);
- return modal;
- };
-
- bootbox.prompt = function() {
- var modal = $(prompt.apply(this, arguments)[0]);
- translate(modal);
- return modal;
- };
+ require(['translator'], function(translator) {
+ var dialog = bootbox.dialog,
+ prompt = bootbox.prompt,
+ confirm = bootbox.confirm;
+
+ function translate(modal) {
+ var header = modal.find('.modal-header'),
+ footer = modal.find('.modal-footer');
+ translator.translate(header.html(), function(html) {
+ header.html(html);
+ });
+ translator.translate(footer.html(), function(html) {
+ footer.html(html);
+ });
+ }
- bootbox.confirm = function() {
- var modal = $(confirm.apply(this, arguments)[0]);
- translate(modal);
- return modal;
- };
+ bootbox.dialog = function() {
+ var modal = $(dialog.apply(this, arguments)[0]);
+ translate(modal);
+ return modal;
+ };
+
+ bootbox.prompt = function() {
+ var modal = $(prompt.apply(this, arguments)[0]);
+ translate(modal);
+ return modal;
+ };
+
+ bootbox.confirm = function() {
+ var modal = $(confirm.apply(this, arguments)[0]);
+ translate(modal);
+ return modal;
+ };
+ });
};
overrides.overrideTimeago = function() {