Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions angular-typeform.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
});

angular.module('angularTypeform')
.controller('ControllerEmbed', ['$scope', 'typeformConfig', '$timeout', function embedController($scope, typeformConfig, $timeout) {
.controller('ControllerEmbed', ['$scope', '$element', 'typeformConfig', '$timeout', function embedController($scope, $element, typeformConfig, $timeout) {

if (!typeformConfig.accountId) {
throw new EvalError('Account ID not set in config');
Expand All @@ -38,25 +38,30 @@

function initTypeformScript() {
var qs,
js,
q,
s,
d = document,
gi = d.getElementById,
ce = d.createElement,
gt = d.getElementsByTagName,
id = 'typef_orm_widget',
b = 'https://s3-eu-west-1.amazonaws.com/share.typeform.com/';
js,
q,
s,
d=document,
gi=d.getElementById,
ce=d.createElement,
gt=d.getElementsByTagName,
id="typef_orm_widget",
b="https://embed.typeform.com/";

if (!gi.call(d, id)) {
js = ce.call(d, 'script');
js.id = id;
js.src = b + 'widget.js';
q = gt.call(d, 'script')[0];
q.parentNode.insertBefore(js, q)
js=ce.call(d,"script");
js.id=id;
js.src=b+"embed.js";
q=gt.call(d,"script")[0];
q.parentNode.insertBefore(js,q);
} else {

var tfIdAndHidden = $scope.tfHidden ? $scope.tfId + '?' + $scope.tfHidden : $scope.tfId;

//For angular apps
new Typeform.Widget
// new Typeform.Widget
var typeFormUrl = 'https://' + $scope.accountId + '.typeform.com/to/' + tfIdAndHidden;
new window.typeformEmbed.makeWidget($element[0], typeFormUrl);
}
}

Expand All @@ -72,15 +77,18 @@
replace: true,
scope: {
tfId: '@',
tfHidden: '@',
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>',
template: '<div class="typeform-widget" ng-attr-data-url="https://{{accountId}}.typeform.com/to/{{tfIdAndHidden}}" ng-attr-data-text="{{tfText}}" ng-attr-style="{{style}}"></div>',
controller: 'ControllerEmbed',
link: function (scope, element, attrs) {

var defaultStyle = "height:100%; margin:0;";
scope.style= scope.tfStyle ? scope.tfStyle : defaultStyle;

scope.tfIdAndHidden = scope.tfHidden ? scope.tfId + '?' + scope.tfHidden : scope.tfId;
}
};
});
Expand Down
23 changes: 23 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "angular-typeform",
"version": "0.0.2",
"description": "An angular 1.x directive for Typeform",
"main": "angular-typeform.js",
"authors": [
"Adrian Latorre"
],
"license": "MIT",
"keywords": [
"angular",
"directive",
"typeform"
],
"homepage": "https://github.com/willylatorre/angular-typeform",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
]
}