jQueryのプラグイン使うときに、モデルの値が読み込まれてからjQueryプラグイン適用したい場合があったので、directiveでやってみることに。
angular-at-on-load-element
###*
* angular at-on-load-element
*
* @author atomita
* @license MIT
* @version 0.0.1
###
angular.module("at-on-load-element", []).directive("atOnLoadElement", ["$timeout", ($timeout)->
{
restrict: "AC"
scope: true
link: (scope, iElement, iAttrs)->
apply = iAttrs.atOnLoadElement
if apply
scope.element = iElement
scope.attrs = iAttrs
scope.angular = angular
$timeout -> scope.$apply(apply)
return
}
]).directive("atOnLoadElementFromFirst", ["$timeout", ($timeout)->
{
restrict: "AC"
scope: true
link: (scope, iElement, iAttrs)->
apply = iAttrs.atOnLoadElementFromFirst
$parent = scope
loop
$parent = $parent.$parent
if $parent
if "$first" of $parent
$first = $parent.$first
break
else
break
if apply and $first
scope.element = iElement
scope.attrs = iAttrs
scope.angular = angular
$timeout -> scope.$apply(apply)
return
}
]).directive("atOnLoadElementFromMiddle", ["$timeout", ($timeout)->
{
restrict: "AC"
scope: true
link: (scope, iElement, iAttrs)->
apply = iAttrs.atOnLoadElementFromMiddle
$parent = scope
loop
$parent = $parent.$parent
if $parent
if "$middle" of $parent
$middle = $parent.$middle
break
else
break
if apply and $middle
scope.element = iElement
scope.attrs = iAttrs
scope.angular = angular
$timeout -> scope.$apply(apply)
return
}
]).directive("atOnLoadElementFromLast", ["$timeout", ($timeout)->
{
restrict: "AC"
scope: true
link: (scope, iElement, iAttrs)->
apply = iAttrs.atOnLoadElementFromLast
$parent = scope
loop
$parent = $parent.$parent
if $parent
if "$last" of $parent
$last = $parent.$last
break
else
break
if apply and $last
scope.element = iElement
scope.attrs = iAttrs
scope.angular = angular
$timeout -> scope.$apply(apply)
return
}
])