This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // UseCases: | |
| // function CB(dataUrl, newSize) { console.info(newSize.w, newSize.h); }; | |
| // To set specific width: resizeImage(url, {w: 200}, CB); | |
| // To set specific height: resizeImage(url, {h: 200}, CB); | |
| // To rediuce size by percent: resizeImage(url, {r: .5}, CB); | |
| // To change export quality add {q: .5} (default & max is 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function toDataUrl(url, callback) { | |
| var xhr = new XMLHttpRequest(); | |
| xhr.responseType = 'blob'; | |
| xhr.onload = function () { | |
| var reader = new FileReader(); | |
| reader.onloadend = function () { | |
| callback(reader.result); | |
| } | |
| reader.readAsDataURL(xhr.response); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| String.prototype.toPersianDigits = function () { | |
| var id = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']; | |
| return this.replace(/[0-9]/g, function (w) { | |
| return id[+w]; | |
| }); | |
| }; | |
| String.prototype.toEnglishDigits = function () { | |
| var id = { '۰': '0', '۱': '1', '۲': '2', '۳': '3', '۴': '4', '۵': '5', '۶': '6', '۷': '7', '۸': '8', '۹': '9' }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // My answer to question http://stackoverflow.com/questions/38062482/money-formatting-directive-in-angular/38112095#38112095 | |
| app.directive('price', [function () { | |
| return { | |
| require: 'ngModel', | |
| link: function (scope, element, attrs, ngModel) { | |
| attrs.$set('ngTrim', "false"); | |
| var formatter = function(str, isNum) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.directive('ngEnter', function() { | |
| return function(scope, element, attrs) { | |
| element.bind("keydown keypress", function(event) { | |
| if (event.which === 13) { | |
| scope.$apply(function() { | |
| scope.$eval(attrs.ngEnter); | |
| }); | |
| event.preventDefault(); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // for html strings that contain expressiona or other angular directives | |
| app.directive('template', ['$compile', function($compile) { | |
| return function(scope, element, attrs) { | |
| attrs.$observe("template", function(_newVal) { | |
| scope.$applyAsync(function() { | |
| element.replaceWith($compile(_newVal)(scope)); | |
| }); | |
| }); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.directive('ngValidation', function () { | |
| return { | |
| require: 'ngModel', | |
| scope: { | |
| ngValidation: '=' | |
| }, | |
| link: function (scope, element, attrs, ngModel) { | |
| scope.$watch('ngValidation', function (newVal) { | |
| if (!(newVal instanceof Object)) return; |