File:  [LON-CAPA] / loncom / html / htmlarea / popups / Attic / fullscreen.html
Revision 1.1: download - view: text, annotated - select for diffs
Wed Feb 18 08:07:16 2004 UTC (20 years, 5 months ago) by www
Branches: MAIN
CVS tags: HEAD
Install HTMLArea

    1: <html>
    2: <head><title>Fullscreen Editor</title>
    3: <style type="text/css">
    4: @import url(../htmlarea.css);
    5: html, body {	margin: 0px; border: 0px; background-color: buttonface; } </style>
    6: 
    7: <!--
    8: <script type="text/javascript" src="../htmlarea.js"></script>
    9: <script type="text/javascript" src="../htmlarea-lang-en.js"></script>
   10: <script type="text/javascript" src="../dialog.js"></script>
   11: -->
   12: 
   13: <script type="text/javascript">
   14: // load same scripts that were present in the opener page
   15: var scripts = opener.document.getElementsByTagName("script");
   16: var head = document.getElementsByTagName("head")[0];
   17: for (var i = 0; i < scripts.length; ++i) {
   18:   var script = scripts[i];
   19:   if (typeof script.src != "undefined" && /\S/.test(script.src)) {
   20:     // document.write("<scr" + "ipt type=" + "\"script/javascript\"");
   21:     // document.write(" src=\"../" + script.src + "\"></scr" + "ipt>");
   22:     var new_script = document.createElement("script");
   23:     if (/^http:/i.test(script.src)) {
   24:       new_script.src = script.src;
   25:     } else {
   26:       new_script.src = "../" + script.src;
   27:     }
   28:     head.appendChild(new_script);
   29:   }
   30: }
   31: </script>
   32: 
   33: <script type="text/javascript">
   34: 
   35: var parent_object  = null;
   36: var editor         = null;      // to be initialized later [ function init() ]
   37: 
   38: /* ---------------------------------------------------------------------- *\
   39:   Function    : 
   40:   Description : 
   41: \* ---------------------------------------------------------------------- */
   42: 
   43: function _CloseOnEsc(ev) {
   44:   if (document.all) {
   45:     // IE
   46:     ev = window.event;
   47:   }
   48:   if (ev.keyCode == 27) {
   49:     // update_parent();
   50:     window.close();
   51:     return;
   52:   }
   53: }
   54: 
   55: /* ---------------------------------------------------------------------- *\
   56:   Function    : cloneObject
   57:   Description : copy an object by value instead of by reference
   58:   Usage       : var newObj = cloneObject(oldObj);
   59: \* ---------------------------------------------------------------------- */
   60: 
   61: function cloneObject(obj) {
   62:   var newObj          = new Object; 
   63: 
   64:   // check for array objects
   65:   if (obj.constructor.toString().indexOf("function Array(") == 1) {
   66:     newObj = obj.constructor();
   67:   }
   68: 
   69:   // check for function objects (as usual, IE is fucked up)
   70:   if (obj.constructor.toString().indexOf("function Function(") == 1) {
   71:     newObj = obj; // just copy reference to it
   72:   } else for (var n in obj) {
   73:     var node = obj[n];
   74:     if (typeof node == 'object') { newObj[n] = cloneObject(node); }
   75:     else                         { newObj[n] = node; }
   76:   }
   77:   
   78:   return newObj;
   79: }
   80: 
   81: /* ---------------------------------------------------------------------- *\
   82:   Function    : resize_editor
   83:   Description : resize the editor when the user resizes the popup
   84: \* ---------------------------------------------------------------------- */
   85: 
   86: function resize_editor() {  // resize editor to fix window
   87:   var newHeight;
   88:   if (document.all) {
   89:     // IE
   90:     newHeight = document.body.offsetHeight - editor._toolbar.offsetHeight;
   91:     if (newHeight < 0) { newHeight = 0; }
   92:   } else {
   93:     // Gecko
   94:     newHeight = window.innerHeight - editor._toolbar.offsetHeight;
   95:   }
   96:   if (editor.config.statusBar) {
   97:     newHeight -= editor._statusBar.offsetHeight;
   98:   }
   99:   editor._textArea.style.height = editor._iframe.style.height = newHeight + "px";
  100: }
  101: 
  102: /* ---------------------------------------------------------------------- *\
  103:   Function    : init
  104:   Description : run this code on page load
  105: \* ---------------------------------------------------------------------- */
  106: 
  107: function init() {
  108:   parent_object      = opener.HTMLArea._object;
  109:   var config         = cloneObject( parent_object.config );
  110:   config.editorURL   = "../";
  111:   config.width       = "100%";
  112:   config.height      = "auto";
  113: 
  114:   // change maximize button to minimize button
  115:   config.btnList["popupeditor"] = [ 'Minimize Editor', 'images/fullscreen_minimize.gif', true,
  116:                                     function() { window.close(); } ];
  117: 
  118:   // generate editor and resize it
  119:   editor = new HTMLArea("editor", config);
  120:   editor.generate();
  121:   editor._iframe.style.width = "100%";
  122:   editor._textArea.style.width = "100%";
  123:   resize_editor();
  124: 
  125:   // set child window contents and event handlers, after a small delay
  126:   setTimeout(function() {
  127:     editor.setHTML(parent_object.getInnerHTML());
  128: 
  129:     // switch mode if needed
  130:     if (parent_object._mode == "textmode") { editor.setMode("textmode"); }
  131: 
  132:     // continuously update parent editor window
  133:     setInterval(update_parent, 500);
  134: 
  135:     // setup event handlers
  136:     document.body.onkeypress = _CloseOnEsc;
  137:     editor._doc.body.onkeypress = _CloseOnEsc;
  138:     editor._textArea.onkeypress = _CloseOnEsc;
  139:     window.onresize = resize_editor;
  140:   }, 333);                      // give it some time to meet the new frame
  141: }
  142: 
  143: /* ---------------------------------------------------------------------- *\
  144:   Function    : update_parent
  145:   Description : update parent window editor field with contents from child window
  146: \* ---------------------------------------------------------------------- */
  147: 
  148: function update_parent() {
  149:   // use the fast version
  150:   parent_object.setHTML(editor.getInnerHTML());
  151: }
  152: 
  153: 
  154: </script>
  155: </head>
  156: <body scroll="no" onload="init()" onunload="update_parent()">
  157: 
  158: <form style="margin: 0px; border: 1px solid; border-color: threedshadow threedhighlight threedhighlight threedshadow;">
  159: <textarea name="editor" id="editor" style="width:100%; height:300px">&nbsp;</textarea>
  160: </form>
  161: 
  162: </body></html>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>