Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#967 closed defect (worksforme)

widget/RichText.js - document.write unnecessarily wipes page

Reported by: srini at youos Owned by: alex
Priority: high Milestone:
Component: Widgets Version: 0.3
Keywords: RichText Cc:
Blocked by: Blocking:

Description

RichText widget does a document.write() which ends up overwriting the entire page if the widget is loaded dynamically after the page has been loaded. This document.write can be avoided.

Possible Fix:

Index: RichText.js
===================================================================
--- RichText.js (revision 2588)
+++ RichText.js (revision 2589)
@@ -20,10 +20,11 @@
 dojo.require("dojo.string");

 // used to save content
-try {
-       document.write('<textarea id="dojo.widget.RichText.savedContent" ' +
-               'style="display:none;position:absolute;top:-100px;left:-100px;height:3px;width:3px;overflow:hidden;"></textarea>');
-}catch(e){ }
+//try {
+//     document.write('<textarea id="dojo.widget.RichText.savedContent" ' +
+//             'style="display:none;position:absolute;top:-100px;left:-100px;height:3px;width:3px;overflow:hidden;"></textarea>');
+//}catch(e){ }

 dojo.widget.defineWidget(
        "dojo.widget.html.RichText",
@@ -195,6 +196,12 @@

                        if(this.saveName != ""){
                                var saveTextarea = document.getElementById("dojo.widget.RichText.savedContent");
+                                // create saved content textarea on demand, under body
+                                if (! saveTextarea)
+                                {
+                                  document.body.innerHTML += "<textarea id="dojo.widget.RichText.savedContent" style="display:none;position:absolute;top:-100px;left:-100px;height:3px;width:3px;overflow:hidden;"></textarea>";
+                                 saveTextarea = document.getElementById("dojo.widget.RichText.savedContent");
+                                }
                                if (saveTextarea.value != "") {
                                        var datas = saveTextarea.value.split(this._SEPARATOR);
                                        for (var i = 0; i < datas.length; i++) {
@@ -1303,6 +1310,12 @@
                 */
                _saveContent: function(e){
                        var saveTextarea = document.getElementById("dojo.widget.RichText.savedContent");
+                        // create saved content textarea on demand, under body
+                        if (! saveTextarea)
+                        {
+                          document.body.innerHTML += "<textarea id="dojo.widget.RichText.savedContent" style="display:none;position:absolute;top:-100px;left:-100px;height:3px;width:3px;overflow:hidden;"></textarea>";
+                         saveTextarea = document.getElementById("dojo.widget.RichText.savedContent");
+                        }
                        saveTextarea.value += this._SEPARATOR + this.saveName + ":" + this.getEditorContent();
                },

Change History (4)

comment:1 Changed 8 years ago by srini

Possible test case using Editor which requires RichText:

<html>
<head>

<script type="text/javascript" src="dojo.js"></script>

<script type="text/javascript">

function doMakeRich()
{
  dojo.require("dojo.widget.Editor");
  var editor = dojo.widget.fromScript("Editor", {}, 
                                    dojo.byId("california"));
  
}
</script>

</head>

<body>
<div id="california">I live in on the West Coast.</div>
</body>

<script type="text/javascript">
setTimeout("doMakeRich();", 4000);
</script>

</html>

comment:2 Changed 8 years ago by dylan

  • Milestone set to 0.4
  • Owner changed from anonymous to alex

I don't believe this is an issue with Editor2. Please verify and close.

comment:3 Changed 8 years ago by dylan

  • Resolution set to worksforme
  • Status changed from new to closed

comment:4 Changed 7 years ago by anonymous

  • Milestone 0.4 deleted

Milestone 0.4 deleted

Note: See TracTickets for help on using tickets.