angular-typeform
Version:
An angular 1.x directive for Typeform
1 lines • 2.54 kB
JavaScript
!function(){"use strict";angular.module("angularTypeform",[]),angular.module("angularTypeform").provider("typeformConfig",function(){this.accountId="",this.setAccount=function(t){this.accountId=t},this.$get=function(){return this}}),angular.module("angularTypeform").controller("ControllerEmbed",["$scope","typeformConfig","$timeout",function(t,e,r){function n(){var t,e,r=document,n=r.getElementById,o=r.createElement,a=r.getElementsByTagName,c="typef_orm_widget",l="https://s3-eu-west-1.amazonaws.com/share.typeform.com/";n.call(r,c)?new Typeform.Widget:(t=o.call(r,"script"),t.id=c,t.src=l+"widget.js",e=a.call(r,"script")[0],e.parentNode.insertBefore(t,e))}if(!e.accountId)throw new EvalError("Account ID not set in config");t.accountId=e.accountId,r(function(){n()})}]).directive("typeformEmbed",function(){return{restrict:"EA",replace:!0,scope:{tfId:"@",tfText:"@",tfStyle:"@"},template:'<div class="typeform-widget" ng-attr-data-url="https://{{accountId}}.typeform.com/to/{{tfId}}" ng-attr-data-text="{{tfText}}" ng-attr-style="{{style}}"></div>',controller:"ControllerEmbed",link:function(t,e,r){var n="height:100%; margin:0;";t.style=t.tfStyle?t.tfStyle:n}}}),angular.module("angularTypeform").controller("ControllerLink",["$scope","typeformConfig","$timeout",function(t,e,r){function n(t){if(!t)return i;switch(t){case f:return f;case i:default:return i}}function o(t){var e,r,n,o,a=document,c=a.getElementById,l=a.createElement,i=a.getElementsByTagName,s="typef_orm_share",u="https://s3-eu-west-1.amazonaws.com/share.typeform.com/";c.call(a,s)||(r=l.call(a,"script"),r.id=s,r.src=u+"share.js",n=i.call(a,"script")[0],n.parentNode.insertBefore(r,n)),s+="_",t!=f||c.call(a,s)||(e=l.call(a,"link"),e.rel="stylesheet",e.id=s,e.href=u+"share-button.css",o=i.call(a,"head")[0],o.appendChild(e,o))}function a(t){if(!t)return"1";switch(t){case l:return"2";case c:default:return"1"}}var c="popup",l="banner",i="link",f="button";if(!e.accountId)throw new EvalError("Account ID not set in config");t.accountId=e.accountId;var s=n(t.tfType);t.type=s,t.mode=a(t.tfMode),r(function(){o(s)})}]).directive("typeformLink",function(){return{restrict:"EA",replace:!0,scope:{tfMode:"@",tfType:"@",tfId:"@",tfText:"@",tfStyle:"@"},template:'<a ng-attr-class="typeform-share {{type}}" ng-attr-href="https://{{accountId}}.typeform.com/to/{{tfId}}" ng-attr-data-mode="{{mode}}" ng-attr-style="{{style}}" target="_blank">{{tfText}}</a>',controller:"ControllerLink",link:function(t,e,r){var n="height:100%; margin:0;";t.style=t.tfStyle?t.tfStyle:n}}})}();