change beforeunload to use addEventListener (only supporting IE9 now and better to allow multiple if user wishes); also CamelCase internal variable for consistency; add brackets

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2639 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Brett Zamir 2014-01-31 00:06:50 +00:00
parent 7a4d8949c7
commit 6b5a4e645e
4 changed files with 17 additions and 9 deletions

View File

@ -11,7 +11,7 @@
var svgCanvas = null;
function init_embed() {
function initEmbed() {
var doc, mainButton,
frame = document.getElementById('svgedit');
svgCanvas = new EmbeddedSVGEdit(frame);
@ -43,7 +43,7 @@
$('#save').click(saveSvg);
// Export globals
window.init_embed = init_embed;
window.initEmbed = initEmbed;
});
</script>
</head>
@ -51,6 +51,6 @@
<button id="load">Load example</button>
<button id="save">Save data</button>
<br/>
<iframe src="svg-editor.html" width="900px" height="600px" id="svgedit" onload="init_embed();"></iframe>
<iframe src="svg-editor.html" width="900px" height="600px" id="svgedit" onload="initEmbed();"></iframe>
</body>
</html>

View File

@ -220,7 +220,9 @@ svgedit.history.RemoveElementCommand.prototype.unapply = function(handler) {
svgedit.transformlist.removeElementFromListMap(this.elem);
if (this.nextSibling == null) {
if (window.console) console.log('Error: reference element was lost');
if (window.console) {
console.log('Error: reference element was lost');
}
}
this.parent.insertBefore(this.elem, this.nextSibling);

View File

@ -1801,7 +1801,9 @@
var operaRepaint = function() {
// Repaints canvas in Opera. Needed for stroke-dasharray change as well as fill change
if (!window.opera) return;
if (!window.opera) {
return;
}
$('<p/>').hide().appendTo('body').remove();
};
@ -4235,7 +4237,7 @@
$('#cmenu_canvas li').disableContextMenu();
canv_menu.enableContextMenuItems('#delete,#cut,#copy');
window.onbeforeunload = function() {
window.addEventListener('beforeunload', function() {
if ('localStorage' in window) {
var name = 'svgedit-' + Editor.curConfig.canvasName;
window.localStorage.setItem(name, svgCanvas.getSvgString());
@ -4252,7 +4254,7 @@
// Browser already asks question about closing the page
return uiStrings.notification.unsavedChanges;
}
};
}, false);
Editor.openPrep = function(func) {
$('#main_menu').hide();

View File

@ -82,7 +82,9 @@ svgedit.utilities.encode64 = function(input) {
// base64 strings are 4/3 larger than the original string
// input = svgedit.utilities.encodeUTF8(input); // convert non-ASCII characters
input = svgedit.utilities.convertToXMLReferences(input);
if(window.btoa) return window.btoa(input); // Use native if available
if(window.btoa) {
return window.btoa(input); // Use native if available
}
var output = new Array( Math.floor( (input.length + 2) / 3 ) * 4 );
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
@ -116,7 +118,9 @@ svgedit.utilities.encode64 = function(input) {
// Function: svgedit.utilities.decode64
// Converts a string from base64
svgedit.utilities.decode64 = function(input) {
if(window.atob) return window.atob(input);
if(window.atob) {
return window.atob(input);
}
var output = '';
var chr1, chr2, chr3 = '';
var enc1, enc2, enc3, enc4 = '';