$(function() {
    var $document         = $(document),
        selector          = '[data-rangeslider]',
        $inputRange       = $(selector);

//Handles value bubbles over rangesliders

    var valueBubble = '<output class="rangeslider__value-bubble" />',
    tempPosition, position;

    $inputRange.rangeslider({
      polyfill: false,
      onInit: function() {
          this.$range.append($(valueBubble));
          this.update();
      },
      onSlide: function(pos, value) {



        var $valueBubble = $('.rangeslider__value-bubble', this.$range);
        tempPosition = pos + this.grabX;
        position = (tempPosition <= this.handleWidth) ? this.handleWidth : (tempPosition >= this.maxHandleX) ? this.maxHandleX : tempPosition;
        
        if ($valueBubble.length) {
          $valueBubble[0].style.left = Math.ceil(position) + 'px';
          $valueBubble[0].innerHTML = value+"%";
        }


      },

//Handles slider value changes based on slider positions
        onSlideEnd: function(position, value ) {
        
          sliding_input = this.$range.parent().attr('id');
          control_value = $(this)[0].value;

          function controlSliders(a,b){

            //theRanges = ['#range_1 [data-rangeslider]','#range_2 [data-rangeslider]','#range_3 [data-rangeslider]','#range_4 [data-rangeslider]'];
            // ^ Simplified below!
            var theRanges = []
            $('.ranges').each(function(){
              theRanges.push('#' + $(this).attr('id') + ' [data-rangeslider]'); 
            });
            //theRangesValues = [$(range_1 [data-rangeslider]).value, $(range_2 [data-rangeslider]).value, $(range_3 [data-rangeslider]).value, $(range_4 [data-rangeslider]).value];  

            switch(a) {

                case 'range_1':
                    theRanges.splice(0, 1);
                    break;
                case 'range_2': 
                    theRanges.splice(1, 1);
                    break;
                case 'range_3':
                    theRanges.splice(2, 1);
                    break;
                case 'range_4':
                    theRanges.splice(3, 1);
                    break;    
            }          
           
              //console.log(theRangesValues);
              target_inputs = $(theRanges[0] + ', ' + theRanges[1] + ', ' + theRanges[2] + ', ' + theRanges[3]);
              
              target_values = (100 - b)/3;
              
              //Change the value of the other sliders when the user adjusts a slider
              $(target_inputs).val(target_values).change();

               console.log('sliding input' + ' ' + a);
               console.log('control value' + ' ' + b); 
               console.log('target inputs' + ' ' + target_inputs); 
               console.log(theRanges);

          }

          controlSliders(sliding_input,control_value);

       }
    });


});
@@ -1048,23 +1048,23 @@
         
-sliding
+control
 _input =
@@ -1397,16 +1397,17 @@
 ges = %5B%5D
+;
 %0A       
@@ -1552,181 +1552,8 @@
     
-  //theRangesValues = %5B$(range_1 %5Bdata-rangeslider%5D).value, $(range_2 %5Bdata-rangeslider%5D).value, $(range_3 %5Bdata-rangeslider%5D).value, $(range_4 %5Bdata-rangeslider%5D).value%5D;  
 %0A%0A  
@@ -2084,24 +2084,26 @@
             
+//
 target_input
@@ -2196,32 +2196,393 @@
 %0A              %0A
+              //alert(theRanges);%0A%0A              var theRangeValues = %5B%5D;%0A              var q = theRanges.length;%0A           %0A              //Set other slider values on single slider move%0A              for (var i = 0; i %3C q; i++) %7B%0A                %0A                //console.log($(theRanges%5Bi%5D).val());%0A                current_values = $(theRanges%5Bi%5D).val();%0A  
               ta
@@ -2614,33 +2614,361 @@
 ;%0A              
+  
 %0A
+                //Target Inputs%0A                target_inputs = $(theRanges%5Bi%5D);%0A%0A                 console.log('current values = ' + i + ' ' + current_values);%0A                 console.log('target inputs = ' + i + ' ' + target_inputs.attr('id'));%0A                 console.log('target values = ' + i + ' ' + target_values);%0A%0A  
               //
@@ -3050,16 +3050,18 @@
         
+  
 $(target
@@ -3095,24 +3095,88 @@
 .change();%0A%0A
+              %7D%0A%0A%0A              %0A              %0A              %0A%0A
             
@@ -3191,23 +3191,23 @@
 le.log('
-sliding
+control
  input' 
@@ -3259,16 +3259,21 @@
 ol value
+!! = 
 ' + ' ' 
@@ -3285,32 +3285,35 @@
  %0A              
+ //
  console.log('ta
@@ -3313,48 +3313,24 @@
 log(
-'target inputs' + ' ' + target_input
+theRangeValue
 s);
- 
 %0A   
@@ -3332,32 +3332,35 @@
 ;%0A              
+ //
  console.log(the
@@ -3360,32 +3360,77 @@
 log(
-theRanges);%0A%0A          %7D
+$('#range_1 %5Bdata-rangeslider%5D').val());%0A%0A          %7D%0A%0A%0A          %0A%0A%0A
 %0A%0A  
@@ -3456,15 +3456,15 @@
 ers(
-sliding
+control
 _inp

Improve JS