sunjavagroups / jwysiwyg

Automatically exported from code.google.com/p/jwysiwyg
GNU General Public License v2.0
0 stars 0 forks source link

Auto update textarea #11

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Put this after "this.initFrame()":

//update textarea value on events
$('form').bind("submit", this.saveContent.closure(this));
$($(this.editor).document()).bind("keydown", this.saveContent.closure(this));
$($(this.editor).document()).bind("mousedown",this.saveContent.closure(this));

And put this closure on top of the file:
Function.prototype.closure = function(obj)
{
  // Init object storage.
  if (!window.__objs)
  {
    window.__objs = [];
    window.__funs = [];
  }

  // For symmetry and clarity.
  var fun = this;

  // Make sure the object has an id and is stored in the object store.
  var objId = obj.__objId;
  if (!objId)
    __objs[objId = obj.__objId = __objs.length] = obj;

  // Make sure the function has an id and is stored in the function store.
  var funId = fun.__funId;
  if (!funId)
    __funs[funId = fun.__funId = __funs.length] = fun;

  // Init closure storage.
  if (!obj.__closures)
    obj.__closures = [];

  // See if we previously created a closure for this object/function pair.
  var closure = obj.__closures[funId];
  if (closure)
    return closure;

  // Clear references to keep them out of the closure scope.
  obj = null;
  fun = null;

  // Create the closure, store in cache and return result.
  return __objs[objId].__closures[funId] = function ()
  {
    return __funs[funId].apply(__objs[objId], arguments);
  };
};

Original issue reported on code.google.com by cim...@gmail.com on 12 Feb 2008 at 12:41

GoogleCodeExporter commented 8 years ago
This way the texarea will automaticly have the value of wysiwyg editor.
When you compress that closure code and put it in its own file it's less than 
1kb.

Original comment by cim...@gmail.com on 12 Feb 2008 at 12:42

GoogleCodeExporter commented 8 years ago
I did it at my own way. I don't found the advantage of the closure function. I 
added
this lines at the bottom of the init function:

{{{
  $('form').submit(function() { self.saveContent(); });
  $( $(this.editor).document() ).keydown(function() { self.saveContent(); });
  $( $(this.editor).document() ).mousedown(function() { self.saveContent(); });
}}}

From revision 5 it will be available.
See you,

Original comment by joksnet on 12 Feb 2008 at 2:10

GoogleCodeExporter commented 8 years ago
Instead of "keydown" better use "keyup", because otherwise the last character 
is not
copied to the textarea - and not submitted within the form.

Original comment by stephan...@googlemail.com on 13 May 2008 at 1:57

GoogleCodeExporter commented 8 years ago
This issue was killing me and "keyup" nailed it. The problem was that i 
couldn't load
jWysiwyg on the fly (create an instance in dynamically loaded content). Unless i
loaded the instance with the page it wouldn't catch the last action and send it 
to
the textarea. So you'd be left with unfinished words or missing sections of 
text if
you had cut an pasted them in.

Line 428 was:
$(this.editorDoc).keydown(function() { self.saveContent(); })

I've changed it to:
$(this.editorDoc).keyup(function() { self.saveContent(); })

I'm wondering if i'm missing something here (i'm a bit simple sometimes) or if 
this
should be an official permanent change?

Cheers.

Original comment by afi...@gmail.com on 11 Jun 2008 at 11:23

GoogleCodeExporter commented 8 years ago
I've change it to

    $(this.editorDoc).keyup(function() { self.saveContent(); })
                     .mouseout(function() { self.saveContent();});

Original comment by danlee...@gmail.com on 18 Jun 2008 at 7:48

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I've changed it to:
$(this.editorDoc).keyup(function() { self.saveContent(); })

I did the same thing and it works fine !

Original comment by benoit....@gmail.com on 1 Dec 2008 at 4:31

GoogleCodeExporter commented 8 years ago
I have some problems becuase when you wirte the textarea doen't update at the 
same
time I add this

 $(this.editorDoc).keydown(function() { self.saveContent(); })
             .mousedown(function() { self.saveContent(); })
             .keyup(function() { self.saveContent(); }); // ADD BY ME

Original comment by rigo.fas...@gmail.com on 23 Jan 2009 at 5:34

GoogleCodeExporter commented 8 years ago
insertImage : {
 visible : true,
   exec    : function()
     {
      if ( $.browser.msie )
      this.editorDoc.execCommand('insertImage', true, null);
       else
        {
          /*var szURL = prompt('URL', 'http://');
              if ( szURL && szURL.length > 0 )
         this.editorDoc.execCommand('insertImage',false,szURL);                    */

var name="file"+fupload;
var szURL = "";
var docMoc = this.editorDoc;
jQuery('#fileUpload').append("<input type='file' class='"+name+"' 
name='images[]' /><br>");
                        jQuery("input."+name+"").change(function(e){

$in=$(this);
var random_=Math.floor((Math.random()*1000)*(Math.random()*100));
szURL = "../files/"+random_+""+$(this).val();
docMoc.execCommand('insertImage', false, szURL);
jQuery('#fileUpload').append("<input type='hidden' value='"+random_+"' 
name='fnames[]' /><br>");
jQuery('#textarea2IFrame').focus();

    ////******how do i save the jWysiwyg editor text to textarea2 without clicking back on jWysiwyg editor.

});

                        /**/
                    }

Original comment by rjli...@gmail.com on 14 Jun 2010 at 10:09

GoogleCodeExporter commented 8 years ago
hey there, how could I modify the onKeyUp event to give me character count. if 
possible. Thanks

Original comment by taimoor....@gmail.com on 8 Jul 2011 at 12:28