diff --git a/gulpfile.babel.js b/gulpfile.babel.js index de3379b..32acdac 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -1,4 +1,5 @@ const gulp = require('gulp') +const fs = require('fs') const path = require('path') const merge = require('event-stream').merge const map = require('map-stream') @@ -41,19 +42,32 @@ gulp.task('styles', () => { ) }) +gulp.task('lib:ondemand', (cb) => { + const dir = './libs/ondemand' + const code = fs.readdirSync(dir).map(file => { + return `window['${file}'] = function () { + ${fs.readFileSync(path.join(dir, file))} + };\n` + }).join('') + + fs.writeFileSync('./tmp/ondemand.js', code) + + cb() +}) + // Chrome gulp.task('chrome:template', () => { return buildTemplate({CHROME: true}) }) -gulp.task('chrome:js', ['chrome:template'], () => { +gulp.task('chrome:js', ['chrome:template', 'lib:ondemand'], () => { return buildJs(['./src/config/chrome/overrides.js'], {CHROME: true}) }) gulp.task('chrome', ['chrome:js'], () => { return merge( pipe('./icons/**/*', './tmp/chrome/icons'), - pipe(['./libs/**/*', './tmp/octotree.*', './src/config/chrome/manifest.json'], './tmp/chrome/'), + pipe(['./libs/**/*', '!./libs/ondemand{,/**}', './tmp/octotree.*', './tmp/ondemand.js', './src/config/chrome/manifest.json'], './tmp/chrome/'), pipe('./src/config/chrome/background.js', $.babel(), './tmp/chrome/') ) }) @@ -87,14 +101,14 @@ gulp.task('firefox:template', () => { return buildTemplate({FIREFOX: true}) }) -gulp.task('firefox:js', ['firefox:template'], () => { +gulp.task('firefox:js', ['firefox:template', 'lib:ondemand'], () => { return buildJs([], {FIREFOX: true}) }) gulp.task('firefox', ['firefox:js'], () => { return merge( pipe('./icons/**/*', './tmp/firefox/data/icons'), - pipe(['./libs/**/*', './tmp/octotree.*'], './tmp/firefox/data'), + pipe(['./libs/**/*', '!./libs/ondemand{,/**}', './tmp/octotree.*', './tmp/ondemand.js'], './tmp/firefox/data'), pipe('./src/config/firefox/firefox.js', $.babel(), './tmp/firefox/lib'), pipe('./src/config/firefox/package.json', './tmp/firefox') ) @@ -109,7 +123,7 @@ gulp.task('safari:template', () => { return buildTemplate({SAFARI: true}) }) -gulp.task('safari:js', ['safari:template'], () => { +gulp.task('safari:js', ['safari:template', 'lib:ondemand'], () => { return buildJs([], {SAFARI: true}) }) @@ -117,7 +131,7 @@ gulp.task('safari', ['safari:js'], () => { return merge( pipe('./icons/**/*', './tmp/safari/octotree.safariextension/icons'), pipe( - ['./libs/**/*', './tmp/octotree.*', './src/config/safari/**/*'], + ['./libs/**/*', '!./libs/ondemand{,/**}', './tmp/octotree.*', './tmp/ondemand.js', './src/config/safari/**/*'], './tmp/safari/octotree.safariextension/' ) ) diff --git a/libs/jquery.pjax.js b/libs/ondemand/jquery.pjax.js similarity index 100% rename from libs/jquery.pjax.js rename to libs/ondemand/jquery.pjax.js diff --git a/libs/turbolinks.js b/libs/ondemand/turbolinks.js similarity index 100% rename from libs/turbolinks.js rename to libs/ondemand/turbolinks.js diff --git a/src/adapters/adapter.js b/src/adapters/adapter.js index ce51960..08ded9f 100644 --- a/src/adapters/adapter.js +++ b/src/adapters/adapter.js @@ -1,5 +1,6 @@ class Adapter { - constructor() { + constructor(deps) { + deps.forEach(dep => window[dep]()) this._defaultBranch = {} this._observe() } diff --git a/src/adapters/github.js b/src/adapters/github.js index cb5196e..4353621 100644 --- a/src/adapters/github.js +++ b/src/adapters/github.js @@ -16,7 +16,8 @@ const GH_CONTAINERS = '.container' class GitHub extends Adapter { constructor() { - super() + super(['jquery.pjax.js']) + $(document) .ready(() => this._detectLocationChange()) .on('pjax:send', () => $(document).trigger(EVENT.REQ_START)) diff --git a/src/adapters/gitlab.js b/src/adapters/gitlab.js index 3c96fd2..dd3f0b7 100644 --- a/src/adapters/gitlab.js +++ b/src/adapters/gitlab.js @@ -11,7 +11,7 @@ const GL_PROJECT_ID = '#project_id' class GitLab extends Adapter { constructor(store) { - super() + super(['turbolinks.js']) // GitLab (for now) embeds access token in the page of a logged-in user. // Use it to set the token if one isn't available. diff --git a/src/config/chrome/background.js b/src/config/chrome/background.js index 3008799..1629341 100644 --- a/src/config/chrome/background.js +++ b/src/config/chrome/background.js @@ -17,10 +17,9 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { const jsFiles = [ 'jquery.js', 'jquery-ui.js', - 'jquery.pjax.js', - 'turbolinks.js', 'jstree.js', 'keymaster.js', + 'ondemand.js', 'octotree.js' ] diff --git a/src/config/firefox/firefox.js b/src/config/firefox/firefox.js index 30ddf05..19d5f2f 100644 --- a/src/config/firefox/firefox.js +++ b/src/config/firefox/firefox.js @@ -5,9 +5,9 @@ pageMod.PageMod({ include: ['https://github.com/*', 'https://gitlab.com/*'], contentScriptFile : [data.url('jquery.js'), data.url('jquery-ui.js'), - data.url('jquery.pjax.js'), data.url('jstree.js'), data.url('keymaster.js'), + data.url('ondemand.js'), data.url('octotree.js') ], contentStyleFile : [data.url('jstree.css'), diff --git a/src/config/safari/Info.plist b/src/config/safari/Info.plist index e8c8604..c0b3c2d 100755 --- a/src/config/safari/Info.plist +++ b/src/config/safari/Info.plist @@ -1,68 +1,68 @@ - - Author - Buu Nguyen - Builder Version - 9537.75.14 - CFBundleDisplayName - octotree - CFBundleIdentifier - com.buunguyen.octotree - CFBundleInfoDictionaryVersion - 6.0 - CFBundleShortVersionString - 2.0.0 - CFBundleVersion - 2.0.0 - Chrome - - Content - Scripts + Author + Buu Nguyen + Builder Version + 9537.75.14 + CFBundleDisplayName + octotree + CFBundleIdentifier + com.buunguyen.octotree + CFBundleInfoDictionaryVersion + 6.0 + CFBundleShortVersionString + 2.0.0 + CFBundleVersion + 2.0.0 + Chrome + + Content - Start + Scripts + + Start + + jquery.js + jquery-ui.js + jstree.js + keymaster.js + ondemand.js + octotree.js + + + Stylesheets - jquery.js - jquery-ui.js - jquery.pjax.js - jstree.js - keymaster.js - octotree.js + jstree.css + octotree.css + + Whitelist + + https://github.com/* + https://gitlab.com/* - Stylesheets - - jstree.css - octotree.css - - Whitelist - - https://github.com/* - https://gitlab.com/* - - - Description - Display GitHub code in tree format - ExtensionInfoDictionaryVersion - 1.0 - Permissions - - Website Access + Description + Display GitHub code in tree format + ExtensionInfoDictionaryVersion + 1.0 + Permissions - Allowed Domains - - github.com - gitlab.com - - Include Secure Pages - - Level - Some + Website Access + + Allowed Domains + + github.com + gitlab.com + + Include Secure Pages + + Level + Some + + Website + https://github.com/buunguyen/octotree - Website - https://github.com/buunguyen/octotree - diff --git a/src/constants.js b/src/constants.js index 6cb5bd4..7043b79 100644 --- a/src/constants.js +++ b/src/constants.js @@ -24,11 +24,11 @@ const DEFAULTS = { // @ifndef SAFARI HOTKEYS : '⌘+⇧+s, ⌃+⇧+s', // @endif - GHEURLS : '', - GLEURLS : '', - WIDTH : 232, POPUP : false, - SHOWN : false + WIDTH : 232, + SHOWN : false, + GHEURLS : '', + GLEURLS : '' } const EVENT = { diff --git a/src/octotree.js b/src/octotree.js index 3ccc128..6e2d2c8 100755 --- a/src/octotree.js +++ b/src/octotree.js @@ -119,7 +119,9 @@ $(document).ready(() => { currRepo = repo treeView.show(repo, token) } - else treeView.syncSelection() + else { + treeView.syncSelection() + } } } else {