Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation #1

Open
wants to merge 95 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
4a6567f
Add ability to skip width or height when computing bounds
mcarlson May 7, 2014
f8bc408
Add locking
mcarlson May 7, 2014
6ed3cc9
Fix touch events on iOS
mcarlson May 7, 2014
6fbc951
Warn when extending nonexistant classes
mcarlson May 7, 2014
5efa6c9
Add lz.window class to get window width/height
mcarlson May 7, 2014
0596ae0
Add shim for proxying events across apps
mcarlson May 7, 2014
3db9051
Add wraplayout
mcarlson May 7, 2014
7de504d
Genre data binding prototype
mcarlson May 7, 2014
c4127a0
Warn for missing classname in replicator
mcarlson May 8, 2014
ae1c7fe
Add sorting, filtering and locking to replicators
mcarlson May 8, 2014
2ae4f14
Add timelayout
mcarlson May 8, 2014
5698749
Add timeline, movies and thumbnails demos
mcarlson May 8, 2014
cfe0128
Show movies across multiple genres, less coffeescript
mcarlson May 8, 2014
971a199
Add pooling, destroy replicated instances when replicator is destroyed
mcarlson May 22, 2014
c970490
Fix property binding for multiple attributes in the same scope
mcarlson May 22, 2014
bb77c50
Set parent and name attributes in an explicit order
mcarlson May 22, 2014
e924d76
Prevent duplicate initializations. Preserve tagnames for synamically …
mcarlson May 22, 2014
217167c
Fix 2 way binding in data.html example
mcarlson May 22, 2014
4b0f810
Don't autoload builtin classes
mcarlson May 24, 2014
41472b4
Default margin and padding to 0
mcarlson May 24, 2014
7c06f5c
Add named functions for profiling, etc. Add stub for class methods.
mcarlson May 24, 2014
5864c93
Inputtext has a fixed width by default
mcarlson May 24, 2014
8b51d84
Update data example
mcarlson May 24, 2014
02f4b4d
Autoinclude class extends="xxx" classes, ignore script tags
mcarlson May 24, 2014
57eb666
Add script include for jsonpath to replicator
mcarlson May 24, 2014
6393396
Add lazy/deferred replicatio
mcarlson May 24, 2014
3ca2715
Allow shim to filter messages
mcarlson May 24, 2014
622239e
Update examples
mcarlson May 24, 2014
e16955d
Add audio example
mcarlson May 24, 2014
2fb68d3
Update timeline example
mcarlson May 24, 2014
a565d6b
Set global reference when using id attribute
mcarlson May 24, 2014
233bdcf
Name constraint callbacks for profiler, make more efficient
mcarlson May 24, 2014
fb0268d
Update shim to use primus
mcarlson May 24, 2014
d25e1af
Bypass the server when the connection is down
mcarlson May 24, 2014
d7b0246
Add support for <class scriptinclude="/foo/bar/baz.js"...></class>
mcarlson May 25, 2014
944320e
Add loaded boolean, set duration earlier, reset time to 0 when stopped.
mcarlson May 25, 2014
18b7608
Add play/pause button, time readout
mcarlson May 25, 2014
53b84a2
Use scriptincludes
mcarlson May 25, 2014
9cec8a5
Use scriptincludes, parameterize pingtime, send error events
mcarlson May 25, 2014
bb6393f
Forcibly bind methods to their scope
mcarlson May 25, 2014
2320a24
Add stats class
mcarlson May 25, 2014
85fcfdf
Load threejs libs from remote site
mcarlson May 25, 2014
b0a50a7
Show bus errors
mcarlson May 25, 2014
9e56c17
Add local copy of stats.min.js from threejs
mcarlson May 25, 2014
4a8c45a
Allow external script includes
mcarlson May 25, 2014
69bd13e
Load class scriptincludes in lexical order, clean up and document aut…
mcarlson May 25, 2014
089ebd2
Add support for debug, strict and nocache compiler flags, activate by…
mcarlson May 25, 2014
fb8aa4c
Refactor threejs.html, add threejs baseclass
mcarlson May 25, 2014
5995a86
Add id setter for node, change audioplayer and shim to extend node in…
mcarlson May 25, 2014
1367f1e
Update threejs demo
mcarlson May 25, 2014
d52cbf4
Prevent duplicate renders
mcarlson May 25, 2014
e7c624d
Update coffeescript compiler
mcarlson May 25, 2014
a3eb602
cleanup
mcarlson May 25, 2014
e3488f5
Add toggle to audio player, update demos. threejs spacebar toggles pl…
mcarlson May 25, 2014
35256b0
Allow scriptincludes attribute anywhere, accept a comma-separated lis…
mcarlson May 25, 2014
640e5fd
Add gyro, touch event classes
mcarlson Jun 3, 2014
627f62c
Don't use jquery for window resize events
mcarlson Jul 28, 2014
b6f1cba
Warn for failing scriptincludes
mcarlson Jul 28, 2014
045e675
Convert FFT audio data to arrays on numbers, clean up transport ui
mcarlson Jul 28, 2014
ebd9b13
Add index
mcarlson Jul 28, 2014
31bdd2c
Only serialize to JSON if it's needed
mcarlson Jul 28, 2014
b85a2d1
Prefix all internal properties with $
mcarlson Jul 30, 2014
487bf48
Add support for states
mcarlson Jul 30, 2014
8b7fbe6
Move value caching from view to sprite
mcarlson Jul 30, 2014
72fc374
Fix text height measurements for non-multiline text
mcarlson Jul 30, 2014
e49b001
Merge branch 'master' into onejs
mcarlson Jul 30, 2014
d533900
Fix braino
mcarlson Jul 30, 2014
3ec5739
Revert "Move value caching from view to sprite"
mcarlson Jul 30, 2014
c058105
Clean up and unify states
mcarlson Jul 30, 2014
ae1a191
Use applied setter to apply/remove state
mcarlson Jul 30, 2014
1f0f9ad
Use bindAttribute so constraints and event handler bindings work in s…
mcarlson Jul 30, 2014
a193fd6
Update to newest one_base.js
mcarlson Jul 30, 2014
a5b9ebf
Try harder to remove listeners in stopListening()
mcarlson Jul 30, 2014
71fc9ac
Factor @installMethods and @installHandlers out of Node's constructor…
mcarlson Jul 30, 2014
c0fb5ee
Fix braino in getAbsolute()
mcarlson Jul 30, 2014
b33a890
Make text and inputtext unselectable
mcarlson Jul 30, 2014
48ef55e
Prefer arguments for callbacks, instead of looking in the scope
mcarlson Jul 30, 2014
3f591c8
Fully working states implementation!
mcarlson Jul 30, 2014
c70ec1a
Only skip name attributes if they are set on the state
mcarlson Jul 30, 2014
303d3eb
Add move dragstate to classes/dragstate.lzx
mcarlson Jul 30, 2014
fb0c096
Autoload one_base.js when needed
mcarlson Jul 30, 2014
4e162aa
Fix toggling of text.multiline attribute
mcarlson Jul 30, 2014
38b55b8
Update README.md
mcarlson Aug 8, 2014
95f1a26
Update README.md
mcarlson Aug 8, 2014
d7f3b72
Update README.md
mcarlson Aug 8, 2014
3eb78be
Update README.md
mcarlson Aug 8, 2014
5df3d54
Update README.md
mcarlson Aug 8, 2014
723c180
Update README.md
mcarlson Aug 8, 2014
993ad29
first pass on interactive documentation. contains two hard coded plac…
LorienHW Aug 21, 2014
437ef92
Add dragaxis attribute to dragstate
mcarlson Aug 21, 2014
3af699e
Only measure the width if text.measuresize, fix resizing when the mul…
mcarlson Aug 21, 2014
98b3a1f
Fix inline datasets
mcarlson Aug 21, 2014
3750549
Fix https://github.com/teem2/dreem/issues/4
mcarlson Aug 21, 2014
2d67c9f
first pass on interactive documentation. contains two hard coded plac…
LorienHW Aug 21, 2014
531cf36
Merge branch 'documentation' of https://github.com/teem2/dreem into d…
mcarlson Aug 22, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

docs/.idea
*.map
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
rheses
======

running
--------
A web server is currently required to serve LZX autoincludes, as it satisfies the same-origin policy. Any simple web server will do, here's a one liner that works in most cases:

python -m SimpleHTTPServer

Once the server is running, visit [http://localhost:8000/data.html]()

building
--------
This is only required when editing the coffeescript core.

coffee -j layout.js -mo ./ -cw *.coffee


running
--------

python -m SimpleHTTPServer

and visit [http://localhost:8000/data.html]()
93 changes: 93 additions & 0 deletions audio.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<html>
<head>
<title>dr33m</title>
<style type="text/css">
body {
background-color: white;
font-family: 'Helvetica';
font-size: 36px;
margin: 0px;
padding: 0px;
font-size: 14px;
}
input {
font-family: 'Helvetica';
font-size: 14px;
margin: 0px;
padding: 0px;
width: 100px;
}
</style>
<script type="text/javascript" src="lib/jquery-1.9.1.js"></script>
<script type="text/javascript" src="lib/acorn.js"></script>
<script type="text/javascript" src="lib/coffee-script.js"></script>
<script type="text/javascript" src="layout.js"></script>
<link href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
<view>
<shim id="bus"></shim>

<audioplayer id="audio" url="music/03_Homage Sliders.mp3" fftsize="1024" fftsmoothing="0" playing="true">
<handler name="onfft" args="fft">
// Deal with JSON.stringify() issues by converting to a regular array
var copy = Array.apply([], fft);
bus.send('fft', copy);
</handler>
</audioplayer>

<simplelayout attribute="y" axis="height" spacing="0"></simplelayout>

<class name="timetext" extends="text">
<!-- TODO: evaluate setters and overrides -->
<setter name="text" args="time" type="coffee">
minutes = Math.floor(time / 60)
seconds = Math.floor(time) - minutes * 60
seconds = '0' + seconds if (seconds < 10)
text = minutes + ':' + seconds
if (text != @text)
@sprite.text(text)
@updateSize()
</setter>
</class>

<view bgcolor="${audio.playing ? 'green' : 'gray'}" opacity="${audio.loaded ? 1 : .8}" width="${(audio.loadprogress * audio.fftsize * .5)}" height="20">
<handler name="onclick">
audio.toggle();
</handler>
<view name="playhead" bgcolor="red" width="${(audio.time / audio.duration) * this.parent.width}" height="20"></view>
<view y="3" x="${this.parent.playhead.width}" width="${this.parent.width - this.x}">
<simplelayout spacing="2"></simplelayout>
<view width="16" class="fa fa-spin fa-spinner">
<method name="updateState">
if (audio.loaded) {
this.setAttribute('class', 'fa fa-play')
if (audio.playing && ! audio.paused) {
this.setAttribute('class', 'fa fa-pause')
} else {
this.setAttribute('class', 'fa fa-play')
}
} else {
this.setAttribute('class', 'fa fa-spin fa-spinner')
}
</method>
<handler name="onloaded" method="updateState" reference="audio"></handler>
<handler name="onpaused" method="updateState" reference="audio"></handler>
<handler name="onplaying" method="updateState" reference="audio"></handler>
</view>
<view width="16" class="fa fa-stop" onclick="audio.stop()"></view>
<timetext y="-1" text="${audio.time}"></timetext>
<text y="-1">/</text>
<timetext y="-1" text="${audio.duration}"></timetext>
</view>
</view>

<class name="bar" width="1" bgcolor="red" height="${this.data}"></class>

<view height="256">
<simplelayout spacing="0"></simplelayout>
<replicator name="foo" classname="bar" data="${audio.fft}" pooling="true"></replicator>
</view>
</view>
</body>
</html>
132 changes: 132 additions & 0 deletions classes/audioplayer.lzx
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<class name="audioplayer" extends="node">
<attribute name="url" value="" type="string"></attribute>
<attribute name="loadprogress" value="0" type="number"></attribute>
<attribute name="loaded" value="false" type="boolean"></attribute>
<attribute name="playing" value="false" type="boolean"></attribute>
<attribute name="paused" value="false" type="boolean"></attribute>
<attribute name="loop" value="false" type="boolean"></attribute>
<attribute name="time" value="0" type="number"></attribute>
<attribute name="duration" value="0" type="number"></attribute>
<attribute name="fftsize" value="0" type="number"></attribute>
<attribute name="fftsmoothing" value="0.8" type="number"></attribute>
<attribute name="fft" value="[]" type="expression"></attribute>
<handler name="onurl" args="url">
if (! url) return;
var _this = this;
function updateProgress(evt) {
if (evt.lengthComputable) {
var percentComplete = (evt.loaded / evt.total);
_this.setAttribute('loadprogress', percentComplete);
}
}

this.sendEvent('loading', url);
var request = new XMLHttpRequest();
this.setAttribute('loaded', false);
request.open('GET', url, true);
request.onprogress=updateProgress;
request.responseType = 'arraybuffer';

// Decode asynchronously
request.onload = function() {
_this.context.decodeAudioData(request.response, function(buffer) {
_this.buffer = buffer;
_this.setAttribute('duration', buffer.duration);
_this.setAttribute('loaded', true);
if (_this.playing && ! _this.paused) {
_this.play();
}
});
}
this.buffer = null;
request.send();
</handler>
<handler name="oninit">
// Fix up prefixing
window.AudioContext = window.AudioContext || window.webkitAudioContext;
this.context = new AudioContext();
var _this = this;
this.context.oncomplete = function() {
_this.setAttribute('playing', false);
}
this.gain = null;
this.fftNode = null;
this.buffer = null;
this.startOffset = 0;
this.startTime = 0;
</handler>
<method name="play">
this.setAttribute('playing', true);
if (! this.buffer) return;

// track the time when playback started
this.startTime = this.context.currentTime;
this.setAttribute('paused', false);
// creates a sound source
this.source = this.context.createBufferSource();

this.source.loop = this.loop;
// tell the source which sound to play
this.source.buffer = this.buffer;
// Create a gain node.
//this.gain = this.context.createGain();
// Create fft
this.fftNode = this.context.createAnalyser();
if (this.fftsize) {
this.fftNode.fftSize = this.fftsize;
this.fftNode.smoothingTimeConstant = this.fftsmoothing;
}

// Connect the source to the gain node.
this.source.connect(this.fftNode);
// Connect the gain node to the destination.
this.fftNode.connect(this.context.destination);
// play the source now
if (!this.source.start)
this.source.start = source.noteOn;
this.source.start(0, this.startOffset % this.duration);
</method>
<method name="stop">
// store state to start playback after load
this.setAttribute('playing', false);
if (! this.source) return;

if (!this.source.stop)
this.source.stop = source.noteOff;
this.source.stop(0);
this.setAttribute('time', 0);
this.startTime = this.startOffset = 0;
</method>
<method name="pause">
this.setAttribute('paused', true);
if (! this.source) return;
if (!this.source.stop)
this.source.stop = source.noteOff;
this.source.stop();
this.startOffset += (this.context.currentTime - this.startTime);
// console.log('this.startOffset', this.startOffset);
this.setAttribute('paused', true);
</method>
<method name="toggle">
if (! this.playing || this.paused) {
this.play();
} else {
this.pause();
}
</method>
<handler name="onidle" reference="lz.idle">
if (! (this.fftNode && this.playing && ! this.paused)) return;

var time = this.context.currentTime - this.startTime + this.startOffset;
if (time > this.duration) {
this.stop();
}
this.setAttribute('time', time % this.duration);

if (this.fftsize) {
var data = new Uint8Array(this.fftsize);
this.fftNode.getByteFrequencyData(data);
this.setAttribute('fft', data)
}
</handler>
</class>
24 changes: 15 additions & 9 deletions classes/boundslayout.lzx
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
<!-- Set the parent's width/height to match the bounds of all its children -->
<class name="boundslayout" extends="layout" type="coffee">
<attribute name="ignoreattr" type="string" value=""></attribute>
<attribute name="width" type="number" value="0"></attribute>
<attribute name="height" type="number" value="0"></attribute>
<handler name="oninit">
# console.log('oninit', this)
</handler>
<handler name="onsubview" args="subview">
# console.log('onsubview bound', @update, subview, this)
@listenTo(subview, 'x y width height', @update)
listeners = ""
listeners += "width x " unless @ignoreattr == 'width'
listeners += "height y " unless @ignoreattr == 'height'
# console.log('onsubview bound', listeners, subview, this)
@listenTo(subview, listeners, @update)
</handler>
<method name="update" args="value, sender, attribute">
# console.log('skip', @skip, @locked)
return if @skip()
locked = @locked
@locked = true

# TODO: fix to track outliers (and maybe thresholds) and update everything when all outliers go below that threshold
if false # and sender? and value? and (@lastlength == @parent.subviews.length)
# update based on sender attribute where available
Expand All @@ -36,17 +42,17 @@
for subview, len in @parent.subviews
continue if subview.ignorelayout
# console.log 'updating', subview, @attribute, pos
width = Math.max(width, subview.x + subview.width)
height = Math.max(height, subview.y + subview.height)
width = Math.max(width, subview.x + subview.width) unless @ignoreattr == 'width'
height = Math.max(height, subview.y + subview.height) unless @ignoreattr == 'height'
# return if isNaN(width) or isNaN(height)
# console.log 'value', subview, width, height

@lastlength = len

@setAttribute('width', width) unless @.width == width
@setAttribute('height', height) unless @.height == height
@parent.setAttribute('width', width) unless @parent.width == width
@parent.setAttribute('height', height) unless @parent.height == height
@locked = false
@setAttribute('width', width) unless @ignoreattr == 'width' or @width == width
@setAttribute('height', height) unless @ignoreattr == 'height' or @height == height
@parent.setAttribute('width', width) unless @ignoreattr == 'width' or @parent.width == width
@parent.setAttribute('height', height) unless @ignoreattr == 'height' or @parent.height == height
@locked = locked
</method>
</class>
6 changes: 3 additions & 3 deletions classes/dataset.lzx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
lz.datasets[@name] = @
</handler>
<attribute name="url" type="string" value=""></attribute>
<handler name="ontextcontent">
if @textcontent
@setAttribute('data', JSON.parse(@textcontent))
<handler name="on$textcontent">
if @$textcontent
@setAttribute('data', JSON.parse(@$textcontent))
# console.log('data', @name, @data)
</handler>
<handler name="onurl" method="loadURL"></handler>
Expand Down
26 changes: 26 additions & 0 deletions classes/dragstate.lzx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<class name="dragstate" extends="state">
<attribute name="dragaxis" value="both" type="string"></attribute>
<handler name="onapplied" args="applied">
//console.log('onapplied', applied, this)
if (applied) {
var pos = this.parent.getAbsolute();
this.startx = lz.mouse.x - pos.x;
this.starty = lz.mouse.y - pos.y;
//console.log('startx', pos, lz.mouse.x, lz.mouse.y, this.startx, this.starty)
}
</handler>
<handler name="onx" reference="lz.mouse" args="x">
if (this.dragaxis == 'both' || this.dragaxis == 'x') {
this.updatePos('x', x - this.parent.getAbsolute().x - this.startx)
}
</handler>
<handler name="ony" reference="lz.mouse" args="y">
if (this.dragaxis == 'both' || this.dragaxis == 'y') {
this.updatePos('y', y - this.parent.getAbsolute().y - this.starty);
}
</handler>
<method name="updatePos" args="name, val">
//console.log('updatePos', name, val, this, this.updatePos)
this.setAttribute(name, val)
</method>
</class>
27 changes: 27 additions & 0 deletions classes/gyro.lzx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<class name="gyro" scriptincludes="https://raw.githubusercontent.com/tomgco/gyro.js/master/js/gyro.min.js">
<attribute name="x" value="0" type="number"></attribute>
<attribute name="y" value="0" type="number"></attribute>
<attribute name="z" value="0" type="number"></attribute>
<attribute name="alpha" value="0" type="number"></attribute>
<attribute name="beta" value="0" type="number"></attribute>
<attribute name="gamma" value="0" type="number"></attribute>
<attribute name="compass" value="0" type="number"></attribute>
<attribute name="compassaccuracy" value="0" type="number"></attribute>
<handler name="oninit">
var _this = this;
// TODO: use lzidle to throttle
window.addEventListener('devicemotion', function(ev) {
var o = ev.accelerationIncludingGravity;
for (var key in o) {
_this.setAttribute(key, o[key]);
}
});
window.addEventListener('deviceorientation', function(ev) {
_this.setAttribute('alpha', ev.alpha);
_this.setAttribute('beta', ev.beta);
_this.setAttribute('gamma', ev.gamma);
_this.setAttribute('compassaccuracy', ev.webkitCompassAccuracy);
_this.setAttribute('compass', ev.webkitCompassHeading);
});
</handler>
</class>
Loading