From 18e82f87c127bcbd6e4f9f75e7ab8d78616db4ab Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 10 Dec 2014 17:17:18 -0800 Subject: [PATCH] CRM-15578 - Extract crmUiId --- js/angular-crm-ui.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/js/angular-crm-ui.js b/js/angular-crm-ui.js index 77c2d2f5b9..5d895fa350 100644 --- a/js/angular-crm-ui.js +++ b/js/angular-crm-ui.js @@ -1,14 +1,25 @@ /// crmUi: Sundry UI helpers (function (angular, $, _) { - var idCount = 0; var partialUrl = function (relPath) { return CRM.resourceUrls['civicrm'] + '/partials/crmUi/' + relPath; }; - angular.module('crmUi', []) + .factory('crmUiId', function() { + var idCount = 0; + // Get the HTML ID of an element. If none available, assign one. + return function crmUiId(el){ + var id = el.attr('id'); + if (!id) { + id = 'crmUi_' + (++idCount); + el.attr('id', id); + } + return id; + }; + }) + // example
...content...
// WISHLIST: crmCollapsed should support two-way/continous binding .directive('crmUiAccordion', function() { @@ -102,7 +113,7 @@ // example:
{{mydata}}
// example:
// example:
- .directive('crmUiField', function() { + .directive('crmUiField', function(crmUiId) { function createReqStyle(req) { return {visibility: req ? 'inherit' : 'hidden'}; } @@ -150,9 +161,7 @@ // 2. Make sure that inputs are well-defined (with name+id). - if (!input.attr('id')) { - input.attr('id', 'crmUi_' + (++idCount)); - } + crmUiId(input); $(label).attr('for', input.attr('id')); // 3. Monitor is the "required" and "$valid" properties -- 2.25.1