no need to set var, just use rjs

v1.18.x
Julian Lam 9 years ago
parent 6470f2ef53
commit ff8fb0e9ab

@ -1,86 +1,82 @@
'use strict'; 'use strict';
/* global bootbox, translator */ /* global bootbox */
var overrides = overrides || {}; var overrides = overrides || {};
if ('undefined' !== typeof window) { if ('undefined' !== typeof window) {
(function ($, undefined) { (function ($, undefined) {
var translator; require(['translator'], function(translator) {
require(['translator'], function(_translator) { $.fn.getCursorPosition = function() {
translator = _translator; var el = $(this).get(0);
}); var pos = 0;
if('selectionStart' in el) {
$.fn.getCursorPosition = function() { pos = el.selectionStart;
var el = $(this).get(0); } else if('selection' in document) {
var pos = 0; el.focus();
if('selectionStart' in el) { var Sel = document.selection.createRange();
pos = el.selectionStart; var SelLength = document.selection.createRange().text.length;
} else if('selection' in document) { Sel.moveStart('character', -el.value.length);
el.focus(); pos = Sel.text.length - SelLength;
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();
} }
}); return pos;
}; };
//http://stackoverflow.com/questions/511088/use-javascript-to-place-cursor-at-end-of-text-in-text-input-element $.fn.selectRange = function(start, end) {
$.fn.putCursorAtEnd = function() { if(!end) {
return this.each(function() { end = start;
$(this).focus();
if (this.setSelectionRange) {
var len = $(this).val().length * 2;
this.setSelectionRange(len, len);
} else {
$(this).val($(this).val());
} }
this.scrollTop = 999999; return this.each(function() {
}); if (this.setSelectionRange) {
}; this.focus();
this.setSelectionRange(start, end);
$.fn.translateHtml = function(str) { } else if (this.createTextRange) {
return translate(this, 'html', str); var range = this.createTextRange();
}; range.collapse(true);
range.moveEnd('character', end);
$.fn.translateText = function(str) { range.moveStart('character', start);
return translate(this, 'text', str); range.select();
}; }
$.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);
}); });
}); };
}
//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:{}}); })(jQuery || {fn:{}});
(function(){ (function(){
@ -107,43 +103,40 @@ if ('undefined' !== typeof window) {
})(); })();
overrides.overrideBootbox = function () { overrides.overrideBootbox = function () {
var dialog = bootbox.dialog, require(['translator'], function(translator) {
prompt = bootbox.prompt, var dialog = bootbox.dialog,
confirm = bootbox.confirm; 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);
});
}
var translator; bootbox.dialog = function() {
require(['translator'], function(_translator) { var modal = $(dialog.apply(this, arguments)[0]);
translator = _translator; 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;
};
}); });
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;
};
bootbox.confirm = function() {
var modal = $(confirm.apply(this, arguments)[0]);
translate(modal);
return modal;
};
}; };
overrides.overrideTimeago = function() { overrides.overrideTimeago = function() {

Loading…
Cancel
Save