-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular.integralui.checkbox.min.js
35 lines (32 loc) · 11.2 KB
/
angular.integralui.checkbox.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
filename: angular.integralui.checkbox.min.js
version : 1.4.0
Copyright © 2014-2016 Lidor Systems. All rights reserved.
This file is part of the "IntegralUI" Library.
The contents of this file are subject to the IntegralUI Studio for Web License, and may not be used except in compliance with the License.
A copy of the License should have been installed in the product's root installation directory or it can be found at
http://www.lidorsystems.com/products/web/studio/license-agreement.aspx.
This SOFTWARE is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language
governing rights and limitations under the License. Any infringement will be prosecuted under applicable laws.
*/
angular.module("integralui").factory("IntegralUICheckBoxService",["$rootScope","IntegralUIPublicService",function(c,h){return{refresh:function(d){c.$broadcast(d+"-refresh")},resumeLayout:function(d){c.$broadcast(d+"-resume-layout")},suspendLayout:function(d){c.$broadcast(d+"-suspend-layout")},updateLayout:function(d){c.$broadcast(d+"-update-layout")}}}]).controller("IntegralUICheckBoxController",["$scope","$element","IntegralUIInternalService",function(c,h,d){var b=this;b.defaultStyle={general:"iui-checkbox",
box:{general:"iui-checkbox-box",disabled:"iui-checkbox-box-disabled",checked:"iui-checkbox-checked",indeterminate:"iui-checkbox-indeterminate",unchecked:"iui-checkbox-unchecked"},content:{general:"iui-checkbox-content",disabled:"iui-checkbox-content-disabled"}};b.options={};this.updateOptions=function(a){a?(b.options={autoCheck:d.isFieldAvailable(a.autoCheck,!0),checked:d.isFieldAvailable(a.checked,!1),checkState:d.isFieldAvailable(a.checkState,"unchecked"),controlStyle:b.defaultStyle,enabled:d.isFieldAvailable(a.enabled,
!0),rtl:d.isFieldAvailable(a.rtl,!1),text:d.isFieldAvailable(a.text,""),threeState:d.isFieldAvailable(a.threeState,!1)},b.updateControlStyle(a.controlStyle)):b.options={autoCheck:!0,checked:!1,checkState:"unchecked",controlStyle:b.defaultStyle,enabled:!0,rtl:!1,text:"",threeState:!1}};b.updateOptions();this.getCheckValue=function(a){return"checked"==a?"checked":1==b.options.threeState&&"indeterminate"==a?"indeterminate":"unchecked"};this.setCheckValue=function(a){!1!==(1==b.options.threeState?b.callCheckStateChanging(a):
b.callCheckedChanging(a))&&(b.options.checkState="unchecked"==a?1==b.options.threeState?"indeterminate":"checked":"indeterminate"==a?"checked":"unchecked",b.options.checked="checked"==b.options.checkState?!0:!1,angular.isDefined(c.checked)&&(c.checked=b.options.checked),angular.isDefined(c.checkState)&&(c.checkState=b.options.checkState),angular.isDefined(c.checkState)||1!=b.options.threeState?angular.isDefined(c.checked)||0!=b.options.threeState||b.callCheckedChanged(b.options.checkState):b.callCheckStateChanged(b.options.checkState))};
this.callCheckedChanging=function(a){a=b.getCheckValue(a);var d="checked"==a?!0:!1;return angular.isDefined(c.events)&&c.events.checkedChanging?c.events.checkedChanging({checked:d,checkState:a}):c.checkedChanging({e:{checked:d,checkState:a}})};this.callCheckedChanged=function(a){a=b.getCheckValue(a);var d="checked"==a?!0:!1;angular.isDefined(c.events)&&c.events.checkedChanged?c.events.checkedChanged({checked:d,checkState:a}):c.checkedChanged({e:{checked:d,checkState:a}})};this.callCheckStateChanging=
function(a){a=b.getCheckValue(a);var d="checked"==a?!0:!1;return angular.isDefined(c.events)&&c.events.checkstateChanging?c.events.checkstateChanging({checked:d,checkState:a}):c.checkstateChanging({e:{checked:d,checkState:a}})};this.callCheckStateChanged=function(a){a=b.getCheckValue(a);var d="checked"==a?!0:!1;angular.isDefined(c.events)&&c.events.checkstateChanged?c.events.checkstateChanged({checked:d,checkState:a}):c.checkstateChanged({e:{checked:d,checkState:a}})};this.callClick=function(a){a=
b.getCheckValue(a);var d="checked"==a?!0:!1;angular.isDefined(c.events)&&c.events.click?c.events.click({checked:d,checkState:a}):c.click({e:{checked:d,checkState:a}})};this.callEnabledChanged=function(a){angular.isDefined(c.events)&&c.events.enabledChanged?c.events.enabledChanged({enabled:a}):c.enabledChanged({e:{enabled:a}})};this.callStyleChanged=function(a){angular.isDefined(c.events)&&c.events.styleChanged?c.events.styleChanged({style:a}):c.styleChanged({e:{style:a}})};b.allowUpdate=!0;this.suspendLayout=
function(){b.allowUpdate=!1};this.resumeLayout=function(){b.allowUpdate=!0;b.updateLayout()};c.$on(c.name+"-refresh",function(a){b.refresh()});c.$on(c.name+"-resume-layout",function(a){b.resumeLayout()});c.$on(c.name+"-suspend-layout",function(a){b.suspendLayout()});c.$on(c.name+"-update-layout",function(a){b.updateLayout()});c.$watch("autoCheck",function(a,c){a!==c&&(b.options.autoCheck=a)});c.$watch("checked",function(a,c){a!==c&&(b.options.checked=1==a?!0:!1,b.options.checkState=b.options.checked?
"checked":"unchecked",b.updateCheckMark(),b.callCheckedChanged(b.options.checkState))});c.$watch("checkState",function(a,c){a!==c&&(b.options.checkState=b.getCheckValue(a),b.options.checked="checked"==b.options.checkState?!0:!1,b.updateCheckMark(),b.callCheckStateChanged(b.options.checkState))});c.$watch("controlStyle",function(a,c){a!==c&&(b.options.controlStyle=a,b.refresh(),b.callStyleChanged(a))});c.$watch("enabled",function(a,c){a!==c&&(b.options.enabled=a,b.refresh(),b.updateCheckMark(),b.callEnabledChanged(a))});
c.$watch("options",function(a,c){a!==c&&(b.updateOptions(a),b.updateLayout())},!0);c.$watch("rtl",function(a,c){a!==c&&(b.options.rtl=a,b.updateLayout())});c.$watch("text",function(a,c){a!==c&&(b.options.text=a)});c.$watch("threeState",function(a,c){a!==c&&(b.options.threeState=a,0==b.options.threeState&&"indeterminate"==b.options.checkState&&b.setCheckValue("checked"))});var f=function(a){return a?{general:d.isFieldAvailable(a.general,"iui-checkbox-box"),disabled:d.isFieldAvailable(a.disabled,"iui-checkbox-disabled"),
checked:d.isFieldAvailable(a.checked,"iui-checkbox-checked"),indeterminate:d.isFieldAvailable(a.indeterminate,"iui-checkbox-indeterminate"),unchecked:d.isFieldAvailable(a.unchecked,"iui-checkbox-unchecked")}:b.defaultStyle.box},l=function(a){return a?{general:d.isFieldAvailable(a.general,"iui-checkbox-content"),disabled:d.isFieldAvailable(a.disabled,"iui-checkbox-content-disabled")}:b.defaultStyle.content};this.updateControlStyle=function(a){b.options.controlStyle=a?{general:d.isFieldAvailable(a.general,
"iui-checkbox"),box:f(a.box),content:l(a.content)}:{general:d.isFieldAvailable(b.defaultStyle.general,"iui-checkbox"),box:f(b.defaultStyle.box),content:l(b.defaultStyle.content)}}}]).directive("iuiCheckbox",["$timeout","$interval","IntegralUIInternalService",function(c,h,d){return{restrict:"EA",controller:"IntegralUICheckBoxController",transclude:!0,replace:!0,template:'<div data-element="checkbox"><canvas></canvas><div ng-transclude></div></div>',scope:{autoCheck:"=",checked:"=",checkState:"=",controlStyle:"=",
enabled:"=",name:"@",options:"=?",rtl:"=",text:"@",threeState:"=",checkedChanging:"&",checkedChanged:"&",checkstateChanging:"&",checkstateChanged:"&",click:"&",enabledChanged:"&",styleChanged:"&",events:"=?"},link:function(b,f,l,a,h){var e=f.children().eq(0),g=f.children().eq(1);b.$on("$destroy",function(a){f.unbind("click touchstart");m()});var m=function(){e.unbind("click mouseup touchstart")},n=function(){e.bind("click",function(b){0!=a.options.enabled&&(a.setCheckValue(a.options.checkState),a.callClick(a.options.checkState),
a.updateLayout());b.stopPropagation()});e.bind("mouseup",function(a){a.stopPropagation()});e.bind("touchstart",function(b){b.preventDefault();var c=d.getTouchData(b);c&&0<c.length&&(0!=a.options.enabled&&(a.setCheckValue(a.options.checkState),a.callClick(a.options.checkState),a.updateLayout()),b.stopPropagation())})};f.bind("click",function(b){0!=a.options.enabled&&a.options.autoCheck&&(a.setCheckValue(a.options.checkState),a.updateLayout())});f.bind("touchstart",function(b){b.preventDefault();(b=
d.getTouchData(b))&&0<b.length&&0!=a.options.enabled&&a.options.autoCheck&&(a.setCheckValue(a.options.checkState),a.updateLayout())});a.updateCheckMark=function(){if(e){var b=getComputedStyle(e[0])["background-image"];if(b&&"none"!=b)k();else if("CANVAS"==e[0].tagName){k();getComputedStyle(e[0]);var b=getComputedStyle(e[0]).color,c=e[0].getContext("2d"),d=e[0].width,f=e[0].height;c.beginPath();c.rect(0,0,d,f);c.fillStyle="#ffffff";c.fill();"checked"==a.options.checkState?(c.lineWidth=12<f?3:1,c.strokeStyle=
b,"indeterminate"==a.options.checkState&&(c.strokeStyle="#808080"),c.beginPath(),c.moveTo(3,f/2+1),c.lineTo(0+d/2,0+f-3),c.stroke(),c.beginPath(),c.moveTo(0+d/2-1,0+f-3),c.lineTo(0+d-3,3),c.stroke()):"indeterminate"==a.options.checkState&&(c.beginPath(),c.rect(4,4,d-8,f-8),c.fillStyle=b,c.fill())}}};a.updateLayout=function(){if(a.allowUpdate){m();a.refresh();var b=c(function(){var d="ltr";!0===a.options.rtl&&(d="rtl");f.css("direction",d);if((d=getComputedStyle(e[0])["background-image"])&&"none"!=
d)e.remove(),e=angular.element("<span></span>"),f.prepend(e),k();else{e.remove();e=angular.element("<canvas></canvas>");f.prepend(e);k();var d=getComputedStyle(e[0]).width,h=getComputedStyle(e[0]).height;e[0].width=d?parseInt(d,10):14;e[0].height=h?parseInt(h,10):14;!0===a.options.rtl?(e.css("left","auto"),e.css("right",0)):(e.css("left",0),e.css("right","auto"));a.updateCheckMark()}0==g.children().length&&g.css("padding",0);n();c.cancel(b)},1)}};var k=function(){var b=a.defaultStyle.box.general+
" "+a.defaultStyle.box[a.options.checkState];a.options.controlStyle&&a.options.controlStyle.box&&(a.options.controlStyle.box.general&&d.isString(a.options.controlStyle.box.general)&&(b+=" "+a.options.controlStyle.box.general),0==a.options.enabled&&a.options.controlStyle.box.disabled&&d.isString(a.options.controlStyle.box.disabled)?b+=" "+a.options.controlStyle.box.disabled:a.options.controlStyle.box[a.options.checkState]&&d.isString(a.options.controlStyle.box[a.options.checkState])&&(b+=" "+a.options.controlStyle.box[a.options.checkState]));
e.removeAttr("class");e.addClass(b)};a.refresh=function(){f.removeAttr("class");f.addClass(a.defaultStyle.general);a.options.controlStyle&&d.isString(a.options.controlStyle.general)&&f.addClass(a.options.controlStyle.general);0<e.length&&k();0<g.length&&(g.removeAttr("class"),g.addClass(a.defaultStyle.content.general),a.options.controlStyle&&(a.options.controlStyle.content&&d.isString(a.options.controlStyle.content.general)&&g.addClass(a.options.controlStyle.content.general),0==a.options.enabled&&
a.options.controlStyle.content.disabled&&d.isString(a.options.controlStyle.content.disabled)&&g.addClass(a.options.controlStyle.content.disabled)))};angular.isDefined(b.options)?a.updateOptions(b.options):(0==b.autoCheck&&(a.options.autoCheck=b.autoCheck),1==b.checked&&(a.options.checked=b.checked,a.options.checkState="checked"),angular.isDefined(b.checkState)&&(a.options.checkState=b.checkState,a.options.checked="checked"==a.options.checkState?!0:!1),angular.isDefined(b.controlStyle)&&a.updateControlStyle(b.controlStyle),
0==b.enabled&&(a.options.enabled=b.enabled),1==b.rtl&&(a.options.rtl=b.rtl),angular.isDefined(b.text)&&(a.options.text=b.text),!0===b.threeState&&(a.options.threeState=b.threeState));a.updateLayout()}}}]);