├── LICENSE ├── README.md ├── angular-dojo.js └── test.html /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Andreas Drobisch and contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | angular-dojo 2 | ============ 3 | 4 | AngularJS directives for dojo widgets 5 | 6 | Usage 7 | ----- 8 | eg: 9 | `````` 10 | 11 | ``` 12 | angular.module('app', [ 13 | 'angular-dojo' 14 | ]); 15 | ``` 16 | 17 | Examples 18 | -------- 19 | See [test.html](test.html) 20 | 21 | License 22 | ------- 23 | *angular-dojo* may be used under the terms of the MIT license, see [LICENSE](LICENSE) 24 | -------------------------------------------------------------------------------- /angular-dojo.js: -------------------------------------------------------------------------------- 1 | angular.module('angular-dojo', []).directive('dojoWidget', function($timeout) { 2 | 3 | var parseProps = function(props, scope) { 4 | if (typeof props === 'undefined') return {}; 5 | 6 | props = '[{' + props + '}]'; 7 | return eval(props)[0]; 8 | }; 9 | 10 | return { 11 | restrict: "A", 12 | replace: false, 13 | transclude: false, 14 | require: '?ngModel', 15 | scope: { 16 | 'ngModel' : '=?', 17 | 'ngClick' : '&', 18 | 'ngChange' : '&', 19 | 'dojoStore' : '&', 20 | 'dojoProps' : '@', 21 | 'dojoDisplayValue' : '=?' 22 | }, 23 | link: function(scope, element, attrs, model) { 24 | require(["dojo/ready", "dijit/dijit", attrs.dojoWidget, "dojo/on"], function(ready, dijit, DojoWidget, on) { 25 | 26 | ready(function () { 27 | scope.widget = new DojoWidget({}, element[0]); 28 | 29 | attrs.$observe('dojoProps', function(dojoProps) { 30 | scope.widget.set(parseProps(dojoProps, scope)); 31 | }); 32 | 33 | attrs.$observe('dojoStore', function() { 34 | if (scope.dojoStore != undefined) { 35 | scope.widget.store = scope.dojoStore(); 36 | } 37 | }); 38 | 39 | scope.$watch('ngModel', function() { 40 | if (scope.ngModel != undefined) { 41 | if (attrs.dojoWidget == 'dijit/form/FilteringSelect' || attrs.dojoWidget == 'dijit/form/Select') { 42 | scope.widget.set('item', scope.ngModel); 43 | } 44 | else { 45 | scope.widget.set('value', scope.ngModel); 46 | scope.widget.set('checked', scope.ngModel); 47 | } 48 | } 49 | }); 50 | 51 | on(scope.widget, "blur", function () { 52 | if (scope.widget.displayedValue != undefined) { 53 | scope.dojoDisplayValue = scope.widget.displayedValue; 54 | } 55 | }); 56 | 57 | on(scope.widget, "change", function(newValue) { 58 | if (attrs.dojoWidget == 'dijit/form/FilteringSelect' || attrs.dojoWidget == 'dijit/form/Select') { 59 | scope.ngModel = this.item; 60 | } 61 | else { 62 | scope.ngModel = newValue; 63 | } 64 | 65 | $timeout(function() { 66 | scope.$apply(); 67 | if (scope.ngChange != undefined) { 68 | scope.ngChange(); 69 | } 70 | }); 71 | }); 72 | 73 | on(scope.widget, 'click', function() { 74 | $timeout(function() { 75 | scope.$apply(); 76 | if (scope.ngClick != undefined) { 77 | scope.ngClick(); 78 | } 79 | }); 80 | }); 81 | }); 82 | }); 83 | } 84 | }; 85 | }); 86 | -------------------------------------------------------------------------------- /test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 |