Skip to content

Commit

Permalink
Merge pull request #9 from talis/ent_1377_double_click_bookmark_problems
Browse files Browse the repository at this point in the history
ENT-1377 double click bookmark problems
  • Loading branch information
Richard Gubby authored Oct 7, 2019
2 parents 9206983 + 011d4f8 commit 12fa558
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

.idea
bower_components/
dist/
node_modules/
30 changes: 12 additions & 18 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,21 @@
*
* This only does anything when the bookmarking button is clicked
*/
chromeOrBrowser().browserAction.onClicked.addListener(function(tab) {
chromeOrBrowser().browserAction.onClicked.addListener(function(currentTab) {
// If no institution has been set, go to the options page to set one
getActiveTenant(function (tenantCode) {
if (!tenantCode) {
if (window.confirm(chromeOrBrowser().i18n.getMessage('noTenantAlert'))) {
// browser.runtime.openOptionsPage() not supported by ms-edge, so here's a workaround
chromeOrBrowser().tabs.create({
url: chromeOrBrowser().extension.getURL("options.html")
});
}
// browser.runtime.openOptionsPage() not supported by ms-edge, so here's a workaround
chromeOrBrowser().tabs.create({
url: chromeOrBrowser().extension.getURL("options.html")
});
} else {
chromeOrBrowser().tabs.executeScript(null, {
file: "/js/bookmarker.js",
runAt: 'document_end'
}, function () {
chromeOrBrowser().tabs.sendMessage(currentTab.id, {tenantCode: tenantCode});
});
}

chromeOrBrowser().tabs.executeScript(null, {
file: "/js/bookmarker.js",
runAt: 'document_end'
});

chromeOrBrowser().tabs.query({active: true, currentWindow: true}, function(tabs) {
chromeOrBrowser().tabs.sendMessage(tabs[0].id, {tenantCode: tenantCode});
return true;
});
return true;
});
});
30 changes: 19 additions & 11 deletions js/bookmarker.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
/*
* Content script to inject the dynamic bookmarking JS directly into the page.
*/

(function() {
function chromeOrBrowser() {
return this.browser || chrome;
}

/**
* Injected into page to redirect to the dynamic page parser
*
* @param {String} tenantCode
*/
function bookmarkPage(tenantCode, cb) {
function bookmarkPage(tenantCode) {
var bookmarkingScriptId = '__talis_' + tenantCode + '_bookmarkingScript';

if (document.getElementById(bookmarkingScriptId)) {
document.getElementById(bookmarkingScriptId).remove();
}

var bookmarker = document.createElement('script');
bookmarker.setAttribute(
'src',
'https://bookmarking.talis.com/' + tenantCode + '/parser?bookmarkButtonVersion=1&uri=' +
'src',
'https://bookmarking.talis.com/' + tenantCode + '/parser?bookmarkButtonVersion=1&uri=' +
encodeURIComponent(encodeURI(window.location.href)) + '&bookmarkVersion=1&title=' +
encodeURIComponent(document.title) + '&hasJquery=no'
);
document.body.appendChild(bookmarker);
cb();
);
bookmarker.setAttribute('id', bookmarkingScriptId);

if (document.body) {
document.body.appendChild(bookmarker);
}
}
chromeOrBrowser().runtime.onMessage.addListener(function(message, sender, sendResponse) {
bookmarkPage(message.tenantCode, function () {
sendResponse({status: 'ok'});
});

chromeOrBrowser().runtime.onMessage.addListener(function (message) {
bookmarkPage(message.tenantCode);
});
})();
3 changes: 3 additions & 0 deletions js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ $(function() {

function loadTenantList() {
getActiveTenant(function(activeTenant) {
if (!activeTenant) {
$('#optionsHelp').html('<div class="alert alert-warning">' + chromeOrBrowser().i18n.getMessage('noTenantAlert') + '</div>');
}
$('#tenantCode').val(activeTenant);
getTenants(function(tenants) {
var matched = false;
Expand Down
1 change: 1 addition & 0 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<div class="row" id="status">

</div>
<div class="row" id="optionsHelp"></div>
<div class="row">
<div class="col-xs-2">
<span data-message="optionsInstitutionLabel">Institution:</span><br>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "talis-reading-lists-bookmarker",
"version": "0.3.5",
"version": "0.3.6",
"description": "A browser extension to bookmark resources to Talis Aspire Reading Lists",
"devDependencies": {
"grunt": "^1.0.1",
Expand Down

0 comments on commit 12fa558

Please sign in to comment.