diff options
Diffstat (limited to 'theme/javascript/utils')
-rw-r--r-- | theme/javascript/utils/appcache.js | 15 | ||||
-rw-r--r-- | theme/javascript/utils/dropdown.js | 27 | ||||
-rwxr-xr-x | theme/javascript/utils/execute.js | 97 | ||||
-rwxr-xr-x | theme/javascript/utils/sharing.js | 5 | ||||
-rw-r--r-- | theme/javascript/utils/url.js | 2 |
5 files changed, 32 insertions, 114 deletions
diff --git a/theme/javascript/utils/appcache.js b/theme/javascript/utils/appcache.js deleted file mode 100644 index e813ab0..0000000 --- a/theme/javascript/utils/appcache.js +++ /dev/null @@ -1,15 +0,0 @@ -define([], function() { - var isAvailable = (typeof applicationCache !== "undefined"); - - var init = function() { - if (!isAvailable) return; - - window.applicationCache.addEventListener('updateready', function() { - window.location.reload(); - }, false); - }; - - return { - init: init - }; -});
\ No newline at end of file diff --git a/theme/javascript/utils/dropdown.js b/theme/javascript/utils/dropdown.js new file mode 100644 index 0000000..fe4e1f4 --- /dev/null +++ b/theme/javascript/utils/dropdown.js @@ -0,0 +1,27 @@ +define([ + "jQuery" +], function($) { + + var toggleDropdown = function(e) { + var $dropdown = $(e.currentTarget).parent().find(".dropdown-menu"); + + $dropdown.toggleClass("open"); + e.stopPropagation(); + e.preventDefault(); + }; + + var closeDropdown = function(e) { + $(".dropdown-menu").removeClass("open"); + }; + + // Bind all dropdown + var init = function() { + $(document).on('click', ".toggle-dropdown", toggleDropdown); + $(document).on('click', ".dropdown-menu", function(e){ e.stopPropagation(); }); + $(document).on("click", closeDropdown); + }; + + return { + init: init + }; +}); diff --git a/theme/javascript/utils/execute.js b/theme/javascript/utils/execute.js deleted file mode 100755 index eb2a19b..0000000 --- a/theme/javascript/utils/execute.js +++ /dev/null @@ -1,97 +0,0 @@ -define([ - "execute/javascript" -], function(javascript) { - var LANGUAGES = { - "javascript": javascript - }; - - - var evalJS = function(lang, code, callback) { - var ready = false; - var finished = false; - - var finish = function() { - if(finished) { - return console.error('Already finished'); - } - finished = true; - return callback.apply(null, arguments); - }; - - var repl; - - // Handles all our events - var eventHandler = function(data, eventType) { - console.log([eventType, data]); - switch(eventType) { - case 'progress': - // Update UI loading bar - break; - case 'timeout': - finish(new Error(data)); - break; - case 'result': - finish(null, { - value: data, - type: 'result' - }); - break; - case 'error': - if(ready) { - return finish(null, { - value: data, - type: 'error' - }); - } - return finish(new Error(data)); - break - case 'ready': - // We're good to get results and stuff back now - ready = true; - // Eval our code now that the runtime is ready - repl.eval(code); - break; - default: - console.log('Unhandled event =', eventType, 'data =', data); - } - }; - - repl = new lang.REPL({ - input: eventHandler, - output: eventHandler, - result: eventHandler, - error: eventHandler, - progress: eventHandler, - timeout: { - time: 30000, - callback: eventHandler - } - }); - - repl.loadLanguage(lang.id, eventHandler); - }; - - var execute = function(lang, solution, validation, context, callback) { - // Language data - var langd = LANGUAGES[lang]; - - // Check language is supported - if (!langd) return callback(new Error("Language '"+lang+"' not available for execution")); - - // Validate with validation code - var code = [ - context, - solution, - langd.assertCode, - validation, - ].join(langd.sep); - evalJS(langd, code, function(err, res) { - if(err) return callback(err); - - if (res.type == "error") callback(new Error(res.value)); - else callback(null, res.value); - }); - }; - - return execute; -}); diff --git a/theme/javascript/utils/sharing.js b/theme/javascript/utils/sharing.js index 4889b40..3599b27 100755 --- a/theme/javascript/utils/sharing.js +++ b/theme/javascript/utils/sharing.js @@ -16,13 +16,16 @@ define([ }, "weibo": function($el) { window.open("http://service.weibo.com/share/share.php?content=utf-8&url="+encodeURIComponent(url)+"&title="+encodeURIComponent(title)) + }, + "instapaper": function($el) { + window.open("http://www.instapaper.com/text?u="+encodeURIComponent(url)); } }; // Bind all sharing button var init = function() { - $(document).on("click", "a[data-sharing]", function(e) { + $(document).on("click", "a[data-sharing],button[data-sharing]", function(e) { if (e) e.preventDefault(); var type = $(this).data("sharing"); diff --git a/theme/javascript/utils/url.js b/theme/javascript/utils/url.js index dbb1570..0254299 100644 --- a/theme/javascript/utils/url.js +++ b/theme/javascript/utils/url.js @@ -1,5 +1,5 @@ define([ - "vendors/URIjs/src/URI" + "URIjs/URI" ], function(URI) { // Joins path segments. Preserves initial "/" and resolves ".." and "." // Does not support using ".." to go above/outside the root. |