Skip to content

Commit 48d5889

Browse files
committed
Added support of slideshare and speakerdeck syntax and autocomplete
1 parent 2ad54c5 commit 48d5889

2 files changed

Lines changed: 76 additions & 1 deletion

File tree

public/js/extra.js

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,45 @@ function finishView(view) {
194194
blockquote_color.each(function (key, value) {
195195
$(value).closest("blockquote").css('border-left-color', $(value).attr('data-color'));
196196
});
197+
//slideshare
198+
view.find(".slideshare.raw").removeClass("raw")
199+
.each(function (key, value) {
200+
$.ajax({
201+
type: 'GET',
202+
url: '//www.slideshare.net/api/oembed/2?url=http://www.slideshare.net/' + $(value).attr('slideshareid') + '&format=json',
203+
jsonp: 'callback',
204+
dataType: 'jsonp',
205+
success: function (data) {
206+
$(value).html(data.html);
207+
}
208+
});
209+
});
210+
//speakerdeck
211+
view.find(".speakerdeck.raw").removeClass("raw")
212+
.each(function (key, value) {
213+
var url = 'https://speakerdeck.com/oembed.json?url=https%3A%2F%2Fspeakerdeck.com%2F' + encodeURIComponent($(value).attr('speakerdeckid'));
214+
//use yql because speakerdeck not support jsonp
215+
$.ajax({
216+
url: 'https://query.yahooapis.com/v1/public/yql',
217+
data: {
218+
q: "select * from json where url ='" + url + "'",
219+
format: "json"
220+
},
221+
dataType: "jsonp",
222+
success: function (data) {
223+
var json = data.query.results.json;
224+
var html = json.html;
225+
var ratio = json.height / json.width;
226+
$(value).html(html);
227+
var iframe = $(value).children('iframe');
228+
var src = iframe.attr('src');
229+
if (src.indexOf('//') == 0)
230+
iframe.attr('src', 'https:' + src);
231+
iframe.css('max-width', '100%');
232+
iframe.attr('width', '540').attr('height', (540 * ratio) + 15);
233+
}
234+
});
235+
});
197236
//render title
198237
document.title = renderTitle(view);
199238
}
@@ -656,8 +695,36 @@ var tocPlugin = new Plugin(
656695
return '<div class="toc"></div>';
657696
}
658697
);
698+
//slideshare
699+
var slidesharePlugin = new Plugin(
700+
// regexp to match
701+
/{%slideshare\s*([\d\D]*?)\s*%}/,
702+
703+
// this function will be called when something matches
704+
function (match, utils) {
705+
var slideshareid = match[1];
706+
var div = $('<div class="slideshare raw"></div>');
707+
div.attr('slideshareid', slideshareid);
708+
return div[0].outerHTML;
709+
}
710+
);
711+
//speakerdeck
712+
var speakerdeckPlugin = new Plugin(
713+
// regexp to match
714+
/{%speakerdeck\s*([\d\D]*?)\s*%}/,
715+
716+
// this function will be called when something matches
717+
function (match, utils) {
718+
var speakerdeckid = match[1];
719+
var div = $('<div class="speakerdeck raw"></div>');
720+
div.attr('speakerdeckid', speakerdeckid);
721+
return div[0].outerHTML;
722+
}
723+
);
659724
md.use(youtubePlugin);
660725
md.use(vimeoPlugin);
661726
md.use(gistPlugin);
662727
md.use(mathjaxPlugin);
663-
md.use(tocPlugin);
728+
md.use(tocPlugin);
729+
md.use(slidesharePlugin);
730+
md.use(speakerdeckPlugin);

public/js/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ var supportExternals = [
104104
{
105105
text: '{%gist gistid %}',
106106
search: 'gist'
107+
},
108+
{
109+
text: '{%slideshare slideshareid %}',
110+
search: 'slideshare'
111+
},
112+
{
113+
text: '{%speakerdeck speakerdeckid %}',
114+
search: 'speakerdeck'
107115
}
108116
];
109117
var supportExtraTags = [

0 commit comments

Comments
 (0)