bergie / hallo

Simple rich text editor (contentEditable) for jQuery UI
http://hallojs.org/
MIT License
2.43k stars 314 forks source link

Status of the hallolink plugin #183

Closed lambdazen closed 11 years ago

lambdazen commented 11 years ago

Hi,

I am using HalloEditor to build a programmable Wiki, and am very happy with how it works.

I would like to use the link feature (hallolink) to allow users to create links. I see from your project documentation that this feature doesn't work currently.

What is the problem with the plugin? How would you suggest that I proceed? I can help fix the problem, if I can.

Regards,

Sridhar.

styks1987 commented 11 years ago

I am also interested in a solution for this.

grobmeier commented 11 years ago

+1

couresel commented 11 years ago

If you feel comfortable modifying the .js file, there's a line that resembles "dialog.dialog('close');" around line# 251

Move that line up to so that it is above line# 230 which reads "widget.options.editable.restoreSelection(widget.lastSelection);"

The result function should look something like this:

      dialog.dialog('close');
      widget.options.editable.restoreSelection(widget.lastSelection);
      if (isEmptyLink(link)) {
        selectionStart = widget.lastSelection.startContainer;
        if (widget.lastSelection.collapsed) {
          widget.lastSelection.setStartBefore(selectionStart);
          widget.lastSelection.setEndAfter(selectionStart);
          window.getSelection().addRange(widget.lastSelection);
        }
        document.execCommand("unlink", null, "");
      } else {
        if (!(/:\/\//.test(link)) && !(/^mailto:/.test(link))) {
          link = 'http://' + link;
        }
        if (widget.lastSelection.startContainer.parentNode.href === void 0) {
          document.execCommand("createLink", null, link);
        } else {
          widget.lastSelection.startContainer.parentNode.href = link;
        }
      }
      widget.options.editable.element.trigger('change');
      widget.options.editable.removeAllSelections();
      return false;

Please let me/us know if this works for you.

marcobarbosa commented 11 years ago

"What is the problem with the plugin? How would you suggest that I proceed?"

+1

I'll take a look at @couresel code above but it would be good to know what's missing or what the problem is. I'm also in the need for this as soon as possible.

openinformation commented 11 years ago

I guess the code above is from the 1.02 release?

We are using the latest version from master: here inserting the first link works fine, but trying to insert a second link throws the following error:

TypeError: widget.lastSelection.startContainer.parentNode is null (Line 1719)

The workaround is to click outside the editable and then inside again... Not sure whether this is a problem with rangy or the way hallo.js handles selections.

couresel commented 11 years ago

The change above has been committed to the project, however you will have to compile the coffee script src. I am assuming that the js file in the project is from a previous stable commit.

It might be worth building the js from the coffee scripts in the src directory; I have not tried that just yet.

openinformation commented 11 years ago

I took the examples/hallo.js file from master, which indicates it has been recently build. But I can build from coffee script and try again.

lambdazen commented 11 years ago

Is anyone getting this error while closing the dialog?

Uncaught SyntaxError: Invalid regular expression: /(^|.)dialog-overlay(.|$)/: Stack overflow

It looks like an infinite loop in jquery.event.remove(). I doesn't matter where I do the dialog.dialog('close').

If anyone has got the link window to close, please let me know which version of jquery you are using. I am on 1.8.3 which may be old.

lambdazen commented 11 years ago

Update: The issue in my last post (infinite loop in jquery.event.remove) seems to be in jQuery.

In the jquery.js file, I had to add

    // Detach an event or set of events from an element
    remove: function( elem, types, handler, selector, mappedTypes ) {
        ...
        // Unbind all events (on this namespace, if provided) for the element
        if ( !type ) {
            for ( type in events ) {
                if (type) { // Added a check here
                jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
            }
        }
        ...

After this change the link editing seems to work fine. I am using dialogs elsewhere, but didn't run into this problem. I'm not sure why closing the dialog created an issue in hallo.

@couresel

I couldn't see a difference in behavior when moving the dialog close up from 251 to 230. I think I'm missing something. What was the problem that this change addressed?

lambdazen commented 11 years ago

I have put up this jsfiddle for everyone's reference: http://jsfiddle.net/f5XYV/2/

This shows the link feature working without any changes. I think the issue I faced with jquery might have to do with some interaction with bootstrap or my application code. At this point, the link feature works from my point of view. I have not done heavy testing of the fiddle, so we might still have issues.

@marcobarbosa, @styks1987, @grobmeier, @couresel , @openinformation : If all of you are OK, we can close this issue.

grobmeier commented 11 years ago

@lambdazen Yeah I think you can close this. I can confirm its working with the tip version.

bergie commented 11 years ago

@grobmeier cool!

marcobarbosa commented 11 years ago

Yep, all good! Thanks!

couresel commented 11 years ago

No complaints here. Feel free to close as deemed appropriate.