/** * angular-help-me * @version v0.0.1 - 2016-05-20 * @link https://github.com/marshal003/angular-help-me * @author Vinit Kumar Rai * @license MIT License, http://www.opensource.org/licenses/MIT */ "use strict";angular.module("hiComponents.helpMe",[]).value("hiHelpDB",{aboutHelp:"The help DB will contain a JSON of key value pair, that would be used to display help content. Use help-text directive by passing the key to get the help content."}).service("hiHelpDBService",["hiHelpDB",function(a){return{get:function(){return a}}}]).service("hiHelpDesk",["$rootScope","$templateCache","hiHelpDBService","$q",function(a,b,c,d){var e={},f=!0,g=null,h="helpMe.directiveHTML",i=!1,j="tooltip",k=function(a){return angular.isDefined(g)&&g in e?e[g][a]:e[a]},l=function(){f=!f,a.$broadcast("hihelpMe-toggle-help-text")},m=function(){return f},n=function(b){f=b,a.$broadcast("hihelpMe-toggle-help-text")},o=function(a){b.put(h,a)},p=function(a){return a||(a=h),b.get(a)},q=function(){b.get(h)||o(''),t(c.get())},r=function(b){g=b,a.$broadcast("hihelpMe-on-locale-change")},s=function(a,b){for(var c in b)c in a&&angular.isObject(b[c])?s(a[c],b[c]):a[c]=b[c]},t=function(b){d.when(b).then(function(b){s(e,b),a.$broadcast("hihelpMe-on-db-change")})},u=function(b,c,d){angular.isDefined(d)?(d in e||(e[d]={}),e[d][b]=c):e[b]=c,a.$broadcast("hihelpMe-on-db-update")},v=function(a){i=a},w=function(a){j=a},x=function(){return j},y=function(){return i};return q(),{addHelpText:u,getHelpForKey:k,toggleHelpText:l,isHelpModeOn:m,setHelpMode:n,setHelpTemplate:o,getHelpTemplate:p,setHelpDatabase:t,setLocale:r,helpTextAsDataAttribute:v,renderHelpTextAsDataAtrribute:y,getHelpTextDataAttribite:x,setHelpTextDataAttribute:w}}]).directive("hiHelpText",function(){return{scope:!0,restrict:"A",controller:["$scope","$compile","hiHelpDesk","$log",function(a,b,c,d){a.helpKey="",a.getHelpElement=function(d){var e=angular.element(c.getHelpTemplate(d));return b(e)(a)},a.getHelpText=function(b){a.helpKey=b,a.helpText=c.getHelpForKey(b),e()};var e=function(){a.showHelpText=c.isHelpModeOn()&&void 0!==a.helpText&&a.helpText.length>0,a.displayTextAsAttribute&&a.updateElementDataAttribute(a.showHelpText,a.helpText)};a.$on("hihelpMe-toggle-help-text",function(){e()}),a.$on("hihelpMe-on-locale-change",function(){a.helpText=c.getHelpForKey(a.helpKey),e()}),a.$on("hihelpMe-on-db-change",function(){a.helpText=c.getHelpForKey(a.helpKey),e()}),a.$on("hihelpMe-on-db-update",function(b,d){d.key===a.helpKey&&(a.helpText=c.getHelpForKey(a.helpKey),e())}),a.renderHelpTextAsDataAtrribute=function(a){return!a.hiHelpTpl&&(a.helpTextAsDataAttr||c.renderHelpTextAsDataAtrribute())},a.getHelpAttribute=function(a){return a.helpTextAsDataAttr&&a.helpTextAsDataAttr.length>0?a.helpTextAsDataAttr:c.getHelpTextDataAttribite()}}],link:function(a,b,c){if(""!==c.hiHelpText){var d=function(){var a=["input","select","textarea"],c=b.prop("tagName").toLowerCase();return-1===a.indexOf(c)},e=a.getHelpAttribute(c);a.displayTextAsAttribute=a.renderHelpTextAsDataAtrribute(c),a.updateElementDataAttribute=function(a,c){a===!0?b.attr(e,c):b.removeAttr(e)};var f=function(){if(!a.renderHelpTextAsDataAtrribute(c)){var e=a.getHelpElement(c.hiHelpTpl);d()?b.append(e):b.after(e)}};a.getHelpText(c.hiHelpText),f()}}}});