Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //javascript.js**************
- //******************************************************************************************************
- //finds section by range in heights
- function Section() {
- this.currentKey;
- this.offsets;
- this.sectionID;
- this.prefixPath;
- $('div#tull').append('Section set!<br>');
- }
- //constructor
- Section.prototype.construct = function (topOffset) {
- this.sectionID = ['heim', 'tilbud', 'galleri', 'feedback'];
- this.offsets = [];
- this.prefixPath = 'body>section#content>section#';
- this.topOffset = topOffset;
- //sets the offsets values
- for (var u = 0; u < this.sectionID.length; u++) {
- this.offsets[u] = $(this.prefixPath+this.sectionID[u]).offset().top;
- }
- //gets the currentKey
- for (var i = 0; i < this.offsets.length; i++) {
- if (i + 1 != this.offsets.length) {
- if (this.topOffset >= this.offsets[i] && this.topOffset < this.offsets[i + 1]) {
- this.currentKey = i;
- break;
- }
- } else if (this.topOffset >= this.offsets[i]) {
- this.currentKey = i;
- break;
- }
- }
- $('div#tull').append('__construct set currentKey to: '+this.currentKey+'<br>');
- return false;
- }
- //change attribute
- Section.prototype.changeIDString = function () {
- this.top = $('body>nav#main').offset().top;
- for (var i = 0; i < this.offsets.length; i++) {
- if (i + 1 == this.offsets.length) {
- this.currentKey = 1;
- break;
- }
- if (this.top >= this.offsets[i] && this.top < this.offsets[i + 1]) {
- this.currentKey = 1;
- break;
- }
- }
- return false;
- }
- //get current
- Section.prototype.getIDString = function () {
- $('div#tull').append('getIDString!<br>');
- return this.sectionID[this.currentKey];
- }
- //set classes
- Section.prototype.setAttributes = function (virgin) {
- $('div#tull').append('Setting attributes..<br>');
- this.virgin = virgin;
- if (!this.virgin) {
- this.changeIDString();
- }
- $('#current').removeAttr('id');
- $('[data-gotoSection="#' + this.getIDString() + '"]').attr('id', 'current');
- $('div#tull').append('Attributes set!<br>');
- }
- var Section = new Section();
- //footer.php*****************
- [...]
- //find the section
- Section.construct(topOffset);
- Section.setAttributes(true);
- //Section.changeIDString(); vil bli brukt i ein repeterende loop etter omskrivning
- [...]
Advertisement
Add Comment
Please, Sign In to add comment