@@ -127,7 +127,7 @@ ngAnnotate.factory "NGAnnotation", ->
127
127
128
128
return Annotation
129
129
130
- ngAnnotate .directive " ngAnnotate" , ($rootScope , $compile , $http , $q , NGAnnotation , NGAnnotatePopup , NGAnnotateTooltip )->
130
+ ngAnnotate .directive " ngAnnotate" , ($rootScope , $compile , $http , $q , $controller , NGAnnotation , NGAnnotatePopup , NGAnnotateTooltip )->
131
131
return {
132
132
restrict : " A"
133
133
scope :
@@ -143,7 +143,6 @@ ngAnnotate.directive "ngAnnotate", ($rootScope, $compile, $http, $q, NGAnnotatio
143
143
activePopups = []
144
144
activeTooltips = []
145
145
146
-
147
146
# Cache the template when we fetch it
148
147
popupTemplateData = " "
149
148
tooltipTemplateData = " "
@@ -160,7 +159,9 @@ ngAnnotate.directive "ngAnnotate", ($rootScope, $compile, $http, $q, NGAnnotatio
160
159
161
160
# Setting options
162
161
options =
162
+ popupController : " "
163
163
popupTemplateUrl : " "
164
+ tooltipController : " "
164
165
tooltipTemplateUrl : " "
165
166
options = angular .extend options, $scope .options
166
167
@@ -178,25 +179,11 @@ ngAnnotate.directive "ngAnnotate", ($rootScope, $compile, $http, $q, NGAnnotatio
178
179
clearPopups ()
179
180
clearTooltips ()
180
181
181
- getPopupTemplate = (url )->
182
- if popupTemplateData .length
183
- deferred = $q .defer ()
184
- deferred .resolve popupTemplateData
185
- return deferred .promise
186
-
187
- return $http .get (url).then (response)->
188
- popupTemplateData = response .data
189
- return response .data
190
-
191
- getTooltipTemplate = (url )->
192
- if tooltipTemplateData .length
193
- deferred = $q .defer ()
194
- deferred .resolve tooltipTemplateData
195
- return deferred .promise
182
+ $http .get (options .popupTemplateUrl ).then (response)->
183
+ popupTemplateData = response .data
196
184
197
- return $http .get (url).then (response)->
198
- tooltipTemplateData = response .data
199
- return response .data
185
+ $http .get (options .tooltipTemplateUrl ).then (response)->
186
+ tooltipTemplateData = response .data
200
187
201
188
removeChildren = (annotation )->
202
189
for i in [annotation .children .length - 1 .. 0 ] by - 1
@@ -257,6 +244,9 @@ ngAnnotate.directive "ngAnnotate", ($rootScope, $compile, $http, $q, NGAnnotatio
257
244
return annotation
258
245
259
246
onSelect = (event )->
247
+ if popupTemplateData .length is 0
248
+ return
249
+
260
250
try
261
251
annotation = createAnnotation ()
262
252
$scope .$apply ()
@@ -273,6 +263,9 @@ ngAnnotate.directive "ngAnnotate", ($rootScope, $compile, $http, $q, NGAnnotatio
273
263
loadAnnotationPopup annotation, $span, true
274
264
275
265
onClick = (event )->
266
+ if popupTemplateData .length is 0
267
+ return
268
+
276
269
$target = angular .element event .target
277
270
targetId = if (attrId = $target .attr (" data-annotation-id" ))? then parseInt (attrId, 10 )
278
271
@@ -292,6 +285,9 @@ ngAnnotate.directive "ngAnnotate", ($rootScope, $compile, $http, $q, NGAnnotatio
292
285
loadAnnotationPopup annotation, $target, false
293
286
294
287
onMouseEnter = (event )->
288
+ if tooltipTemplateData .length is 0
289
+ return
290
+
295
291
event .stopPropagation ()
296
292
$target = angular .element event .target
297
293
targetId = if (attrId = $target .attr (" data-annotation-id" ))? then parseInt (attrId, 10 )
@@ -318,17 +314,27 @@ ngAnnotate.directive "ngAnnotate", ($rootScope, $compile, $http, $q, NGAnnotatio
318
314
319
315
activeTooltips .push tooltip
320
316
321
- getTemplatePromise = getTooltipTemplate options .tooltipTemplateUrl
322
- getTemplatePromise .then (template)->
323
- $compile (angular .element (template)) tooltip .scope , ($content )->
324
- tooltip .$el .html $content
325
- tooltip .$el .appendTo " body"
326
- tooltip .positionTop ()
327
- tooltip .positionLeft element .offset ().left - tooltip .$el .innerWidth ()
328
- tooltip .show ()
317
+ locals =
318
+ $scope : tooltip .scope
319
+ $template : tooltipTemplateData
320
+
321
+ tooltip .$el .html locals .$template
322
+ tooltip .$el .appendTo " body"
323
+
324
+ if options .tooltipController
325
+ controller = $controller options .tooltipController , locals
326
+ tooltip .$el .data " $ngControllerController" , controller
327
+ tooltip .$el .children ().data " $ngControllerController" , controller
328
+
329
+ $compile (tooltip .$el ) tooltip .scope
330
+ tooltip .positionTop ()
331
+ tooltip .positionLeft element .offset ().left - tooltip .$el .innerWidth ()
332
+ tooltip .scope .$apply ()
333
+ tooltip .show ()
329
334
330
335
onMouseLeave = (event )->
331
336
event .stopPropagation ()
337
+
332
338
$target = angular .element event .target
333
339
targetId = if (attrId = $target .attr (" data-annotation-id" ))? then parseInt (attrId, 10 )
334
340
@@ -368,14 +374,23 @@ ngAnnotate.directive "ngAnnotate", ($rootScope, $compile, $http, $q, NGAnnotatio
368
374
369
375
activePopups .push popup
370
376
371
- getTemplatePromise = getPopupTemplate options .popupTemplateUrl
372
- getTemplatePromise .then (template)->
373
- $compile (angular .element (template)) popup .scope , ($content )->
374
- popup .$el .html $content
375
- popup .$el .appendTo " body"
376
- popup .positionTop ()
377
- popup .positionLeft element .offset ().left - popup .$el .innerWidth ()
378
- popup .show ()
377
+ locals =
378
+ $scope : popup .scope
379
+ $template : popupTemplateData
380
+
381
+ popup .$el .html locals .$template
382
+ popup .$el .appendTo " body"
383
+
384
+ if options .popupController
385
+ controller = $controller options .popupController , locals
386
+ popup .$el .data " $ngControllerController" , controller
387
+ popup .$el .children ().data " $ngControllerController" , controller
388
+
389
+ $compile (popup .$el ) popup .scope
390
+ popup .positionTop ()
391
+ popup .positionLeft element .offset ().left - popup .$el .innerWidth ()
392
+ popup .scope .$apply ()
393
+ popup .show ()
379
394
380
395
element .on " mouseover" , " span" , onMouseEnter
381
396
element .on " mouseleave" , " span" , onMouseLeave
0 commit comments