Skip to content

Commit

Permalink
Merge pull request #10 from talis/plat-3779-support-ca
Browse files Browse the repository at this point in the history
  • Loading branch information
kiyanwang authored Aug 25, 2020
2 parents 12fa558 + 6871157 commit 5810106
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 50 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
14.2
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ Talis Aspire Reading Lists Bookmarking Extension
================================================

Requirements:
- [npm](https://www.npmjs.com/)
- [nvm](https://github.com/nvm-sh/nvm)

This project provides an alternative to the Talis Aspire Reading Lists Bookmarking Bookmarklet,
This project provides an alternative to the Talis Aspire Reading Lists Bookmarking Bookmarklet,
which can be forked and rebranded for distribution in institutional enterprise environments.

The extension should work with:
Expand Down Expand Up @@ -38,13 +38,17 @@ The different sizes will be used by different browsers in different ways.

All strings in the extension can be edited by changing the values in the language files in the `_locales` directory.

To build the files for the extension,
```
To build the files for the extension,
```bash
$ git checkout https://github.com/talis/rl-bookmarking-extension.git
$ cd rl-bookmarking-extension
# use nvm to switch to the version of nodejs that is required
$ nvm use
$ npm install # This should also run bower install
# replace ./images/*.png and ./_locales with institutional preferences
$ grunt # This will build a Chrome/Opera/Vivaldi extension
$ grunt dist-manifold # This will build a [Manifoldjs](https://github.com/pwa-builder/ManifoldJS) compatible manifest, which can be used to package an MS Edge extension
$ grunt --identifier="{AMO UUID}" # This will build the extension with a Mozilla Add-on Identifier
$ $(npm bin)/grunt # This will build a Chrome/Opera/Vivaldi extension
$ $(npm bin)/grunt dist-manifold # This will build a [Manifoldjs](https://github.com/pwa-builder/ManifoldJS) compatible manifest, which can be used to package an MS Edge extension
$ $(npm bin)/grunt --identifier="{AMO UUID}" # This will build the extension with a Mozilla Add-on Identifier
```

The `./dist` directory should then contain everything you need for a `.crx`, `.xpi`, `.zip`, etc.
26 changes: 18 additions & 8 deletions js/allTenants.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
/**
* Use this to populate the list of institutions in the options menu. In order for a tenant to
* Use this to populate the list of institutions in the options menu. In order for a tenant to
* appear, it *must* have an `apps.rl` value (which can be anything)
*
*
* The non-branded 'Talis' extension should use the tenant list from:
* https://talis-public.s3-eu-west-1.amazonaws.com/talis.com/customers.json
*/
var allTenants = {
"broadminster" : {
"name" : "Broadminster University",
"apps" : {
"apps" : {
"rl" : true
}
},
"region" : "EUAPAC"
},
"broadminster_old" : {
"broadminster_old" : {
"name" : "Old Broadminster University",
"apps" : {
"rl" : true
}
},
"region" : "EUAPAC"
},
"cst" : {
"name" : "CST | Talis Training",
"apps" : {
"rl" : true
}
},
"region" : "EUAPAC"
},
"testfour" : {
"name" : "Test Four | Talis Testing",
"apps" : {
"rl" : true
},
"region" : "CA"
}
};
};
8 changes: 4 additions & 4 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
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) {
getActiveTenant(function (tenant) {
if (!tenant) {
// browser.runtime.openOptionsPage() not supported by ms-edge, so here's a workaround
chromeOrBrowser().tabs.create({
url: chromeOrBrowser().extension.getURL("options.html")
Expand All @@ -16,8 +16,8 @@ chromeOrBrowser().browserAction.onClicked.addListener(function(currentTab) {
file: "/js/bookmarker.js",
runAt: 'document_end'
}, function () {
chromeOrBrowser().tabs.sendMessage(currentTab.id, {tenantCode: tenantCode});
chromeOrBrowser().tabs.sendMessage(currentTab.id, {tenant: tenant});
});
}
});
});
});
16 changes: 11 additions & 5 deletions js/bookmarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,23 @@
*
* @param {String} tenantCode
*/
function bookmarkPage(tenantCode) {
var bookmarkingScriptId = '__talis_' + tenantCode + '_bookmarkingScript';
function bookmarkPage(tenant) {
var bookmarkingScriptId = '__talis_' + tenant.code + '_bookmarkingScript';

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

var bookmarker = document.createElement('script');
var bookmarkingEndpoint = (
tenant.region === 'CA' ?
'https://bookmarking.ca.talis.com' :
'https://bookmarking.talis.com'
);

bookmarker.setAttribute(
'src',
'https://bookmarking.talis.com/' + tenantCode + '/parser?bookmarkButtonVersion=1&uri=' +
bookmarkingEndpoint + '/' + tenant.code + '/parser?bookmarkButtonVersion=1&uri=' +
encodeURIComponent(encodeURI(window.location.href)) + '&bookmarkVersion=1&title=' +
encodeURIComponent(document.title) + '&hasJquery=no'
);
Expand All @@ -33,6 +39,6 @@
}

chromeOrBrowser().runtime.onMessage.addListener(function (message) {
bookmarkPage(message.tenantCode);
bookmarkPage(message.tenant);
});
})();
})();
35 changes: 20 additions & 15 deletions js/options.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@

$(function() {


$('#tenantList').on('change', function() {
$('#tenantCode').val($('#tenantList').val());
if ($('#specifyTenant:selected').length > 0) {
$('#manualEntry').removeClass('hidden');
} else {
} else {
$('#manualEntry').addClass('hidden');
}
});
$('#save').on('click', function() {
saveActiveTenant($('#tenantCode').val(), function() {
// Update status to let user know options were saved.
$('#status').html('<div class="alert alert-success">' + chromeOrBrowser().i18n.getMessage('optionsSettingsSaved') + '</div>');
setTimeout(function() {
$('#status').textContent = '';
}, 750);
getTenants(function(tenants) {
for (var tenantCode in tenants) {
if (tenantCode === $('#tenantCode').val()) {
saveActiveTenant(tenants[tenantCode], function() {
// Update status to let user know options were saved.
$('#status').html('<div class="alert alert-success">' + chromeOrBrowser().i18n.getMessage('optionsSettingsSaved') + '</div>');
$('#optionsHelp').addClass('hidden');
setTimeout(function() {
$('#status').textContent = '';
}, 750);
});
}
}
});
});

Expand All @@ -34,21 +39,21 @@ function loadTenantList() {
if (!activeTenant) {
$('#optionsHelp').html('<div class="alert alert-warning">' + chromeOrBrowser().i18n.getMessage('noTenantAlert') + '</div>');
}
$('#tenantCode').val(activeTenant);

getTenants(function(tenants) {
var matched = false;
for (var tenantCode in tenants) {
if (tenantCode == activeTenant) {
if (activeTenant && tenantCode === activeTenant.code) {
matched = true;
$('#tenantList option:last-of-type').before('<option class="tenantCode" value="' + tenantCode + '" selected>' + tenants[tenantCode] + '</option>');
$('#tenantList option:last-of-type').before('<option class="tenantCode" value="' + tenantCode + '" selected>' + tenants[tenantCode].name + '</option>');
} else {
$('#tenantList option:last-of-type').before('<option class="tenantCode" value="' + tenantCode + '">' + tenants[tenantCode] + '</option>');
$('#tenantList option:last-of-type').before('<option class="tenantCode" value="' + tenantCode + '">' + tenants[tenantCode].name + '</option>');
}
}
if (activeTenant && !matched) {
$('#specifyTenant').attr('selected', 'selected');
$('#manualEntry').removeClass('hidden');
}
});
});
}
});
}
21 changes: 12 additions & 9 deletions js/tenants.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if (!storage) {
/**
* @callback activeTenant
*
* @param {string} tenantCode - Currently active tenant code
* @param {object} tenant - Currently active tenant
*/
/**
* Returns the saved 'active' tenant from browser storage
Expand All @@ -43,23 +43,23 @@ function getActiveTenant(cb) {
}

/**
* Stores the preferred tenantCode in browser storage
* Stores the preferred tenant in browser storage
*
* @param {string} tenantCode
* @param {object} tenant
* @param {function()} cb - Callback to run once stored
*/
function saveActiveTenant(tenantCode, cb) {
function saveActiveTenant(tenant, cb) {
storage.set({
activeTenant: tenantCode
activeTenant: tenant
}, function() {
if (chromeOrBrowser().runtime.lastError) {
storage = chromeOrBrowser().storage.local;
return saveActiveTenant(tenantCode, cb);
return saveActiveTenant(tenant, cb);
} else {
getActiveTenant(function(t) {
if (typeof t === 'undefined') {
storage = chromeOrBrowser().storage.local;
return saveActiveTenant(tenantCode, cb);
return saveActiveTenant(tenant, cb);
} else {
cb();
}
Expand All @@ -84,8 +84,11 @@ function getTenants(cb) {
var tenants = {};
getTenantList(function(tenantList) {
for (var code in tenantList) {
if (tenantList[code].hasOwnProperty('apps') && tenantList[code].apps.hasOwnProperty('rl')) {
tenants[code] = tenantList[code].name;
var tenant = tenantList[code];
tenant.code = code;

if (tenant.hasOwnProperty('apps') && tenant.apps.hasOwnProperty('rl')) {
tenants[code] = tenant;
}
}
cb(tenants);
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "talis-reading-lists-bookmarker",
"version": "0.3.6",
"version": "0.3.7",
"description": "A browser extension to bookmark resources to Talis Aspire Reading Lists",
"devDependencies": {
"grunt": "^1.0.1",
"grunt-contrib-copy": "^1.0.0"
"grunt-contrib-copy": "^1.0.0",
"manifoldjs": "^0.7.6"
},
"dependencies": {
"bootstrap": "^3.3.6",
Expand Down

0 comments on commit 5810106

Please sign in to comment.