Guest User

Untitled

a guest
Aug 20th, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //javascript.js**************
  2. function Section() {
  3.     this.currentKey;
  4.     this.offsets = [];
  5.     this.sectionID;
  6.     this.prefixPath;
  7.     this.topOffset;
  8. }
  9.  
  10. //constructor
  11. Section.prototype.construct = function (topOffset) {
  12.  
  13.     this.sectionID = ['heim', 'tilbud', 'galleri', 'feedback'];
  14.     this.prefixPath = 'body>section#content>section#';
  15.     this.topOffset = topOffset;
  16.  
  17.     //sets the offsets values
  18.     for (var u = 0; u < this.sectionID.length; u++) {
  19.         this.offsets[u] = $(this.prefixPath+this.sectionID[u]).offset().top;
  20.     }
  21.     return false;
  22. }
  23.  
  24. //change attribute
  25. Section.prototype.changeIDString = function () {
  26.     //gets the currentKey
  27.     for (var i = 0; i < this.offsets.length; i++) {
  28.         if (i + 1 != this.offsets.length) {
  29.             if (this.topOffset >= this.offsets[i] && this.topOffset < this.offsets[i + 1]) {
  30.                 this.currentKey = i;
  31.                 break;
  32.             }
  33.         } else if (this.topOffset >= this.offsets[i]) {
  34.             this.currentKey = i;
  35.             break;
  36.         }
  37.     }
  38.     return false;
  39. }
  40.  
  41. //get current
  42. Section.prototype.getIDString = function () {
  43.     return this.sectionID[this.currentKey];
  44. }
  45.  
  46. //set classes
  47. Section.prototype.setAttributes = function () {
  48.     $('#current').removeAttr('id');
  49.     $('[data-gotoSection="#' + this.getIDString() + '"]').attr('id', 'current');
  50. }
  51.  
  52.  
  53. var Section = new Section();
  54.  
  55.  
  56.  
  57. //footer.php*****************
  58. [...]
  59.     //find the section
  60.     Section.construct(topOffset);
  61.     Section.changeIDString();
  62.     Section.setAttributes();
  63. [...]
Advertisement
Add Comment
Please, Sign In to add comment