PageSourceSearch

https://vicensvives.com/shop/assets/controllers/main.directives.js

js vicensvives.com collected 2026-10-02 05:46:07 UTC 12,658 bytes, 288 lines download raw bytes

1(function () {
2    'use strict';
3
4    angular
5        .module('App')
6        .directive('icheck', function ($timeout, $parse) {
7            return {
8                require: 'ngModel',
9                link: function ($scope, element, $attrs, ngModel) {
10                    return $timeout(function () {
11                        var value;
12                        value = $attrs['value'];
13
14                        $scope.$watch($attrs['ngModel'], function (newValue) {
15                            $(element).iCheck('update');
16                        });
17
18                        $scope.$watch($attrs['ngDisabled'], function (newValue) {
19                            $(element).iCheck(newValue ? 'disable' : 'enable');
20                            $(element).iCheck('update');
21                        })
22
23                        return $(element).iCheck({
24                            checkboxClass: 'icheckbox_minimal-grey position-relative',
25                            radioClass: 'iradio_minimal-grey'
26
27                        }).on('ifChanged', function (event) {
28                            if ($(element).attr('type') === 'checkbox' && $attrs['ngModel']) {
29                                $scope.$apply(function () {
30                                    return ngModel.$setViewValue(event.target.checked);
31                                })
32                            }
33                        }).on('ifClicked', function (event) {
34                            if ($(element).attr('type') === 'radio' && $attrs['ngModel']) {
35                                return $scope.$apply(function () {
36                                    //set up for radio buttons to be de-selectable
37                                    if (ngModel.$viewValue != value)
38                                        return ngModel.$setViewValue(value);
39                                    else
40                                        ngModel.$setViewValue(null);
41                                    ngModel.$render();
42                                    return
43                                });
44                            }
45                        });
46                    });
47                }
48            };
49        })
50        .directive('convertToNumber', function () {
51            return {
52                require: 'ngModel',
53                link: function (scope, element, attrs, ngModel) {
54                    ngModel.$parsers.push(function (val) {
55                        return parseInt(val, 10);
56                    });
57
58                    ngModel.$formatters.push(function (val) {
59                        if (val == undefined)
60                            return val;
61                        else
62                            return '' + val;
63                    });
64                }
65            };
66        })
67        .directive('convertToBoolean', function () {
68            return {
69                require: 'ngModel',
70                link: function (scope, element, attrs, ngModel) {
71                    ngModel.$parsers.push(function (val) {
72                        return (val == 1);
73                    });
74
75                    ngModel.$formatters.push(function (val) {
76                        return (val == 1);
77                    });
78                }
79            };
80        })
81        .directive('convertToFloat', function () {
82            return {
83                require: 'ngModel',
84                link: function (scope, element, attrs, ngModel) {
85                    ngModel.$parsers.push(function (val) {
86                        return parseFloat(val);
87                    });
88
89
90                    ngModel.$formatters.push(function (val) {
91                        return '' + val;
92                    });
93                }
94            };
95        })
96        .directive('restrictTo', function () {
97            return {
98                restrict: 'A',
99                link: function (scope, element, attrs) {
100                    var re = RegExp(attrs.restrictTo);
101                    var exclude = /Backspace|Enter|Tab|Delete|Del|ArrowUp|Up|ArrowDown|Down|ArrowLeft|Left|ArrowRight|Right/;
102
103                    element[0].addEventListener('keydown', function (event) {
104                        if (!exclude.test(event.key) && !re.test(event.key)) {
105                            event.preventDefault();
106                        }
107                    });
108                }
109            }
110        })
111        .directive('ngEnter', function () { //a directive to 'enter key press' in elements with the "ng-enter" attribute
112            return function (scope, element, attrs) {
113                element.bind("keydown keypress", function (event) {
114                    if (event.which === 13) {
115                        scope.$apply(function () {
116                            scope.$eval(attrs.ngEnter);
117                        });
118                        event.preventDefault();
119                    }
120                })
121            };
122        })
123        .directive('focusMe', function ($timeout) {
124            return {
125                link: function (scope, element, attrs) {
126                    scope.$watch(attrs.focusMe, function (value) {
127                        if (value === true) {
128                            //$timeout(function() {
129                            element[0].focus();
130                            scope[attrs.focusMe] = false;
131                            //});
132                        }
133                    });
134                }
135            };
136        })
137        .directive('validIban', function () {
138            return {
139                restrict: 'A',
140                require: 'ngModel',
141                link: function (scope, element, attr, ctrl) {// 4th argument contain model information
142                    ctrl.$validators.invalidiban = function (value, viewValue) {
143                        if (IBAN.isValid(value)) // if not valid IBAN
144                        {
145                            return true;
146                        }
147                        else {
148                            return false;
149                        }
150                    }
151
152                    // Función que devuelve los números correspondientes a cada letra
153                    function getNumIBAN(letra) {
154                        var letras = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
155                        return letras.search(letra) + 10;
156                    }
157
158                    // Función que calcula el módulo sin hacer ninguna división
159                    function mod(dividendo, divisor) {
160                        var cDividendo = '';
161                        var cResto = '';
162
163                        for (var i in dividendo) {
164                            var cChar = dividendo[i];
165                            var cOperador = cResto + '' + cDividendo + '' + cChar;
166
167                            if (cOperador < parseInt(divisor)) {
168                                cDividendo += '' + cChar;
169                            } else {
170                                cResto = cOperador % divisor;
171                                if (cResto == 0) {
172                                    cResto = '';
173                                }
174                                cDividendo = '';
175                            }
176                        }
177                        cResto += '' + cDividendo;
178                        if (cResto == '') {
179                            cResto = 0;
180                        }
181                        return cResto;
182                    }
183
184                    // El típico trim que inexplicamente JavaScript no trae implementado
185                    function trim(texto) {
186                        return texto.replace(/^\s+/g, '').replace(/\s+$/g, '');
187                    }
188
189                    // Función que comprueba el IBAN
190                    function validaIBAN(IBAN) {
191                        if (IBAN == undefined) IBAN = '';
192                        IBAN = IBAN.toUpperCase();
193                        IBAN = trim(IBAN); // Quita espacios al principio y al final
194                        IBAN = IBAN.replace(/\s/g, ""); // Quita espacios del medio
195                        var num1, num2;
196                        var isbanaux;
197                        if (IBAN.length != 24) { // En España el IBAN son 24 caracteres
198                            return false;
199                        } else {
200                            num1 = getNumIBAN(IBAN.substring(0, 1));
201                            num2 = getNumIBAN(IBAN.substring(1, 2));
202                            isbanaux = IBAN.substr(4) + String(num1) + String(num2) + IBAN.substr(2, 2);
203                            var resto = mod(isbanaux, 97);
204                            return (resto == 1);
205                        }
206                    }
207                }
208            }
209        })
210        .directive('validateEmailExists', function($http) {
211            return {
212              restrict: 'A',
213                 scope: true,
214                 require: 'ngModel',
215                 link: function(scope, elem, attrs, ctrls) {
216                     var ngModel = ctrls;
217                     scope.$watch(attrs.ngModel, function(email) {
218                        var url = window.__env.apiUrl + '/comprador/exists_email?email='+email;
219
220                        $http.get(url)
221                        .then(function(data) {
222                           var data = data.data;
223                           if (data.exists_email) {
224                                console.log('existe mail');
225                                ngModel.$setValidity('notExistEmail', false);
226                           } else {
227                                ngModel.$setValidity('notExistEmail', true);
228                                console.log('no existe mail');
229                           }
230                         }, function(error) {
231                              ngModel.$setValidity('notExistEmail', true);
232                         });
233                     });
234                 }
235           }
236         })
237        .directive('nDecimals', function nDecimals() {
238            return {
239                restrict: 'A',
240                link: function (scope, element, attr) {
241                    element.on('input', function (e) {
242                        // Read the attribute to know the 'N' number places
243                        var maxDecimal = Number(element.attr('n-Decimals'));
244                        //Read the enetered value
245                        var sal = element.val();
246                        var parts;
247                        if (sal.indexOf(".") !== -1) {
248                            parts = sal.split(".");
249                            if (parts[1].length > maxDecimal) {
250                                element.val(sal.substr(0, sal.length - 1));
251                            }
252                        }
253                    });
254                    // destroy event.
255                    scope.$on('$destroy', function () {
256                        element.off('input');
257                    });
258                }
259            };
260        })
261        .directive('switch', function(){
262            return {
263              restrict: 'AE'
264            , replace: true
265            , transclude: true
266            , template: function(element, attrs) {
267                var html = '';
268                html += '<span';
269                html +=   ' class="switch' + (attrs.class ? ' ' + attrs.class : '') + '"';
270                html +=   attrs.ngModel ? ' ng-click="' + attrs.disabled + ' ? ' + attrs.ngModel + ' : ' + attrs.ngModel + '=!' + attrs.ngModel + (attrs.ngChange ? '; ' + attrs.ngChange + '()"' : '"') : '';
271                html +=   ' ng-class="{ checked:' + attrs.ngModel + ', disabled:' + attrs.disabled + ' }"';
272                html +=   '>';
273                html +=   '<small></small>';
274                html +=   '<input type="checkbox"';
275                html +=     attrs.id ? ' id="' + attrs.id + '"' : '';
276                html +=     attrs.required ? ' required="' + attrs.required + '"' : '';
277                html +=     attrs.name ? ' name="' + attrs.name + '"' : '';
278                html +=     attrs.ngModel ? ' ng-model="' + attrs.ngModel + '"' : '';
279                html +=     ' style="display:none" />';
280                html +=     '<span class="switch-text">'; /*adding new container for switch text*/
281                html +=     attrs.on ? '<span class="on">'+attrs.on+'</span>' : ''; /*switch text on value set by user in directive html markup*/
282                html +=     attrs.off ? '<span class="off">'+attrs.off + '</span>' : ' ';  /*switch text off value set by user in directive html markup*/
283                html += '</span>';
284                return html;
285              }
286            }
287          });
288})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.