| @@ 1211-1302 (lines=92) @@ | ||
| 1208 | angular.module('ui.bootstrap.isClass', []) |
|
| 1209 | .directive('uibIsClass', [ |
|
| 1210 | '$animate', |
|
| 1211 | function ($animate) { |
|
| 1212 | // 11111111 22222222 |
|
| 1213 | var ON_REGEXP = /^\s*([\s\S]+?)\s+on\s+([\s\S]+?)\s*$/; |
|
| 1214 | // 11111111 22222222 |
|
| 1215 | var IS_REGEXP = /^\s*([\s\S]+?)\s+for\s+([\s\S]+?)\s*$/; |
|
| 1216 | ||
| 1217 | var dataPerTracked = {}; |
|
| 1218 | ||
| 1219 | return { |
|
| 1220 | restrict: 'A', |
|
| 1221 | compile: function(tElement, tAttrs) { |
|
| 1222 | var linkedScopes = []; |
|
| 1223 | var instances = []; |
|
| 1224 | var expToData = {}; |
|
| 1225 | var lastActivated = null; |
|
| 1226 | var onExpMatches = tAttrs.uibIsClass.match(ON_REGEXP); |
|
| 1227 | var onExp = onExpMatches[2]; |
|
| 1228 | var expsStr = onExpMatches[1]; |
|
| 1229 | var exps = expsStr.split(','); |
|
| 1230 | ||
| 1231 | return linkFn; |
|
| 1232 | ||
| 1233 | function linkFn(scope, element, attrs) { |
|
| 1234 | linkedScopes.push(scope); |
|
| 1235 | instances.push({ |
|
| 1236 | scope: scope, |
|
| 1237 | element: element |
|
| 1238 | }); |
|
| 1239 | ||
| 1240 | exps.forEach(function(exp, k) { |
|
| 1241 | addForExp(exp, scope); |
|
| 1242 | }); |
|
| 1243 | ||
| 1244 | scope.$on('$destroy', removeScope); |
|
| 1245 | } |
|
| 1246 | ||
| 1247 | function addForExp(exp, scope) { |
|
| 1248 | var matches = exp.match(IS_REGEXP); |
|
| 1249 | var clazz = scope.$eval(matches[1]); |
|
| 1250 | var compareWithExp = matches[2]; |
|
| 1251 | var data = expToData[exp]; |
|
| 1252 | if (!data) { |
|
| 1253 | var watchFn = function(compareWithVal) { |
|
| 1254 | var newActivated = null; |
|
| 1255 | instances.some(function(instance) { |
|
| 1256 | var thisVal = instance.scope.$eval(onExp); |
|
| 1257 | if (thisVal === compareWithVal) { |
|
| 1258 | newActivated = instance; |
|
| 1259 | return true; |
|
| 1260 | } |
|
| 1261 | }); |
|
| 1262 | if (data.lastActivated !== newActivated) { |
|
| 1263 | if (data.lastActivated) { |
|
| 1264 | $animate.removeClass(data.lastActivated.element, clazz); |
|
| 1265 | } |
|
| 1266 | if (newActivated) { |
|
| 1267 | $animate.addClass(newActivated.element, clazz); |
|
| 1268 | } |
|
| 1269 | data.lastActivated = newActivated; |
|
| 1270 | } |
|
| 1271 | }; |
|
| 1272 | expToData[exp] = data = { |
|
| 1273 | lastActivated: null, |
|
| 1274 | scope: scope, |
|
| 1275 | watchFn: watchFn, |
|
| 1276 | compareWithExp: compareWithExp, |
|
| 1277 | watcher: scope.$watch(compareWithExp, watchFn) |
|
| 1278 | }; |
|
| 1279 | } |
|
| 1280 | data.watchFn(scope.$eval(compareWithExp)); |
|
| 1281 | } |
|
| 1282 | ||
| 1283 | function removeScope(e) { |
|
| 1284 | var removedScope = e.targetScope; |
|
| 1285 | var index = linkedScopes.indexOf(removedScope); |
|
| 1286 | linkedScopes.splice(index, 1); |
|
| 1287 | instances.splice(index, 1); |
|
| 1288 | if (linkedScopes.length) { |
|
| 1289 | var newWatchScope = linkedScopes[0]; |
|
| 1290 | angular.forEach(expToData, function(data) { |
|
| 1291 | if (data.scope === removedScope) { |
|
| 1292 | data.watcher = newWatchScope.$watch(data.compareWithExp, data.watchFn); |
|
| 1293 | data.scope = newWatchScope; |
|
| 1294 | } |
|
| 1295 | }); |
|
| 1296 | } else { |
|
| 1297 | expToData = {}; |
|
| 1298 | } |
|
| 1299 | } |
|
| 1300 | } |
|
| 1301 | }; |
|
| 1302 | }]); |
|
| 1303 | angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootstrap.isClass']) |
|
| 1304 | ||
| 1305 | .value('$datepickerSuppressError', false) |
|
| @@ 1210-1301 (lines=92) @@ | ||
| 1207 | angular.module('ui.bootstrap.isClass', []) |
|
| 1208 | .directive('uibIsClass', [ |
|
| 1209 | '$animate', |
|
| 1210 | function ($animate) { |
|
| 1211 | // 11111111 22222222 |
|
| 1212 | var ON_REGEXP = /^\s*([\s\S]+?)\s+on\s+([\s\S]+?)\s*$/; |
|
| 1213 | // 11111111 22222222 |
|
| 1214 | var IS_REGEXP = /^\s*([\s\S]+?)\s+for\s+([\s\S]+?)\s*$/; |
|
| 1215 | ||
| 1216 | var dataPerTracked = {}; |
|
| 1217 | ||
| 1218 | return { |
|
| 1219 | restrict: 'A', |
|
| 1220 | compile: function(tElement, tAttrs) { |
|
| 1221 | var linkedScopes = []; |
|
| 1222 | var instances = []; |
|
| 1223 | var expToData = {}; |
|
| 1224 | var lastActivated = null; |
|
| 1225 | var onExpMatches = tAttrs.uibIsClass.match(ON_REGEXP); |
|
| 1226 | var onExp = onExpMatches[2]; |
|
| 1227 | var expsStr = onExpMatches[1]; |
|
| 1228 | var exps = expsStr.split(','); |
|
| 1229 | ||
| 1230 | return linkFn; |
|
| 1231 | ||
| 1232 | function linkFn(scope, element, attrs) { |
|
| 1233 | linkedScopes.push(scope); |
|
| 1234 | instances.push({ |
|
| 1235 | scope: scope, |
|
| 1236 | element: element |
|
| 1237 | }); |
|
| 1238 | ||
| 1239 | exps.forEach(function(exp, k) { |
|
| 1240 | addForExp(exp, scope); |
|
| 1241 | }); |
|
| 1242 | ||
| 1243 | scope.$on('$destroy', removeScope); |
|
| 1244 | } |
|
| 1245 | ||
| 1246 | function addForExp(exp, scope) { |
|
| 1247 | var matches = exp.match(IS_REGEXP); |
|
| 1248 | var clazz = scope.$eval(matches[1]); |
|
| 1249 | var compareWithExp = matches[2]; |
|
| 1250 | var data = expToData[exp]; |
|
| 1251 | if (!data) { |
|
| 1252 | var watchFn = function(compareWithVal) { |
|
| 1253 | var newActivated = null; |
|
| 1254 | instances.some(function(instance) { |
|
| 1255 | var thisVal = instance.scope.$eval(onExp); |
|
| 1256 | if (thisVal === compareWithVal) { |
|
| 1257 | newActivated = instance; |
|
| 1258 | return true; |
|
| 1259 | } |
|
| 1260 | }); |
|
| 1261 | if (data.lastActivated !== newActivated) { |
|
| 1262 | if (data.lastActivated) { |
|
| 1263 | $animate.removeClass(data.lastActivated.element, clazz); |
|
| 1264 | } |
|
| 1265 | if (newActivated) { |
|
| 1266 | $animate.addClass(newActivated.element, clazz); |
|
| 1267 | } |
|
| 1268 | data.lastActivated = newActivated; |
|
| 1269 | } |
|
| 1270 | }; |
|
| 1271 | expToData[exp] = data = { |
|
| 1272 | lastActivated: null, |
|
| 1273 | scope: scope, |
|
| 1274 | watchFn: watchFn, |
|
| 1275 | compareWithExp: compareWithExp, |
|
| 1276 | watcher: scope.$watch(compareWithExp, watchFn) |
|
| 1277 | }; |
|
| 1278 | } |
|
| 1279 | data.watchFn(scope.$eval(compareWithExp)); |
|
| 1280 | } |
|
| 1281 | ||
| 1282 | function removeScope(e) { |
|
| 1283 | var removedScope = e.targetScope; |
|
| 1284 | var index = linkedScopes.indexOf(removedScope); |
|
| 1285 | linkedScopes.splice(index, 1); |
|
| 1286 | instances.splice(index, 1); |
|
| 1287 | if (linkedScopes.length) { |
|
| 1288 | var newWatchScope = linkedScopes[0]; |
|
| 1289 | angular.forEach(expToData, function(data) { |
|
| 1290 | if (data.scope === removedScope) { |
|
| 1291 | data.watcher = newWatchScope.$watch(data.compareWithExp, data.watchFn); |
|
| 1292 | data.scope = newWatchScope; |
|
| 1293 | } |
|
| 1294 | }); |
|
| 1295 | } else { |
|
| 1296 | expToData = {}; |
|
| 1297 | } |
|
| 1298 | } |
|
| 1299 | } |
|
| 1300 | }; |
|
| 1301 | }]); |
|
| 1302 | angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootstrap.isClass']) |
|
| 1303 | ||
| 1304 | .value('$datepickerSuppressError', false) |
|