Advertisement:

Author Topic: [SOLVED] How remove "type="text/javascript"" from osc_enqueue_script function  (Read 320 times)

AdrianOlmedo

  • Newbie
  • *
  • Posts: 42
  • Working with Osclass 3.7.3
I have this couple of lines of code in head.php:

Code: [Select]
osc_register_script('jquery-ui-min', osc_current_web_theme_js_url('jquery-ui.min.js'), array('jquery'));
osc_enqueue_script('jquery-ui-min');

that generate the following:

Code: [Select]
<script type="text/javascript" src="http://localhost/osclass/oc-content/themes/template/js/jquery.min.js"></script>
But the html5 validator marks error, saying that type="text/javascript" is obsolete and should not be placed

How remove type="text/javascript" ?
« Last Edit: August 10, 2018, 01:38:44 am by AdrianOlmedo »

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 1979
  • osclass.work

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 1979
  • osclass.work
Re: How remove "type="text/javascript"" from osc_enqueue_script function
« Reply #2 on: August 03, 2018, 03:23:10 am »
Btw. you shouldn't worry too much about W3C compliance, for several reasons. Those are just warnings, not errors. And, who knows, why you should remove compatibility with some older browsers/systems this way? It doesn't do any harm.

Regards

AdrianOlmedo

  • Newbie
  • *
  • Posts: 42
  • Working with Osclass 3.7.3
Re: How remove "type="text/javascript"" from osc_enqueue_script function
« Reply #3 on: August 03, 2018, 05:37:57 am »
Hi, edit Scripts.php near the end:

https://github.com/osclass/Osclass/blob/master/oc-includes/osclass/classes/Scripts.php#L89

Regards

That is a direct solution, I asked if there was a way to do it from the theme (functions.php)

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 1979
  • osclass.work
Re: How remove "type="text/javascript"" from osc_enqueue_script function
« Reply #4 on: August 03, 2018, 02:45:25 pm »
Only if you avoid using it (not recommended).

Regards

patrickFromCroatia

  • Sr. Member
  • ****
  • Posts: 473
Re: How remove "type="text/javascript"" from osc_enqueue_script function
« Reply #5 on: August 03, 2018, 02:53:20 pm »
Hello,

I've seen code similar to this in Shopclass theme's functions.php. Might be a solution to your problem.

Code: [Select]
<?php
osc_remove_hook
'header' 'osc_load_scripts' );

function 
cust_load_scripts() {
    foreach ( 
Scripts::newInstance()->getScripts() as $script ) {
        echo 
'<script src="' osc_apply_filter'theme_url' $script ) . '"></script>' PHP_EOL;
    }
}
osc_add_hook'header' 'cust_load_scripts' );
?>


Regards.

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 1979
  • osclass.work
Re: How remove "type="text/javascript"" from osc_enqueue_script function
« Reply #6 on: August 04, 2018, 02:29:16 am »
You can invent your own functions or extend core for sure, but in this case it's simpler and much faster to modify a single core file, instead of every other theme or plugin. It's your choice, really. But, as I mentioned earlier, the goal is not very important. W3C and HTML5 is a "work in progress", which means unless you continuously check for compliance, at one point you might become incompatible again. Better invest your time & energy into more important issues, than simple html scheme rules IMHO.

Regards

AdrianOlmedo

  • Newbie
  • *
  • Posts: 42
  • Working with Osclass 3.7.3
Re: How remove "type="text/javascript"" from osc_enqueue_script function
« Reply #7 on: August 10, 2018, 01:41:09 am »
Hello,

I've seen code similar to this in Shopclass theme's functions.php. Might be a solution to your problem.

Code: [Select]
<?php
osc_remove_hook
'header' 'osc_load_scripts' );

function 
cust_load_scripts() {
    foreach ( 
Scripts::newInstance()->getScripts() as $script ) {
        echo 
'<script src="' osc_apply_filter'theme_url' $script ) . '"></script>' PHP_EOL;
    }
}
osc_add_hook'header' 'cust_load_scripts' );
?>


Regards.

Perfect, it works. Thank you all