From d2cb92e828f5fd098cd0e5472fcd987e4cab3c37 Mon Sep 17 00:00:00 2001 From: benweet Date: Fri, 26 Sep 2014 00:25:01 +0100 Subject: [PATCH] Refactorized sharing links --- README.md | 2 +- public/res/extensions/dialogManageSharing.js | 4 +- public/res/extensions/welcomeTour.js | 2 +- public/res/html/bodyEditor.html | 5 +- public/res/html/dialogAbout.html | 2 +- .../res/html/dialogManageSharingLocation.html | 3 - public/res/img/button.svg | 41 ++-- public/res/publisher.js | 7 +- public/res/sharing.js | 207 +++++++----------- views/landing.html | 4 +- 10 files changed, 109 insertions(+), 168 deletions(-) diff --git a/README.md b/README.md index ca189d88..bcefc55b 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Support StackEdit: ### Documentation: - - [Welcome document][2] + - [Hello! document][2] - [Developer guide][3] - [Theming guide][4] diff --git a/public/res/extensions/dialogManageSharing.js b/public/res/extensions/dialogManageSharing.js index 74d4f1b8..ecb400cd 100644 --- a/public/res/extensions/dialogManageSharing.js +++ b/public/res/extensions/dialogManageSharing.js @@ -2,7 +2,7 @@ define([ "jquery", "underscore", "classes/Extension", - "text!html/dialogManageSharingLocation.html", + "text!html/dialogManageSharingLocation.html" ], function($, _, Extension, dialogManageSharingLocationHTML) { var dialogManageSharing = new Extension("dialogManageSharing", 'Button "Share"', false, true); @@ -32,8 +32,6 @@ define([ }, ''); shareListElt.innerHTML = linkListHtml; - eventMgr.onTweet(); - $msgShareListElt.toggleClass('hide', linkListHtml.length === 0); $msgNoShareElt.toggleClass('hide', linkListHtml.length !== 0); }; diff --git a/public/res/extensions/welcomeTour.js b/public/res/extensions/welcomeTour.js index 75375198..b3374563 100644 --- a/public/res/extensions/welcomeTour.js +++ b/public/res/extensions/welcomeTour.js @@ -93,7 +93,7 @@ define([ title: 'Comments/discussions', content: [ '

New in StackEdit 4: the comments button lets you create inline discussions!

', - 'Tip: Reopen the Welcome Document from Settings>Utils to discover other new features.' + 'Tip: Reopen the Hello! document from Settings>Utils to discover other new features.' ].join(""), placement: 'right', reflex: true diff --git a/public/res/html/bodyEditor.html b/public/res/html/bodyEditor.html index 06eae0d4..72c3fc6d 100644 --- a/public/res/html/bodyEditor.html +++ b/public/res/html/bodyEditor.html @@ -1251,15 +1251,12 @@
- Create - your own extension...
- Welcome document Welcome tour diff --git a/public/res/html/dialogAbout.html b/public/res/html/dialogAbout.html index 3c99b565..e17eb623 100644 --- a/public/res/html/dialogAbout.html +++ b/public/res/html/dialogAbout.html @@ -41,7 +41,7 @@
Sponsorship:
- +

diff --git a/public/res/html/dialogManageSharingLocation.html b/public/res/html/dialogManageSharingLocation.html index 4d7cfb5a..16237f68 100644 --- a/public/res/html/dialogManageSharingLocation.html +++ b/public/res/html/dialogManageSharingLocation.html @@ -1,6 +1,3 @@ -

- + - + - - - - + - - - - - + + + + + - - - - - - - + + + + + + + - - + + - - + + diff --git a/public/res/publisher.js b/public/res/publisher.js index 290a076f..7a6873e9 100644 --- a/public/res/publisher.js +++ b/public/res/publisher.js @@ -8,7 +8,6 @@ define([ "eventMgr", "fileSystem", "fileMgr", - "sharing", "monetizejs", "classes/Provider", "classes/AsyncTask", @@ -23,7 +22,7 @@ define([ "providers/sshProvider", "providers/tumblrProvider", "providers/wordpressProvider" -], function($, _, constants, utils, storage, settings, eventMgr, fileSystem, fileMgr, sharing, MonetizeJS, Provider, AsyncTask) { +], function($, _, constants, utils, storage, settings, eventMgr, fileSystem, fileMgr, MonetizeJS, Provider, AsyncTask) { var publisher = {}; @@ -248,9 +247,7 @@ define([ provider.publish(publishAttributes, fileDesc.frontMatter, title, content, function(error) { if(error === undefined) { publishAttributes.provider = provider; - sharing.createLink(publishAttributes, function() { - createPublishIndex(fileDesc, publishAttributes); - }); + createPublishIndex(fileDesc, publishAttributes); } }); diff --git a/public/res/sharing.js b/public/res/sharing.js index 65a1eaab..1fb3218f 100644 --- a/public/res/sharing.js +++ b/public/res/sharing.js @@ -1,135 +1,90 @@ define([ - "jquery", - "underscore", - "constants", - "utils", - "eventMgr", - "fileMgr", - "classes/AsyncTask", - "classes/Provider", - "providers/downloadProvider", - "providers/gistProvider" + "jquery", + "underscore", + "constants", + "utils", + "eventMgr", + "fileMgr", + "classes/AsyncTask", + "classes/Provider", + "providers/downloadProvider", + "providers/gistProvider" ], function($, _, constants, utils, eventMgr, fileMgr, AsyncTask, Provider) { - var sharing = {}; + var sharing = {}; - // Create a map with providerId: providerModule - var providerMap = _.chain(arguments).map(function(argument) { - return argument instanceof Provider && [ - argument.providerId, - argument - ]; - }).compact().object().value(); + // Create a map with providerId: providerModule + var providerMap = _.chain(arguments).map(function(argument) { + return argument instanceof Provider && [ + argument.providerId, + argument + ]; + }).compact().object().value(); - // Listen to offline status changes - var isOffline = false; - eventMgr.addListener("onOfflineChanged", function(isOfflineParam) { - isOffline = isOfflineParam; - }); + // Listen to offline status changes + var isOffline = false; + eventMgr.addListener("onOfflineChanged", function(isOfflineParam) { + isOffline = isOfflineParam; + }); - sharing.createLink = function(attributes, callback) { - var provider = providerMap[attributes.provider.providerId]; - // Don't create link if link already exists or provider is not - // compatible for sharing - if(attributes.sharingLink !== undefined || provider === undefined || - // Or document is not published in markdown format - attributes.format != "markdown") { - callback(); - return; - } - // Twitter does that for us - /* - var task = new AsyncTask(); - var shortUrl; - task.onRun(function() { - if(isOffline === true) { - task.chain(); - return; - } - var url = [ - constants.MAIN_URL, - 'viewer#!provider=', - provider.providerId - ]; - _.each(provider.sharingAttributes, function(attributeName) { - url.push('&'); - url.push(attributeName); - url.push('='); - url.push(encodeURIComponent(attributes[attributeName])); - }); - url = url.join(""); - $.getJSON("https://api-ssl.bitly.com/v3/shorten", { - "access_token": constants.BITLY_ACCESS_TOKEN, - "longUrl": url - }, function(response) { - if(response.data) { - shortUrl = response.data.url; - attributes.sharingLink = shortUrl; - } - else { - eventMgr.onError("An error occured while creating sharing link."); - attributes.sharingLink = url; - } - task.chain(); - }); - }); - function onFinish() { - callback(); - } - task.onSuccess(onFinish); - task.onError(onFinish); - task.enqueue(); - */ - var url = [ - constants.MAIN_URL, - 'viewer#!provider=', - provider.providerId - ]; - _.each(provider.sharingAttributes, function(attributeName) { - url.push('&'); - url.push(attributeName); - url.push('='); - url.push(encodeURIComponent(attributes[attributeName])); - }); - attributes.sharingLink = url.join(''); - callback(); - }; + sharing.getViewerLink = function(attributes) { + var provider = providerMap[attributes.provider.providerId]; + // Don't create link if provider is not compatible for sharing + if(provider === undefined || + // Or document is not published in markdown format + attributes.format != "markdown") { + return; + } + var url = [ + constants.MAIN_URL, + 'viewer#!provider=', + provider.providerId + ]; + _.each(provider.sharingAttributes, function(attributeName) { + url.push('&'); + url.push(attributeName); + url.push('='); + url.push(encodeURIComponent(attributes[attributeName])); + }); + attributes.sharingLink = url.join(''); + callback(); + }; - eventMgr.addListener("onReady", function() { - if(window.viewerMode === false) { - return; - } - // Check parameters to see if we have to download a shared document - var providerId = utils.getURLParameter("provider"); - if(providerId === undefined) { - providerId = "download"; - } - var provider = providerMap[providerId]; - if(provider === undefined) { - return; - } - var importParameters = {}; - _.each(provider.sharingAttributes, function(attributeName) { - var parameter = utils.getURLParameter(attributeName); - if(!parameter) { - importParameters = undefined; - return; - } - importParameters[attributeName] = parameter; - }); - if(importParameters === undefined) { - return; - } - $("#preview-contents, .navbar .file-title-navbar").hide(); - provider.importPublic(importParameters, function(error, title, content) { - $("#preview-contents, .navbar .file-title-navbar").show(); - if(error) { - return; - } - var fileDesc = fileMgr.createFile(title, content, undefined, undefined, true); - fileMgr.selectFile(fileDesc); - }); - }); + eventMgr.addListener("onReady", function() { + if(window.viewerMode === false) { + return; + } + // Check parameters to see if we have to download a shared document + var providerId = utils.getURLParameter("provider"); + if(providerId === undefined) { + providerId = "download"; + } + var provider = providerMap[providerId]; + if(provider === undefined) { + return; + } + var importParameters = {}; + _.each(provider.sharingAttributes, function(attributeName) { + var parameter = utils.getURLParameter(attributeName); + if(!parameter) { + importParameters = undefined; + return; + } + importParameters[attributeName] = parameter; + }); + if(importParameters === undefined) { + return; + } + $("#preview-contents, .navbar .file-title-navbar").hide(); + provider.importPublic(importParameters, function(error, title, content) { + $("#preview-contents, .navbar .file-title-navbar").show(); + if(error) { + return; + } + var fileDesc = fileMgr.createFile(title, content, undefined, undefined, true); + fileMgr.selectFile(fileDesc); + }); + }); - return sharing; + return sharing; }); diff --git a/views/landing.html b/views/landing.html index a84c7355..b7c0387e 100644 --- a/views/landing.html +++ b/views/landing.html @@ -142,8 +142,8 @@ } .social i::before { - margin-right: 10px; - margin-left: -5px; + margin-right: 8px; + margin-left: -3px; } .social a {