Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Detecting if the head tag has a particular script

Is there a way to check if the head tag has a script. for eg
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript">

Comments

  • Options
    edited April 2007
    the $Head object has an array called $Scripts . With a proper method, you could go through it and check. I would suggest using the delegate "PreRender" possibly:
    function headcontrol_checkforscript(&$Head,$myScript) { $found = false; foreach ($Head->Scripts as $value) { if ($value == $myScript) $found = true; } if (!$found) { $Head->AddScript($myScript); } $Context->AddToDelegate('Head', 'PreRender', 'headcontrol_checkforscript');
  • Options
    edited April 2007
    thanks
  • Options
    nps. did it work?
  • Options
    I'm looking for a way to get ride of the JQuery dependency requirement. by having all jquery based extensions to include jquery on its own. If jquery is already included then its skipped else added to the head.

    the AddScript should disallow duplicate scripts. If the script is already in the Scripts array, it should skip an attempt to put duplicate ones
  • Options
    edited April 2007
    yea I agree about that. maybe you can ask Mark for an improvement on the next version of Vanilla?

    of course u can always hack/modify the Head class yourself by adding this to the first line of the AddScript function: if (in_array($ScriptLocation,$this->Scripts)) return;edited to ScriptLocation
This discussion has been closed.