1var weightNumerator = { 2 $container: undefined, 3 $cols: undefined, 4 5 itemHeight: undefined, 6 longTouch: undefined, 7 8 touchstartY: undefined, 9 touchmoveY: undefined, 10 moveY: undefined, 11 12 init: function() { 13 var self = this; 14 15 var $wn = $('#weight-numerator'); 16 self.itemHeight = $wn.find('.number').first().height(); 17 18 self.$container = $wn.find('#inner-container'); 19 20 self.$cols = $wn.find('.number-col'); 21 22 self.onWindowResize(); 23 24 this.setWeight(parseInt($('#mc-weight').val())); 25 26 27 // 28 self.$cols.on("touchstart", function(e) { 29 self.touchStart(e, $(this)); 30 }); 31 32 document.addEventListener('touchmove', function(e) { 33 if ($(e.target).closest('#inner-container').length) { 34 self.touchMove(e, $(e.target).closest('.number-col')); 35 } 36 }, {passive: false}); 37 38 self.$cols.on("touchend", function(e) { 39 self.touchEnd(e, $(this)); 40 }); 41 42 $(window).resize(function() { 43 self.onWindowResize(); 44 }); 45 }, 46 47 touchStart: function(event, $col) { 48 var self = this; 49 50 // Test for flick. 51 self.longTouch = false; 52 setTimeout(function() { 53 self.longTouch = true; 54 }, 250); 55 56 // Get the original touch position. 57 this.touchstartY = event.originalEvent.touches[0].pageY; 58 59 // The movement gets all janky if there's a transition on the elements. 60 self.$container.find('.animate').removeClass('animate'); 61 }, 62 63 touchMove: function(event, $col) { 64 event.preventDefault(); 65 // Continuously return touch position. 66 this.touchmoveY = event.touches[0].pageY; 67 // Calculate column total scroll 68 this.moveY = (parseInt($col.data('index')) || 0) * this.itemHeight + (this.touchstartY - this.touchmoveY); 69 70 var availableScroll = this._getColItemsReserve($col) * this.itemHeight; 71 72 if (this.moveY < availableScroll && this.moveY > 0) { 73 $col.css('transform','translate3d(0, -' + this.moveY + 'px, 0)'); 74 } 75 }, 76 77 touchEnd: function(event, $col) { 78 var oldIndex = parseInt($col.data('index')); 79 80 // Calculate the distance swiped. 81 var absMove = Math.abs(oldIndex * this.itemHeight - this.moveY); 82 // 83 var index = oldIndex; 84 if (absMove > this.itemHeight / 2 || this.longTouch === false) { 85 /*// scroll by one number functionally 86 if (this.moveY > index * this.itemHeight && index < this._getColItemsReserve($col)) { 87 index++; 88 } 89 else if (this.moveY < index * this.itemHeight && index > 0) { 90 index--; 91 }*/ 92 93 // multiple numbers scroll 94 index = Math.round(this.moveY / this.itemHeight); 95 if (index < 0) { 96 index = 0; 97 } 98 else if (index > this._getColItemsReserve($col)) { 99 index = this._getColItemsReserve($col); 100 } 101 } 102 103 this.moveToIndex(index, $col); 104 105 $col.data('index', index); 106 // get value by index 107 var value = this._getColItemsReserve($col) - index; 108 $col.data('value', value); 109 110 // trigger event weight changed 111 var wcEvent = jQuery.Event('weight-changed'); 112 wcEvent.weight = this.getWeight(); 113 $('body').trigger(wcEvent); 114 }, 115 116 moveToIndex: function(index, $col) { 117 $col.addClass('animate').css('transform', 'translate3d(0, -' + index * this.itemHeight + 'px, 0)'); 118 }, 119 120 setWeight: function(weight) { 121 var self = this; 122 var currWeight = weight; 123 self.$cols.each(function() { 124 var ratio = parseInt($(this).data('ratio')); 125 var numValue = Math.floor(currWeight / ratio); 126 $(this).data('value', numValue); 127 128 // get index by value 129 var index = self._getColItemsReserve($(this)) - numValue; 130 self.moveToIndex(index, $(this)); 131 $(this).data('index', index); 132 133 currWeight -= numValue * ratio; 134 }); 135 136 // trigger event weight changed 137 var wcEvent = jQuery.Event('weight-changed'); 138 wcEvent.weight = this.getWeight(); 139 $('body').trigger(wcEvent); 140 }, 141 142 143 getWeight: function() { 144 var weight = 0; 145 this.$cols.each(function() { 146 weight += (parseInt($(this).data('value'))) * parseInt($(this).data('ratio')); 147 }); 148 149 return weight; 150 }, 151 152 setupDOM: function() { 153 this.itemHeight = this.$container.find('.number').first().height(); 154 }, 155 156 onWindowResize: function() { 157 this.setupDOM(); 158 }, 159 160 _getColItemsReserve: function($col) { 161 return $col.find('.number').length - 1; 162 } 163};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.