vendor/assets/javascripts/metro-ui/input-control.js in metro-ui-rails-0.15.8.12 vs vendor/assets/javascripts/metro-ui/input-control.js in metro-ui-rails-0.15.8.13
- old
+ new
@@ -1,11 +1,17 @@
/**
* jQuery plugin for input elements for Metro UI CSS framework
*/
(function($) {
+ var pluginName = 'Input',
+ initAllSelector = '.input-control',
+ paramKeys = [];
- $.Input = function(element, options) {
+ $[pluginName] = function(element, options) {
+ if (!element) {
+ return $()[pluginName]({initAll: true});
+ }
var defaults = {
};
var plugin = this;
@@ -24,80 +30,84 @@
/**
* initialize text input element behavior
*/
var initTextInput = function () {
- var helper,
- $helper,
+ var $helper,
input;
- helper = $element.children('.helper').get(0);
+ $helper = $element.children('.helper');
- if (!helper) {
+ if (!$helper.get(0)) {
return;
}
- $helper = $(helper);
+ $helper.attr('tabindex', '-1');
+ $helper.attr('type', 'button');
- // clear text when clock on helper
+ // clear text when click on helper
$helper.on('click', function () {
input = $element.children('input');
- input.attr('value', '');
+ if (input.prop('readonly')) {
+ return;
+ }
+ input.val('');
input.focus();
- }).on('click', function(e){e.preventDefault(); return false;});
+ });
};
/**
* initialize password input element behavior
*/
var initPasswordInput = function () {
- var helper,
- $helper,
+ var $helper,
password,
text;
- helper = $element.children('.helper').get(0);
- if (!helper) {
+ $helper = $element.children('.helper');
+ if (!$helper.get(0)) {
return;
}
text = $('<input type="text" />');
password = $element.children('input');
- $helper = $(helper);
+ $helper.attr('tabindex', '-1');
+ $helper.attr('type', 'button');
// insert text element and hode password element when push helper
$helper.on('mousedown', function () {
password.hide();
text.insertAfter(password);
- text.attr('value', password.attr('value'));
- }).on('click', function(e){e.preventDefault(); return false;});
+ text.val(password.val());
+ });
// return password and remove text element
$helper.on('mouseup, mouseout', function () {
text.detach();
password.show();
password.focus();
- }).on('click', function(e){e.preventDefault(); return false;});
+ });
};
plugin.init();
};
- $.fn.Input = function(options) {
- return this.each(function() {
- if (undefined == $(this).data('Input')) {
- var plugin = new $.Input(this, options);
- $(this).data('Input', plugin);
+ $.fn[pluginName] = function(options) {
+ var elements = options && options.initAll ? $(initAllSelector) : this;
+ return elements.each(function() {
+ var that = $(this),
+ params = {},
+ plugin;
+ if (undefined == that.data(pluginName)) {
+ $.each(paramKeys, function(index, key){
+ params[key[0].toLowerCase() + key.slice(1)] = that.data('param' + key);
+ });
+ plugin = new $[pluginName](this, params);
+ that.data(pluginName, plugin);
}
});
- }
-
-})(jQuery);
-
-$(function(){
- var allInputs = $('.input-control');
- allInputs.each(function (index, input) {
- var params = {};
- $input = $(input);
-
- $input.Input(params);
+ };
+ // autoinit
+ $(function(){
+ //$()[pluginName]({initAll: true});
});
-});
+
+})(jQuery);
\ No newline at end of file