Guest User

Untitled

a guest
Aug 20th, 2013
56
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.offsets = [];
  15.     this.prefixPath = 'body>section#content>section#';
  16.     this.topOffset = topOffset;
  17.  
  18.     //sets the offsets values
  19.     for (var u = 0; u < this.sectionID.length; u++) {
  20.         this.offsets[u] = $(this.prefixPath+this.sectionID[u]).offset().top;
  21.     }
  22.     return false;
  23. }
  24.  
  25. //change attribute
  26. Section.prototype.changeIDString = function () {
  27.     //gets the currentKey
  28.     for (var i = 0; i < this.offsets.length; i++) {
  29.         if (i + 1 != this.offsets.length) {
  30.             if (this.topOffset >= this.offsets[i] && this.topOffset < this.offsets[i + 1]) {
  31.                 this.currentKey = i;
  32.                 break;
  33.             }
  34.         } else if (this.topOffset >= this.offsets[i]) {
  35.             this.currentKey = i;
  36.             break;
  37.         }
  38.     }
  39.     return false;
  40. }
  41.  
  42. //get current
  43. Section.prototype.getIDString = function () {
  44.     return this.sectionID[this.currentKey];
  45. }
  46.  
  47. //set classes
  48. Section.prototype.setAttributes = function () {
  49.     $('#current').removeAttr('id');
  50.     $('[data-gotoSection="#' + this.getIDString() + '"]').attr('id', 'current');
  51. }
  52.  
  53.  
  54. var Section = new Section();
  55.  
  56.  
  57.  
  58. //footer.php*****************
  59. [...]
  60.     //find the section
  61.     Section.construct(topOffset);
  62.     Section.changeIDString();
  63.     Section.setAttributes();
  64. [...]
Advertisement
Add Comment
Please, Sign In to add comment