- knob optimization ($.attr instead of $.style)

This commit is contained in:
jean-emmanuel 2015-09-15 15:09:24 +02:00 • committed by bordun
parent bbc9189068
commit 4ba84f43a9
2 changed files with 16 additions and 15 deletions

View file

@ -251,15 +251,10 @@ mapToScale = function(value,rangeIn,rangeOut,reverse) {
// get rotation plugin (@Ivo Renkema)
$.fn.getRotation = function () {
var matrix = this.css("transform")
if(typeof matrix === 'string' && matrix !== 'none') {
var values = matrix.split('(')[1].split(')')[0].split(',');
var a = values[0];
var b = values[1];
var angle = Math.round(Math.atan2(b, a) * (180/Math.PI));
var style = this.attr("style")
if(typeof style === 'string' && style !== 'none') {
var angle = parseInt(style.split('(')[1].split(')')[0])
} else { var angle = 0; }
if (angle<0) angle = 360+angle
return angle;

View file

@ -398,7 +398,7 @@ createWidget.fader = function(widgetData,container){
widget.trigger('sync')
},{ relative:true });
},{ relative:true });
widgetData.range = widgetData.range || {'min':0,'max':1}
@ -436,7 +436,7 @@ createWidget.fader = function(widgetData,container){
widget.getValue = function(){
var h = handle.size
var h = clip(handle.size,[0,100])
for (var i=0;i<rangeKeys.length-1;i++) {
if (h <= rangeKeys[i+1] && h >= rangeKeys[i]) {
return mapToScale(h,[rangeKeys[i],rangeKeys[i+1]],[rangeVals[i],rangeVals[i+1]])
@ -508,13 +508,18 @@ createWidget.knob = function(widgetData) {
widget.find('.pip.min').text(pipmin)
widget.find('.pip.max').text(pipmax)
knob.css('transform','rotate(45deg)').drag('init',function(){
knob.rotation = 0
var offR = 0
knob.attr('style','transform:rotate(45deg)').drag('init',function(){
offR = knob.getRotation()
})
knob.drag(function( ev, dd ){
var r = clip(-dd.deltaY*2+offR,[0,270])
knob.css('transform', 'rotateZ('+r+'deg)')
knob.attr('style','transform:rotateZ('+r+'deg)')
knob.rotation = r
if (r>180) {
knob.addClass('d3')
@ -524,7 +529,7 @@ createWidget.knob = function(widgetData) {
knob.removeClass('d3 d2')
}
var v = widget.getValue()
var v = mapToScale(r,[0,270],[range.min,range.max])
widget.sendValue(v);
widget.trigger('sync')
@ -534,7 +539,7 @@ createWidget.knob = function(widgetData) {
widget.getValue = function() {
return mapToScale(knob.getRotation(),[0,270],[range.min,range.max])
return mapToScale(knob.rotation,[0,270],[range.min,range.max])
}
widget.showValue = function(v) {
input.val(v+unit)
@ -546,6 +551,7 @@ createWidget.knob = function(widgetData) {
}
widget.setValue = function(v,send,sync) {
var r = mapToScale(v,[range.min,range.max],[0,270])
knob.rotation = r
if (r>180) {
knob.addClass('d3')
@ -556,7 +562,7 @@ createWidget.knob = function(widgetData) {
}
knob.css('transform', 'rotateZ('+r+'deg)')
knob.attr('style','transform:rotateZ('+r+'deg)')
var v = widget.getValue() || v
widget.showValue(v);