From ad6af1d94a7eff6278586a7ee1e0200452fdff32 Mon Sep 17 00:00:00 2001 From: Cristian CIOFU Date: Sat, 23 Jan 2016 11:19:58 +0100 Subject: [PATCH 1/4] Custom method + on/off custom values Gives the user the ability to : - add a custom made function with whatever parameters he may need - add custom values to on/off values for the cases where the model is not based on true/false values --- README.md | 16 ++++++++++++++++ angular-ui-switch.js | 23 ++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c7400e3..209326a 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,22 @@ Add optional on/off text ``` +Add custom values for `ON` / `OFF` (if your model is not based on true/false values) +```html +
+ +
{{ enabled }} +
+``` + +Add a custom method to `on-click` event +```html +
+ +
{{ enabled }} +
+``` + Disabled state ```html
diff --git a/angular-ui-switch.js b/angular-ui-switch.js index 9a6b591..2dc8051 100644 --- a/angular-ui-switch.js +++ b/angular-ui-switch.js @@ -7,10 +7,31 @@ angular.module('uiSwitch', []) , transclude: true , template: function(element, attrs) { var html = ''; + var extraMethod = ''; + + if (attrs.ngOnClick) { + extraMethod += '; ' + attrs.ngOnClick; + } + if (attrs.ngChange) { + extraMethod += '; ' + attrs.ngChange + '()'; + } + html += ' Date: Sat, 23 Jan 2016 11:23:13 +0100 Subject: [PATCH 2/4] Updated min.js file --- angular-ui-switch.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/angular-ui-switch.min.js b/angular-ui-switch.min.js index 6f6da0f..b6bc81d 100644 --- a/angular-ui-switch.min.js +++ b/angular-ui-switch.min.js @@ -1 +1 @@ -angular.module("uiSwitch",[]).directive("switch",function(){return{restrict:"AE",replace:!0,transclude:!0,template:function(n,e){var s="";return s+="'+e.on+"":"",s+=e.off?''+e.off+"":" ",s+=""}}}); \ No newline at end of file +angular.module("uiSwitch",[]).directive("switch",function(){return{restrict:"AE",replace:!0,transclude:!0,template:function(e,n){var l="",a="";return n.ngOnClick&&(a+="; "+n.ngOnClick),n.ngChange&&(a+="; "+n.ngChange+"()"),l+="'+n.on+"":"",l+=n.off?''+n.off+"":" ",l+=""}}}); From 2d8b86f64281824f02c114d4c7efca242e6cb4bc Mon Sep 17 00:00:00 2001 From: Cristian CIOFU Date: Sat, 23 Jan 2016 11:25:07 +0100 Subject: [PATCH 3/4] Removed some unnecessary blank lines --- angular-ui-switch.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/angular-ui-switch.js b/angular-ui-switch.js index 2dc8051..7a3d383 100644 --- a/angular-ui-switch.js +++ b/angular-ui-switch.js @@ -18,12 +18,9 @@ angular.module('uiSwitch', []) html += ' Date: Tue, 16 Feb 2016 20:30:05 +0100 Subject: [PATCH 4/4] Removed two lines that would appear twice otherwise, causing Angular to complain about multiple ngclick --- angular-ui-switch.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/angular-ui-switch.js b/angular-ui-switch.js index 7a3d383..6b77397 100644 --- a/angular-ui-switch.js +++ b/angular-ui-switch.js @@ -18,8 +18,6 @@ angular.module('uiSwitch', []) html += '