You are viewing the PKP Support Forum | PKP Home Wiki

plugin insert javascript in header

OJS development discussion, enhancement requests, third-party patches and plug-ins.

Moderators: jmacgreg, btbell, michael, bdgregg, barbarah, asmecher

Forum rules
The Public Knowledge Project Support Forum is moving to http://forum.pkp.sfu.ca

This forum will be maintained permanently as an archived historical resource, but all new questions should be added to the new forum. Questions will no longer be monitored on this old forum after March 30, 2015.

plugin insert javascript in header

Postby MarieNyst » Thu Dec 13, 2012 10:06 am

Hi !

I would like to insert javascript in header. For this, I've my register function here :

Code: Select all
function register($category, $path) {
        if (parent::register($category, $path)) {
              if ($this->getEnabled()) {
                // Insert header on every header (callback function checks if it addition is really need)
                HookRegistry::register('TemplateManager::display',array(&$this, 'callback'));
            return true;
        return false;

and my callback function here :

Code: Select all
function callback($hookName, $args) {
      //First argument is a TemplateManager object.
        $templateMgr =& $args[0];

        //Getting some context.
        $journal = &Request::getJournal();
        $journalId = $journal->getJournalId();
        $page = Request::getRequestedPage();
        $op = Request::getRequestedOp();
        $currentJournal = $templateMgr->get_template_vars('currentJournal');

        //Add additionalHeader just in a few pages of the current Journal:
        if (!empty($currentJournal))
         //Extending template's head:
            $additionalHeadData = $templateMgr->get_template_vars('additionalHeadData');
            $additionalHeadData .= "\n\n        <!-- Keywords Headers -->\n";
            $additionalHeadData .= $templateMgr->fetch('./plugins/generic/keywords/generatedFiles/keywordsChoiceScript.js.tpl');
            $additionalHeadData .= "        <!-- Keywords Headers -->";

            $templateMgr->assign('additionalHeadData', $additionalHeadData);
        return false;

and my script here :

Code: Select all
{literal}<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
 a {color:#333; text-decoration:none}
 a:hover {color:#ccc; text-decoration:none}

   <!-- style doesn't mater -->
   function keywordsSetOptions(chosen) {
<!-- script that I've already tested-->
$(document).ready(function() {
    <!-- some other things I've tested -->

Nothing happens, my headers are still the same... Did I make it wrong ?
Posts: 24
Joined: Thu Nov 29, 2012 9:35 pm

Re: plugin insert javascript in header

Postby asmecher » Thu Dec 13, 2012 11:55 am

Hi MarieNyst,

You probably need to register the plugin in the database; have a look at http://pkp.sfu.ca/support/forum/viewtopic.php?f=9&t=7909#p30755 or http://pkp.sfu.ca/support/forum/viewtopic.php?f=9&t=9067#p35235 for some further discussion. There is also some howto documentation at http://pkp.sfu.ca/wiki/index.php/Writing_a_Block_Plugin.

Alec Smecher
Public Knowledge Project Team
Posts: 10015
Joined: Wed Aug 10, 2005 12:56 pm

Re: plugin insert javascript in header

Postby MarieNyst » Fri Dec 14, 2012 8:44 am

I made the upgrade and it works.

thank you
Posts: 24
Joined: Thu Nov 29, 2012 9:35 pm

Return to OJS Development

Who is online

Users browsing this forum: No registered users and 1 guest