Skip to content

Commit

Permalink
opts values now passing with data('uxTextLimit')
Browse files Browse the repository at this point in the history
data-opt name changed, and ready/selector classes removed from wrapper
  • Loading branch information
bcinarli committed Dec 24, 2014
1 parent 84b1d34 commit 3e3a1cb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/_uxrocket-textlimit.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* @author Bilal Cinarli */
$version: 0.2;
$version: 0.6.0;

/** -------------------------------------------
Text Limit functions
Expand Down
33 changes: 21 additions & 12 deletions lib/uxrocket.textlimit.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
opts;


var TextLimit = function(el,options){
var TextLimit = function(el,options, selector){
var $el = $(el);

opts = $.extend({}, defaults, options, $el.data());
opts.maxLength = parseInt($el.attr('maxlength'));

$el.data('opts', opts);
$el.data('uxTextLimit', opts);

// set plugin layout for css and additional objects
setLayout($el);
Expand All @@ -36,17 +36,24 @@
bindUIActions($el, opts.maxLength);
};

var setLayout = function($el){
var columns = ' ' + $el.context.className,
$remaining = $el.siblings(opts.remaining),
chars = opts.maxLength - $el.val().length,
var setLayout = function($el){
var columns = '',
_opts = $el.data('uxTextLimit'),
$remaining = $el.siblings(_opts.remaining),
chars = _opts.maxLength - $el.val().length,
visible = '';

columns = ' ' + $el.context.className.replace('uxitd-textlimit-ready', '');

if(_opts.selector.charAt(0) == '.') {
columns = columns.replace(' ' + _opts.selector.substr(1), '');
}

if(chars < 0){
chars = 0;
}

if(opts.visible === false){
if(_opts.visible === false){
visible = ' uxitd-hide-remaining';
}

Expand All @@ -58,7 +65,7 @@
}

if($remaining.length < 1){
$el.after('<span title="Kalan karakter sayısı" class="uxitd-textlimit-remaining ' + opts.remaining.substring(1, opts.remaining.length) + '">' + chars + '</span>');
$el.after('<span title="Kalan karakter sayısı" class="uxitd-textlimit-remaining ' + _opts.remaining.substring(1, _opts.remaining.length) + '">' + chars + '</span>');
}
else {
$remaining.addClass('uxitd-textlimit-remaining').attr('title', 'Kalan karakter sayısı');
Expand Down Expand Up @@ -92,7 +99,7 @@
var charCount = function($el, maxLength, $remaining){
var currentVal = $el.val(),
currentSize = currentVal.length,
opts = $el.data('opts'),
_opts = $el.data('uxTextLimit'),
remaining = maxLength - currentSize;

if(remaining < 0)
Expand All @@ -102,13 +109,15 @@
}

if(remaining === 0){
callback(opts.onLimit);
callback(_opts.onLimit);
}

$remaining.text(remaining);
};

ux = $.fn.textlimit = $.uxlimit = function(options){
var selector = this.selector;

return this.each(function(){
var $el = $(this),
limit;
Expand All @@ -120,12 +129,12 @@
$el.addClass('uxitd-textlimit-ready');

// call the constructor
limit = new TextLimit(this, options);
limit = new TextLimit(this, options, selector);
});
};

// version
ux.version = "0.5.1";
ux.version = "0.6.0";

// settings
ux.settings = defaults;
Expand Down
4 changes: 4 additions & 0 deletions version.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
## Versiyon 0.6.0
- DEĞİŞİKLİK: Input elemanından wrapper üzerine class isimleri aktarılırken, "uxitd-textlimit-ready" ve selector classı kaldırılmaya başlandı.
- FIX: Diğer pluginlerden gelen data ile karıştığı için data('opt') tanımları data('uxTextLimit') olarak değiştirildi.

## Versiyon 0.5.1
- FIX: Class kontrolleri yüzünden, eklenecek eleman inputun kendisi mi yoksa değil mi kontrolü eklendi.

0 comments on commit 3e3a1cb

Please sign in to comment.