SHOW:
|
|
- or go back to the newest paste.
| 1 | //javascript.js************** | |
| 2 | //****************************************************************************************************** | |
| 3 | //finds section by range in heights | |
| 4 | ||
| 5 | function Section() {
| |
| 6 | this.currentKey; | |
| 7 | this.offsets; | |
| 8 | this.sectionID; | |
| 9 | this.prefixPath; | |
| 10 | - | $.when(Section.construct(topOffset)).done(function(){
|
| 10 | + | $('div#tull').append('Section set!<br>');
|
| 11 | - | $.when(Section.changeIDString()).done(function(){
|
| 11 | + | } |
| 12 | - | Section.setAttributes(); |
| 12 | + | |
| 13 | - | }); |
| 13 | + | //constructor |
| 14 | - | }); |
| 14 | + | Section.prototype.construct = function (topOffset) {
|
| 15 | ||
| 16 | this.sectionID = ['heim', 'tilbud', 'galleri', 'feedback']; | |
| 17 | this.offsets = []; | |
| 18 | this.prefixPath = 'body>section#content>section#'; | |
| 19 | this.topOffset = topOffset; | |
| 20 | ||
| 21 | //sets the offsets values | |
| 22 | for (var u = 0; u < this.sectionID.length; u++) {
| |
| 23 | this.offsets[u] = $(this.prefixPath+this.sectionID[u]).offset().top; | |
| 24 | } | |
| 25 | ||
| 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 | ||
| 39 | $('div#tull').append('__construct set currentKey to: '+this.currentKey+'<br>');
| |
| 40 | ||
| 41 | return false; | |
| 42 | } | |
| 43 | ||
| 44 | //change attribute | |
| 45 | Section.prototype.changeIDString = function () {
| |
| 46 | this.top = $('body>nav#main').offset().top;
| |
| 47 | ||
| 48 | for (var i = 0; i < this.offsets.length; i++) {
| |
| 49 | if (i + 1 == this.offsets.length) {
| |
| 50 | this.currentKey = 1; | |
| 51 | break; | |
| 52 | } | |
| 53 | if (this.top >= this.offsets[i] && this.top < this.offsets[i + 1]) {
| |
| 54 | this.currentKey = 1; | |
| 55 | break; | |
| 56 | } | |
| 57 | } | |
| 58 | ||
| 59 | return false; | |
| 60 | } | |
| 61 | ||
| 62 | //get current | |
| 63 | Section.prototype.getIDString = function () {
| |
| 64 | $('div#tull').append('getIDString!<br>');
| |
| 65 | return this.sectionID[this.currentKey]; | |
| 66 | } | |
| 67 | ||
| 68 | //set classes | |
| 69 | Section.prototype.setAttributes = function (virgin) {
| |
| 70 | $('div#tull').append('Setting attributes..<br>');
| |
| 71 | this.virgin = virgin; | |
| 72 | if (!this.virgin) {
| |
| 73 | this.changeIDString(); | |
| 74 | } | |
| 75 | $('#current').removeAttr('id');
| |
| 76 | $('[data-gotoSection="#' + this.getIDString() + '"]').attr('id', 'current');
| |
| 77 | $('div#tull').append('Attributes set!<br>');
| |
| 78 | } | |
| 79 | ||
| 80 | ||
| 81 | var Section = new Section(); | |
| 82 | //footer.php***************** | |
| 83 | [...] | |
| 84 | //find the section | |
| 85 | Section.construct(topOffset); | |
| 86 | Section.setAttributes(true); | |
| 87 | ||
| 88 | //Section.changeIDString(); vil bli brukt i ein repeterende loop etter omskrivning | |
| 89 | [...] |