Why is $ shorthand disabled?


  • Swedes

    Need to write jQuery and not $. This breaks third party js libs. Whats is the correct way to include 3party modules only when the plugin is used. In my case a widget that is only used on one page.


  • Global Moderator

    It's not disabled, works just fine.


  • Swedes

    If you use it in a template file, then its disabled.

    I get
    Uncaught ReferenceError: $ is not defined

    from

    $(document).ready(function(){
     $("#msgid").html("This is Hello World by JQuery");
    });
    
    </script>
    
    This is Hello World by HTML
    
    <div id="msgid">
    </div>
    

    What is the correct way to load jQuery into a plugin? Do I you use plugin.json to enable this?

    "scripts": [
    "static/lib/main.js"
    ],
    "acpScripts": [
    "static/lib/admin.js"
    ],

    Should scripts be used for public scripst to like jquery? Jquery must be enabled by default right?


  • Global Moderator

    If you have your code in the scripts in plugin.json, jQuery will be available when they run.

    Scripts in templates can run before jQuery loads into the page.


  • Swedes

    ok, so html widgets and template files need to check if jQuery is loaded. But script added by script tag in plugin.js allways have jquery support 🙂


Log in to reply
 

Suggested Topics

  • 6
  • 6
  • 5
  • 3
  • 2
| |