/*
* jQuery liTranslit v 1.4
* http://masscode.ru/index.php/k2/item/28-litranslit
*
* Copyright 2013, Linnik Yura
* Free to use
*
* Last Update 25.10.2014
*/
(function ($) {
var methods = {
init: function (options) {
var o = {
eventType:'keyup blur copy paste cut start',
elAlias: $(this), //Элемент, в который будет записываться результат транслитерации или false
reg:'', //'" "="-","ж"="zzzz"' or false or ''
translated: function (el, text, eventType) {},
caseType: 'lower', // lower(default), upper, inherit - регистр выходных данных
status:true,
string:'' //используется для транслита строковой переменной
};
if (options) {
$.extend(o, options);
}
var general = $(this);
if(!general.length){
general = $('
').text(o.string);
}
return general.each(function(){
var
elName = $(this),
elAlias = o.elAlias.length ? o.elAlias.css({wordWrap:'break-word'}) : general.css({wordWrap:'break-word'}),
nameVal;
elName.data({
status:o.status
})
var inser_trans = function(result,e) {
if(o.caseType == 'upper'){
result = result.toUpperCase();
}
if(o.caseType == 'lower'){
result = result.toLowerCase();
}
if(elName.data('status') && o.elAlias){
if (elAlias.prop("value") !== undefined) {
elAlias.val(result);
}else{
elAlias.html(result);
}
}
if(result != ''){
if (o.translated !== undefined) {
var type;
if(e == undefined){
type = 'no event';
}else{
type = e.type;
}
o.translated(elName, result, type);
}
}
}
var customReg = function(str){
customArr = o.reg.split(',');
for(var i=0;i|\!|\||@|#|$|%|^|\^|\$|\\|\/|&|\*|\(\)|\|\/|;|\+|№|,|\?|:|\[|\]/g, "");
return string;
};
})
},
disable: function () {
$(this).data({
status:false
})
},
enable: function () {
$(this).data({
status:true
})
}
};
$.fn.liTranslit = function (method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Метод ' + method + ' в jQuery.liTranslit не существует');
}
};
})(jQuery);