summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
authorWu Cheng-Han2015-12-22 17:51:07 -0600
committerWu Cheng-Han2015-12-22 17:51:07 -0600
commit48d5889a30ea7a16f724a9222e8df7b365edb307 (patch)
treee9356e8ef995b2bc25e7a4a9434146002c8ed169 /public
parent2ad54c516a5c3cd88345b9c0f6e5a720050c935d (diff)
Added support of slideshare and speakerdeck syntax and autocomplete
Diffstat (limited to 'public')
-rw-r--r--public/js/extra.js69
-rw-r--r--public/js/index.js8
2 files changed, 76 insertions, 1 deletions
diff --git a/public/js/extra.js b/public/js/extra.js
index 5eb1f28a..e8f7f5d0 100644
--- a/public/js/extra.js
+++ b/public/js/extra.js
@@ -194,6 +194,45 @@ function finishView(view) {
blockquote_color.each(function (key, value) {
$(value).closest("blockquote").css('border-left-color', $(value).attr('data-color'));
});
+ //slideshare
+ view.find(".slideshare.raw").removeClass("raw")
+ .each(function (key, value) {
+ $.ajax({
+ type: 'GET',
+ url: '//www.slideshare.net/api/oembed/2?url=http://www.slideshare.net/' + $(value).attr('slideshareid') + '&format=json',
+ jsonp: 'callback',
+ dataType: 'jsonp',
+ success: function (data) {
+ $(value).html(data.html);
+ }
+ });
+ });
+ //speakerdeck
+ view.find(".speakerdeck.raw").removeClass("raw")
+ .each(function (key, value) {
+ var url = 'https://speakerdeck.com/oembed.json?url=https%3A%2F%2Fspeakerdeck.com%2F' + encodeURIComponent($(value).attr('speakerdeckid'));
+ //use yql because speakerdeck not support jsonp
+ $.ajax({
+ url: 'https://query.yahooapis.com/v1/public/yql',
+ data: {
+ q: "select * from json where url ='" + url + "'",
+ format: "json"
+ },
+ dataType: "jsonp",
+ success: function (data) {
+ var json = data.query.results.json;
+ var html = json.html;
+ var ratio = json.height / json.width;
+ $(value).html(html);
+ var iframe = $(value).children('iframe');
+ var src = iframe.attr('src');
+ if (src.indexOf('//') == 0)
+ iframe.attr('src', 'https:' + src);
+ iframe.css('max-width', '100%');
+ iframe.attr('width', '540').attr('height', (540 * ratio) + 15);
+ }
+ });
+ });
//render title
document.title = renderTitle(view);
}
@@ -656,8 +695,36 @@ var tocPlugin = new Plugin(
return '<div class="toc"></div>';
}
);
+//slideshare
+var slidesharePlugin = new Plugin(
+ // regexp to match
+ /{%slideshare\s*([\d\D]*?)\s*%}/,
+
+ // this function will be called when something matches
+ function (match, utils) {
+ var slideshareid = match[1];
+ var div = $('<div class="slideshare raw"></div>');
+ div.attr('slideshareid', slideshareid);
+ return div[0].outerHTML;
+ }
+);
+//speakerdeck
+var speakerdeckPlugin = new Plugin(
+ // regexp to match
+ /{%speakerdeck\s*([\d\D]*?)\s*%}/,
+
+ // this function will be called when something matches
+ function (match, utils) {
+ var speakerdeckid = match[1];
+ var div = $('<div class="speakerdeck raw"></div>');
+ div.attr('speakerdeckid', speakerdeckid);
+ return div[0].outerHTML;
+ }
+);
md.use(youtubePlugin);
md.use(vimeoPlugin);
md.use(gistPlugin);
md.use(mathjaxPlugin);
-md.use(tocPlugin); \ No newline at end of file
+md.use(tocPlugin);
+md.use(slidesharePlugin);
+md.use(speakerdeckPlugin); \ No newline at end of file
diff --git a/public/js/index.js b/public/js/index.js
index 03f5e587..f37244bb 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -104,6 +104,14 @@ var supportExternals = [
{
text: '{%gist gistid %}',
search: 'gist'
+ },
+ {
+ text: '{%slideshare slideshareid %}',
+ search: 'slideshare'
+ },
+ {
+ text: '{%speakerdeck speakerdeckid %}',
+ search: 'speakerdeck'
}
];
var supportExtraTags = [