Code Monkey home page Code Monkey logo

Comments (3)

mar10 avatar mar10 commented on August 30, 2024

I have not seen this error before. It seems like $ is defined, but $.ui is not. So query-1.11.1.min.js was loaded, but jquery-ui.min.js was not.
You could add some logging there, to verify.
I also noticed an id="jquery-ui-lib" attribute: is there any dynamic magic happening to modify or add header script tags?

from jquery-ui-contextmenu.

brunoflmg avatar brunoflmg commented on August 30, 2024

Answering your question... yes. Those script tags and link tags are added dynamically.

I found a way to avoid this issue. Maybe it will be a good idea to implement something like this in your plugin before start it. Before this part maybe **var supportSelectstart = "onselectstart" in document.createElement("div") ... **

/**
 * This var will indicate if jquery ui is already loaded or not
 */
var jqueryUiIsLoaded;

/**
 * Add context menu to document
 */
function addContextMenuToDocument() {
    jqueryUiIsLoaded = setTimeout(function(){
        // check if jquery ui was loaded
        if ($.ui) {
            // bind contextmenu event to document
            addContextMenu();

            // stop this check to continue executing
            stopChecking();
        }
    }, 300);
}

/**
 * Stop to look for jquery ui
 */
function stopChecking() {
    clearTimeout(jqueryUiIsLoaded);
}

/**
 * Bind contextmenu event to document
 */
function addContextMenu() {
    // apply jquery ui context menu to any element on the page
    $(document).contextmenu({
        delegate: "body",
        autoFocus: true,
        preventContextMenuForPopup: true,
        preventSelect: true,
        taphold: true,
        menu: [{
            title: "Cut",
            cmd: "cut",
            uiIcon: "ui-icon-scissors",
        }, {
            title: "Copy",
            cmd: "copy",
            uiIcon: "ui-icon-copy",
        }, {
            title: "Paste",
            cmd: "paste",
            uiIcon: "ui-icon-clipboard",
        }]
    });
}

/**
 * Jquery page ready listener function
 */
$(function() {
    addContextMenuToDocument();
});

from jquery-ui-contextmenu.

mar10 avatar mar10 commented on August 30, 2024

Maybe it will be a good idea to implement something like this in your plugin before start it.

jQuery UI is simply a requirement for this plugin, and don't think that it is the responsibility of plugins to wait for all dependencies to be loaded.
The root problem seems to be that you initialize on page load

$(function() {
    ...
 }

which is too early in your case. Instead you should initialize in the ready-event (or similar) of your loader.
Most AMD loaders, like requirejs offer callbacks or other mechanisms for this.

from jquery-ui-contextmenu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.