CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • Adding some javascript on every "page" from within an extension
Pages: [1]

Author Topic: Adding some javascript on every "page" from within an extension  (Read 535 times)

demeritcowboy

  • Ask me questions
  • ****
  • Posts: 570
  • Karma: 42
  • CiviCRM version: Always the latest!
  • CMS version: Drupal 6 mostly, still evaluating 7.
  • MySQL version: Mix of 5.0 / 5.1 / 5.5
  • PHP version: 5.3, usually on Windows
Adding some javascript on every "page" from within an extension
February 24, 2014, 08:43:59 am
I'm probably missing something simple, but how do I add some javascript on every "page" from within an extension. By page I mean the whole page that the browser sees. I know how to do this in a drupal module, but would like to do it from within an extension so that it's not drupal-only. Hook_pageRun and buildForm don't run on every "page". And ideally I don't want it to run multiple times once for each ajax call within a "page", but I can probably work around that.

Where do I put the call to CRM_Core_Resources::singleton()->addScriptFile('com.example.foo', 'bar.js') ?

Thanks

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Adding some javascript on every "page" from within an extension
February 24, 2014, 08:47:37 am
Maybe this one runs on every page?
http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterContent

To your other point, please note that CRM_Core_Resources::addFoo does not do anything when in an ajax callback context.
Try asking your question on the new CiviCRM help site.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Adding some javascript on every "page" from within an extension
February 24, 2014, 08:49:34 am
Damn, coleman is too fast ;)

yes, alterContent works both on page and form
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

demeritcowboy

  • Ask me questions
  • ****
  • Posts: 570
  • Karma: 42
  • CiviCRM version: Always the latest!
  • CMS version: Drupal 6 mostly, still evaluating 7.
  • MySQL version: Mix of 5.0 / 5.1 / 5.5
  • PHP version: 5.3, usually on Windows
Re: Adding some javascript on every "page" from within an extension
February 24, 2014, 09:24:13 am
Ok, thanks for the pointers.

demeritcowboy

  • Ask me questions
  • ****
  • Posts: 570
  • Karma: 42
  • CiviCRM version: Always the latest!
  • CMS version: Drupal 6 mostly, still evaluating 7.
  • MySQL version: Mix of 5.0 / 5.1 / 5.5
  • PHP version: 5.3, usually on Windows
Re: Adding some javascript on every "page" from within an extension
February 24, 2014, 10:00:43 am
That works, and I can just append to the $content without having to search for something to replace since the content is actually just the "inner" part of the page.

Also I can see the hook is being called for ajax (e.g. buildCustomData) but it seems to then strip the javascript I've added (in this hook it's just straight html text, not using addScriptFile). So it works out.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • Adding some javascript on every "page" from within an extension

This forum was archived on 2017-11-26.