[support] Jquery breaks old code...

Yani akayani at aapt.net.au
Fri Mar 1 17:40:34 UTC 2013


Drupal 7.

Amazing it worked perfectly until the update of jQuery.

It would have been done shortly after the release of Drupal 7 guided by
whatever tutorials I had at the time. 

Yani



-----Original Message-----
From: support-bounces at drupal.org [mailto:support-bounces at drupal.org] On
Behalf Of Metzler, David
Sent: Saturday, 02 March 2013 2:15 AM
To: 'support at drupal.org'
Subject: Re: [support] Jquery breaks old code...

Are you also pushing to drupal 7 or drupal 6.  I noticed that your drupal
behaviors model is using the drupal 6 mechanism.  Is it possible that you
are also porting to drupal 7?   

You also have some document.ready overrides that should be coded as drupal
behaviors. 




-----Original Message-----
From: support-bounces at drupal.org [mailto:support-bounces at drupal.org] On
Behalf Of Yani
Sent: Thursday, February 28, 2013 11:13 PM
To: support at drupal.org
Subject: [support] Jquery breaks old code...

Hi,

I've had to up the version of Jquery I'm using to support a few newer
modules. In the process this has broken code I'd written that has worked for
a year. Assuming I haven't added a syntax error in looking at it... and it
being really basic code... I wonder if someone has hit this in the past and
has any clues...

Here is the code...


Yani



/**
 * Theme behaviours for zeropoint 
 * Author: Yani 
 */

//Global Vars
var displayCode;
var urlCode;
var coment = '-doc';
var docUrl;
var mediaUrl;
var planStatus = new Object;
planStatus.help == 'off';
var protect;
//defined as object to be used a associative array for menu status
var switch1; 

(function($) {
  Drupal.behaviors.zeroPoint = {
    attach : function(context, settings) {
      //Drupal Jquery wrapper
      
alert('Got to scripts.js X3');

      // Plan menu version 2
      // run the default

      $("'#item-20t':not(.z-processed)", context);
      //view plan & media
      {
        $('#item-20t', context).click(function() {
          manageBlocks('media');
        });
        $('#item-20t', context).addClass('z-processed');
      }

      $("'#item-40t':not(.z-processed)", context);
      //view author
      {
        $('#item-40t', context).click(function() {
          manageBlocks('author');
        });
        $('#item-40t', context).addClass('z-processed');
      }

      $("'#item-30t':not(.z-processed)", context);
      //view document in co-ment
      {
        $('#item-30t', context).click(function() {
          manageBlocks('document');
        });
        $('#item-30t', context).addClass('z-processed');
      }

      $("'#item-50t'':not(.z-processed)", context);
      //view survey
      {
        $('#item-50t', context).click(function() {
          manageBlocks('survey');
        });
        $('#item-50t', context).addClass('z-processed');
      }

      $("'#item-60t':not(.z-processed)", context);
      //view help
      {
        $('#item-60t', context).click(function() {
          $('.region-user2', context).css('margin-top', '200px');
          $('.region-user2', context).css('margin-left', '-1025px');
          manageBlocks('help');
        });
        $('#item-60t', context).addClass('z-processed');
      }

      // close button

      $("'.x-close':not(.z-processed)", context); {
        $('.x-close', context).click(function() {
          if(switch1 == 'on') {
            $('.region-user2').hide();
            planStatus.help = 'off';
            switch1 = 'off';
            alert('Turn off: ' +  switch1);
          } else {
            $('.region-user2').hide();
            switch1 = 'off';
            planStatus.help = 'off';
            alert('An error has occurred in selecting the help');
          }
        });
        $('.x-close', context).addClass('z-processed');
      }

      // menu actions for the plan list page

      $("'#item-1t':not(.z-processed)", context); {
        $('#item-1b', context).hide();
        $('#item-1t', context).hover(function() {
          $('#item-1b').show();
        }, function() {
          $('#item-1b').hide();
        });
        $('#item-1t', context).addClass('z-processed');
      }

      $("'#item-3t':not(.z-processed)", context); {
        $('#item-3b', context).hide();
        $('#item-3t', context).hover(function() {
          $('#item-3b').show();
        }, function() {
          $('#item-3b').hide();
        });
        $('#item-3t', context).addClass('z-processed');
      }

      $("'#item-4b':not(.z-processed)", context); {
        $('#item-4b', context).hide();
        $('#item-4t', context).hover(function() {
          $('#item-4b').show();
        }, function() {
          $('#item-4b').hide();
        });
        $('#item-4b', context).addClass('z-processed');
      }

      $("'#item-5t':not(.z-processed)", context);
      //view help
      {
        $('.region-user2', context).hide();
        $('.region-user2', context).css('margin-top', '+250px');
        $('.region-user2', context).css('margin-left', '-5px');

        //add a class to enable positioning in css

        $('#item-5t', context).click(function() {
          if(switch1 == 'off' || !switch1) {
            $('.region-user2').show();
            switch1 = 'on';
            //alert('Turn on: ' + switch1);
          } else if(switch1 == 'on') {
            $('.region-user2').hide();
            switch1 = 'off';
            //alert('Turn off: ' +  switch1);
          } else {
            alert('An error has occurred in selecting the help. Error 201');
          }

        });

        $('#item-5t', context).addClass('z-processed');
      }

      // clean up for header image
      $("'#headimg':not(.z-processed)", context); {
        $('#headimg', context).hide();
        $('#header', context).hide();
        //menu, logo etc need for loading order
        $('#header', context).delay(200).show();
        $('#headimg', context).fadeIn(1000);
        $('#headimg', context).addClass('z-processed');
      }

      // creation of video iframe
      $("'.video-plan':not(.z-processed)", context); {
        var myvideo = $('.field-name-field-video-url .field-item').html();
        if(myvideo != null && $('.video-plan').length == 0) {
          //alert ('myvideo Var : ' + myvideo);
          $('.field-name-body', context).append('<div
class="rtecenter"><iframe class="video-plan" allowfullscreen=""
frameborder="0" height="480" src="http://' + myvideo + '"
width="640"></iframe></div>');
          $('.video-plan', context).addClass('z-processed');
        }
      }



      var checkHide = (window.location.href);

      
      if (!(checkHide == 'http://www.peacepharm.org/plans' || checkHide ==
'http://peacepharm.org/plans')) {
        $('#top_bg').show();
        //alert ('IF What is checkHide '+ checkHide);
      }else{
        $('#top_bg').hide();
        //alert ('ELSE What is checkHide '+ checkHide);
      }
      
      
        


// *** set up for page on load ***

      $('#book-navigation-3').hide();
      //planStatus.survey = 'load';
      
      var hrefz = window.location.href.slice(window.location.href);
      var split1 = hrefz.split('/');
      var split2 = split1[4];
     // alert ('Is media by url split 2 - ' + split2);
      var split3 = split2.charAt(split2.length -1);
     // alert ('Is media by url split 3 - ' + split3);
      
      var  setupaction = $.cookie('tbp-menu');
      //alert ('whats the cookie - ' + setupaction)
      if (setupaction == 'loadDoc'){
        //do nothing just reset the cookie
        //  alert ('does this run and reset the cookie?');        
        $.cookie('tbp-menu', ''); 
        $('#top_bg').hide();
               /* }else if  (setupaction == 'loadSurvey'){
                  docUrl = $.cookie('tbp-document');
                  alert ('Cookie docUrl loaded - ' + docUrl);
                  window.open(docUrl, '_parent'); 
                  manageBlocks('survey');
               */
               
      
      
       }else if (split3 == 'a'){ //} || (!(checkHide ==
'http://www.peacepharm.org/plans' || checkHide ==
//'http://peacepharm.org/plans'))){
        // otherwise set up the media page and the survey
        // alert ('does this run and set manage blocks?');

        manageBlocks('media');  
        
      }


        
      //end wrapper
    }
  }
}(jQuery));
// Note the wrapper is different for Drupal Behaviors
// --------------------------- End set up
----------------------------------------------------------------------------
-----------//




function manageBlocks(menu) {( function($) {
    $(document).ready(function() {
      // jQuery wrapper

      hideBlocks();
      var checkHide = (window.location.href);
      if(checkHide == 'http://www.peacepharm.org/plans' || checkHide ==
'http://peacepharm.org/plans') {
        $('#top_bg').hide();
      /* Supports one of the following menu items as var menu
      * media, author, document, survey, help
      *
      *Check see we are on a plan page and save the key as a cookie
      *grab the bit of the url that comes after /plans/
      * var href = location.href; // get the url
      */
      // Hides to run when ** any button ** is pressed
      
      $('.region-user2').hide();
      $('.region-user3').hide();
      $('#plan-extra-bar').hide();
      //$('#top_bg').hide();
      $('.lock-icon').hide();
      $('#book-navigation-3').hide();
      // use to hide nav when JS is implimented
      $('.field-name-field-video-url').hide();
      $('.field-name-field-author').hide();
      $('.field-name-field-profile').hide();
      $('.field-name-field-url-survey').hide();
      $('.field-name-field-www-site').hide();
      $('.field-name-field-facebook-group').hide();
      $('.field-name-field-facebook-page').hide();
      $('.field-name-field-author-skype').hide();
      }
      
      var href = window.location.href.slice(window.location.href);
      var split = href.split('/plans/');
      // split the string;
      var afterSplit = 'Not a plan';
      if(split[1] != null) {
          afterSplit = split[1];
          var urlCode = $.trim(afterSplit);
          //urlCode = urlTemp.split('#');
          //alert('After the  url split: ' + urlCode);
      }

      if(afterSplit != 'Not a plan') {
        $('#top_bg').hide();
      }

      // If everything went well shows split[1], if not then de default
error message is shown
     
     
      
      //clean white space


      //get the code off the form clean
      displayCode = $.trim($('.field-name-field-code .field-items
.field-item').text());
      //alert('Code on the page: ' + displayCode);

      // setup the survey
      var userId = $.trim($('#this-user').text());
      var userRealname = $.trim($('#this-user-name').text());

      // setup for survey iframe to call back with correct vars (tokens
don't work they need to be processed by PHP not JS )
      var surveyPrep = ('<iframe  class="autoHeight" allowfullscreen=""
frameborder="0" height="900px" width="995" id="i-survey" scrolling="off"' +
'src="http://peacepharm.org/limesurvey/index.php?sid=11647' + '&amp;lang=en'
+ '&amp;11647X14X225=Generated for User No. - ' + userId + ' Real Name - ' +
userRealname + ' for evaluation of plan code ' + displayCode + '.' +
'&amp;11647X14X2161=' + userId + '&amp;11647X14X2162=' + displayCode + '"' +
'style="margin:0% auto 0% auto;">If you see this your browser does not
support iframes</iframe>');

 $('#poke-survey').append(surveyPrep);
 
      if($.cookie('tbp-survey') == 'load') {
        alert('Defined Reload Page -- My ID= ' + userId + ' userRealname= '
+ userRealname); //|| planStatus.survey == 'on'
        $('.region-user3').show();
        $.cookie('tbp-survey', '');
        planStatus.survey = 'on'; 
      }



      //alert(menu);

      // media & author information swap
      if(menu == 'media') {
        $.cookie('tbp-menu', 'media');
        if(urlCode == displayCode) {
          showDocs();
          //alert('urlcode: ' + urlCode);
          //alert('display code: ' + displayCode);
        } else {
          //alert('oh no!');
          var href = window.location.href.slice(window.location.href);
          var splitx = href.split('-');
          // split the string;
          //alert ('split x0: ' + splitx[0]);
          //alert ('split x1: ' + splitx[1]);
          window.open(splitx[0], "_parent");
          //showDocs(); //happens when a plan page is loaded in all cases
        }
      }

      if(menu == 'author') {
        $.cookie('tbp-menu', 'media');
        //alert('urlcode: ' + urlCode);
        //alert('display code: ' + displayCode);
        if(urlCode == displayCode) {
          showProfile();
        } else if(urlCode != displayCode) {
          //alert('oh no!');
          var href = window.location.href.slice(window.location.href);
          var splitx = href.split('-');
          // split the string;
          //alert ('split x0: ' + splitx[0]);
          //alert ('split x1: ' + splitx[1]);

          window.open(splitx[0], "_parent");
        } else {
          alert('An unknown error has occurred. Error 202');
        }
      }

      // co-ment document menu on off
      if(menu == 'document') {
        docUrl = ('../plans/' + displayCode + coment);
        $.cookie('tbp-menu', 'loadDoc');
        $.cookie('tbp-document', docUrl);
        //alert('plan status set as: ' + planStatus.url);
        //alert('docUrl the plan call url: ' + docUrl); //what is called
         var loadUrl = $.cookie('tbp-document');
         $.cookie('protect', '');

          //alert('Warning systen update in process documents are not
availiable for 8 hours'); //loadUrl from cookie -- ' + docUrl);

        window.open(docUrl, "_parent");
        //alert('plan status set as: ' + planStatus.url);
      
      }





      // survey menu on settings
      protect = $.cookie('protect');
      if(menu == 'off-survey') {
          $.cookie('tbp-menu', 'survey');
          //alert('Plan status.survey == ' + planStatus.survey);        
          if(planStatus.survey == 'on') {
            $('.region-user3').hide();
            planStatus.survey = 'off';
          }    

            else if(planStatus.survey == 'off') {
              $('.region-user3').show();
              planStatus.survey = 'on';  
            } 
            
          /* 
           else if (!(protect == 'survey')){ 
              if(planStatus.survey == 'load') { 
                 if(urlCode == displayCode) {
                 $('.region-user3').hide();
                 $('#poke-survey').append(surveyPrep);
                 planStatus.survey = 'off';
                 $.cookie('protect', 'survey');
                 alert ('Protect cookie - ' + $.cookie('protect'));
                 alert('Load from media page - ' + planStatus.survey);
                  }
           
                  else if (!(urlCode == displayCode )) {
                      var href =
window.location.href.slice(window.location.href);
                      var splitx = href.split('-');
                      // split the string;
                            if(splitx[1] != undefined) {
                            // set reload cookie  
                            $.cookie('tbp-menu', 'loadSurvey');
                            var tbpPath = (splitx[0]);
                            $.cookie('tbp-document', tbpPath); 
                            alert ('tbp-document url cookie - ' +
$.cookie('tbp-document'));       
                            alert('Load from doc page - ' +
planStatus.survey);
                            $.cookie('protect', 'survey');
                            alert ('Protect cookie - ' +
$.cookie('protect'));
                            window.location.reload()              
                            }    
                  }
                  
              }
            
            }*/
       }




      // help menu on off
      if(menu == 'help') {
            $.cookie('tbp-document', 'media');
        
            if (planStatus.help == 'on' ){
              $('.region-user2').hide();
              switchval = 'off';
              //alert('Turn off: ' + planStatus.help);
            }
            if(planStatus.help == 'off' || !planStatus.help) {
              $('.region-user3').hide();
              $('.region-user2').show();
              switchval = 'on';
            } 
        //run switches
        planStatus.help = switchval;
        switch1 = switchval;
        planStatus.survey = switchval;
        //alert('Turn on: ' + planStatus.help);
              
        } 
      

      //end wrapper
    });
  }(jQuery));
}

//--------------------------------- Following are functions for plan page
---------------------------------------------//

function hideBlocks() {( function($) {
    $(document).ready(function() {   
      // jQuery wrapper
      //$('.region-user3').hide();
      //$('.region-user2').hide();
      $('#plan-extra-bar').hide();
      $('.lock-icon').hide();
      //end wrapper
    });
  }(jQuery));
}

function showDocs() {( function($) {
    $(document).ready(function() {
      // jQuery wrapper
      $('.region-user3').hide();
      $('.rate-widget').show();
      $('.field-name-body').show();
      $('.field-name-field-video-url').hide();
      $('.field-name-field-author').hide();
      $('.field-name-field-profile').hide();
      $('.field-name-field-url-survey').hide();
      $('.field-name-field-www-site').hide();
      $('.field-name-field-facebook-group').hide();
      $('.field-name-field-facebook-page').hide();
      $('.field-name-field-author-skype').hide();
      $('#comments').show();
      $('#plan-img').css('visibility', 'hidden');
      $('#author-img').css('visibility', 'visible');
      planStatus.survey = 'off';
      planStatus.help = 'off';
      //end wrapper
    });
  }(jQuery));
}

function showProfile() {( function($) {
    $(document).ready(function() {
      // jQuery wrapper
      $('.region-user3').hide();
      $('.rate-widget').hide();
      $('.field-name-body').hide();
      $('.field-name-field-video-url').hide();
      $('.field-name-field-author').show();
      $('.field-name-field-profile').show();
      $('.field-name-field-url-survey').hide();
      $('.field-name-field-www-site').show();
      $('.field-name-field-facebook-group').show();
      $('.field-name-field-facebook-page').show();
      $('.field-name-field-author-skype').show();
      $('#comments').hide();
      $('#author-img').css('visibility', 'hidden');
      $('#plan-img').css('visibility', 'visible');
      planStatus.survey = 'off';
      planStatus.help = 'off';
      //end wrapper
    });
  }(jQuery));
}



-- 
[ Drupal support list | http://lists.drupal.org/ ]
-- 
[ Drupal support list | http://lists.drupal.org/ ]



More information about the support mailing list