Skip to content

Commit 99634d0

Browse files
author
hartsantler
committed
dddom.py: testing html5 and jquery/css slider
1 parent 099a1cc commit 99634d0

1 file changed

Lines changed: 51 additions & 19 deletions

File tree

regtests/html/webgl_css3d_simple_editor.html

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
var element = $(el);
7373
var options = opts;
7474
var isMouseDown = false;
75-
var currentVal = 0;
75+
var currentVal = opts.value || 0;
7676

7777
element.wrap('<div/>')
7878
var container = $(el).parent();
@@ -134,6 +134,7 @@
134134
newPos = Math.max(0,newPos);
135135
newPos = Math.min(newPos,upperBound);
136136
currentVal = Math.round((newPos/upperBound)*100,0);
137+
if (typeof options.onInput == 'function') { options.onInput(currentVal)}
137138

138139
container.find('.pp-slider-button').css("left", newPos);
139140
container.find('.pp-slider-tooltip').html(currentVal+'%');
@@ -150,8 +151,8 @@
150151
var dropCallback = function (e) {
151152
isMouseDown = false;
152153
element.val(currentVal);
153-
if(typeof element.options != 'undefined' && typeof element.options.onChanged == 'function'){
154-
element.options.onChanged.call(this, null);
154+
if(typeof options.onChanged == 'function'){
155+
options.onChanged.call(this, null);
155156
}
156157

157158
};
@@ -160,6 +161,8 @@
160161

161162
$(document).mousemove(function(e) { moving(e); });
162163
$(document).mouseup(function(e){ dropCallback(e); });
164+
165+
container.find('.pp-slider-button').css("left", currentVal);
163166

164167
};
165168

@@ -174,7 +177,7 @@
174177
}
175178

176179
$.fn.PPSlider.defaults = {
177-
width: 150
180+
width: 100
178181
};
179182

180183

@@ -338,20 +341,6 @@
338341
ta = create_textarea()
339342
con.appendChild( ta )
340343

341-
slider = document.createElement('input')
342-
slider.setAttribute('type', 'hidden')
343-
slider.setAttribute('value', '40')
344-
slider.setAttribute('id', 'myslider')
345-
con.appendChild( slider )
346-
$("#myslider").PPSlider( width=300 )
347-
348-
349-
#video = this.element3D.create_video(
350-
# mp4='/home/brett/three.js/examples/textures/sintel.mp4',
351-
# ogv='/home/brett/three.js/examples/textures/sintel.ogv'
352-
#)
353-
#this.parentNode.appendChild(video)
354-
355344
pointlight.position.copy( this.element3D.object.position )
356345
pointlight.position.z += 40
357346
gizmo.attach( this.element3D.right_bar )
@@ -438,7 +427,7 @@
438427
#loader.load( 'http://localhost:8000'+file.path, on_load )
439428

440429
def onload(evt):
441-
print(evt.target.result)
430+
global slider
442431
parser = new DOMParser()
443432
collada = loader.parse( parser.parseFromString(evt.target.result, "application/xml") )
444433
print(collada.scene)
@@ -447,6 +436,49 @@
447436
element3D.root.add( collada.scene )
448437
element3D.collada = collada.scene
449438

439+
global X
440+
X = collada.scene
441+
for model in collada.scene.children:
442+
print(model)
443+
div = document.createElement('div')
444+
div.setAttribute('class', 'well')
445+
container.appendChild( div )
446+
h3 = document.createElement('h3')
447+
h3.appendChild( document.createTextNode(model.name) )
448+
div.appendChild( h3 )
449+
450+
if hasattr(model, 'material'): ## could be THREE.Mesh or THREE.SkinnedMesh
451+
print(model.material)
452+
slider = document.createElement('input')
453+
## the native slider looks different on each platform,
454+
## and it is not clickable, because the camera controls preventDefault?
455+
## however, if focused the keyboard arrow keys, can still change the slider values.
456+
## to be safe, instead of using a native slider, we use the custom jquery/css slider.
457+
##slider.setAttribute('type', 'range') ## do not use native slider
458+
#slider.setAttribute('min', 0)
459+
#slider.setAttribute('max', 100)
460+
#slider.setAttribute('step', 1)
461+
#slider.setAttribute('value', 100)
462+
463+
slider.setAttribute('type', 'hidden')
464+
sid = 'slider-'+model.name
465+
slider.setAttribute('id', sid)
466+
div.appendChild( slider )
467+
468+
def onchange(val):
469+
model.material.opacity = val * 0.01
470+
#slider.oninput = onchange
471+
#slider.onchange = onchange
472+
473+
$("#"+sid).PPSlider( width=300, onInput=onchange, value=100 )
474+
475+
def onclick(e):
476+
print('slider clicked')
477+
slider.focus()
478+
slider.onclick = onclick
479+
480+
481+
450482
reader = new FileReader()
451483
reader.onload = onload
452484
reader.readAsText( file )

0 commit comments

Comments
 (0)