From 3b80f1f8c34808b8102b0a3efc4a9f007ea4c1d1 Mon Sep 17 00:00:00 2001 From: jeneg Date: Tue, 4 Oct 2016 18:47:35 +0300 Subject: [PATCH] Added context parameter handler --- dist/angulartics-scroll.min.js | 2 +- dist/angulartics-scroll.min.js.map | 2 +- lib/angulartics-scroll.js | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/dist/angulartics-scroll.min.js b/dist/angulartics-scroll.min.js index d7eb99d..26983c5 100644 --- a/dist/angulartics-scroll.min.js +++ b/dist/angulartics-scroll.min.js @@ -1,2 +1,2 @@ -!function(window,angular){"use strict";angular.module("angulartics.scroll",["angulartics"]).factory("$waypoint",function(){return function(options){return new Waypoint(options)}}).directive("analyticsOn",["$analytics","$waypoint",function($analytics,$waypoint){function isProperty(name){return"scrollby"===name.substr(0,8)}function cast(value){return""===value||"true"===value?!0:"false"===value?!1:value}return{restrict:"A",priority:5,scope:!1,link:function($scope,$element,$attrs){if("scrollby"===$attrs.analyticsOn){var properties={handler:function(){$element.triggerHandler("scrollby"),this.options.triggeronce&&this.destroy()},element:$element[0],continuous:!1,triggeronce:!0};angular.forEach($attrs.$attr,function(attr,name){isProperty(attr)&&(properties[name.slice(8,9).toLowerCase()+name.slice(9)]=cast($attrs[name]))}),$waypoint(properties)}}}}])}(window,window.angular); +!function(window,angular){"use strict";angular.module("angulartics.scroll",["angulartics"]).factory("$waypoint",function(){return function(options){return new Waypoint(options)}}).directive("analyticsOn",["$analytics","$waypoint","$document",function($analytics,$waypoint,$document){function isProperty(name){return"scrollby"===name.substr(0,8)}function cast(value){return""===value||"true"===value||"false"!==value&&value}return{restrict:"A",priority:5,scope:!1,link:function($scope,$element,$attrs){if("scrollby"===$attrs.analyticsOn){var properties={handler:function(){$element.triggerHandler("scrollby"),this.options.triggeronce&&this.destroy()},element:$element[0],continuous:!1,triggeronce:!0};angular.forEach($attrs.$attr,function(attr,name){var key,value;isProperty(attr)&&(key=name.slice(8,9).toLowerCase()+name.slice(9),value="context"===key?$document[0].querySelector($attrs[name]):cast($attrs[name]),properties[key]=value)}),$waypoint(properties)}}}}])}(window,window.angular); //# sourceMappingURL=../dist/angulartics-scroll.min.js.map \ No newline at end of file diff --git a/dist/angulartics-scroll.min.js.map b/dist/angulartics-scroll.min.js.map index 906bf3e..0a22155 100644 --- a/dist/angulartics-scroll.min.js.map +++ b/dist/angulartics-scroll.min.js.map @@ -1 +1 @@ -{"version":3,"file":"dist/angulartics-scroll.min.js","sources":["lib/angulartics-scroll.js"],"names":["window","angular","module","factory","options","Waypoint","directive","$analytics","$waypoint","isProperty","name","substr","cast","value","restrict","priority","scope","link","$scope","$element","$attrs","analyticsOn","properties","handler","triggerHandler","this","triggeronce","destroy","element","continuous","forEach","$attr","attr","slice","toLowerCase"],"mappings":"CAMA,SAAWA,OAAQC,SACnB,YAQAA,SAAQC,OAAO,sBAAuB,gBACrCC,QAAQ,YAAa,WACpB,MAAO,UAASC,SACd,MAAO,IAAIC,UAASD,YAGvBE,UAAU,eAAgB,aAAc,YAAa,SAAUC,WAAYC,WAC1E,QAASC,YAAYC,MACnB,MAA6B,aAAtBA,KAAKC,OAAO,EAAG,GAExB,QAASC,MAAMC,OACb,MAAc,KAAVA,OAA0B,SAAVA,OACX,EACY,UAAVA,OACF,EAEAA,MAIX,OACEC,SAAU,IACVC,SAAU,EACVC,OAAO,EACPC,KAAM,SAAUC,OAAQC,SAAUC,QAChC,GAA2B,aAAvBA,OAAOC,YAAX,CAEA,GAAIC,aACFC,QAAS,WACPJ,SAASK,eAAe,YACpBC,KAAKrB,QAAQsB,aACfD,KAAKE,WAGTC,QAAST,SAAS,GAClBU,YAAY,EACZH,aAAa,EAEfzB,SAAQ6B,QAAQV,OAAOW,MAAO,SAAUC,KAAMtB,MACxCD,WAAWuB,QACbV,WAAWZ,KAAKuB,MAAM,EAAE,GAAGC,cAAcxB,KAAKuB,MAAM,IAAMrB,KAAKQ,OAAOV,UAI1EF,UAAUc,mBAIbtB,OAAQA,OAAOC","sourceRoot":".."} \ No newline at end of file +{"version":3,"sources":["lib/angulartics-scroll.js"],"names":["window","angular","module","factory","options","Waypoint","directive","$analytics","$waypoint","$document","isProperty","name","substr","cast","value","restrict","priority","scope","link","$scope","$element","$attrs","analyticsOn","properties","handler","triggerHandler","this","triggeronce","destroy","element","continuous","forEach","$attr","attr","key","slice","toLowerCase","querySelector"],"mappings":"CAMA,SAAWA,OAAQC,SACnB,YAQAA,SAAQC,OAAO,sBAAuB,gBACrCC,QAAQ,YAAa,WACpB,MAAO,UAASC,SACd,MAAO,IAAIC,UAASD,YAGvBE,UAAU,eAAgB,aAAc,YAAa,YAAa,SAAUC,WAAYC,UAAWC,WAClG,QAASC,YAAYC,MACnB,MAA6B,aAAtBA,KAAKC,OAAO,EAAG,GAExB,QAASC,MAAMC,OACb,MAAc,KAAVA,OAA0B,SAAVA,OAEC,UAAVA,OAGFA,MAIX,OACEC,SAAU,IACVC,SAAU,EACVC,OAAO,EACPC,KAAM,SAAUC,OAAQC,SAAUC,QAChC,GAA2B,aAAvBA,OAAOC,YAAX,CAEA,GAAIC,aACFC,QAAS,WACPJ,SAASK,eAAe,YACpBC,KAAKtB,QAAQuB,aACfD,KAAKE,WAGTC,QAAST,SAAS,GAClBU,YAAY,EACZH,aAAa,EAEf1B,SAAQ8B,QAAQV,OAAOW,MAAO,SAAUC,KAAMtB,MAC5C,GAAIuB,KAAKpB,KAELJ,YAAWuB,QACbC,IAAMvB,KAAKwB,MAAM,EAAE,GAAGC,cAAczB,KAAKwB,MAAM,GAG7CrB,MADU,YAARoB,IACMzB,UAAU,GAAG4B,cAAchB,OAAOV,OAElCE,KAAKQ,OAAOV,OAGtBY,WAAWW,KAAOpB,SAItBN,UAAUe,mBAIbvB,OAAQA,OAAOC","file":"dist/angulartics-scroll.min.js","sourceRoot":".."} \ No newline at end of file diff --git a/lib/angulartics-scroll.js b/lib/angulartics-scroll.js index b04418d..a47073b 100644 --- a/lib/angulartics-scroll.js +++ b/lib/angulartics-scroll.js @@ -19,7 +19,7 @@ angular.module('angulartics.scroll', ['angulartics']) return new Waypoint(options); }; }) -.directive('analyticsOn', ['$analytics', '$waypoint', function ($analytics, $waypoint) { +.directive('analyticsOn', ['$analytics', '$waypoint', '$document', function ($analytics, $waypoint, $document) { function isProperty (name) { return name.substr(0, 8) === 'scrollby'; } @@ -52,8 +52,18 @@ angular.module('angulartics.scroll', ['angulartics']) triggeronce: true }; angular.forEach($attrs.$attr, function (attr, name) { + var key, value; + if (isProperty(attr)) { - properties[name.slice(8,9).toLowerCase()+name.slice(9)] = cast($attrs[name]); + key = name.slice(8,9).toLowerCase()+name.slice(9); + + if (key === 'context') { + value = $document[0].querySelector($attrs[name]); + } else { + value = cast($attrs[name]); + } + + properties[key] = value; } });