From f183918883a29dfdafdd097edcabf459bc4b7f89 Mon Sep 17 00:00:00 2001 From: Rashad Majali Date: Tue, 30 Apr 2013 15:28:51 +0300 Subject: [PATCH 1/2] adding 'RTL' support. --- jquery.superLabels.js | 19 ++++++++++++------- jquery.superLabels.min.js | 10 ---------- 2 files changed, 12 insertions(+), 17 deletions(-) delete mode 100644 jquery.superLabels.min.js diff --git a/jquery.superLabels.js b/jquery.superLabels.js index a464328..8435fa5 100644 --- a/jquery.superLabels.js +++ b/jquery.superLabels.js @@ -21,12 +21,13 @@ easingIn:($.easing && $.easing.def ? 'easeInOutCubic' : false), // The easing in function to use for the slide. easingOut:($.easing && $.easing.def ? 'easeInOutCubic' : false), // The easing out function to use for the slide. fadeDuration:250, // Duration of animation when it's fade only. - labelLeft:0, // The distance from the left for the label. + labelOffset:0, // The distance from the left/right for the label. labelTop:0, // The distance from the top for the label. noAnimate:false, // Whether or not to animate (slide and fade) the label. If true, we'll just hide it. opacity:0.5, // The opacity to fade the label to. slide:true, // Whether or not to slide the label across the input field. - wrapSelector:false // The selector for the element you have wrapping each field. + wrapSelector:false, // The selector for the element you have wrapping each field. + rtl: false }, acceptedInputTypes = ['text', 'search', 'url', 'tel', 'email', 'password', 'number'], acceptedElements = ['input', 'textarea', 'select'], @@ -186,13 +187,15 @@ } _field.css({ zIndex:_defaults.baseZindex+1 }).addClass('sl_field'); - _label.css({ - left:_noVal(_field) ? _defaults.labelLeft : $(_field).width()-_label.width(), + var labelCss = { opacity:_opacity, position:'absolute', top:_defaults.labelTop, zIndex:_defaults.baseZindex+2 - }).addClass('sl_label'); + }; + var pos = _defaults.rtl ? 'right' : 'left'; + labelCss[pos] = _noVal(_field) ? _defaults.labelOffset : $(_field).width()-_label.width(); + _label.css(labelCss).addClass('sl_label'); } }; @@ -212,7 +215,8 @@ } if (_defaults.slide) { - _to.left = $(this).width()-_label.width(); + var pos = _defaults.rtl ? 'right' : 'left'; + _to[pos] = $(this).width()-_label.width(); _to.opacity = _defaults.opacity; } else { _duration = _defaults.fadeDuration; @@ -236,7 +240,8 @@ } if (_defaults.slide) { - _to.left = _defaults.labelLeft; + var pos = _defaults.rtl ? 'right' : 'left'; + _to[pos] = _defaults.labelOffset; } else { _duration = _defaults.fadeDuration; } diff --git a/jquery.superLabels.min.js b/jquery.superLabels.min.js deleted file mode 100644 index c2699c7..0000000 --- a/jquery.superLabels.min.js +++ /dev/null @@ -1,10 +0,0 @@ -/*! - * Title: jQuery Super Labels Plugin - Give your forms a helping of awesome! - * Author: Rémy Bach - * Version: 2.0.4 - * License: http://remybach.mit-license.org - * Url: http://github.com/remybach/jQuery.superLabels - * Description: - * This plugin allows you to display your form labels on top of your form fields, saving you space on your page. - */ -;(function(t){"use strict";var e,a,i,s,n,l,o,r,d={autoCharLimit:!1,baseZindex:0,duration:500,easingIn:t.easing&&t.easing.def?"easeInOutCubic":!1,easingOut:t.easing&&t.easing.def?"easeInOutCubic":!1,fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:!1,opacity:.5,slide:!0,wrapSelector:!1},u=["text","search","url","tel","email","password","number"],h=["input","textarea","select"];t.fn.superLabels=function(l){var o,r=[];return 0===this.length?!1:(o=t.extend({},d),t(this).data("slDefaults",t.extend(o,l||{})).addClass("sl-defaults"),1===this.length&&/form/i.test(this[0].tagName)?r=t(h.join(","),this):this.length>1?this.each(function(){/form/i.test(this.tagName)?t.merge(r,t(h.join(","),this)):r.push(this)}):r=this,t(r).each(function(){var l,o,r=t(this),d=r.attr("placeholder");return-1===("input"===r[0].tagName.toLowerCase()&&t.inArray(r.attr("type"),u))&&-1!==t.inArray(r[0].tagName.toLowerCase(),h)?!0:(l=e(this),d&&(0===l.length?(o='",o+="",o=t(o),l=o,r.before(l)):l.attr("title",d),r.removeAttr("placeholder")),0===l.length?!0:(a(r,l),this.tagName.match(/select/i)||(r.focus(i),r.blur(s),r.change(s),r.bind("input",n),r.bind("propertychange",s),r.keyup(n),l.click(function(){r.focus()})),void 0))}))},e=function(e){var a,i=t(e).closest(".sl-defaults").data("slDefaults"),s=t(e).siblings("label");return 0===s.length&&(i.wrapSelector?s=t(e).parents(i.wrapSelector).find("label"):(a=e.id||e.name,s=t('[for="'+a+'"]'))),s},a=function(e,a){var i,s=e.data("slCharLimit"),n=t(e).closest(".sl-defaults").data("slDefaults"),d=0;e[0].tagName.match(/select/i)?(i=0===e.find("[selected]").length?" selected":"",e.prepend('"),a.css("display","none")):(("auto"===s||n.autoCharLimit&&isNaN(s))&&r(e,a),l(e)?d=1:o(e)&&(d=n._opacity),e.css({zIndex:n.baseZindex+1}).addClass("sl_field"),a.css({left:l(e)?n.labelLeft:t(e).width()-a.width(),opacity:d,position:"absolute",top:n.labelTop,zIndex:n.baseZindex+2}).addClass("sl_label"))},i=function(){var a,i=t(this).closest(".sl-defaults").data("slDefaults"),s=i.duration,n={opacity:0};if(l(this)){if(a=e(this),i.noAnimate)return a.hide(),!1;i.slide?(n.left=t(this).width()-a.width(),n.opacity=i.opacity):s=i.fadeDuration,a.stop(!0,!1).animate(n,s,i.easingOut)}},s=function(){var a,i=t(this).closest(".sl-defaults").data("slDefaults"),s=i.duration,o={opacity:1};if(l(this)){if(a=e(this),i.noAnimate)return a.show(),!1;i.slide?o.left=i.labelLeft:s=i.fadeDuration,a.stop(!0,!1).animate(o,s,i.easingOut)}else n.apply(this)},n=function(){var a,i=t(this).closest(".sl-defaults").data("slDefaults"),s=0;return i.noAnimate?!1:(a=e(this),l(this)&&a.css("opacity")>0||!l(this)&&0===a.css("opacity")?!1:((l(this)&&0!==a.css("opacity")||o(this))&&(s=i.opacity),a.stop(!0,!1).animate({opacity:s},i.fadeDuration,i.easingOut),void 0))},l=function(e){return""===t(e).val()},o=function(e){var a=t(e).data("slCharLimit");return a&&"number"==typeof a?(e=e.length?e[0]:e,a&&e.value&&a>=e.value.length):!1},r=function(e,a){var i,s,n="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",l=["font-family","font-size","font-weight","letter-spacing","line-height","text-shadow","text-transform"],o=t("
"+n+"
");t.each(l,function(t,a){o.css(a,e.css(a))}),o.css({position:"absolute",visibility:"hidden"}),e.parent().append(o),s=Math.round(o.width()/n.length),o.remove(),i=e.width()-a.width(),e.data("slCharLimit",Math.floor(i/s))}})(jQuery); \ No newline at end of file From 16495006f3d757a05498fb20a4d53601955d55c3 Mon Sep 17 00:00:00 2001 From: Rashad Majali Date: Tue, 30 Apr 2013 15:41:40 +0300 Subject: [PATCH 2/2] RTL comment. --- jquery.superLabels.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jquery.superLabels.js b/jquery.superLabels.js index 8435fa5..9567548 100644 --- a/jquery.superLabels.js +++ b/jquery.superLabels.js @@ -27,7 +27,7 @@ opacity:0.5, // The opacity to fade the label to. slide:true, // Whether or not to slide the label across the input field. wrapSelector:false, // The selector for the element you have wrapping each field. - rtl: false + rtl: false // is direction 'Right-To-Left' ? }, acceptedInputTypes = ['text', 'search', 'url', 'tel', 'email', 'password', 'number'], acceptedElements = ['input', 'textarea', 'select'], @@ -347,4 +347,4 @@ } }; /* /nominify */ -})(jQuery); \ No newline at end of file +})(jQuery);