Forums

Load javascript from external file with dependencies (3 posts)

  1. Jorge_Ricardo
    Member
    Posted 1 year ago #

    I'm trying to use javascript plugins that need jquery as a dependency. I tried almost everything and I can't make it run. What I've done so far is:
    - Load scripts in themes' header.php (In header.php. Maskedinput and meiomask are the plugins I'm trying to use):

    <script src="/JavaScript/jquery.js" type="text/javascript"></script>
    <script src="/JavaScript/maskedinput.js" type="text/javascript"></script>
    <script src="/JavaScript/meiomask.js" type="text/javascript"></script>

    - Enqueue/register plugins (still in header.php):

    <?php
    	wp_enqueue_script('handle_jquery', 'http://my_ip/JavaScript/jquery.js');
    	wp_register_script('handle_meiomask', 'http://my_ip/JavaScript/meiomask.js', array('handle_jquery'));
           wp_register_script('handle_maskedinput', 'http://my_ip/JavaScript/maskedinput.js', array('handle_jquery'));
    ?>

    - Call function (in header.php, as required by plugin maskedinput):

    <script type="text/javascript">
       $(function() {
         $('input[@name=htmlDataInicio]').mask('99/99/9999');
       });
    </script>
    
    <script type="text/javascript">
    jQuery(function($){
       $("htmlDataInicio").mask("99/99/9999");
    });
    </script>
    
    <script type="text/javascript">
    jQuery(function($){
       $("#htmlDataInicio").mask("99/99/9999");
    });
    </script>

    - Put alt="wanted_mask" (as required by meiomask plugin):

    <p><b>Recursos: </b><input type="text" id="decimal" name="some_name" alt="decimal" /></p>

    And the plugins don't work.

    Any help appreciated. Thanks.

  2. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/Javascript/jquery.js"></script>

    does it work any better like this to load them?

    (assuming the scripts are in a Javascript folder, in your theme)

  3. Jorge_Ricardo
    Member
    Posted 1 year ago #

    First of all, thanks RVoodoo.
    But my problem is not loading the scripts. I've loaded them and tested with a simple button and an alert message and it worked fine. So I guess they are loading. My problem is that maskedinput and meiomask plugins need jquery as a dependency. So my problem is wp_enqueue/wp_register functions (or that's what I think, at least).
    So, anyone knows how to make dependencies work?

Topic Closed

This topic has been closed to new replies.

About this Topic