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) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Unable to extend core common.js
Pages: [1]

Author Topic: Unable to extend core common.js  (Read 428 times)

VitorFF

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 1
  • CiviCRM version: 4.4.11
  • CMS version: Drupal 7.27
  • MySQL version: 5.5
  • PHP version: 5.4
Unable to extend core common.js
September 11, 2014, 08:17:58 am
Hello all!

I'm trying to extend the common.js  so that CRM.alerts arriving from a specific page are not created.
Obviously I don't want to change core code but rather create a custom version of this file.

But so far I'm not being able to make this new custom.js file override the core one, can any one help me with that?

Thank you!

Vitor
Why don't you take a look at this? (You will not regret it!)

Capitalisation Corrector : https://civicrm.org/extensions/capitalisation-corrector

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Unable to extend core common.js
September 11, 2014, 10:42:07 am
If you think about the way javascript works, it's better to override just the function not the entire file.

What messages are you wanting to suppress?
Try asking your question on the new CiviCRM help site.

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: Unable to extend core common.js
September 11, 2014, 11:43:29 am
Coleman, are you suggesting something like:

Code: [Select]
// myext.php
...
CRM_Core_Resources::singleton()->addScript('myext', 'my-alert.js', 100);
...

// my-alert.js
(function(){
    var oldAlert = CRM.alert;
    CRM.alert = function(...) {
        if (inSpecialCase()) {
            doSomethingSpecial();
        } else {
            oldAlert.apply(this, arguments);
        }
    };
})();

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Unable to extend core common.js
September 11, 2014, 11:53:12 am
Yes exactly, but I didn't want to jump the gun and provide that example if it wasn't appropriate to the situation :P

I'm not sure why VitorFF wants to suppress messages on a certain page but I could guess that it might be to get rid of annoying "Saved" messages. If that's the case, just upgrade to 4.5 and we've already fixed it. Or it might be to prevent the duplicate contact alert, which can be turned off in preferences. Or it might be something else that has a non-code solution :)
Try asking your question on the new CiviCRM help site.

VitorFF

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 1
  • CiviCRM version: 4.4.11
  • CMS version: Drupal 7.27
  • MySQL version: 5.5
  • PHP version: 5.4
Re: Unable to extend core common.js
September 12, 2014, 01:36:03 am
Thanks for your help!

I'm indeed trying to suppress the "Saved" message on a couple of pages.

I'm going to try totten's suggestion and then get back on how it worked.

Thanks again!
Why don't you take a look at this? (You will not regret it!)

Capitalisation Corrector : https://civicrm.org/extensions/capitalisation-corrector

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Unable to extend core common.js
September 12, 2014, 05:24:32 am
@VitorFF since that is already fixed in 4.5 (no more annoying "Saved" messages) and 4.5 will be released next week, wouldn't it be a better use of your time to just upgrade?
Try asking your question on the new CiviCRM help site.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Unable to extend core common.js

This forum was archived on 2017-11-26.