Skip to content

Commit

Permalink
Complete support for file:// urls
Browse files Browse the repository at this point in the history
  • Loading branch information
Dynalon committed Oct 25, 2013
1 parent cddd624 commit 621233f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 18 deletions.
3 changes: 2 additions & 1 deletion js/gimmicks/facebooklike.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
var language = window.navigator.userLanguage || window.navigator.language;
var code = language + "_" + language.toUpperCase();
var fbRootDiv = $('<div id="fb-root" />');
var fbscript ='(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/' + code + '/all.js#xfbml=1"; fjs.parentNode.insertBefore(js, fjs);}(document, "script", "facebook-jssdk"));';
var fbScriptHref = $.md.prepareLink ('connect.facebook.net/' + code + '/all.js#xfbml=1', { forceHTTP: true });
var fbscript ='(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "' + fbScriptHref + '"; fjs.parentNode.insertBefore(js, fjs);}(document, "script", "facebook-jssdk"));';

var facebookLikeGimmick = {
name: 'FacebookLike',
Expand Down
2 changes: 1 addition & 1 deletion js/gimmicks/googlemaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function googlemapsReady() {

// load the googlemaps js from the google server
$.md.registerScript(this, scripturl, {
license: 'OTHER',
license: 'EXCEPTION',
loadstage: 'skel_ready',
finishstage: 'bootstrap'
});
Expand Down
2 changes: 1 addition & 1 deletion js/gimmicks/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
$links.remove();
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = '//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML';
script.src = $.md.prepareLink('cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML', { forceHTTP: true });
document.getElementsByTagName('head')[0].appendChild(script);
}

Expand Down
26 changes: 13 additions & 13 deletions js/gimmicks/themechooser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
'use strict';

var themes = [
{ name: 'bootstrap', url: '//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css' },
{ name: 'amelia', url: '//netdna.bootstrapcdn.com/bootswatch/3.0.0/amelia/bootstrap.min.css' },
{ name: 'cerulean', url: '//netdna.bootstrapcdn.com/bootswatch/3.0.0/cerulean/bootstrap.min.css' },
{ name: 'cosmo', url: '//netdna.bootstrapcdn.com/bootswatch/3.0.0/cosmo/bootstrap.min.css' },
{ name: 'cyborg', url: '//netdna.bootstrapcdn.com/bootswatch/3.0.0/cyborg/bootstrap.min.css' },
{ name: 'flatly', url: '//netdna.bootstrapcdn.com/bootswatch/3.0.0/flatly/bootstrap.min.css' },
{ name: 'journal', url: '//netdna.bootstrapcdn.com/bootswatch/3.0.0/journal/bootstrap.min.css' },
{ name: 'readable', url: '//netdna.bootstrapcdn.com/bootswatch/3.0.0/readable/bootstrap.min.css' },
{ name: 'simplex', url: '//netdna.bootstrapcdn.com/bootswatch/3.0.0/simplex/bootstrap.min.css' },
{ name: 'slate', url: '//netdna.bootstrapcdn.com/bootswatch/3.0.0/slate/bootstrap.min.css' },
{ name: 'spacelab', url: '//netdna.bootstrapcdn.com/bootswatch/3.0.0/spacelab/bootstrap.min.css' },
{ name: 'united', url: '//netdna.bootstrapcdn.com/bootswatch/3.0.0/united/bootstrap.min.css' }
{ name: 'bootstrap', url: 'netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css' },
{ name: 'amelia', url: 'netdna.bootstrapcdn.com/bootswatch/3.0.0/amelia/bootstrap.min.css' },
{ name: 'cerulean', url: 'netdna.bootstrapcdn.com/bootswatch/3.0.0/cerulean/bootstrap.min.css' },
{ name: 'cosmo', url: 'netdna.bootstrapcdn.com/bootswatch/3.0.0/cosmo/bootstrap.min.css' },
{ name: 'cyborg', url: 'netdna.bootstrapcdn.com/bootswatch/3.0.0/cyborg/bootstrap.min.css' },
{ name: 'flatly', url: 'netdna.bootstrapcdn.com/bootswatch/3.0.0/flatly/bootstrap.min.css' },
{ name: 'journal', url: 'netdna.bootstrapcdn.com/bootswatch/3.0.0/journal/bootstrap.min.css' },
{ name: 'readable', url: 'netdna.bootstrapcdn.com/bootswatch/3.0.0/readable/bootstrap.min.css' },
{ name: 'simplex', url: 'netdna.bootstrapcdn.com/bootswatch/3.0.0/simplex/bootstrap.min.css' },
{ name: 'slate', url: 'netdna.bootstrapcdn.com/bootswatch/3.0.0/slate/bootstrap.min.css' },
{ name: 'spacelab', url: 'netdna.bootstrapcdn.com/bootswatch/3.0.0/spacelab/bootstrap.min.css' },
{ name: 'united', url: 'netdna.bootstrapcdn.com/bootswatch/3.0.0/united/bootstrap.min.css' }
];
var themeChooserGimmick = {
name: 'Themes',
Expand Down Expand Up @@ -58,7 +58,7 @@
$('style[id*=bootstrap]').remove();

$('<link rel="stylesheet" type="text/css">')
.attr('href', theme.url)
.attr('href', $.md.prepareLink(theme.url))
.appendTo('head');
}

Expand Down
5 changes: 3 additions & 2 deletions js/gimmicks/twitter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(function($) {
//'use strict';
// no license information given in the widget.js -> OTHER
var twitterscript = '!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");';
var widgetHref = $.md.prepareLink('platform.twitter.com/widgets.js');
var twitterscript = '!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="' + widgetHref + '";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");';
var twitterGimmick = {
name: 'TwitterGimmick',
version: $.md.version,
Expand All @@ -25,7 +26,7 @@
var href = $link.attr('href');
if (href.indexOf ('twitter.com') <= 0) {
user = $link.attr('href');
href = '//twitter.com/' + user;
href = $.md.prepareLink('twitter.com/' + user);
}
else {
return;
Expand Down
19 changes: 19 additions & 0 deletions js/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@
});
};

// turns hostname/path links into http://hostname/path links
// we need to do this because if accessed by file:///, we need a different
// transport scheme for external resources (like http://)
$.md.prepareLink = function(link, options) {
options = options || {};
var ownProtocol = window.location.protocol;

if (options.forceSSL)
return 'https://' + link;
if (options.forceHTTP)
return 'http://' + link;

if (ownProtocol === 'file:') {
return 'http://' + link;
}
// default: use the same as origin resource
return '//' + link;
};

// associate a link trigger for a gimmick. i.e. [gimmick:foo]() then
// foo is the trigger and will invoke the corresponding gimmick
$.md.linkGimmick = function(module, trigger, callback, stage) {
Expand Down

0 comments on commit 621233f

Please sign in to comment.