diff --git a/src/bootstrap-filestyle.js b/src/bootstrap-filestyle.js index e62264c..5ee1d4b 100644 --- a/src/bootstrap-filestyle.js +++ b/src/bootstrap-filestyle.js @@ -251,10 +251,55 @@ 'clip' : 'rect(0px 0px 0px 0px)' // using 0px for work in IE8 }).attr('tabindex', "-1").after(_self.$elementFilestyle); - _self.$elementFilestyle.find(_self.options.buttonBefore ? 'label' : ':input').css({ - 'border-top-left-radius': '.25rem', - 'border-bottom-left-radius': '.25rem' - }); + if($('html').attr("dir") === "rtl" || $('body').css('direction') === "rtl"){ + + if(_self.options.buttonBefore === true){ + _self.$elementFilestyle.find('label').css({ + 'border-top-left-radius': '0rem', + 'border-bottom-left-radius': '0rem' + }); + _self.$elementFilestyle.find(':input').css({ + 'border-top-left-radius': '.25rem', + 'border-bottom-left-radius': '.25rem', + 'border-top-right-radius': '0rem', + 'border-bottom-right-radius': '0rem' + }); + }else{ + _self.$elementFilestyle.find(':input').css({ + 'border-top-right-radius': '.25rem', + 'border-bottom-right-radius': '.25rem', + 'border-top-left-radius': '0rem', + 'border-bottom-left-radius': '0rem' + }); + _self.$elementFilestyle.find('label').css({ + 'border-top-right-radius': '0rem', + 'border-bottom-right-radius': '0rem' + }); + } + }else{ + + if(_self.options.buttonBefore === true){ + _self.$elementFilestyle.find('label').css({ + 'border-top-right-radius': '0rem', + 'border-bottom-right-radius': '0rem' + }); + _self.$elementFilestyle.find(':input').css({ + 'border-top-left-radius': '0rem', + 'border-bottom-left-radius': '0rem' + }); + }else{ + _self.$elementFilestyle.find(':input').css({ + 'border-top-left-radius': '.25rem', + 'border-bottom-left-radius': '.25rem', + 'border-top-right-radius': '0rem', + 'border-bottom-right-radius': '0rem' + }); + _self.$elementFilestyle.find('label').css({ + 'border-top-left-radius': '0rem', + 'border-bottom-left-radius': '0rem' + }); + } + } _self.$elementFilestyle.find('[name="filedrag"]').css({ position: 'absolute', @@ -420,4 +465,4 @@ $this.filestyle(options); }); }); -})(window.jQuery); \ No newline at end of file +})(window.jQuery); diff --git a/src/bootstrap-filestyle.min.js b/src/bootstrap-filestyle.min.js index e09feea..aeed12d 100644 --- a/src/bootstrap-filestyle.min.js +++ b/src/bootstrap-filestyle.min.js @@ -7,4 +7,4 @@ * Version 2.1.0 * Licensed under the MIT license. */ -!function(e){"use strict";var t=0,i=function(t,i){this.options=i,this.$elementFilestyle=[],this.$element=e(t)};i.prototype={clear:function(){this.$element.val(""),this.$elementFilestyle.find(":text").val(""),this.$elementFilestyle.find(".badge").remove()},destroy:function(){this.$element.removeAttr("style").removeData("filestyle"),this.$elementFilestyle.remove()},disabled:function(e){return e!==!0&&e!==!1?this.options.disabled:(this.options.disabled=e,this.$element.prop("disabled",this.options.disabled),this.$elementFilestyle.find("label").prop("disabled",this.options.disabled),this.options.disabled?this.$elementFilestyle.find("label").css("opacity","0.65"):this.$elementFilestyle.find("label").css("opacity","1"),void 0)},dragdrop:function(e){return e!==!0&&e!==!1?this.options.dragdrop:void(this.options.dragdrop=e)},buttonBefore:function(e){if(e===!0)this.options.buttonBefore||(this.options.buttonBefore=e,this.options.input&&(this.$elementFilestyle.remove(),this.constructor(),this.pushNameFiles()));else{if(e!==!1)return this.options.buttonBefore;this.options.buttonBefore&&(this.options.buttonBefore=e,this.options.input&&(this.$elementFilestyle.remove(),this.constructor(),this.pushNameFiles()))}},input:function(e){if(e===!0)this.options.input||(this.options.input=e,this.options.buttonBefore?this.$elementFilestyle.append(this.htmlInput()):this.$elementFilestyle.prepend(this.htmlInput()),this.pushNameFiles(),this.$elementFilestyle.find(".group-span-filestyle").addClass("input-group-btn"));else{if(e!==!1)return this.options.input;this.options.input&&(this.options.input=e,this.$elementFilestyle.find(":text").remove(),this.$elementFilestyle.find(".group-span-filestyle").removeClass("input-group-btn"))}},size:function(e){if(void 0===e)return this.options.size;this.options.size=e;var t=this.$elementFilestyle.find("label"),i=this.$elementFilestyle.find("input");t.removeClass("btn-lg btn-sm"),i.removeClass("form-control-lg form-control-sm"),"nr"!=this.options.size&&(t.addClass("btn-"+this.options.size),i.addClass("form-control-"+this.options.size))},placeholder:function(e){return void 0===e?this.options.placeholder:(this.options.placeholder=e,void this.$elementFilestyle.find("input").attr("placeholder",e))},text:function(e){return void 0===e?this.options.text:(this.options.text=e,void this.$elementFilestyle.find("label .text").html(this.options.text))},btnClass:function(e){return void 0===e?this.options.btnClass:(this.options.btnClass=e,void this.$elementFilestyle.find("label").attr({"class":"btn "+this.options.btnClass+" btn-"+this.options.size}))},badge:function(e){if(e===!0){this.options.badge=e;var t=this.pushNameFiles();this.$elementFilestyle.find("label").append(' '+t.length+"")}else{if(e!==!1)return this.options.badge;this.options.badge=e,this.$elementFilestyle.find(".badge").remove()}},badgeName:function(e){return void 0===e?this.options.badgeName:(this.options.badgeName=e,void this.$elementFilestyle.find(".badge").attr({"class":"badge "+this.options.badgeName}))},htmlIcon:function(e){return void 0!==e&&(this.options.htmlIcon=e),this.options.htmlIcon},htmlInput:function(){return this.options.input?' ':""},pushNameFiles:function(){var e="",t=[];void 0===this.$element[0].files?t[0]={name:this.$element[0]&&this.$element[0].value}:t=this.$element[0].files;for(var i=0;i",n=i.options.buttonBefore?l+i.htmlInput():i.htmlInput()+l,i.$elementFilestyle=e('
'+n+"
"),i.$elementFilestyle.find(".group-span-filestyle").attr("tabindex","0").keypress(function(e){return 13===e.keyCode||32===e.charCode?(i.$elementFilestyle.find("label").click(),!1):void 0}),i.$element.css({position:"absolute",clip:"rect(0px 0px 0px 0px)"}).attr("tabindex","-1").after(i.$elementFilestyle),i.$elementFilestyle.find(i.options.buttonBefore?"label":":input").css({"border-top-left-radius":".25rem","border-bottom-left-radius":".25rem"}),i.$elementFilestyle.find('[name="filedrag"]').css({position:"absolute",width:"100%",height:i.$elementFilestyle.height()+"px","z-index":-1}),(i.options.disabled||i.$element.attr("disabled"))&&(i.$element.attr("disabled","true"),i.options.disabled?i.$elementFilestyle.find("label").css("opacity","0.65"):i.$elementFilestyle.find("label").css("opacity","1")),i.$element.change(function(){var e=i.pushNameFiles();i.options.badge?0==i.$elementFilestyle.find(".badge").length?i.$elementFilestyle.find("label").append(' '+e.length+""):0==e.length?i.$elementFilestyle.find(".badge").remove():i.$elementFilestyle.find(".badge").html(e.length):i.$elementFilestyle.find(".badge").remove(),i.options.onChange(e)}),window.navigator.userAgent.search(/firefox/i)>-1&&i.$elementFilestyle.find("label").click(function(){return i.$element.click(),!1}),e(document).on("dragover",function(t){t.preventDefault(),t.stopPropagation(),i.options.dragdrop&&e('[name="filedrag"]').css("z-index","9")}).on("drop",function(t){t.preventDefault(),t.stopPropagation(),i.options.dragdrop&&e('[name="filedrag"]').css("z-index","-1")}),i.$elementFilestyle.find('[name="filedrag"]').on("dragover",function(e){e.preventDefault(),e.stopPropagation()}).on("dragenter",function(e){e.preventDefault(),e.stopPropagation()}).on("drop",function(t){if(t.originalEvent.dataTransfer&&!i.options.disabled&&i.options.dragdrop&&t.originalEvent.dataTransfer.files.length){t.preventDefault(),t.stopPropagation(),i.$element[0].files=t.originalEvent.dataTransfer.files;var n=i.pushNameFiles();i.options.badge?0==i.$elementFilestyle.find(".badge").length?i.$elementFilestyle.find("label").append(' '+n.length+""):0==n.length?i.$elementFilestyle.find(".badge").remove():i.$elementFilestyle.find(".badge").html(n.length):i.$elementFilestyle.find(".badge").remove(),e('[name="filedrag"]').css("z-index","-1")}})}};var n=e.fn.filestyle;e.fn.filestyle=function(t,n){var s="",l=this.each(function(){if("file"===e(this).attr("type")){var l=e(this),o=l.data("filestyle"),a=e.extend({},e.fn.filestyle.defaults,t,"object"==typeof t&&t);o||(l.data("filestyle",o=new i(this,a)),o.constructor()),"string"==typeof t&&(s=o[t](n))}});return void 0!==typeof s?s:l},e.fn.filestyle.defaults={text:"Choose file",htmlIcon:"",btnClass:"btn-secondary",size:"nr",input:!0,badge:!1,badgeName:"badge-light",buttonBefore:!1,dragdrop:!0,disabled:!1,placeholder:"",onChange:function(){}},e.fn.filestyle.noConflict=function(){return e.fn.filestyle=n,this},e(function(){e(".filestyle").each(function(){var t=e(this),i={input:"false"!==t.attr("data-input"),htmlIcon:t.attr("data-icon"),buttonBefore:"true"===t.attr("data-buttonBefore"),disabled:"true"===t.attr("data-disabled"),size:t.attr("data-size"),text:t.attr("data-text"),btnClass:t.attr("data-btnClass"),badge:"true"===t.attr("data-badge"),dragdrop:"false"!==t.attr("data-dragdrop"),badgeName:t.attr("data-badgeName"),placeholder:t.attr("data-placeholder")};t.filestyle(i)})})}(window.jQuery); \ No newline at end of file +!function(o){"use strict";var n=0,r=function(e,t){this.options=t,this.$elementFilestyle=[],this.$element=o(e)};r.prototype={clear:function(){this.$element.val(""),this.$elementFilestyle.find(":text").val(""),this.$elementFilestyle.find(".badge").remove()},destroy:function(){this.$element.removeAttr("style").removeData("filestyle"),this.$elementFilestyle.remove()},disabled:function(e){if(!0!==e&&!1!==e)return this.options.disabled;this.options.disabled=e,this.$element.prop("disabled",this.options.disabled),this.$elementFilestyle.find("label").prop("disabled",this.options.disabled),this.options.disabled?this.$elementFilestyle.find("label").css("opacity","0.65"):this.$elementFilestyle.find("label").css("opacity","1")},dragdrop:function(e){if(!0!==e&&!1!==e)return this.options.dragdrop;this.options.dragdrop=e},buttonBefore:function(e){if(!0===e)this.options.buttonBefore||(this.options.buttonBefore=e,this.options.input&&(this.$elementFilestyle.remove(),this.constructor(),this.pushNameFiles()));else{if(!1!==e)return this.options.buttonBefore;this.options.buttonBefore&&(this.options.buttonBefore=e,this.options.input&&(this.$elementFilestyle.remove(),this.constructor(),this.pushNameFiles()))}},input:function(e){if(!0===e)this.options.input||(this.options.input=e,this.options.buttonBefore?this.$elementFilestyle.append(this.htmlInput()):this.$elementFilestyle.prepend(this.htmlInput()),this.pushNameFiles(),this.$elementFilestyle.find(".group-span-filestyle").addClass("input-group-btn"));else{if(!1!==e)return this.options.input;this.options.input&&(this.options.input=e,this.$elementFilestyle.find(":text").remove(),this.$elementFilestyle.find(".group-span-filestyle").removeClass("input-group-btn"))}},size:function(e){if(void 0===e)return this.options.size;this.options.size=e;var t=this.$elementFilestyle.find("label"),i=this.$elementFilestyle.find("input");t.removeClass("btn-lg btn-sm"),i.removeClass("form-control-lg form-control-sm"),"nr"!=this.options.size&&(t.addClass("btn-"+this.options.size),i.addClass("form-control-"+this.options.size))},placeholder:function(e){if(void 0===e)return this.options.placeholder;this.options.placeholder=e,this.$elementFilestyle.find("input").attr("placeholder",e)},text:function(e){if(void 0===e)return this.options.text;this.options.text=e,this.$elementFilestyle.find("label .text").html(this.options.text)},btnClass:function(e){if(void 0===e)return this.options.btnClass;this.options.btnClass=e,this.$elementFilestyle.find("label").attr({class:"btn "+this.options.btnClass+" btn-"+this.options.size})},badge:function(e){if(!0===e){this.options.badge=e;var t=this.pushNameFiles();this.$elementFilestyle.find("label").append(' '+t.length+"")}else{if(!1!==e)return this.options.badge;this.options.badge=e,this.$elementFilestyle.find(".badge").remove()}},badgeName:function(e){if(void 0===e)return this.options.badgeName;this.options.badgeName=e,this.$elementFilestyle.find(".badge").attr({class:"badge "+this.options.badgeName})},htmlIcon:function(e){return void 0!==e&&(this.options.htmlIcon=e),this.options.htmlIcon},htmlInput:function(){return this.options.input?' ':""},pushNameFiles:function(){var e="",t=[];void 0===this.$element[0].files?t[0]={name:this.$element[0]&&this.$element[0].value}:t=this.$element[0].files;for(var i=0;i",e=i.options.buttonBefore?t+i.htmlInput():i.htmlInput()+t,i.$elementFilestyle=o('
'+e+"
"),i.$elementFilestyle.find(".group-span-filestyle").attr("tabindex","0").keypress(function(e){if(13===e.keyCode||32===e.charCode)return i.$elementFilestyle.find("label").click(),!1}),i.$element.css({position:"absolute",clip:"rect(0px 0px 0px 0px)"}).attr("tabindex","-1").after(i.$elementFilestyle),"rtl"===o("html").attr("dir")||"rtl"===o("body").css("direction")?!0===i.options.buttonBefore?(i.$elementFilestyle.find("label").css({"border-top-left-radius":"0rem","border-bottom-left-radius":"0rem"}),i.$elementFilestyle.find(":input").css({"border-top-left-radius":".25rem","border-bottom-left-radius":".25rem","border-top-right-radius":"0rem","border-bottom-right-radius":"0rem"})):(i.$elementFilestyle.find(":input").css({"border-top-right-radius":".25rem","border-bottom-right-radius":".25rem","border-top-left-radius":"0rem","border-bottom-left-radius":"0rem"}),i.$elementFilestyle.find("label").css({"border-top-right-radius":"0rem","border-bottom-right-radius":"0rem"})):!0===i.options.buttonBefore?(i.$elementFilestyle.find("label").css({"border-top-right-radius":"0rem","border-bottom-right-radius":"0rem"}),i.$elementFilestyle.find(":input").css({"border-top-left-radius":"0rem","border-bottom-left-radius":"0rem"})):(i.$elementFilestyle.find(":input").css({"border-top-left-radius":".25rem","border-bottom-left-radius":".25rem","border-top-right-radius":"0rem","border-bottom-right-radius":"0rem"}),i.$elementFilestyle.find("label").css({"border-top-left-radius":"0rem","border-bottom-left-radius":"0rem"})),i.$elementFilestyle.find('[name="filedrag"]').css({position:"absolute",width:"100%",height:i.$elementFilestyle.height()+"px","z-index":-1}),(i.options.disabled||i.$element.attr("disabled"))&&(i.$element.attr("disabled","true"),i.options.disabled?i.$elementFilestyle.find("label").css("opacity","0.65"):i.$elementFilestyle.find("label").css("opacity","1")),i.$element.change(function(){var e=i.pushNameFiles();i.options.badge?0==i.$elementFilestyle.find(".badge").length?i.$elementFilestyle.find("label").append(' '+e.length+""):0==e.length?i.$elementFilestyle.find(".badge").remove():i.$elementFilestyle.find(".badge").html(e.length):i.$elementFilestyle.find(".badge").remove(),i.options.onChange(e)}),-1'+t.length+""):0==t.length?i.$elementFilestyle.find(".badge").remove():i.$elementFilestyle.find(".badge").html(t.length):i.$elementFilestyle.find(".badge").remove(),o('[name="filedrag"]').css("z-index","-1")}})}};var e=o.fn.filestyle;o.fn.filestyle=function(s,n){var l="",e=this.each(function(){if("file"===o(this).attr("type")){var e=o(this),t=e.data("filestyle"),i=o.extend({},o.fn.filestyle.defaults,s,"object"==typeof s&&s);t||(e.data("filestyle",t=new r(this,i)),t.constructor()),"string"==typeof s&&(l=t[s](n))}});return void 0!==typeof l?l:e},o.fn.filestyle.defaults={text:"Choose file",htmlIcon:"",btnClass:"btn-secondary",size:"nr",input:!0,badge:!1,badgeName:"badge-light",buttonBefore:!1,dragdrop:!0,disabled:!1,placeholder:"",onChange:function(){}},o.fn.filestyle.noConflict=function(){return o.fn.filestyle=e,this},o(function(){o(".filestyle").each(function(){var e=o(this),t={input:"false"!==e.attr("data-input"),htmlIcon:e.attr("data-icon"),buttonBefore:"true"===e.attr("data-buttonBefore"),disabled:"true"===e.attr("data-disabled"),size:e.attr("data-size"),text:e.attr("data-text"),btnClass:e.attr("data-btnClass"),badge:"true"===e.attr("data-badge"),dragdrop:"false"!==e.attr("data-dragdrop"),badgeName:e.attr("data-badgeName"),placeholder:e.attr("data-placeholder")};e.filestyle(t)})})}(window.jQuery); diff --git a/test/index.html b/test/index.html index d202240..6ded5aa 100644 --- a/test/index.html +++ b/test/index.html @@ -7,7 +7,7 @@ Testing - Bootstrap FileStyle - +