Added monetizejs calls

This commit is contained in:
benweet 2014-08-11 00:42:40 +01:00
parent 8ccbe7cae4
commit d7cfc938f1
2 changed files with 81 additions and 56 deletions

View File

@ -10,12 +10,13 @@ define([
"storage", "storage",
"settings", "settings",
"eventMgr", "eventMgr",
"monetizejs",
"text!html/bodyIndex.html", "text!html/bodyIndex.html",
"text!html/bodyViewer.html", "text!html/bodyViewer.html",
"text!html/tooltipSettingsTemplate.html", "text!html/tooltipSettingsTemplate.html",
"storage", "storage",
'pagedown' 'pagedown'
], function($, _, crel, editor, layout, constants, utils, storage, settings, eventMgr, bodyIndexHTML, bodyViewerHTML, settingsTemplateTooltipHTML) { ], function($, _, crel, editor, layout, constants, utils, storage, settings, eventMgr, MonetizeJS, bodyIndexHTML, bodyViewerHTML, settingsTemplateTooltipHTML) {
var core = {}; var core = {};
@ -325,6 +326,59 @@ define([
eventMgr.onReady(); eventMgr.onReady();
}; };
var monetize = new MonetizeJS({
applicationID: 'iklMbzDI7dvMEScb'
});
var $alerts = $();
function hasPaid(payments) {
return payments && (
(payments.chargeOption && payments.chargeOption.alias == 'once') ||
(payments.subscriptionOption && payments.subscriptionOption.alias == 'monthly') ||
(payments.subscriptionOption && payments.subscriptionOption.alias == 'yearly'));
}
function removeAlerts() {
$alerts.remove();
$alerts = $();
}
function performPayment() {
monetize.getPayments({
pricingOptions: [
'once',
'monthly',
'yearly'
]
}, function(err, payments) {
if(hasPaid(payments)) {
eventMgr.onMessage('Thank you for sponsoring StackEdit!');
removeAlerts();
}
});
}
var checkPayment = _.debounce(function() {
if(isOffline) {
return;
}
monetize.getPaymentsImmediate(function(err, payments) {
if(!hasPaid(payments)) {
_.each(document.querySelectorAll('.modal-body'), function(modalBodyElt) {
var $elt = $('<div class="alert alert-danger">Please consider <a href="#">sponsoring StackEdit</a> for $1/month (or <a href="#">sign in</a> if you\'re already a sponsor).</div>');
$elt.find('a').click(performPayment);
modalBodyElt.insertBefore($elt[0], modalBodyElt.firstChild);
$alerts = $alerts.add($elt);
});
}
else {
removeAlerts();
}
});
}, 1000);
eventMgr.addListener('onOfflineChanged', checkPayment);
// Other initialization that are not prioritary // Other initialization that are not prioritary
eventMgr.addListener("onReady", function() { eventMgr.addListener("onReady", function() {
@ -521,7 +575,8 @@ define([
document.getElementById('input-settings-theme').innerHTML = themeOptions; document.getElementById('input-settings-theme').innerHTML = themeOptions;
} }
$('.modal-header').append('<a class="dialog-header-message" href="https://github.com/benweet/stackedit/issues/385" target="_blank">Give your feedback <i class="icon-megaphone"></i></a>'); //$('.modal-header').append('<a class="dialog-header-message" href="https://github.com/benweet/stackedit/issues/385" target="_blank">Give your feedback <i class="icon-megaphone"></i></a>');
checkPayment();
}); });
return core; return core;

View File

@ -1,61 +1,31 @@
define([ define([
"underscore", "jquery",
"constants", "underscore",
"utils", "constants",
"classes/Extension", "utils",
"text!html/dialogAbout.html", "classes/Extension",
], function(_, constants, utils, Extension, dialogAboutHTML) { "monetizejs",
"text!html/dialogAbout.html"
], function($, _, constants, utils, Extension, MonetizeJS, dialogAboutHTML) {
var dialogAbout = new Extension("dialogAbout", 'Dialog "About"'); var dialogAbout = new Extension("dialogAbout", 'Dialog "About"');
var libraries = { var monetize = new MonetizeJS({
"Bootstrap": "http://getbootstrap.com/", applicationID: 'iklMbzDI7dvMEScb'
"Bootstrap Tour": "http://bootstraptour.com/", });
"crel": "https://github.com/KoryNunn/crel",
"FileSaver.js": "https://github.com/eligrey/FileSaver.js/",
"Fontello": "http://fontello.com/",
"Font Awesome and others...": "res/libs/fontello/LICENSE.txt",
"Gatekeeper": "https://github.com/prose/gatekeeper",
"Github.js": "https://github.com/michael/github",
"Hammer.js": "http://eightmedia.github.io/hammer.js/",
"Highlight.js": "http://softwaremaniacs.org/soft/highlight/en/",
"jGrowl": "https://github.com/stanlemon/jGrowl/",
"jQuery": "http://jquery.com/",
"jsondiffpatch": "https://github.com/benjamine/jsondiffpatch",
"MathJax": "http://www.mathjax.org/",
"Mousetrap": "http://craig.is/killing/mice",
"PageDown": "https://code.google.com/p/pagedown/",
"PageDown Extra": "https://github.com/jmcmanus/pagedown-extra/",
"Prettify": "https://code.google.com/p/google-code-prettify/",
"Prism": "http://prismjs.com/",
"Rangy": "https://code.google.com/p/rangy/",
"RequireJS": "http://requirejs.org/",
"RequireJS LESS plugin": "https://github.com/guybedford/require-less",
"stacktrace.js": "http://stacktracejs.com/",
"to-markdown": "https://github.com/domchristie/to-markdown",
"Underscore.js": "http://underscorejs.org/",
"waitForImages": "https://github.com/alexanderdickson/waitForImages",
"XRegExp": "https://github.com/slevithan/xregexp",
"yaml.js": "https://github.com/jeremyfa/yaml.js"
};
var projects = { dialogAbout.onReady = function() {
"StackEdit Download Proxy": "https://github.com/benweet/stackedit-download-proxy", utils.addModal('modal-about', _.template(dialogAboutHTML, {
"StackEdit HTMLtoPDF": "https://github.com/benweet/stackedit-htmltopdf", version: constants.VERSION
"StackEdit Picasa Proxy": "https://github.com/benweet/stackedit-picasa-proxy", }));
"StackEdit SSH Proxy": "https://github.com/benweet/stackedit-ssh-proxy", $('.modal-about .sponsorship-button').click(function() {
"StackEdit Tumblr Proxy": "https://github.com/benweet/stackedit-tumblr-proxy", monetize.getPayments({
"StackEdit WordPress Proxy": "https://github.com/benweet/stackedit-wordpress-proxy", summary: true
}; }, function() {
});
});
};
dialogAbout.onReady = function() { return dialogAbout;
utils.addModal('modal-about', _.template(dialogAboutHTML, {
libraries: libraries,
projects: projects,
version: constants.VERSION
}));
};
return dialogAbout;
}); });