This needs to be added again after refactoring: using a settimout function to create a (500ms) delay in the ajax callback.

That way, the ajax call will only be made when a user stops typing (for half a second) instead after each keypress. When the user continues typing within 500ms , the timout is cancelled.

It would be nice to eventually create a config screen for settings like the 500ms but that should become a seperate issue and can be hardcoded for now.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mcoirault’s picture

Status: Active » Needs review
FileSize
7.13 KB

Here is the patch that add timeout feature to the latest refactoring.

The timeout delay is still hardcoded but easily modifiable since it's a static property of CKEDITOR_mentions object.

On a side note, there was a weird character at the top a the file (probably the utf8 BOM). I removed it.

askibinski’s picture

Thanks! Will test the patch asap.

askibinski’s picture

Status: Needs review » Needs work

Patch doesn't apply anymore because of changes in #2030269: Insert code replaces all realname instances, including existing.

Could je maybe reroll it against the current dev?

mcoirault’s picture

Sure. I'll post back a new patch within 5h.

mcoirault’s picture

Here it is. Timeout is working great but ajax return seem broken

I had to replace $.get() with $ajax() to understand why the ajax request was failing. It seems that something is messing with the return of ckeditor_mentions_getpeople(). An array is appended to the regular json, and I have no clue where it comes from.

Here is whats it returns:

{
    "html": "\u003Cdiv class=\u0022view view-ckeditor-mentions view-id-ckeditor_mentions view-display-id-block view-dom-id-\u0022\u003E\n        \n  \n  \n      \u003Cdiv class=\u0022view-content\u0022\u003E\n      \u003Cdiv class=\u0022item-list\u0022\u003E    \u003Cul\u003E          \u003Cli class=\u0022\u0022\u003E  \n          \u003Ca class=\u0022mention-users\u0022 data-uid=\u00223\u0022 data-realname=\u0022Drew Robertson\u0022\u003EDrew Robertson\u003C\/a\u003E  \u003C\/li\u003E\n      \u003C\/ul\u003E\u003C\/div\u003E    \u003C\/div\u003E\n  \n  \n  \n  \n  \n  \n\u003C\/div\u003E"
}[
    {
        "command": "settings",
        "settings": {
            "basePath": "\/",
            "pathPrefix": "",
            "ajaxPageState": {
                "theme": "commons_origins",
                "theme_token": "Rv7S02CIpP2gBgHDfJUrTcJWPdZjxOA0SQVIetRZXo4"
            },
            "custom_search": {
                "form_target": "_self",
                "solr": 0
            }
        },
        "merge": true
    }
]

Putting a die() right after drupal_json_output(array('html' => $html)); solve the problem, but it's ugly as hell.

Can you test on your environnement?

mcoirault’s picture

I think the error came from ckeditor_mentions.ajax.inc which was printing a json output instead of returning a string for the hook_menu to process. Then hook_menu apply drupal_json_output on it (via the delivery callback parameter).

That being said, drupal still add many parameters around our html but we are able to retreive it fairly easily in plugin.js.

I'm not too sure about that solution, so please let me know if it sounds good or not.

On the other hand, drupal_exit(); seems to be another solution to our problem.

askibinski’s picture

I'll check it out this weekend!

askibinski’s picture

Status: Needs work » Fixed

I had to apply the patch manually because:

patch -p1 --dry-run < add-timeout-to-last-refactor-2032897-6.patch

gave me an error:

patch unexpectedly ends in middle of line 
patch: **** Only garbage was found in the patch input.

I think there is some weirdness in your patches, not sure what though, never seen that error.

Anyway, I applied it manually and it works, two things:

  1. I can't reproduce the json output problem, so I didn't remove drupal_json_output. Can you checkout the latest dev and see if it's still there
  2. I didn't apply the $.ajax because it was for debugging like you said yourself. If you think it's better than we can add it through a new issue.
mcoirault’s picture

I can't reproduce the json output problem, so I didn't remove drupal_json_output. Can you checkout the latest dev and see if it's still there

I reverted my work back to the current dev, but I still had to add a drupal_exit() right after drupal_json_output() to make it work without modifying a lot of files. It seems that my clean install of Drupal Commons adds junk after the json output but I can't figure out why nor where.

I still think it's a good idea to ensure this module can work on both regular and Commons (given the small amount of work to make it so). Moreover, a drupal_exit after a json output seems to be a fairly common in the community to ensure the json is clean (correct me if I'm wrong).

I joined the small patch for this, just in case.

askibinski’s picture

Status: Fixed » Needs review

Seems like a good idea :)

askibinski’s picture

Assigned: Unassigned » askibinski

assign

askibinski’s picture

Status: Needs review » Closed (fixed)

Comitted! Thanks!

http://drupalcode.org/project/ckeditor_mentions.git/commit/38f4f28

PS: Check out the latest release. It also has a js polyfill to make settimeout work in IE9.