jordandelozier / wysibb

WYSIWYG BBcode editor
http://www.wysibb.com
246 stars 86 forks source link

Multiple textareas problem - #97

Closed jrubaloff closed 2 years ago

jrubaloff commented 9 years ago

When multiple bbcode textareas exist on a page, there is a problem. If the cursor is in the first textarea, form submissions and everything works well. However, if the cursor is in any other textareas on the page, submission fails - it never gets to the event. It does work when in source/bbcode view.

We really want to use this library but this could be a show stopper for us. Any chance you can fix?

icamys commented 9 years ago

For those who are still looking for a solution I found out that if you comment 3 rows in file jquery.wysibb.js it will fix the problem:

// file jquery.wysibb.js

...
setBodyFocus: function() {
    $.log("Set focus to WysiBB editor");
    if (this.options.bbmode) {
        if (!this.$txtArea.is(":focus")) {
            this.$txtArea.focus();
        }
    }else{
        //if (!this.$body.is(":focus")) {
        //  this.$body.focus();
        //}
    }
},
...

Also there is an issue with assigning the same id attribute to several textareas. It can be fixed by introducing and appealing to a global variable, for ex. wysibb_lastid instead of $.wysibb.prototype.lastid. The point is that variable $.wysibb is created and called for each selector match separately. That's why $.wysibb.prototype.lastid will never be incremented and always be equal to 2.

// file jquery.wysibb.js

...
$.wysibb.prototype = {
    lastid : 1,
...

Here it should be incremented all the time, but it happens only once:

// file jquery.wysibb.js

...
//UTILS
setUID: function(el,attr) {
    var id = "wbbid_"+(++this.lastid); // <====
    if (el) {
        $(el).attr(attr || "id",id);
    }
    return id;
},
...

Here's my fix for that: https://github.com/icamys/WysiBB/commit/6b76e9d142d1827cac310c2431cb4193cbfb76b9