Created
April 6, 2015 17:56
-
-
Save TrevorJTClarke/cc762bd22c95fc826aed to your computer and use it in GitHub Desktop.
Chrome Inline Install Angular Directive
This file contains hidden or 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
/** | |
* chromeInstall | |
* a directive for inline install of a chrome extension from a website using Angular | |
* | |
* Make sure that the head meta data contains: | |
* <link rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/CHROME_EXTENSION_ID"> | |
*/ | |
yourApp.directive('chromeInstall', | |
[function() { | |
return { | |
link: function (scope, el, attrs) { | |
// NOTE: change to your chrome extension ID | |
var _URL = 'https://chrome.google.com/webstore/detail/CHROME_EXTENSION_ID'; | |
function chromeFailed() { | |
window.location.href = _URL; | |
} | |
function finishInstall() { | |
console.log("Installed!"); | |
} | |
el.bind('click', function(e) { | |
if (chrome.webstore.install) { | |
chrome.webstore.install(_URL, finishInstall, chromeFailed ); | |
} else { | |
chromeFailed(); | |
} | |
}); | |
} | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment