# HG changeset patch
# User Alex Leone <acleone ~AT~ gmail.com>
# Date 1263875060 28800
# Node ID 4bcb7619f6b6f2a459a8bb02c178bbcfff14d9b8
# Parent  96f896200e93681425b98a432aec6ebe65eeba3d
#7434 Hides java applets before showing modal prompts.

diff --git a/sagenb/data/sage/js/notebook_lib.js b/sagenb/data/sage/js/notebook_lib.js
--- a/sagenb/data/sage/js/notebook_lib.js
+++ b/sagenb/data/sage/js/notebook_lib.js
@@ -525,6 +525,46 @@ function set_cursor_position(cell, n) {
 // Misc page functions -- for making the page work nicely
 //
 ///////////////////////////////////////////////////////////////////
+
+function hide_java_applets() {
+    /*
+    Hides all <object type="application/x-java-applet"></object> by moving
+    them off the screen and putting a box of the same size in the same place.
+     */
+    $('object[type="application/x-java-applet"]').each(function () {
+        var me = $(this),
+            width = me.width(),
+            height = me.height();
+        me.css({
+            "margin-left": "-" + (width + 1000) + "px"
+        });    
+        me.after(
+            $('<table><tbody><tr><td align="center" valign="middle">' + 
+              'Java Applet Hidden</td></tr></tbody></table>').css({
+                "margin-top": '-' + height.toString() + 'px',
+                "width": width.toString() + 'px',
+                "height": height.toString() + 'px',
+                "border": "1px solid black",
+                "background-color": "#ccc",
+                "color": "black"
+            })
+        );
+    });
+}
+
+function show_java_applets() {
+    /*
+    Shows all the java applets hid with applet_hide().
+    */
+    $('object[type="application/x-java-applet"]').each(function () {
+        var me = $(this);
+        me.css({
+            "margin-left": "0px"
+        });
+        me.next().remove();
+    });
+}
+
 function modal_prompt(form_options, options, modal_options) {
     /*
     Displays a prompt with a modal dialog. Use this instead of
@@ -587,22 +627,8 @@ function modal_prompt(form_options, opti
     submit_value = options.submit || 'OK';
     css = options.css || {};
 
-    
-
-    new_prompt = $(modal_prompt_element);
-    $('body').append(new_prompt);
-    new_prompt.css(css);
-
-    new_form = new_prompt.find('form');
-    if (options.id) {
-        new_prompt.attr('id', options.id);
-    }
-    if (options.form_id) {
-        new_form.attr('id', options.form_id);
-    }
-
     overlay_close = options.overlay_close;
-    if (!options.overlay_close) {
+    if (typeof(options.overlay_close) === 'undefined') { 
         overlay_close = true;
     }
 
@@ -616,8 +642,9 @@ function modal_prompt(form_options, opti
         } else if (typeof(close_behavior) === 'function') {
             close_behavior();
         }
+        show_java_applets();
     };
-
+    
     modal_options = $.extend({
         autoOpen: true,
         bgiframe: true,
@@ -627,6 +654,18 @@ function modal_prompt(form_options, opti
     },
     modal_options);
 
+    new_prompt = $(modal_prompt_element);
+    $('body').append(new_prompt);
+    new_prompt.css(css);
+
+    new_form = new_prompt.find('form');
+    if (options.id) {
+        new_prompt.attr('id', options.id);
+    }
+    if (options.form_id) {
+        new_form.attr('id', options.form_id);
+    }
+
     // Prompt setup.
     new_prompt.find('div.message').html(message);
     input = new_prompt.find('input', 'div.field').attr('value', default_value).css('width', '100%');
@@ -646,6 +685,7 @@ function modal_prompt(form_options, opti
     };
 
     new_form.ajaxForm(form_options);
+    hide_java_applets();
     new_prompt.dialog(modal_options);
     input.select();
 }
