Don't wait for onload.

This commit is contained in:
bootstraponline
2012-05-18 15:57:41 -06:00
parent 40fdd2aa74
commit f7d3f6b3f0
@@ -133,58 +133,83 @@ $.save = function( commitMessage ) {
} // end else
}
window.onload = function() {
/* Load markdown from /data/page into the ace editor. */
jQuery.ajax({
/* Load markdown from /data/page into the ace editor. */
jQuery.ajax({
type: "GET",
url: "/data/" + $.key("page"),
success: function(data) {
editorSession.setValue(data);
}
});
});
$("#save").click(function() {
$("#save").click(function() {
$.save();
});
});
// Hide dimmer, comment tool panel, and comment.
$("#commentcancel").click(function() {
// Hide dimmer, comment tool panel, and comment.
$("#commentcancel").click(function() {
// Restore focus on commentcancel but not on
// savecommentconfirm because the latter loads
// a new page.
hideCommentWindow();
editor.focus();
});
});
var isCommentHidden = true;
var isCommentHidden = true;
function hideCommentWindow() {
function hideCommentWindow() {
isCommentHidden = true;
darkness.style.visibility = "hidden";
commentToolPanel.style.visibility = "hidden";
comment.style.visibility = "hidden";
}
}
// Show dimmer, comment tool panel, and comment.
$("#savecomment").click(function() {
// Show dimmer, comment tool panel, and comment.
$("#savecomment").click(function() {
isCommentHidden = false;
darkness.style.visibility = "visible";
commentToolPanel.style.visibility = "visible";
comment.style.visibility = "visible";
// Set focus so typing can begin immediately.
commentEditor.focus();
});
});
$("#savecommentconfirm").click(function() {
$("#savecommentconfirm").click(function() {
$.save(commentEditorSession.getValue());
hideCommentWindow();
});
});
// onChange calls applyTimeout which rate limits the calling of makePreviewHtml based on render time.
editor.on('change', applyTimeout);
makePreviewHtml(); // preview default text on load
// onChange calls applyTimeout which rate limits the calling of makePreviewHtml based on render time.
editor.on('change', applyTimeout);
function resize() {
var cssTextSet = function( element, css ){
element.style.cssText = css;
};
var cssAttrSet = function( element, css ){
element.setAttribute( 'style', css );
};
/*
Redefine the function based on browser support.
element - the element to set the css on
css - a fully formed css string. ex: "top: 0; left: 0;"
Avoid reflow by batching CSS changes.
http://dev.opera.com/articles/view/efficient-javascript/?page=3#stylechanges
*/
var cssSet = function( element, css ) {
if( typeof( element.style.cssText ) != 'undefined' ) {
cssTextSet( element, css );
cssSet = cssTextSet;
} else {
cssAttrSet( element, css );
cssSet = cssAttrSet;
}
};
function resize() {
var width = $(window).width();
var widthHalf = width / 2;
var widthFourth = widthHalf / 2;
@@ -235,22 +260,21 @@ window.onload = function() {
"height:" + height + "px;" +
commentHidden;
cssSet(darkness, darknessStyle);
}
}
window.jsm.resize = resize;
window.jsm.resize = resize;
/*
/*
Resize can be called an absurd amount of times
and will crash the page without debouncing.
http://benalman.com/projects/jquery-throttle-debounce-plugin/
https://github.com/cowboy/jquery-throttle-debounce
http://unscriptable.com/2009/03/20/debouncing-javascript-methods/
*/
$(window).resize( $.debounce( 100, resize ) );
*/
$(window).resize( $.debounce( 100, resize ) );
// resize for the intial page load
resize();
};
// resize for the intial page load
resize();
var elapsedTime;
var oldInputText = "";
@@ -276,32 +300,6 @@ var ieSafePreviewSet = function (text) {
parent.insertBefore(content, sibling);
}
var cssTextSet = function( element, css ){
element.style.cssText = css;
}
var cssAttrSet = function( element, css ){
element.setAttribute( 'style', css );
}
/*
Redefine the function based on browser support.
element - the element to set the css on
css - a fully formed css string. ex: "top: 0; left: 0;"
Avoid reflow by batching CSS changes.
http://dev.opera.com/articles/view/efficient-javascript/?page=3#stylechanges
*/
var cssSet = function( element, css ) {
if( typeof( element.style.cssText ) != 'undefined' ) {
cssTextSet( element, css );
cssSet = cssTextSet;
} else {
cssAttrSet( element, css );
cssSet = cssAttrSet;
}
}
var previewSet = function( text ) {
try {
nonSuckyBrowserPreviewSet( text );
@@ -379,6 +377,9 @@ var makePreviewHtml = function () {
}
};
// preview default text on load
makePreviewHtml();
// setTimeout is already used. Used as an event listener.
var applyTimeout = function () {
if (timeout) {