Jump to:

5542 Posts in 1739 Topics by 1225 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Random JavaScript at the bottom of the page code

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1739 Views
  • Alex S
    Avatar
    Community Member
    30 Posts

    Random JavaScript at the bottom of the page code Link to this post

    Hey,

    This is a follow-on I guess from this thread: http://www.silverstripe.org/archive/show/1406#post1406 . Basically, there's a lump of JavaScript appearing towards the end of my page code which is preventing anything like light-whatever or JQuery from functioning. It's as follows:

    <script type="text/javascript" src="http://mysite/jsparty/prototype.js?m=1226464322"></script><script type="text/javascript" src="http://mysite/jsparty/behaviour.js?m=1228253400"></script><script type="text/javascript" src="http://mysite/jsparty/prototype_improvements.js?m=1195165918"></script><script type="text/javascript" src="http://mysite/sapphire/javascript/i18n.js?m=1236311236"></script><script type="text/javascript" src="http://mysite/sapphire/javascript/lang/en_US.js?m=1229303948"></script><script type="text/javascript" src="http://mysite/sapphire/javascript/Validator.js?m=1236311236"></script><script type="text/javascript">//<![CDATA[
    Behaviour.register({
       '#SearchForm_SearchForm': {
          validate : function(fromAnOnBlur) {
             initialiseForm(this, fromAnOnBlur);
             
             
             var error = hasHadFormError();
             if(!error && fromAnOnBlur) clearErrorMessage(fromAnOnBlur);
             
             return !error;
          },
          onsubmit : function() {
             if(typeof this.bypassValidation == 'undefined' || !this.bypassValidation) return this.validate();
          }
       },
       '#SearchForm_SearchForm input' : {
          initialise: function() {
             if(!this.old_onblur) this.old_onblur = function() { return true; }
             if(!this.old_onfocus) this.old_onfocus = function() { return true; }
          },
          onblur : function() {
             if(this.old_onblur()) {
                // Don't perform instant validation for CalendarDateField fields; it creates usability wierdness.
                if(this.parentNode.className.indexOf('calendardate') == -1 || this.value) {
                   return $('SearchForm_SearchForm').validate(this);
                } else {
                   return true;
                }
             }
          }
       },
       '#SearchForm_SearchForm select' : {
          initialise: function() {
             if(!this.old_onblur) this.old_onblur = function() { return true; }
          },
          onblur : function() {
             if(this.old_onblur()) {
                return $('SearchForm_SearchForm').validate(this);
             }
          }
       }
    });

    //]]></script>

    I figure it's probably quite necessary for some pages, like pages with comments on, but it appears for any and every page, regardless of whether the comments system is switched on or not. It even pops up when the "$PageComments" is removed from the template. Is there any way to make this a little more targeted, so it only gets included where it's needed?

    Any ideas would be greatly appreciated.

    Cheers,

    Alex

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Random JavaScript at the bottom of the page code Link to this post

    Behaviour.register({
    '#SearchForm_SearchForm': {
    validate : function(fromAnOnBlur) {

    Looks like its the validation JS for the built in search form if you are using that?. You should be able to run jquery fine with it as long as you run it as listed on http://doc.silverstripe.com/doku.php?id=jquery#examples.

    You can completely disable it by adding this to your _config file - Validator::set_javascript_validation_handler('none');

  • Alex S
    Avatar
    Community Member
    30 Posts

    Re: Random JavaScript at the bottom of the page code Link to this post

    Hey,

    Thanks for looking, I tried your suggestion of adding "Validator::set_javascript_validation_handler('none');" to my _config file and that's removed everything that was causing an issue. I'll have a read through the docs about the search validation and see what side effects this will have.

    With the JQuery, I was implementing a modal window as described here: http://www.queness.com/post/77/simple-jquery-modal-window-tutorial which still seemed to require the link to prototype.js to be removed from that bottom set of links for it to work. It also required the "<base..." tag to be removed from the header too though so I figured that a light window solution would be best in the end.

    Cheers for the advice,

    Alex

    1739 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.