forked from googlecreativelab/chrome-music-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug fixes and updates to Sound Spinner experiment
iOS tapper fixes, etc
- Loading branch information
1 parent
d09f254
commit 3243605
Showing
15 changed files
with
356 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright 2016 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
define(function () { | ||
|
||
var OrientationListener = function(callback){ | ||
|
||
window.addEventListener("orientationchange", this._changed.bind(this)); | ||
if (window.screen && window.screen.orientation){ | ||
window.screen.orientation.addEventListener("change", this._screenChange.bind(this)); | ||
} | ||
|
||
this._callback = callback; | ||
}; | ||
|
||
OrientationListener.prototype._changed = function(){ | ||
//check if it's landscape | ||
if (Math.abs(window.orientation) === 90){ | ||
this._callback(); | ||
} | ||
}; | ||
|
||
OrientationListener.prototype._screenChange = function(){ | ||
//check if it's landscape | ||
if (Math.abs(window.screen.orientation.angle) === 90){ | ||
this._callback(); | ||
} | ||
}; | ||
|
||
return OrientationListener; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/** | ||
* Copyright 2016 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
define(["slider.scss"], function (mainStyle) { | ||
|
||
var Slider = function(container, min, max, initialValue){ | ||
|
||
/** | ||
* The minimum slider value | ||
* @type {Number} | ||
* @private | ||
*/ | ||
this._min = min || 0; | ||
|
||
/** | ||
* The maximum slider value | ||
* @type {Number} | ||
* @private | ||
*/ | ||
this._max = max || 100; | ||
|
||
/** | ||
* The slider container | ||
* @type {Element} | ||
* @private | ||
*/ | ||
this._container = document.createElement("div"); | ||
this._container.classList.add("Slider"); | ||
this._container.id = "SpeedSlider"; | ||
container.appendChild(this._container); | ||
|
||
/** | ||
* The slider which captures the inputs | ||
* @type {Element} | ||
* @private | ||
*/ | ||
this._range = document.createElement("input"); | ||
this._range.type = "range"; | ||
this._range.id = "Range"; | ||
this._range.min = min; | ||
this._range.max = max; | ||
this._range.step = 0.01; | ||
this._container.appendChild(this._range); | ||
this._range.addEventListener("input", this._change.bind(this)); | ||
|
||
/** | ||
* The railing behind the handle | ||
* @type {Element} | ||
* @private | ||
*/ | ||
this._rail = document.createElement("div"); | ||
this._rail.id = "Rail"; | ||
this._container.appendChild(this._rail); | ||
|
||
/** | ||
* The railing behind the handle | ||
* @type {Element} | ||
* @private | ||
*/ | ||
this._dot = document.createElement("div"); | ||
this._dot.id = "Dot"; | ||
this._rail.appendChild(this._dot); | ||
|
||
/** | ||
* The handle of the slider | ||
* @type {Element} | ||
* @private | ||
*/ | ||
this._handle = document.createElement("div"); | ||
this._handle.id = "Handle"; | ||
this._container.appendChild(this._handle); | ||
|
||
/** | ||
* Internal number holder | ||
* @type {Number} | ||
* @private | ||
*/ | ||
this._value = 0; | ||
|
||
/** | ||
* Onchange handler | ||
* @type {Function} | ||
*/ | ||
this.onchange = function(){}; | ||
|
||
//set the position initially | ||
this.setValue(initialValue || 0); | ||
|
||
//add a resize handler | ||
window.addEventListener("resize", this._update.bind(this)); | ||
}; | ||
|
||
Slider.prototype._change = function(){ | ||
this._update(); | ||
this._value = parseFloat(this._range.value); | ||
this.onchange(this._range.value); | ||
}; | ||
|
||
Slider.prototype._update = function(){ | ||
var percent = (this._range.value - this._min) / (this._max - this._min); | ||
|
||
if (Math.abs(this._range.value) < 0.15){ | ||
this._range.value = 0; | ||
percent = 0.5; | ||
} | ||
|
||
var handleOffset = this._handle.offsetWidth * percent; | ||
var halfHandle = this._handle.offsetWidth / 2; | ||
var percentPixels = percent * this._container.offsetWidth; | ||
//computer the width in pixels | ||
this._handle.style.left = (percentPixels - handleOffset).toString() + "px"; | ||
}; | ||
|
||
Slider.prototype.animateIn = function(){ | ||
this._container.classList.add("Visible"); | ||
}; | ||
|
||
Slider.prototype.setValue = function(val){ | ||
this._value = val; | ||
this._range.value = val; | ||
this._update(); | ||
}; | ||
|
||
Slider.prototype.getValue = function(){ | ||
return this._value; | ||
}; | ||
|
||
return Slider; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.