Created
August 27, 2014 01:44
-
-
Save ahey/14f75186674a5fdac318 to your computer and use it in GitHub Desktop.
angularjs directive to show the quickbooks connect button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
angular.module('thirdParty') | |
.directive('connectToQuickbooks', function($window){ | |
return { | |
restrict: 'E', | |
template: "<ipp:connectToIntuit></ipp:connectToIntuit>", | |
link: function(scope) { | |
var intuitScriptLoaded = function(){ | |
return $window.intuit | |
&& $window.intuit.ipp | |
&& $window.intuit.ipp.anywhere | |
&& $window.intuit.ipp.anywhere.setup; | |
}; | |
if (intuitScriptLoaded()) { | |
// Hack to get the button to reload when this directive is shown | |
// for the second time, since the QB connect button assumes that | |
// the button is not rendered dynamically | |
$window.intuit.ipp.anywhere.init(); | |
} else { | |
var script = $window.document.createElement("script"); | |
script.type = "text/javascript"; | |
script.src = "//js.appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js"; | |
$window.document.body.appendChild(script); | |
} | |
scope.$watch( | |
intuitScriptLoaded, | |
function(newValue, oldValue) { | |
if(intuitScriptLoaded()) { | |
$window.intuit.ipp.anywhere.setup({ | |
grantUrl: '/' | |
}); | |
} | |
} | |
); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can someone help me on this.
Thanks in advance