diff --git a/dist/angular-bootstrap-toggle.js b/dist/angular-bootstrap-toggle.js
index 2b7782a..75c46b6 100644
--- a/dist/angular-bootstrap-toggle.js
+++ b/dist/angular-bootstrap-toggle.js
@@ -1,7 +1,7 @@
(function () {
'use strict';
- angular.module('ui.toggle',[])
+ angular.module('ui.toggle', [])
.value('$toggleSuppressError', false)
@@ -41,19 +41,7 @@
* Default: ''
* Description: Appends the value to the class attribute of the toggle. This can be used to apply custom styles. Refer to Custom Styles for reference.
*/
- style: '',
- /**
- * Type: integer
- * Default: null
- * Description: Sets the width of the toggle. if set to null, width will be calculated.
- */
- width: null,
- /**
- * Type: integer
- * Default: null
- * Description: Sets the height of the toggle. if set to null, height will be calculated.
- */
- height: null
+ style: ''
})
.controller('ToggleController',
@@ -63,8 +51,10 @@
ngModelCtrl = {$setViewValue: angular.noop};
// Configuration attributes
- angular.forEach(['on', 'off', 'size', 'onstyle', 'offstyle', 'style', 'width', 'height'], function (key, index) {
+ angular.forEach(['on', 'off', 'size', 'onstyle', 'offstyle', 'style'], function (key, index) {
+ //$log.info(key + ':' + $attrs[key]);
self[key] = angular.isDefined($attrs[key]) ? (index < 6 ? $interpolate($attrs[key])($scope.$parent) : $scope.$parent.$eval($attrs[key])) : toggleConfig[key];
+ //$log.info(key + ':' + self[key]);
});
this.init = function (ngModelCtrl_) {
@@ -81,16 +71,24 @@
var labels = self.element.find('label');
angular.element(labels[0]).html(self.on);
angular.element(labels[1]).html(self.off);
-
var spans = self.element.find('span');
+ var wrapperComputedWidth = self.width || Math.max(labels[0].offsetWidth, labels[1].offsetWidth) + (spans[0].offsetWidth / 2);
+ var wrapperComputedHeight = self.height || Math.max(labels[0].offsetHeight, labels[1].offsetHeight);
- var width = self.width || Math.max(labels[0].offsetWidth, labels[1].offsetWidth) + (spans[0].offsetWidth / 2);
- var height = self.height || Math.max(labels[0].offsetHeight, labels[1].offsetHeight);
+ var divs = self.element.find('div');
+ var wrapperWidth = divs[0].offsetWidth;
+ var wrapperHeight = divs[1].offsetHeight;
- $scope.wrapperStyle = {width: width, height: height};
+ $scope.wrapperStyle = {};
+ if (wrapperWidth < wrapperComputedWidth) {
+ $scope.wrapperStyle.width = wrapperComputedWidth + 'px';
+ }
- $scope.onClass = [self.size, 'toggle-on'];
- $scope.offClass = [self.size, 'toggle-off'];
+ if (wrapperHeight < wrapperComputedHeight && self.size != 'btn-xs' && self.size != 'btn-sm') {
+ $scope.wrapperStyle.height = wrapperComputedHeight + 'px';
+ }
+ $scope.onClass = [self.onstyle, self.size, 'toggle-on'];
+ $scope.offClass = [self.offstyle, self.size, 'toggle-off'];
$scope.handleClass = [self.size, 'toggle-handle'];
};
@@ -127,7 +125,7 @@
return {
restrict: 'E',
transclude: true,
- template: '
',
+ template: '',
scope: {
bindModel: '=ngModel'
},
diff --git a/dist/angular-bootstrap-toggle.min.js b/dist/angular-bootstrap-toggle.min.js
index af3b3ea..7a0231c 100644
--- a/dist/angular-bootstrap-toggle.min.js
+++ b/dist/angular-bootstrap-toggle.min.js
@@ -1 +1 @@
-!function(){"use strict";angular.module("ui.toggle",[]).value("$toggleSuppressError",!1).constant("toggleConfig",{on:"On",off:"Off",size:"",onstyle:"btn-primary",offstyle:"btn-default",style:"",width:null,height:null}).controller("ToggleController",["$scope","$attrs","$interpolate","$log","toggleConfig","$toggleSuppressError",function(e,t,n,l,s){var a=this,o={$setViewValue:angular.noop};angular.forEach(["on","off","size","onstyle","offstyle","style","width","height"],function(l,o){a[l]=angular.isDefined(t[l])?6>o?n(t[l])(e.$parent):e.$parent.$eval(t[l]):s[l]}),this.init=function(n){o=n,o.$render=function(){a.render()},o.$viewChangeListeners.push(function(){e.$eval(t.ngChange)});var l=a.element.find("label");angular.element(l[0]).html(a.on),angular.element(l[1]).html(a.off);var s=a.element.find("span"),i=a.width||Math.max(l[0].offsetWidth,l[1].offsetWidth)+s[0].offsetWidth/2,r=a.height||Math.max(l[0].offsetHeight,l[1].offsetHeight);e.wrapperStyle={width:i,height:r},e.onClass=[a.size,"toggle-on"],e.offClass=[a.size,"toggle-off"],e.handleClass=[a.size,"toggle-handle"]},this.render=function(){this.isOn=angular.isDefined(o.$viewValue)?o.$viewValue:!1,e.wrapperClass=this.isOn?[a.onstyle,a.size,a.style]:[a.offstyle,"off ",a.size,a.style]},e.onSwitch=function(){o.$setViewValue(!o.$viewValue),o.$render()},angular.forEach(["ngModel"],function(n){var l=e.$parent.$watch(t[n],function(){o.$render()});e.$parent.$on("$destroy",function(){l()})})}]).directive("toggle",function(){return{restrict:"E",transclude:!0,template:'',scope:{bindModel:"=ngModel"},require:["toggle","ngModel"],controller:"ToggleController",controllerAs:"toggle",link:function(e,t,n,l){var s=l[0],a=l[1];s.element=t,s.init(a)}}})}();
\ No newline at end of file
+!function(){"use strict";angular.module("ui.toggle",[]).value("$toggleSuppressError",!1).constant("toggleConfig",{on:"On",off:"Off",size:"",onstyle:"btn-primary",offstyle:"btn-default",style:""}).controller("ToggleController",["$scope","$attrs","$interpolate","$log","toggleConfig","$toggleSuppressError",function(e,t,n,l,s){var o=this,a={$setViewValue:angular.noop};angular.forEach(["on","off","size","onstyle","offstyle","style"],function(l,a){o[l]=angular.isDefined(t[l])?6>a?n(t[l])(e.$parent):e.$parent.$eval(t[l]):s[l]}),this.init=function(n){a=n,a.$render=function(){o.render()},a.$viewChangeListeners.push(function(){e.$eval(t.ngChange)});var l=o.element.find("label");angular.element(l[0]).html(o.on),angular.element(l[1]).html(o.off);var s=o.element.find("span"),i=o.width||Math.max(l[0].offsetWidth,l[1].offsetWidth)+s[0].offsetWidth/2,r=o.height||Math.max(l[0].offsetHeight,l[1].offsetHeight),f=o.element.find("div"),g=f[0].offsetWidth,c=f[1].offsetHeight;e.wrapperStyle={},i>g&&(e.wrapperStyle.width=i+"px"),r>c&&"btn-xs"!=o.size&&"btn-sm"!=o.size&&(e.wrapperStyle.height=r+"px"),e.onClass=[o.onstyle,o.size,"toggle-on"],e.offClass=[o.offstyle,o.size,"toggle-off"],e.handleClass=[o.size,"toggle-handle"]},this.render=function(){this.isOn=angular.isDefined(a.$viewValue)?a.$viewValue:!1,e.wrapperClass=this.isOn?[o.onstyle,o.size,o.style]:[o.offstyle,"off ",o.size,o.style]},e.onSwitch=function(){a.$setViewValue(!a.$viewValue),a.$render()},angular.forEach(["ngModel"],function(n){var l=e.$parent.$watch(t[n],function(){a.$render()});e.$parent.$on("$destroy",function(){l()})})}]).directive("toggle",function(){return{restrict:"E",transclude:!0,template:'',scope:{bindModel:"=ngModel"},require:["toggle","ngModel"],controller:"ToggleController",controllerAs:"toggle",link:function(e,t,n,l){var s=l[0],o=l[1];s.element=t,s.init(o)}}})}();
\ No newline at end of file