Using canvas input for better perfs
an actual input is generated on focus
This commit is contained in:
parent
ca1250a8b7
commit
f6bb9299ad
6 changed files with 138 additions and 25 deletions
File diff suppressed because one or more lines are too long
|
|
@ -473,14 +473,14 @@ createWidget.xy = function(widgetData) {
|
|||
<div class="handle"></div>
|
||||
</div>
|
||||
<div class="value">
|
||||
<input disabled value="X"></input><input disabled value="Y"></input>
|
||||
<input class="x"></input><input class="y"></input>
|
||||
<div class="input disabled">X</div><div class="input disabled">Y</div>
|
||||
<div class="input x"></div><div class="input y"></div>
|
||||
</div>
|
||||
</div>
|
||||
`),
|
||||
handle = widget.find('.handle'),
|
||||
pad = widget.find('.xy'),
|
||||
value = {x:widget.find('.x'),y:widget.find('.y')},
|
||||
value = {x:widget.find('.x').fakeInput({align:'center'}),y:widget.find('.y').fakeInput({align:'center'})},
|
||||
range = {x:widgetData.rangeX,y:widgetData.rangeY},
|
||||
absolute = widgetData.absolute,
|
||||
split = widgetData.split?
|
||||
|
|
@ -497,8 +497,11 @@ createWidget.xy = function(widgetData) {
|
|||
handle.width = 0
|
||||
|
||||
pad.resize(function(){
|
||||
pad.width = pad.innerWidth()
|
||||
pad.height = pad.innerHeight()
|
||||
var width = pad.innerWidth(),
|
||||
height = pad.innerHeight()
|
||||
if (!width || (pad.height==height && pad.width==width)) return
|
||||
pad.width = width
|
||||
pad.height = height
|
||||
handle[0].setAttribute('style',`transform:translate3d(${pad.width*handle.width/100}px, -${pad.height*handle.height/100}px,0)`)
|
||||
})
|
||||
|
||||
|
|
@ -632,8 +635,8 @@ createWidget.rgb = function(widgetData) {
|
|||
<div class="handle"></div>
|
||||
</div>
|
||||
<div class="value">
|
||||
<input disabled value="R"></input><input disabled value="G"></input><input disabled value="B"></input>
|
||||
<input class="r"></input><input class="g"></input><input class="b"></input>
|
||||
<div class="input disabled">R</div><div class="input disabled">G</div><div class="input disabled">B</div>
|
||||
<div class="input r"></div><div class="input g"></div><div class="input b"></div>
|
||||
</div>
|
||||
</div>`),
|
||||
rgbHandle = widget.find('.rgb .handle'),
|
||||
|
|
@ -641,7 +644,7 @@ createWidget.rgb = function(widgetData) {
|
|||
pad = widget.find('.xy'),
|
||||
huePad = widget.find('.hue'),
|
||||
rgbBg = pad.find('.bg')[0],
|
||||
value = {r:widget.find('input.r'),g:widget.find('input.g'),b:widget.find('input.b')},
|
||||
value = {r:widget.find('.r').fakeInput({align:'center'}),g:widget.find('.g').fakeInput({align:'center'}),b:widget.find('.b').fakeInput({align:'center'})},
|
||||
absolute = widgetData.absolute,
|
||||
split = widgetData.split?
|
||||
typeof widgetData.split == 'object'?
|
||||
|
|
@ -658,8 +661,11 @@ createWidget.rgb = function(widgetData) {
|
|||
hueHandle.width = 0
|
||||
|
||||
pad.resize(function(){
|
||||
pad.width = pad.innerWidth()
|
||||
pad.height = pad.innerHeight()
|
||||
var width = pad.innerWidth(),
|
||||
height = pad.innerHeight()
|
||||
if (!width || (pad.height==height && pad.width==width)) return
|
||||
pad.width = width
|
||||
pad.height = height
|
||||
rgbHandle[0].setAttribute('style',`transform:translate3d(${pad.width*rgbHandle.width/100}px, -${pad.height*rgbHandle.height/100}px,0)`)
|
||||
|
||||
})
|
||||
|
|
@ -869,7 +875,7 @@ createWidget.fader = function(widgetData,container){
|
|||
<div class="pips"></div>
|
||||
</div>
|
||||
</div>
|
||||
<input></input>
|
||||
<div class="input"></div>
|
||||
</div>
|
||||
`),
|
||||
handle = widget.find('.handle'),
|
||||
|
|
@ -877,12 +883,11 @@ createWidget.fader = function(widgetData,container){
|
|||
wrapper = widget.find('.fader-wrapper'),
|
||||
fader = widget.find('.fader'),
|
||||
pips = widget.find('.pips'),
|
||||
input = widget.find('input'),
|
||||
input = widget.find('.input').fakeInput(),
|
||||
unit = widgetData.unit?' '+widgetData.unit.trim(): '',
|
||||
dimension = widgetData.horizontal?'width':'height',
|
||||
axe = dimension=='height'?'X':'Y',
|
||||
absolute = widgetData.absolute
|
||||
|
||||
if (widgetData.horizontal) container.addClass('horizontal')
|
||||
|
||||
handle.size = 0
|
||||
|
|
@ -1044,14 +1049,14 @@ createWidget.knob = function(widgetData) {
|
|||
<div class="pip min"></div>
|
||||
<div class="pip max"></div>
|
||||
</div>
|
||||
<input></input>
|
||||
<div class="input"></div>
|
||||
</div>
|
||||
`),
|
||||
wrapper = widget.find('.knob-wrapper'),
|
||||
mask = widget.find('.knob-mask'),
|
||||
knob = widget.find('.knob'),
|
||||
handle = widget.find('.handle'),
|
||||
input = widget.find('input'),
|
||||
input = widget.find('.input').fakeInput(),
|
||||
range = widgetData.range || {min:0,max:1},
|
||||
unit = widgetData.unit?' '+widgetData.unit.trim(): '',
|
||||
absolute = widgetData.absolute,
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ require('./jquery/jquery.resizable-draggable.js')
|
|||
require('./jquery/jquery.sortable.js')
|
||||
require('./jquery/jquery.drag.js')
|
||||
require('./jquery/jquery.resize.js')
|
||||
require('./jquery/jquery.fake-input.js')
|
||||
|
||||
|
||||
// main js
|
||||
require('./app/app.js')
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ require('./jquery/jquery.resizable-draggable.js')
|
|||
require('./jquery/jquery.sortable.js')
|
||||
require('./jquery/jquery.drag.js')
|
||||
require('./jquery/jquery.resize.js')
|
||||
require('./jquery/jquery.fake-input.js')
|
||||
|
||||
// main js
|
||||
require('./app/app.js')
|
||||
|
|
|
|||
81
app/browser/js/jquery/jquery.fake-input.js
Normal file
81
app/browser/js/jquery/jquery.fake-input.js
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
(function ($) {
|
||||
|
||||
$.fn.fakeInput = function(options) {
|
||||
|
||||
var settings = $.extend({
|
||||
align:'left'
|
||||
}, options );
|
||||
|
||||
var self= this,
|
||||
canvas = $('<canvas></canvas>').appendTo(self),
|
||||
ctx = canvas[0].getContext('2d')
|
||||
|
||||
self.value = undefined
|
||||
self.height = undefined
|
||||
self.width = undefined
|
||||
self.color = $('body').css('color')
|
||||
self.center = settings.align == 'center'
|
||||
|
||||
|
||||
self.attr('tabindex',"0")
|
||||
|
||||
canvas.resize(function(){
|
||||
var width = canvas.width(),
|
||||
height = canvas.height()
|
||||
|
||||
if (height==100 && width==100) return
|
||||
self.height=height
|
||||
self.width=width
|
||||
|
||||
canvas[0].setAttribute('width',width)
|
||||
canvas[0].setAttribute('height',height)
|
||||
|
||||
self.val(self.value)
|
||||
})
|
||||
|
||||
self.val = function(newVal) {
|
||||
if (newVal==undefined) return self.value
|
||||
|
||||
self.value = newVal
|
||||
|
||||
if (!self.height || !self.width || (self.height==100 && self.width==100)) return
|
||||
|
||||
ctx.clearRect(0,0,self.width,self.height)
|
||||
ctx.font = '13px sans-serif'
|
||||
ctx.textBaseline = "top"
|
||||
ctx.fillStyle = self.color
|
||||
|
||||
if (self.center) {
|
||||
ctx.textAlign = settings.align
|
||||
ctx.fillText(newVal,self.width/2,0)
|
||||
} else {
|
||||
ctx.fillText(newVal,0,0)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
self.on('click focus',function(){
|
||||
self.attr('tabindex','-1')
|
||||
var i = $('<input></input>')
|
||||
.prependTo(self)
|
||||
.val(self.value)
|
||||
.focus()
|
||||
.change(function(){
|
||||
self.val($(this).val())
|
||||
// $(this).remove()
|
||||
})
|
||||
i.blur(function(){
|
||||
self.attr('tabindex','0')
|
||||
i.remove()
|
||||
})
|
||||
$(document).on('mousedown.fakeInput touchstart.fakeInput',function(){
|
||||
i.blur()
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
return self
|
||||
|
||||
}
|
||||
})(jQuery)
|
||||
|
|
@ -717,16 +717,40 @@ a {
|
|||
color:$color-accent;
|
||||
}
|
||||
}
|
||||
input {
|
||||
.input {
|
||||
width:100%;
|
||||
height:30rem;
|
||||
border:0;
|
||||
background:transparent;
|
||||
color:$color-text-fade;
|
||||
// color:inherit;
|
||||
display:block;
|
||||
// text-align: center;
|
||||
padding:10rem;
|
||||
padding:7rem 10rem;
|
||||
position: relative;
|
||||
|
||||
input {
|
||||
position: absolute;
|
||||
top:0;
|
||||
left:0;
|
||||
right:0;
|
||||
bottom:0;
|
||||
padding:7rem 10rem;
|
||||
width: 100%;
|
||||
font-family: 'sans-serif';
|
||||
font-size: 13rem;
|
||||
border:0;
|
||||
background: transparent;
|
||||
font: inherit;
|
||||
color:$color-accent;
|
||||
}
|
||||
canvas {
|
||||
width:100%;
|
||||
height:100%;
|
||||
opacity: .8;
|
||||
}
|
||||
input + canvas {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
&:focus {
|
||||
color:$color-accent;
|
||||
|
||||
|
|
@ -1099,10 +1123,10 @@ a {
|
|||
bottom:0;
|
||||
border-top: 1rem solid $color-bg;
|
||||
}
|
||||
input {
|
||||
.input, input {
|
||||
width:50%;
|
||||
float:left;
|
||||
padding: 2rem;
|
||||
height: 30rem;
|
||||
text-align: center;
|
||||
position: relative;
|
||||
}
|
||||
|
|
@ -1163,7 +1187,7 @@ a {
|
|||
|
||||
.rgb-wrapper {
|
||||
padding-bottom: 90rem;
|
||||
input {
|
||||
.input, input {
|
||||
width:33.33%;
|
||||
}
|
||||
}
|
||||
|
|
@ -1288,7 +1312,7 @@ a {
|
|||
bottom:0;
|
||||
left:0;
|
||||
right:0;
|
||||
input {
|
||||
.input {
|
||||
position:absolute;
|
||||
bottom:0;
|
||||
}
|
||||
|
|
@ -1477,7 +1501,7 @@ a {
|
|||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
input {
|
||||
.input {
|
||||
bottom:0;
|
||||
position: absolute;
|
||||
left:0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue