Optimize finishView selector performance by avoid using universal selector, fix finishView code indentation and remove empty line
This commit is contained in:
parent
843f025cb5
commit
eb724b05a7
1 changed files with 47 additions and 48 deletions
|
@ -218,12 +218,12 @@ function finishView(view) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//youtube
|
//youtube
|
||||||
view.find(".youtube.raw").removeClass("raw")
|
view.find("div.youtube.raw").removeClass("raw")
|
||||||
.click(function () {
|
.click(function () {
|
||||||
imgPlayiframe(this, '//www.youtube.com/embed/');
|
imgPlayiframe(this, '//www.youtube.com/embed/');
|
||||||
});
|
});
|
||||||
//vimeo
|
//vimeo
|
||||||
view.find(".vimeo.raw").removeClass("raw")
|
view.find("div.vimeo.raw").removeClass("raw")
|
||||||
.click(function () {
|
.click(function () {
|
||||||
imgPlayiframe(this, '//player.vimeo.com/video/');
|
imgPlayiframe(this, '//player.vimeo.com/video/');
|
||||||
})
|
})
|
||||||
|
@ -253,7 +253,7 @@ function finishView(view) {
|
||||||
console.warn(err);
|
console.warn(err);
|
||||||
}
|
}
|
||||||
//mathjax
|
//mathjax
|
||||||
var mathjaxdivs = view.find('.mathjax.raw').removeClass("raw").toArray();
|
var mathjaxdivs = view.find('span.mathjax.raw').removeClass("raw").toArray();
|
||||||
try {
|
try {
|
||||||
if (mathjaxdivs.length > 1) {
|
if (mathjaxdivs.length > 1) {
|
||||||
MathJax.Hub.Queue(["Typeset", MathJax.Hub, mathjaxdivs]);
|
MathJax.Hub.Queue(["Typeset", MathJax.Hub, mathjaxdivs]);
|
||||||
|
@ -263,52 +263,52 @@ function finishView(view) {
|
||||||
MathJax.Hub.Queue(viewAjaxCallback);
|
MathJax.Hub.Queue(viewAjaxCallback);
|
||||||
}
|
}
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
//sequence diagram
|
//sequence diagram
|
||||||
var sequences = view.find(".sequence-diagram.raw").removeClass("raw");
|
var sequences = view.find("div.sequence-diagram.raw").removeClass("raw");
|
||||||
sequences.each(function (key, value) {
|
sequences.each(function (key, value) {
|
||||||
try {
|
try {
|
||||||
var $value = $(value);
|
var $value = $(value);
|
||||||
var $ele = $(value).parent().parent();
|
var $ele = $(value).parent().parent();
|
||||||
|
|
||||||
var sequence = $value;
|
var sequence = $value;
|
||||||
sequence.sequenceDiagram({
|
sequence.sequenceDiagram({
|
||||||
theme: 'simple'
|
theme: 'simple'
|
||||||
});
|
});
|
||||||
|
|
||||||
$ele.addClass('sequence-diagram');
|
$ele.addClass('sequence-diagram');
|
||||||
$value.children().unwrap().unwrap();
|
$value.children().unwrap().unwrap();
|
||||||
var svg = $ele.find('> svg');
|
var svg = $ele.find('> svg');
|
||||||
svg[0].setAttribute('viewBox', '0 0 ' + svg.attr('width') + ' ' + svg.attr('height'));
|
svg[0].setAttribute('viewBox', '0 0 ' + svg.attr('width') + ' ' + svg.attr('height'));
|
||||||
svg[0].setAttribute('preserveAspectRatio', 'xMidYMid meet');
|
svg[0].setAttribute('preserveAspectRatio', 'xMidYMid meet');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(err);
|
console.warn(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//flowchart
|
//flowchart
|
||||||
var flow = view.find(".flow-chart.raw").removeClass("raw");
|
var flow = view.find("div.flow-chart.raw").removeClass("raw");
|
||||||
flow.each(function (key, value) {
|
flow.each(function (key, value) {
|
||||||
try {
|
try {
|
||||||
var $value = $(value);
|
var $value = $(value);
|
||||||
var $ele = $(value).parent().parent();
|
var $ele = $(value).parent().parent();
|
||||||
|
|
||||||
var chart = flowchart.parse($value.text());
|
var chart = flowchart.parse($value.text());
|
||||||
$value.html('');
|
$value.html('');
|
||||||
chart.drawSVG(value, {
|
chart.drawSVG(value, {
|
||||||
'line-width': 2,
|
'line-width': 2,
|
||||||
'fill': 'none',
|
'fill': 'none',
|
||||||
'font-size': '16px',
|
'font-size': '16px',
|
||||||
'font-family': "'Andale Mono', monospace"
|
'font-family': "'Andale Mono', monospace"
|
||||||
});
|
});
|
||||||
|
|
||||||
$ele.addClass('flow-chart');
|
$ele.addClass('flow-chart');
|
||||||
$value.children().unwrap().unwrap();
|
$value.children().unwrap().unwrap();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(err);
|
console.warn(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//graphviz
|
//graphviz
|
||||||
var Viz = require("viz.js");
|
var Viz = require("viz.js");
|
||||||
var graphvizs = view.find(".graphviz.raw").removeClass("raw");
|
var graphvizs = view.find("div.graphviz.raw").removeClass("raw");
|
||||||
graphvizs.each(function (key, value) {
|
graphvizs.each(function (key, value) {
|
||||||
try {
|
try {
|
||||||
var $value = $(value);
|
var $value = $(value);
|
||||||
|
@ -323,7 +323,6 @@ function finishView(view) {
|
||||||
console.warn(err);
|
console.warn(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//mermaid
|
//mermaid
|
||||||
var mermaids = view.find("div.mermaid.raw").removeClass("raw");
|
var mermaids = view.find("div.mermaid.raw").removeClass("raw");
|
||||||
mermaids.each(function (key, value) {
|
mermaids.each(function (key, value) {
|
||||||
|
@ -370,7 +369,7 @@ function finishView(view) {
|
||||||
$(value).closest("blockquote").css('border-left-color', $(value).attr('data-color'));
|
$(value).closest("blockquote").css('border-left-color', $(value).attr('data-color'));
|
||||||
});
|
});
|
||||||
//slideshare
|
//slideshare
|
||||||
view.find(".slideshare.raw").removeClass("raw")
|
view.find("div.slideshare.raw").removeClass("raw")
|
||||||
.each(function (key, value) {
|
.each(function (key, value) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
|
@ -392,7 +391,7 @@ function finishView(view) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
//speakerdeck
|
//speakerdeck
|
||||||
view.find(".speakerdeck.raw").removeClass("raw")
|
view.find("div.speakerdeck.raw").removeClass("raw")
|
||||||
.each(function (key, value) {
|
.each(function (key, value) {
|
||||||
var url = 'https://speakerdeck.com/oembed.json?url=https%3A%2F%2Fspeakerdeck.com%2F' + encodeURIComponent($(value).attr('data-speakerdeckid'));
|
var url = 'https://speakerdeck.com/oembed.json?url=https%3A%2F%2Fspeakerdeck.com%2F' + encodeURIComponent($(value).attr('data-speakerdeckid'));
|
||||||
//use yql because speakerdeck not support jsonp
|
//use yql because speakerdeck not support jsonp
|
||||||
|
@ -424,7 +423,7 @@ function finishView(view) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
//pdf
|
//pdf
|
||||||
view.find(".pdf.raw").removeClass("raw")
|
view.find("div.pdf.raw").removeClass("raw")
|
||||||
.each(function (key, value) {
|
.each(function (key, value) {
|
||||||
var url = $(value).attr('data-pdfurl');
|
var url = $(value).attr('data-pdfurl');
|
||||||
var inner = $('<div></div>');
|
var inner = $('<div></div>');
|
||||||
|
@ -434,7 +433,7 @@ function finishView(view) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
//syntax highlighting
|
//syntax highlighting
|
||||||
view.find("pre > code.raw").removeClass("raw")
|
view.find("code.raw").removeClass("raw")
|
||||||
.each(function (key, value) {
|
.each(function (key, value) {
|
||||||
var langDiv = $(value);
|
var langDiv = $(value);
|
||||||
if (langDiv.length > 0) {
|
if (langDiv.length > 0) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue