From be7710a872abfb785011793e15c01e181be62d17 Mon Sep 17 00:00:00 2001 From: benweet Date: Sun, 2 Feb 2014 21:00:05 +0000 Subject: [PATCH] Added tweet buttons --- public/res/WELCOME.md | 2 +- public/res/eventMgr.js | 9 +++++ public/res/extensions/dialogManageSharing.js | 19 ++++++++- public/res/extensions/twitter.js | 39 +++++++++++++++++++ public/res/extensions/welcomeTour.js | 11 +++++- public/res/html/dialogAbout.html | 3 ++ .../res/html/dialogManageSharingLocation.html | 3 ++ public/res/styles/main.less | 5 +++ 8 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 public/res/extensions/twitter.js diff --git a/public/res/WELCOME.md b/public/res/WELCOME.md index 0c285fc0..aa9b54ed 100644 --- a/public/res/WELCOME.md +++ b/public/res/WELCOME.md @@ -197,7 +197,7 @@ You can insert a table of contents using the marker `[TOC]`: ### Comments Usually, comments in Markdown are just standard HTML comments. -**StackEdit** extends HTML comments in order to produce useful, highlighted comments in the preview but not in your exported documents. +**StackEdit** extends HTML comments in order to produce useful, highlighted comments in the preview but not in your exported documents. ### MathJax diff --git a/public/res/eventMgr.js b/public/res/eventMgr.js index f729ba5c..e8eb6a4d 100644 --- a/public/res/eventMgr.js +++ b/public/res/eventMgr.js @@ -12,6 +12,7 @@ define([ "extensions/partialRendering", "extensions/buttonMarkdownSyntax", "extensions/googleAnalytics", + "extensions/twitter", "extensions/dialogAbout", "extensions/dialogManagePublication", "extensions/dialogManageSynchronization", @@ -136,6 +137,10 @@ define([ eventMgr.onSaveSettings = function(newExtensionSettings, event) { logger.log("onSaveSettings"); _.each(extensionList, function(extension) { + if(window.lightMode === true && extension.disableInLight === true) { + newExtensionSettings[extension.extensionId] = extension.config; + return; + } var newExtensionConfig = _.extend({}, extension.defaultConfig); newExtensionConfig.enabled = utils.getInputChecked("#input-enable-extension-" + extension.extensionId); var isChecked; @@ -208,6 +213,10 @@ define([ // Operation on ACE addEventHook("onAceCreated"); + + // Refresh twitter buttons + addEventHook("onTweet"); + var onPreviewFinished = createEventHook("onPreviewFinished"); var onAsyncPreviewListenerList = getExtensionListenerList("onAsyncPreview"); diff --git a/public/res/extensions/dialogManageSharing.js b/public/res/extensions/dialogManageSharing.js index 5d92e2de..74d4f1b8 100644 --- a/public/res/extensions/dialogManageSharing.js +++ b/public/res/extensions/dialogManageSharing.js @@ -7,6 +7,11 @@ define([ var dialogManageSharing = new Extension("dialogManageSharing", 'Button "Share"', false, true); + var eventMgr; + dialogManageSharing.onEventMgrCreated = function(eventMgrParam) { + eventMgr = eventMgrParam; + }; + var fileDesc; var shareListElt; var $msgShareListElt; @@ -19,13 +24,16 @@ define([ var linkListHtml = _.reduce(fileDesc.publishLocations, function(result, attributes) { if(attributes.sharingLink) { result += _.template(dialogManageSharingLocationHTML, { - link: attributes.sharingLink + link: attributes.sharingLink, + title: fileDesc.title }); } return result; }, ''); shareListElt.innerHTML = linkListHtml; + eventMgr.onTweet(); + $msgShareListElt.toggleClass('hide', linkListHtml.length === 0); $msgNoShareElt.toggleClass('hide', linkListHtml.length !== 0); }; @@ -35,7 +43,14 @@ define([ refreshDocumentSharing(fileDescParameter); }; - dialogManageSharing.onNewPublishSuccess = refreshDocumentSharing; + dialogManageSharing.onNewPublishSuccess = function(fileDescParameter, publishAttributes) { + refreshDocumentSharing(fileDescParameter); + if(publishAttributes.sharingLink) { + $('.modal').modal('hide'); + $('.modal-manage-sharing').modal('show'); + } + }; + dialogManageSharing.onPublishRemoved = refreshDocumentSharing; dialogManageSharing.onReady = function() { diff --git a/public/res/extensions/twitter.js b/public/res/extensions/twitter.js new file mode 100644 index 00000000..d4866da6 --- /dev/null +++ b/public/res/extensions/twitter.js @@ -0,0 +1,39 @@ +/*globals _gaq */ +define([ + "jquery", + "underscore", + "constants", + "utils", + "classes/Extension", + "settings", +], function($, _, constants, utils, Extension, settings) { + + var twitter = new Extension("twitter", "Twitter", false, true); + + var isLoaded = false; + var isOffline = false; + + var init = function() { + if(isLoaded === false && isOffline === false) { + $.ajax({ + url: 'http://platform.twitter.com/widgets.js', + dataType: "script" + }).done(function() { + isLoaded = true; + }); + } + }; + + twitter.onReady = function() { + init(); + }; + twitter.onOfflineChanged = function(isOfflineParam) { + isOffline = isOfflineParam; + init(); + }; + twitter.onTweet = function() { + isLoaded && window.twttr.widgets.load(); + }; + + return twitter; +}); \ No newline at end of file diff --git a/public/res/extensions/welcomeTour.js b/public/res/extensions/welcomeTour.js index 5c32e912..82cd239b 100644 --- a/public/res/extensions/welcomeTour.js +++ b/public/res/extensions/welcomeTour.js @@ -7,6 +7,11 @@ define([ ], function(_, $, storage, Extension, Tour) { var welcomeTour = new Extension('welcomeTour', 'Welcome tour', false, true); + + var eventMgr; + welcomeTour.onEventMgrCreated = function(eventMgrParam) { + eventMgr = eventMgrParam; + }; welcomeTour.onReady = function() { var tour = new Tour({ @@ -103,9 +108,13 @@ define([ element: '.navbar-inner', title: 'Happy StackWriting!', content: [ - 'Enjoy, and don\'t forget to rate StackEdit on Chrome Web Store...', + '

Enjoy, and don\'t forget to rate StackEdit on Chrome Web Store...

', + '', ].join(""), placement: 'bottom', + onShown: function() { + eventMgr.onTweet(); + } }, ]); if(!_.has(storage, 'welcomeTour')) { diff --git a/public/res/html/dialogAbout.html b/public/res/html/dialogAbout.html index 8e5dd3a7..a35bf957 100644 --- a/public/res/html/dialogAbout.html +++ b/public/res/html/dialogAbout.html @@ -6,6 +6,9 @@ height="64" />