-
Notifications
You must be signed in to change notification settings - Fork 564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(load): add a javascript load queue #159
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,8 @@ | |
<%- css("css/style.min") %> | ||
<%- partial("_partial/config_css") %> | ||
<%- js("js/jquery.min") %> | ||
<%- js("js/queue") %> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
<%- js("js/lazyload.min") %> | ||
|
||
<%- css("css/highlight/" + theme.reading.code_highlight ) %> | ||
|
||
|
@@ -119,6 +121,16 @@ | |
</script> | ||
<% } %> | ||
|
||
<!-- Bing Background --> | ||
<% if(theme.background.bing.enable) { %> | ||
<script type="text/javascript"> | ||
queue.offer(function(){ | ||
$('body').attr("data-original","https://api.i-meto.com/bing?<%= theme.background.bing.parameter %>"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
$('body.lazy').lazyload(); | ||
}); | ||
</script> | ||
<% } %> | ||
|
||
<!-- Custom Head --> | ||
<% if (site.data.head) { %> | ||
<% for (var i in site.data.head) { %> | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
function Queue() { | ||
this.dataStore = []; | ||
this.offer = offer; | ||
this.poll = poll; | ||
this.execNext = execNext; | ||
this.debug = false; | ||
this.startDebug = startDebug; | ||
|
||
|
||
function offer(element) { | ||
if(this.debug) console.log("Offered a Queued Function."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if(typeof element === "function") { | ||
this.dataStore.push(element); | ||
} else { | ||
console.log("You must offer a function."); | ||
} | ||
} | ||
|
||
function poll() { | ||
if(this.debug) console.log("Polled a Queued Function."); | ||
return this.dataStore.shift(); | ||
} | ||
|
||
function execNext() { | ||
var nextfunc=this.poll(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if(nextfunc != undefined) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if(this.debug) console.log("Run a Queued Function."); | ||
nextfunc(); | ||
} | ||
} | ||
|
||
function startDebug(){ | ||
this.debug = true; | ||
} | ||
|
||
} | ||
|
||
var queue = new Queue(); | ||
$(document).ready(function(){ | ||
setTimeout(function(){ | ||
setInterval(function(){ | ||
queue.execNext(); | ||
},500); | ||
},3000); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.