From 428ff1c6915499b62a695a18b8c27a20875b590a Mon Sep 17 00:00:00 2001 From: benweet Date: Sun, 13 Oct 2013 20:58:42 +0100 Subject: [PATCH] Using hash bang in sharing location --- public/res/classes/AsyncTask.js | 58 ++++++++++-------------- public/res/core.js | 11 ++--- public/res/helpers/dropboxHelper.js | 1 - public/res/helpers/githubHelper.js | 3 +- public/res/helpers/googleHelper.js | 1 - public/res/helpers/tumblrHelper.js | 1 - public/res/helpers/wordpressHelper.js | 1 - public/res/html/bodyIndex.html | 2 +- public/res/html/buttonShare.html | 4 +- public/res/providers/downloadProvider.js | 2 +- public/res/sharing.js | 2 +- public/res/styles/main.less | 5 -- public/res/utils.js | 5 +- 13 files changed, 39 insertions(+), 57 deletions(-) diff --git a/public/res/classes/AsyncTask.js b/public/res/classes/AsyncTask.js index 26d688be..f8e0d070 100644 --- a/public/res/classes/AsyncTask.js +++ b/public/res/classes/AsyncTask.js @@ -7,13 +7,14 @@ define([ var taskQueue = []; - function AsyncTask() { + function AsyncTask(force) { this.finished = false; this.timeout = ASYNC_TASK_DEFAULT_TIMEOUT; this.retryCounter = 0; this.runCallbacks = []; this.successCallbacks = []; this.errorCallbacks = []; + this.force = force; } /** @@ -132,45 +133,36 @@ define([ // Run the next task in the queue if any and no other running function runTask() { - - // Wait for user first interaction before running first task - if(isUserReal === false) { - return + + // If there is a task currently running + if(currentTaskRunning === true) { + // If the current task takes too long + if(currentTaskStartTime + currentTask.timeout < utils.currentTime) { + currentTask.error(new Error("A timeout occurred.")); + } + return; } - - // Use defer to avoid stack overflow - //_.defer(function() { - // If there is a task currently running - if(currentTaskRunning === true) { - // If the current task takes too long - if(currentTaskStartTime + currentTask.timeout < utils.currentTime) { - currentTask.error(new Error("A timeout occurred.")); - } + if(currentTask === undefined) { + // If no task in the queue or user has never interacted + if(taskQueue.length === 0 || (!taskQueue[0].force && isUserReal === false)) { return; } - if(currentTask === undefined) { - // If no task in the queue - if(taskQueue.length === 0) { - return; - } - - // Dequeue an enqueued task - currentTask = taskQueue.shift(); - currentTaskStartTime = utils.currentTime; - if(asyncRunning === false) { - asyncRunning = true; - eventMgr.onAsyncRunning(true); - } + // Dequeue an enqueued task + currentTask = taskQueue.shift(); + currentTaskStartTime = utils.currentTime; + if(asyncRunning === false) { + asyncRunning = true; + eventMgr.onAsyncRunning(true); } + } - // Run the task - if(currentTaskStartTime <= utils.currentTime) { - currentTaskRunning = true; - currentTask.chain(); - } - //}); + // Run the task + if(currentTaskStartTime <= utils.currentTime) { + currentTaskRunning = true; + currentTask.chain(); + } } // Call runTask periodically diff --git a/public/res/core.js b/public/res/core.js index 020c0a81..eabb3b6e 100644 --- a/public/res/core.js +++ b/public/res/core.js @@ -45,7 +45,7 @@ define([ } function isUserActive() { - if(userActive === true && utils.currentTime - userLastActivity > USER_IDLE_THRESHOLD) { + if(utils.currentTime - userLastActivity > USER_IDLE_THRESHOLD) { userActive = false; } return userActive && windowUnique; @@ -875,14 +875,14 @@ define([ // Tooltips $(".tooltip-lazy-rendering").tooltip({ - container: '.modal-settings .modal-dialog', + container: '.modal-settings', placement: 'right', trigger: 'hover', title: 'Disable preview rendering while typing in order to offload CPU. Refresh preview after 500 ms of inactivity.' }); $(".tooltip-default-content").tooltip({ html: true, - container: '.modal-settings .modal-dialog', + container: '.modal-settings', placement: 'right', trigger: 'hover', title: 'Thanks for supporting StackEdit by adding a backlink in your documents!' @@ -890,7 +890,7 @@ define([ var tooltipOpen = false; $(".tooltip-usercustom-extension").tooltip({ html: true, - container: '.modal-settings .modal-dialog', + container: '.modal-settings', placement: 'right', trigger: 'manual', title: settingsUserCustomExtensionTooltipHTML @@ -908,7 +908,7 @@ define([ var $tooltipElt = $(tooltipElt); $tooltipElt.tooltip({ html: true, - container: $tooltipElt.parents('.modal-dialog'), + container: $tooltipElt.parents('.modal'), placement: 'right', trigger: 'manual', title: settingsTemplateTooltipHTML @@ -962,7 +962,6 @@ define([ }, ''); document.getElementById('input-settings-theme').innerHTML = themeOptions; } - }); return core; diff --git a/public/res/helpers/dropboxHelper.js b/public/res/helpers/dropboxHelper.js index c6c97e0f..ab93fc13 100644 --- a/public/res/helpers/dropboxHelper.js +++ b/public/res/helpers/dropboxHelper.js @@ -69,7 +69,6 @@ define([ } function localAuthenticate() { if(immediate === false) { - eventMgr.onMessage("Please make sure the Dropbox authorization popup is not blocked by your browser."); // If not immediate we add time for user to enter his // credentials task.timeout = ASYNC_TASK_LONG_TIMEOUT; diff --git a/public/res/helpers/githubHelper.js b/public/res/helpers/githubHelper.js index f317c88d..e29e89c1 100644 --- a/public/res/helpers/githubHelper.js +++ b/public/res/helpers/githubHelper.js @@ -75,7 +75,6 @@ define([ }); } function getCode() { - eventMgr.onMessage("Please make sure the Github authorization popup is not blocked by your browser."); localStorage.removeItem("githubCode"); authWindow = utils.popupWindow('html/github-oauth-client.html?client_id=' + GITHUB_CLIENT_ID, 'stackedit-github-oauth', 960, 600); authWindow.focus(); @@ -205,7 +204,7 @@ define([ }; githubHelper.downloadGist = function(gistId, filename, callback) { - var task = new AsyncTask(); + var task = new AsyncTask(true); connect(task); // No need for authentication var title = undefined; diff --git a/public/res/helpers/googleHelper.js b/public/res/helpers/googleHelper.js index 20649ee2..9ea59f30 100644 --- a/public/res/helpers/googleHelper.js +++ b/public/res/helpers/googleHelper.js @@ -90,7 +90,6 @@ define([ } function localAuthenticate() { if(immediate === false) { - eventMgr.onMessage("Please make sure the Google authorization popup is not blocked by your browser."); task.timeout = ASYNC_TASK_LONG_TIMEOUT; } gapi.auth.authorize({ diff --git a/public/res/helpers/tumblrHelper.js b/public/res/helpers/tumblrHelper.js index 31ce074f..470c37a2 100644 --- a/public/res/helpers/tumblrHelper.js +++ b/public/res/helpers/tumblrHelper.js @@ -63,7 +63,6 @@ define([ }); } function getVerifier() { - eventMgr.onMessage("Please make sure the Tumblr authorization popup is not blocked by your browser."); localStorage.removeItem("tumblrVerifier"); authWindow = utils.popupWindow('html/tumblr-oauth-client.html?oauth_token=' + oauth_object.oauth_token, 'stackedit-tumblr-oauth', 800, 600); authWindow.focus(); diff --git a/public/res/helpers/wordpressHelper.js b/public/res/helpers/wordpressHelper.js index 14f82e1c..4275515f 100644 --- a/public/res/helpers/wordpressHelper.js +++ b/public/res/helpers/wordpressHelper.js @@ -47,7 +47,6 @@ define([ }); } function getCode() { - eventMgr.onMessage("Please make sure the Wordpress authorization popup is not blocked by your browser."); localStorage.removeItem("wordpressCode"); authWindow = utils.popupWindow('html/wordpress-oauth-client.html?client_id=' + WORDPRESS_CLIENT_ID, 'stackedit-wordpress-oauth', 960, 600); authWindow.focus(); diff --git a/public/res/html/bodyIndex.html b/public/res/html/bodyIndex.html index 64f71a06..98b0cf0a 100644 --- a/public/res/html/bodyIndex.html +++ b/public/res/html/bodyIndex.html @@ -846,7 +846,7 @@
"" is not published yet.

- NOTE: You can add publications using "Publish on" sub-menu. + NOTE: You can add publications using the Publish on sub-menu. diff --git a/public/res/providers/downloadProvider.js b/public/res/providers/downloadProvider.js index 207e7fd2..6e6e82d3 100644 --- a/public/res/providers/downloadProvider.js +++ b/public/res/providers/downloadProvider.js @@ -15,7 +15,7 @@ define([ downloadProvider.importPublic = function(importParameters, callback) { var title = undefined; var content = undefined; - var task = new AsyncTask(); + var task = new AsyncTask(true); task.onRun(function() { var url = importParameters.url; var slashUrl = url.lastIndexOf("/"); diff --git a/public/res/sharing.js b/public/res/sharing.js index d7d70788..dd83f5b9 100644 --- a/public/res/sharing.js +++ b/public/res/sharing.js @@ -45,7 +45,7 @@ define([ } var url = [ MAIN_URL, - 'viewer.html?provider=', + 'viewer.html#!provider=', provider.providerId ]; _.each(provider.sharingAttributes, function(attributeName) { diff --git a/public/res/styles/main.less b/public/res/styles/main.less index efd4a564..48dc19d1 100644 --- a/public/res/styles/main.less +++ b/public/res/styles/main.less @@ -138,10 +138,6 @@ a { .transition(~"background-color ease-in-out .15s, color ease-in-out .15s, border-color ease-in-out .15s"); } -.close { - .transition(opacity ease-in-out .15s); -} - .list-group .nav { border-left: 10px solid @blockquote-border-color; margin-left: 10px; @@ -1076,7 +1072,6 @@ ul,ol { font-weight: @close-font-weight; text-shadow: @close-text-shadow; .opacity(.3); - .transition(~"opacity ease-in-out .15s"); &:before { content: '\d7'; } diff --git a/public/res/utils.js b/public/res/utils.js index 10940e2a..eca3b40f 100644 --- a/public/res/utils.js +++ b/public/res/utils.js @@ -11,9 +11,10 @@ define([ // Return a parameter from the URL utils.getURLParameter = function(name) { - var regex = new RegExp(name + "=(.+?)(&|$)"); + // Parameter can be either a search parameter (&name=...) or a hash fragment parameter (#!name=...) + var regex = new RegExp("(?:\\?|\\#\\!|&)" + name + "=(.+?)(?:&|\\#|$)"); try { - return decodeURIComponent(regex.exec(location.search)[1]); + return decodeURIComponent(regex.exec(location.search + location.hash)[1]); } catch(e) { return undefined;