Permalink
Browse files

Set code popped to false when loading a short url. Moved a lot of fun…

…ctions to global to do so.
  • Loading branch information...
1 parent 1a0b1cb commit c8fb5645107c34550720549782f66ed6f7e7d28b @quilime quilime committed Jun 22, 2012
Showing with 69 additions and 65 deletions.
  1. +69 −65 static/toy/main.js
View
@@ -34,7 +34,6 @@ function(utils, events, params, selector, Embr, SC, $){
"use strict";
// UI //
-
var code_text = document.getElementById("code-text")
, save_dialog = document.getElementById("save-dialog")
, save_dialog_link = document.getElementById("save-dialog-link")
@@ -45,51 +44,27 @@ function(utils, events, params, selector, Embr, SC, $){
, canvas_thumbed = false
, canvas_thumb_size = 256;
+ var code = document.getElementById("code")
+ , code_toggle = document.getElementById("code-toggle")
+ , code_save = document.getElementById("code-save")
+ , code_save_indicator = document.getElementById("code-save-indicator")
+ , code_popout = document.getElementById("code-popout")
+ , code_tooltip = $("#code-tooltip > p")
+ , code_window = null
+ , popped_code_text = null
+ , code_open = false
+ , code_popped = false;
+
function initUI(){
- var code = document.getElementById("code")
- , code_toggle = document.getElementById("code-toggle")
- , code_save = document.getElementById("code-save")
- , code_save_indicator = document.getElementById("code-save-indicator")
- , code_popout = document.getElementById("code-popout")
- , code_tooltip = $("#code-tooltip > p")
- , code_window = null
- , popped_code_text = null
- , code_open = false
- , code_popped = false;
-
- function setCodeOpen(open){
- if(open !== code_open){
- code_open = open;
- code_toggle.setAttribute("class", open ? "open" : "shut");
- if(open){
- code.style.visibility = "visible";
- code_save.style.display = "block";
- code_save.style.opacity = "1";
- code_popout.style.display = "block";
- code_popout.style.opacity = "1";
- code.classList.remove("shut");
- setCodePoppedOut(false);
- }
- else{
- events.addTransitionEndListener(code, function(e){
- code.style.visibility = "hidden";
- }, true);
- code.classList.add("shut");
- events.addTransitionEndListener(code_save, function(e){
- code_save.style.display = "none";
- }, true);
- code_save.style.opacity = "0";
- events.addTransitionEndListener(code_popout, function(e){
- code_popout.style.display = "none";
- }, true);
- code_popout.style.opacity = "0";
- }
- }
- }
+
code_toggle.addEventListener("click", function(e){
setCodeOpen(!code_open);
}, false);
+ code_popout.addEventListener("click", function(e){
+ setCodePoppedOut(!code_popped);
+ }, false);
+
function setCodeEdited(edited){
if(edited === undefined)
edited = true;
@@ -109,28 +84,6 @@ function(utils, events, params, selector, Embr, SC, $){
}
code_save.addEventListener("click", saveCode, false);
- function setCodePoppedOut(popped){
- if(popped !== code_popped){
- code_popped = popped;
- if(popped){ // Pop
- var opts = "width=700,height=500,left=50,top=50," +
- "scrollbars=yes,menubar=no,location=no";
- code_window = window.open("pop.html", "code-window", opts);
- code_window.addEventListener("load", onCodeWindowLoad);
- code_window.addEventListener("beforeunload", onCodeWindowUnload);
- }
- else{ // Unpop
- if(code_window){
- code_window.close();
- code_window = null;
- }
- }
- setCodeOpen(!popped);
- }
- }
- code_popout.addEventListener("click", function(e){
- setCodePoppedOut(!code_popped);
- }, false);
function onCodeWindowLoad(){
popped_code_text = code_window.document.getElementById("code-text");
popped_code_text.value = code_text.value;
@@ -216,11 +169,60 @@ function(utils, events, params, selector, Embr, SC, $){
layoutUI();
}, false);
- // TODO: Set this via permalink
- setCodeOpen(true);
+ setCodeOpen(false);
setCodePoppedOut(false);
}
+ function setCodeOpen(open){
+ if(open !== code_open){
+ code_open = open;
+ code_toggle.setAttribute("class", open ? "open" : "shut");
+ if(open){
+ code.style.visibility = "visible";
+ code_save.style.display = "block";
+ code_save.style.opacity = "1";
+ code_popout.style.display = "block";
+ code_popout.style.opacity = "1";
+ code.classList.remove("shut");
+ setCodePoppedOut(false);
+ }
+ else{
+ events.addTransitionEndListener(code, function(e){
+ code.style.visibility = "hidden";
+ }, true);
+ code.classList.add("shut");
+ events.addTransitionEndListener(code_save, function(e){
+ code_save.style.display = "none";
+ }, true);
+ code_save.style.opacity = "0";
+ events.addTransitionEndListener(code_popout, function(e){
+ code_popout.style.display = "none";
+ }, true);
+ code_popout.style.opacity = "0";
+ }
+ }
+ }
+
+ function setCodePoppedOut(popped){
+ if(popped !== code_popped){
+ code_popped = popped;
+ if(popped){ // Pop
+ var opts = "width=700,height=500,left=50,top=50," +
+ "scrollbars=yes,menubar=no,location=no";
+ code_window = window.open("pop.html", "code-window", opts);
+ code_window.addEventListener("load", onCodeWindowLoad);
+ code_window.addEventListener("beforeunload", onCodeWindowUnload);
+ }
+ else{ // Unpop
+ if(code_window){
+ code_window.close();
+ code_window = null;
+ }
+ }
+ setCodeOpen(!popped);
+ }
+ }
+
function updateCanvasRes(){
var scale = canvas_thumbed ? 1 : 1 / canvas_pixel_scale;
canvas_res[0] = canvas.width = Math.floor(canvas.clientWidth * scale);
@@ -625,6 +627,7 @@ function(utils, events, params, selector, Embr, SC, $){
params.lzmaDecompress(hex, function(src){
code_text.value = src;
tryCompile(code_text);
+ setCodeOpen(true);
});
hash_exists = true;
},
@@ -646,6 +649,7 @@ function(utils, events, params, selector, Embr, SC, $){
if(!hash_exists){
tryCompile(code_text);
+ setCodeOpen(true);
}
utils.requestAnimationFrame(render);

0 comments on commit c8fb564

Please sign in to comment.