Jump to content
katapofatico

Problem: Header Tag Module including multiple Javascript files

Recommended Posts

I'm developing a header tag module in order to include jquery validation plugin. I use Firefox browser.

My first attempt works well ...

private function _includeValidation() {
  $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/jquery.validate.min.js" />', $this->group); // $this->group = 'header_tags'
}

... but when I try to include another script...

private function _includeValidation() {
  $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/jquery.validate.min.js" />', $this->group);
  $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/localization/messages_es.min.js" />', $this->group);
}

... the browser only load the first one: jquery.validate.min.js

 

ATTEMPTS

1) If I switch the loading order...

private function _includeValidation() {
  $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/localization/messages_es.min.js" />', $this->group);
  $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/jquery.validate.min.js" />', $this->group);
}

... the browser only load the first one: messages_es.min.js

2) I see that core modules sometimes include a breakline separator, then I try applying it...
 

private function _includeValidation() {
  $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/jquery.validate.min.js" />' . PHP_EOL, $this->group);
  $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/localization/messages_es.min.js" />' . PHP_EOL, $this->group);
}

... the browser only load the first one: jquery.validate.min.js

3) Using "\n" instead of PHP_EOL, as other modules...

private function _includeValidation() {
  $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/jquery.validate.min.js" />' . "\n", $this->group);
  $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/localization/messages_es.min.js" />' . "\n", $this->group);
}

... the browser only load the first one: jquery.validate.min.js

4) Importing another JS file:

private function _includeValidation() {
  $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/jquery.validate.min.js" />', $this->group);
  $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/jquery.scrollTo.min.js" />', $this->group);
}

... the browser only load the first one: jquery.validate.min.js

5) Using the jquery version associated to the query Validation 1.15. I disabled jquery import on template_top and then ...

private function _includeValidation() {
  $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/lib/jquery.js" />', $this->group);
  $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/jquery.validate.min.js" />', $this->group);
}

... the browser only load the first one: jquery.js

6) Import each JS file from distinct modules:

  6.A ) Importing jquery.validate.min.js on ht_noscript.php core module...

    function execute() {
      global $oscTemplate;

      $oscTemplate->addBlock('<noscript><div class="no-script"><div class="no-script-inner">' . tep_output_string(MODULE_HEADER_TAGS_NOSCRIPT_TEXT) . '</div></div></noscript>', $this->group);
      $oscTemplate->addBlock('<style>.no-script { border: 1px solid #ddd; border-width: 0 0 1px; background: #ffff90; font: 14px verdana; line-height: 2; text-align: center; color: #2f2f2f; } .no-script .no-script-inner { margin: 0 auto; padding: 5px; } .no-script p { margin: 0; }</style>', $this->group);
      // My hack:
      $oscTemplate->addBlock('<script type="text/javascript" src="amantis/ext/modules/validation/jquery.validate.min.js" />', $this->group);
    }

  6.B ) ... and importing validation language file on my module:

private function _includeValidation() {
    $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/localization/messages_es.min.js" />', $this->group);
}

... ¡and this works!

 

Experiments lead to me to consider that the problem is in my header tag module file, but it's made from another core header tag module, and it's simple...

 

Has anyone encountered anything like this? Any clue, path will be so appreciated: I'm very frustrated, hours debugging :(

 

Thanks! :pray:

Share this post


Link to post
Share on other sites

@@katapofatico

 

You can paste your modules code here so we can look at it but you could also do something like....

$output = '<script type="text/javascript" src="ext/modules/validation/jquery.validate.min.js" />';
$output .= '<script type="text/javascript" src="ext/modules/validation/localization/messages_es.min.js" />';
  
$oscTemplate->addBlock($output, $this->group);

Also make sure inside your function you include

global $oscTemplate;

Matt

Share this post


Link to post
Share on other sites

@@mattjt83 Thanks for help: I didn't check your idea!... but it doesn't works :( My code whith your idea is here:

<?php

class ht_template_top_general {

    var $code = 'ht_template_top_general';
    var $group = 'header_tags';
    var $title;
    var $description;
    var $sort_order;
    var $enabled = false;

    function ht_template_top_general() {
        $this->title = MODULE_HEADER_TAGS_TEMPLATE_TOP_GENERAL_TITLE;
        $this->description = MODULE_HEADER_TAGS_TEMPLATE_TOP_GENERAL_DESCRIPTION;

        if (defined('MODULE_HEADER_TAGS_TEMPLATE_TOP_GENERAL_STATUS')) {
            $this->sort_order = MODULE_HEADER_TAGS_TEMPLATE_TOP_GENERAL_SORT_ORDER;
            $this->enabled = (MODULE_HEADER_TAGS_TEMPLATE_TOP_GENERAL_STATUS == 'True');
        }
    }

    function execute() {
        global $PHP_SELF, $oscTemplate;
        switch ($PHP_SELF) {
            case FILENAME_CHECKOUT_SHIPPING_ADDRESS: {
                    $validationJs = '<script type="text/javascript" src="amantis/ext/modules/validation/jquery.validate.min.js" />';
                    $validationJs .= '<script type="text/javascript" src="amantis/ext/modules/validation/localization/messages_es.min.js" />';
                    $oscTemplate->addBlock($validationJs, $this->group);
                }
        }
    }

    function isEnabled() {
        return $this->enabled;
    }

    function check() {
        return defined('MODULE_HEADER_TAGS_TEMPLATE_TOP_GENERAL_STATUS');
    }

    function install() {
        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Ajustes generales de Amantis sobre la plantilla', 'MODULE_HEADER_TAGS_TEMPLATE_TOP_GENERAL_STATUS', 'True', 'Ajustes generales de Amantis sobre la plantilla', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_HEADER_TAGS_TEMPLATE_TOP_GENERAL_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
    }

    function remove() {
        tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

    function keys() {
        return array('MODULE_HEADER_TAGS_TEMPLATE_TOP_GENERAL_STATUS', 'MODULE_HEADER_TAGS_TEMPLATE_TOP_GENERAL_SORT_ORDER');
    }

}
Edited by katapofatico

Share this post


Link to post
Share on other sites

@@katapofatico

 

Try this

function execute() {
    global $PHP_SELF, $oscTemplate;
    if ( basename( $PHP_SELF ) == 'checkout_shipping_address.php' ) {
        $validationJs = '<script type="text/javascript" src="amantis/ext/modules/validation/jquery.validate.min.js" />';
        $validationJs .= '<script type="text/javascript" src="amantis/ext/modules/validation/localization/messages_es.min.js" />';
            
        $oscTemplate->addBlock($validationJs, $this->group);
    }
}

Matt

Share this post


Link to post
Share on other sites

 

@@katapofatico

 

Try this

function execute() {
    global $PHP_SELF, $oscTemplate;
    if ( basename( $PHP_SELF ) == 'checkout_shipping_address.php' ) {
        $validationJs = '<script type="text/javascript" src="amantis/ext/modules/validation/jquery.validate.min.js" />';
        $validationJs .= '<script type="text/javascript" src="amantis/ext/modules/validation/localization/messages_es.min.js" />';
            
        $oscTemplate->addBlock($validationJs, $this->group);
    }
}

 

This is not the problem: current page is correctly detected, the first import works. Thanks anyway :)

 

 

 

I would also change

var $group = 'header_tags';

to

var $group = 'footer_scripts';

 

Yes, I have been playing with this variable, and the problem continue :(

Share this post


Link to post
Share on other sites

OK, so the "problem continues". You are saying the scripts are not on the page if you view the source or they just are not functioning properly?

 

As far as the code... I think the switch() in this case is a waste.


Matt

Share this post


Link to post
Share on other sites

 

$validationJs = '<script src="amantis/ext/modules/validation/jquery.validate.min.js"></script>';
$validationJs .= '<script src="amantis/ext/modules/validation/localization/messages_es.min.js"></script>';

 

If that still does not work...

 

 

$validationJs = '<script src="amantis/ext/modules/validation/jquery.validate.min.js"></script><script src="amantis/ext/modules/validation/localization/messages_es.min.js"></script>';

This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites

Also be aware that sometimes you code:

 

src="amantis/ext/modules

 

and sometimes:

 

src="ext/modules

 

Make sure that the path is a true reflection of where the file is located.


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites

Click "mark solved".


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×