mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-16 12:55:19 +03:00
Work in progress aux configuration ranges.
This commit is contained in:
parent
875a81e11d
commit
e892cbdbad
8 changed files with 657 additions and 134 deletions
311
js/libraries/jquery.liblink.js
Normal file
311
js/libraries/jquery.liblink.js
Normal file
|
@ -0,0 +1,311 @@
|
|||
/*jslint browser: true */
|
||||
/*jslint white: true */
|
||||
|
||||
(function( $ ){
|
||||
|
||||
'use strict';
|
||||
|
||||
// Helpers
|
||||
|
||||
// Test in an object is an instance of jQuery or Zepto.
|
||||
function isInstance ( a ) {
|
||||
return a instanceof $ || ( $.zepto && $.zepto.isZ(a) );
|
||||
}
|
||||
|
||||
|
||||
// Link types
|
||||
|
||||
function fromPrefix ( target, method ) {
|
||||
|
||||
// If target is a string, a new hidden input will be created.
|
||||
if ( typeof target === 'string' && target.indexOf('-inline-') === 0 ) {
|
||||
|
||||
// By default, use the 'html' method.
|
||||
this.method = method || 'html';
|
||||
|
||||
// Use jQuery to create the element
|
||||
this.target = this.el = $( target.replace('-inline-', '') || '<div/>' );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function fromString ( target ) {
|
||||
|
||||
// If the string doesn't begin with '-', which is reserved, add a new hidden input.
|
||||
if ( typeof target === 'string' && target.indexOf('-') !== 0 ) {
|
||||
|
||||
this.method = 'val';
|
||||
|
||||
var element = document.createElement('input');
|
||||
element.name = target;
|
||||
element.type = 'hidden';
|
||||
this.target = this.el = $(element);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function fromFunction ( target ) {
|
||||
|
||||
// The target can also be a function, which will be called.
|
||||
if ( typeof target === 'function' ) {
|
||||
this.target = false;
|
||||
this.method = target;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function fromInstance ( target, method ) {
|
||||
|
||||
if ( isInstance( target ) && !method ) {
|
||||
|
||||
// If a jQuery/Zepto input element is provided, but no method is set,
|
||||
// the element can assume it needs to respond to 'change'...
|
||||
if ( target.is('input, select, textarea') ) {
|
||||
|
||||
// Default to .val if this is an input element.
|
||||
this.method = 'val';
|
||||
|
||||
// Fire the API changehandler when the target changes.
|
||||
this.target = target.on('change.liblink', this.changeHandler);
|
||||
|
||||
} else {
|
||||
|
||||
this.target = target;
|
||||
|
||||
// If no method is set, and we are not auto-binding an input, default to 'html'.
|
||||
this.method = 'html';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function fromInstanceMethod ( target, method ) {
|
||||
|
||||
// The method must exist on the element.
|
||||
if ( isInstance( target ) &&
|
||||
(typeof method === 'function' ||
|
||||
(typeof method === 'string' && target[method]))
|
||||
) {
|
||||
this.method = method;
|
||||
this.target = target;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
var
|
||||
/** @const */
|
||||
creationFunctions = [fromPrefix, fromString, fromFunction, fromInstance, fromInstanceMethod];
|
||||
|
||||
|
||||
// Link Instance
|
||||
|
||||
/** @constructor */
|
||||
function Link ( target, method, format ) {
|
||||
|
||||
var that = this, valid = false;
|
||||
|
||||
// Forward calls within scope.
|
||||
this.changeHandler = function ( changeEvent ) {
|
||||
var decodedValue = that.formatInstance.from( $(this).val() );
|
||||
|
||||
// If the value is invalid, stop this event, as well as it's propagation.
|
||||
if ( decodedValue === false || isNaN(decodedValue) ) {
|
||||
|
||||
// Reset the value.
|
||||
$(this).val(that.lastSetValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
that.changeHandlerMethod.call( '', changeEvent, decodedValue );
|
||||
};
|
||||
|
||||
// See if this Link needs individual targets based on its usage.
|
||||
// If so, return the element that needs to be copied by the
|
||||
// implementing interface.
|
||||
// Default the element to false.
|
||||
this.el = false;
|
||||
|
||||
// Store the formatter, or use the default.
|
||||
this.formatInstance = format;
|
||||
|
||||
// Try all Link types.
|
||||
/*jslint unparam: true*/
|
||||
$.each(creationFunctions, function(i, fn){
|
||||
valid = fn.call(that, target, method);
|
||||
return !valid;
|
||||
});
|
||||
/*jslint unparam: false*/
|
||||
|
||||
// Nothing matched, throw error.
|
||||
if ( !valid ) {
|
||||
throw new RangeError("(Link) Invalid Link.");
|
||||
}
|
||||
}
|
||||
|
||||
// Provides external items with the object value.
|
||||
Link.prototype.set = function ( value ) {
|
||||
|
||||
// Ignore the value, so only the passed-on arguments remain.
|
||||
var args = Array.prototype.slice.call( arguments ),
|
||||
additionalArgs = args.slice(1);
|
||||
|
||||
// Store some values. The actual, numerical value,
|
||||
// the formatted value and the parameters for use in 'resetValue'.
|
||||
// Slice additionalArgs to break the relation.
|
||||
this.lastSetValue = this.formatInstance.to( value );
|
||||
|
||||
// Prepend the value to the function arguments.
|
||||
additionalArgs.unshift(
|
||||
this.lastSetValue
|
||||
);
|
||||
|
||||
// When target is undefined, the target was a function.
|
||||
// In that case, provided the object as the calling scope.
|
||||
// Branch between writing to a function or an object.
|
||||
( typeof this.method === 'function' ?
|
||||
this.method :
|
||||
this.target[ this.method ] ).apply( this.target, additionalArgs );
|
||||
};
|
||||
|
||||
|
||||
// Developer API
|
||||
|
||||
/** @constructor */
|
||||
function LinkAPI ( origin ) {
|
||||
this.items = [];
|
||||
this.elements = [];
|
||||
this.origin = origin;
|
||||
}
|
||||
|
||||
LinkAPI.prototype.push = function( item, element ) {
|
||||
this.items.push(item);
|
||||
|
||||
// Prevent 'false' elements
|
||||
if ( element ) {
|
||||
this.elements.push(element);
|
||||
}
|
||||
};
|
||||
|
||||
LinkAPI.prototype.reconfirm = function ( flag ) {
|
||||
var i;
|
||||
for ( i = 0; i < this.elements.length; i += 1 ) {
|
||||
this.origin.LinkConfirm(flag, this.elements[i]);
|
||||
}
|
||||
};
|
||||
|
||||
LinkAPI.prototype.remove = function ( flag ) {
|
||||
var i;
|
||||
for ( i = 0; i < this.items.length; i += 1 ) {
|
||||
this.items[i].target.off('.liblink');
|
||||
}
|
||||
for ( i = 0; i < this.elements.length; i += 1 ) {
|
||||
this.elements[i].remove();
|
||||
}
|
||||
};
|
||||
|
||||
LinkAPI.prototype.change = function ( value ) {
|
||||
|
||||
if ( this.origin.LinkIsEmitting ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.origin.LinkIsEmitting = true;
|
||||
|
||||
var args = Array.prototype.slice.call( arguments, 1 ), i;
|
||||
args.unshift( value );
|
||||
|
||||
// Write values to serialization Links.
|
||||
// Convert the value to the correct relative representation.
|
||||
for ( i = 0; i < this.items.length; i += 1 ) {
|
||||
this.items[i].set.apply(this.items[i], args);
|
||||
}
|
||||
|
||||
this.origin.LinkIsEmitting = false;
|
||||
};
|
||||
|
||||
|
||||
// jQuery plugin
|
||||
|
||||
function binder ( flag, target, method, format ){
|
||||
|
||||
if ( flag === 0 ) {
|
||||
flag = this.LinkDefaultFlag;
|
||||
}
|
||||
|
||||
// Create a list of API's (if it didn't exist yet);
|
||||
if ( !this.linkAPI ) {
|
||||
this.linkAPI = {};
|
||||
}
|
||||
|
||||
// Add an API point.
|
||||
if ( !this.linkAPI[flag] ) {
|
||||
this.linkAPI[flag] = new LinkAPI(this);
|
||||
}
|
||||
|
||||
var linkInstance = new Link ( target, method, format || this.LinkDefaultFormatter );
|
||||
|
||||
// Default the calling scope to the linked object.
|
||||
if ( !linkInstance.target ) {
|
||||
linkInstance.target = $(this);
|
||||
}
|
||||
|
||||
// If the Link requires creation of a new element,
|
||||
// Pass the element and request confirmation to get the changehandler.
|
||||
// Set the method to be called when a Link changes.
|
||||
linkInstance.changeHandlerMethod = this.LinkConfirm( flag, linkInstance.el );
|
||||
|
||||
// Store the linkInstance in the flagged list.
|
||||
this.linkAPI[flag].push( linkInstance, linkInstance.el );
|
||||
|
||||
// Now that Link have been connected, request an update.
|
||||
this.LinkUpdate( flag );
|
||||
}
|
||||
|
||||
/** @export */
|
||||
$.fn.Link = function( flag ){
|
||||
|
||||
var that = this;
|
||||
|
||||
// Delete all linkAPI
|
||||
if ( flag === false ) {
|
||||
|
||||
return that.each(function(){
|
||||
|
||||
// .Link(false) can be called on elements without Links.
|
||||
// When that happens, the objects can't be looped.
|
||||
if ( !this.linkAPI ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.map(this.linkAPI, function(api){
|
||||
api.remove();
|
||||
});
|
||||
|
||||
delete this.linkAPI;
|
||||
});
|
||||
}
|
||||
|
||||
if ( flag === undefined ) {
|
||||
|
||||
flag = 0;
|
||||
|
||||
} else if ( typeof flag !== 'string') {
|
||||
|
||||
throw new Error("Flag must be string.");
|
||||
}
|
||||
|
||||
return {
|
||||
to: function( a, b, c ){
|
||||
return that.each(function(){
|
||||
binder.call(this, flag, a, b, c);
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
}( window.jQuery || window.Zepto ));
|
3
js/libraries/jquery.nouislider.all.min.js
vendored
Normal file
3
js/libraries/jquery.nouislider.all.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
4
js/libraries/jquery.nouislider.min.css
vendored
Normal file
4
js/libraries/jquery.nouislider.min.css
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
/*! noUiSlider - 7.0.9 - 2014-10-08 16:49:45 */
|
||||
|
||||
|
||||
.noUi-target,.noUi-target *{-webkit-touch-callout:none;-webkit-user-select:none;-ms-touch-action:none;-ms-user-select:none;-moz-user-select:none;-moz-box-sizing:border-box;box-sizing:border-box}.noUi-target{position:relative}.noUi-base{width:100%;height:100%;position:relative}.noUi-origin{position:absolute;right:0;top:0;left:0;bottom:0}.noUi-handle{position:relative;z-index:1}.noUi-stacking .noUi-handle{z-index:10}.noUi-state-tap .noUi-origin{-webkit-transition:left .3s,top .3s;transition:left .3s,top .3s}.noUi-state-drag *{cursor:inherit!important}.noUi-base{-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0)}.noUi-horizontal{height:18px}.noUi-horizontal .noUi-handle{width:34px;height:28px;left:-17px;top:-6px}.noUi-vertical{width:18px}.noUi-vertical .noUi-handle{width:28px;height:34px;left:-6px;top:-17px}.noUi-background{background:#FAFAFA;box-shadow:inset 0 1px 1px #f0f0f0}.noUi-connect{background:#3FB8AF;box-shadow:inset 0 0 3px rgba(51,51,51,.45);-webkit-transition:background 450ms;transition:background 450ms}.noUi-origin{border-radius:2px}.noUi-target{border-radius:4px;border:1px solid #D3D3D3;box-shadow:inset 0 1px 1px #F0F0F0,0 3px 6px -5px #BBB}.noUi-target.noUi-connect{box-shadow:inset 0 0 3px rgba(51,51,51,.45),0 3px 6px -5px #BBB}.noUi-dragable{cursor:w-resize}.noUi-vertical .noUi-dragable{cursor:n-resize}.noUi-handle{border:1px solid #D9D9D9;border-radius:3px;background:#FFF;cursor:default;box-shadow:inset 0 0 1px #FFF,inset 0 1px 7px #EBEBEB,0 3px 6px -3px #BBB}.noUi-active{box-shadow:inset 0 0 1px #FFF,inset 0 1px 7px #DDD,0 3px 6px -3px #BBB}.noUi-handle:after,.noUi-handle:before{content:"";display:block;position:absolute;height:14px;width:1px;background:#E8E7E6;left:14px;top:6px}.noUi-handle:after{left:17px}.noUi-vertical .noUi-handle:after,.noUi-vertical .noUi-handle:before{width:14px;height:1px;left:6px;top:14px}.noUi-vertical .noUi-handle:after{top:17px}[disabled] .noUi-connect,[disabled].noUi-connect{background:#B8B8B8}[disabled] .noUi-handle{cursor:not-allowed}
|
4
js/libraries/jquery.nouislider.pips.min.css
vendored
Normal file
4
js/libraries/jquery.nouislider.pips.min.css
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
/*! noUiSlider - 7.0.9 - 2014-10-08 16:49:45 */
|
||||
|
||||
|
||||
.noUi-pips,.noUi-pips *{-moz-box-sizing:border-box;box-sizing:border-box}.noUi-pips{position:absolute;font:400 12px Arial;color:#999}.noUi-value{width:40px;position:absolute;text-align:center}.noUi-value-sub{color:#ccc;font-size:10px}.noUi-marker{position:absolute;background:#CCC}.noUi-marker-large,.noUi-marker-sub{background:#AAA}.noUi-pips-horizontal{padding:10px 0;height:50px;top:100%;left:0;width:100%}.noUi-value-horizontal{margin-left:-20px;padding-top:20px}.noUi-value-horizontal.noUi-value-sub{padding-top:15px}.noUi-marker-horizontal.noUi-marker{margin-left:-1px;width:2px;height:5px}.noUi-marker-horizontal.noUi-marker-sub{height:10px}.noUi-marker-horizontal.noUi-marker-large{height:15px}.noUi-pips-vertical{padding:0 10px;height:100%;top:0;left:100%}.noUi-value-vertical{width:15px;margin-left:20px;margin-top:-5px}.noUi-marker-vertical.noUi-marker{width:5px;height:2px;margin-top:-1px}.noUi-marker-vertical.noUi-marker-sub{width:10px}.noUi-marker-vertical.noUi-marker-large{width:15px}
|
Loading…
Add table
Add a link
Reference in a new issue