PageSourceSearch

https://www.instateam.net/app/js/directives/ui-jq.js

js instateam.net collected 2026-10-01 23:44:42 UTC 3,049 bytes, 86 lines download raw bytes

1'use strict';
2
3/**
4 * 0.1.1
5 * General-purpose jQuery wrapper. Simply pass the plugin name as the expression.
6 *
7 * It is possible to specify a default set of parameters for each jQuery plugin.
8 * Under the jq key, namespace each plugin by that which will be passed to ui-jq.
9 * Unfortunately, at this time you can only pre-define the first parameter.
10 * @example { jq : { datepicker : { showOn:'click' } } }
11 *
12 * @param ui-jq {string} The $elm.[pluginName]() to call.
13 * @param [ui-options] {mixed} Expression to be evaluated and passed as options to the function
14 *     Multiple parameters can be separated by commas
15 * @param [ui-refresh] {expression} Watch expression and refire plugin on changes
16 *
17 * @example <input ui-jq="datepicker" ui-options="{showOn:'click'},secondParameter,thirdParameter" ui-refresh="iChange">
18 */
19angular.module('ui.jq', ['ui.load']).
20  value('uiJqConfig', {}).
21  directive('uiJq', ['uiJqConfig', 'JQ_CONFIG', 'uiLoad', '$timeout', function uiJqInjectingFunction(uiJqConfig, JQ_CONFIG, uiLoad, $timeout) {
22
23  return {
24    restrict: 'A',
25    compile: function uiJqCompilingFunction(tElm, tAttrs) {
26
27      if (!angular.isFunction(tElm[tAttrs.uiJq]) && !JQ_CONFIG[tAttrs.uiJq]) {
28        throw new Error('ui-jq: The "' + tAttrs.uiJq + '" function does not exist');
29      }
30      var options = uiJqConfig && uiJqConfig[tAttrs.uiJq];
31
32      return function uiJqLinkingFunction(scope, elm, attrs) {
33
34        function getOptions(){
35          var linkOptions = [];
36
37          // If ui-options are passed, merge (or override) them onto global defaults and pass to the jQuery method
38          if (attrs.uiOptions) {
39            linkOptions = scope.$eval('[' + attrs.uiOptions + ']');
40            if (angular.isObject(options) && angular.isObject(linkOptions[0])) {
41              linkOptions[0] = angular.extend({}, options, linkOptions[0]);
42            }
43          } else if (options) {
44            linkOptions = [options];
45          }
46          return linkOptions;
47        }
48
49        // If change compatibility is enabled, the form input's "change" event will trigger an "input" event
50        if (attrs.ngModel && elm.is('select,input,textarea')) {
51          elm.bind('change', function() {
52            elm.trigger('input');
53          });
54        }
55
56        // Call jQuery method and pass relevant options
57        function callPlugin() {
58          $timeout(function() {
59            elm[attrs.uiJq].apply(elm, getOptions());
60          }, 0, false);
61        }
62
63        function refresh(){
64          // If ui-refresh is used, re-fire the the method upon every change
65          if (attrs.uiRefresh) {
66            scope.$watch(attrs.uiRefresh, function() {
67              callPlugin();
68            });
69          }
70        }
71
72        if ( JQ_CONFIG[attrs.uiJq] ) {
73          uiLoad.load(JQ_CONFIG[attrs.uiJq]).then(function() {
74            callPlugin();
75            refresh();
76          }).catch(function() {
77            
78          });
79        } else {
80          callPlugin();
81          refresh();
82        }
83      };
84    }
85  };
86}]);

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.