Commit 81c8c47f authored by Xiaowu Zhang's avatar Xiaowu Zhang

add music player in erp5

parent 4f3b3cac
.page{position:absolute;top:30%;left:50%}.loader{position:relative}.loader .circle{position:absolute;width:2.5em;height:2.5em;opacity:0;transform:rotate(225deg);animation-iteration-count:infinite;animation-name:orbit;animation-duration:5.5s;-webkit-transform:rotate(225deg);-webkit-animation-iteration-count:infinite;-webkit-animation-name:orbit;-webkit-animation-duration:5.5s;-moz-transform:rotate(225deg);-moz-animation-iteration-count:infinite;-moz-animation-name:orbit;-moz-animation-duration:5.5s}.loader .circle:after{content:'';position:absolute;width:.3em;height:.3em;border-radius:.3em;background:#0e0d0d}.loader .circle:nth-child(2){animation-delay:240ms;-webkit-delay:240ms;-moz-delay:240ms}.loader .circle:nth-child(3){animation-delay:480ms;-webkit-animation-delay:480ms;-moz-animation-delay:480ms}.loader .circle:nth-child(4){animation-delay:720ms;-webkit-animation-delay:720ms;-moz-animation-delay:720ms}.loader .circle:nth-child(5){animation-delay:960ms;-webkit-animation-delay:960ms;-moz-animation-delay:960ms}@keyframes orbit{0%{transform:rotate(225deg);opacity:1;animation-timing-function:ease-out}7%{transform:rotate(345deg);animation-timing-function:linear}30%{transform:rotate(455deg);animation-timing-function:ease-in-out}39%{transform:rotate(690deg);animation-timing-function:linear}70%{transform:rotate(815deg);opacity:1;animation-timing-function:ease-out}75%{transform:rotate(945deg);animation-timing-function:ease-out}76%{transform:rotate(945deg);opacity:0}100%{transform:rotate(945deg);opacity:0}}@-webkit-keyframes orbit{0%{-webkit-transform:rotate(225deg);opacity:1;-webkit-animation-timing-function:ease-out}7%{-webkit-transform:rotate(345deg);-webkit-animation-timing-function:linear}30%{-webkit-transform:rotate(455deg);-webkit-animation-timing-function:ease-in-out}39%{-webkit-transform:rotate(690deg);-webkit-animation-timing-function:linear}70%{-webkit-transform:rotate(815deg);opacity:1;-webkit-animation-timing-function:ease-out}75%{-webkit-transform:rotate(945deg);-webkit-animation-timing-function:ease-out}76%{-webkit-transform:rotate(945deg);opacity:0}100%{-webkit-transform:rotate(945deg);opacity:0}}@-moz-keyframes orbit{0%{-moz-transform:rotate(225deg);opacity:1;-moz-animation-timing-function:ease-out}7%{-moz-transform:rotate(345deg);-moz-animation-timing-function:linear}30%{-moz-transform:rotate(455deg);-moz-animation-timing-function:ease-in-out}39%{-moz-transform:rotate(690deg);-moz-animation-timing-function:linear}70%{-moz-transform:rotate(815deg);opacity:1;-moz-animation-timing-function:ease-out}75%{-moz-transform:rotate(945deg);-moz-animation-timing-function:ease-out}76%{-moz-transform:rotate(945deg);opacity:0}100%{-moz-transform:rotate(945deg);opacity:0}}
\ No newline at end of file
/*global window, rJS, RSVP, console, $, jQuery, URL, location, webkitURL */
/*jslint nomen: true*/
(function(window, rJS, $, RSVP) {
"use strict";
$.mobile.ajaxEnabled = false;
$.mobile.linkBindingEnabled = false;
$.mobile.hashListeningEnabled = false;
$.mobile.pushStateEnabled = false;
var gadget_list = {
upload: {
"0": "../audioplayer_upload/index.html",
"1": "../audioplayer_playlist_local/index.html",
"2": "../audioplayer_playlist_online/index.html"
},
playlist: {
"0": "../audioplayer_playlist_offline/index.html",
"1": "../audioplayer_playlist_local/index.html",
"2": "../audioplayer_playlist_online/index.html"
},
control: {
"0": "../audioplayer_control/index.html",
"1": "../audioplayer_control/index.html",
"2": "../audioplayer_control/index.html"
}
}, allStorageType = [ "offline", "localhost", "online" ];
function storageType(type) {
return allStorageType[type];
}
function disablePage(g) {
var overlay = document.createElement("div"), loader = document.createElement("div"), controlPanel = g.__element.getElementsByClassName("page")[0], i = 0, circle;
if (controlPanel.firstChild) {
return;
}
overlay.className = "overlay";
loader.className = "loader";
while (i < 5) {
circle = document.createElement("div");
circle.className = "circle";
loader.appendChild(circle);
i += 1;
}
overlay.appendChild(loader);
controlPanel.appendChild(overlay);
}
rJS(window).declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").allowPublicAcquisition("plEnablePage", function() {
var controlPanel = this.__element.getElementsByClassName("page")[0];
if (controlPanel) {
while (controlPanel.firstChild) {
controlPanel.removeChild(controlPanel.firstChild);
}
}
}).allowPublicAcquisition("plDisablePage", function() {
disablePage(this);
}).allowPublicAcquisition("plCreateHttpStorage", function(list) {
return this.getDeclaredGadget("online").push(function(gadget) {
return gadget.createJio({
type: "http",
database: list[0]
});
});
}).allowPublicAcquisition("displayThisPage", function(param_list) {
// Hey, I want to display this page
return this.aq_pleasePublishMyState(param_list[0]);
}).allowPublicAcquisition("plSave", function(param_list) {
this.save = this.save || [];
var key = Object.keys(param_list[0]);
this.save[key[0]] = param_list[0][key[0]];
}).allowPublicAcquisition("plGiveStorageType", function() {
return storageType(this.storageType);
}).allowPublicAcquisition("plGive", function(param_list) {
if (this.save === undefined) {
return this.save;
}
return this.save[param_list[0]];
}).allowPublicAcquisition("allDocs", function(param_list) {
if (this.storageType !== 0) {
param_list[0].save = true;
} else {
param_list[0].save = false;
}
return this.getDeclaredGadget(storageType(this.storageType)).push(function(jio_gadget) {
return jio_gadget.allDocs.apply(jio_gadget, param_list);
});
}).allowPublicAcquisition("jio_post", function(param_list) {
var type;
if (param_list[1] === 0) {
type = 0;
} else {
type = this.storageType;
}
return this.getDeclaredGadget(storageType(type)).push(function(jio_gadget) {
return jio_gadget.post.apply(jio_gadget, param_list);
});
}).allowPublicAcquisition("jio_putAttachment", function(param_list) {
var type;
if (param_list[1] === 0) {
type = 0;
} else {
type = this.storageType;
}
return this.getDeclaredGadget(storageType(type)).push(function(jio_gadget) {
return jio_gadget.putAttachment.apply(jio_gadget, param_list);
});
}).allowPublicAcquisition("jio_getAttachment", function(param_list) {
return this.getDeclaredGadget(storageType(this.storageType)).push(function(jio_gadget) {
return jio_gadget.getAttachment.apply(jio_gadget, param_list);
});
}).allowPublicAcquisition("jio_get", function(param_list) {
return this.getDeclaredGadget(storageType(this.storageType)).push(function(jio_gadget) {
return jio_gadget.get.apply(jio_gadget, param_list);
});
}).allowPublicAcquisition("jio_remove", function(param_list) {
if (this.storageType === 0) {
return this.getDeclaredGadget(storageType(this.storageType)).push(function(jio_gadget) {
return jio_gadget.remove.apply(jio_gadget, param_list);
});
}
}).allowPublicAcquisition("displayThisTitle", function(param_list) {
var header = this.__element.getElementsByTagName("h1")[0];
header.innerHTML = param_list[0];
});
rJS(window).ready(function(g) {
return g.getDeclaredGadget("localhost").push(function(gadget) {
return gadget.createJio({
type: "http",
database: "http://localhost:8080/"
});
}).push(function() {
return g.getDeclaredGadget("offline");
}).push(function(gadget) {
return gadget.createJio({
type: "indexeddb",
database: "test"
});
});
}).declareMethod("render", function(options) {
var gadget = this, page_gadget, element, page_element;
element = gadget.__element.getElementsByClassName("gadget_container")[0];
if (options.page === undefined) {
// Redirect to the about page
return gadget.aq_pleasePublishMyState({
page: "playlist"
}).push(gadget.pleaseRedirectMyHash.bind(gadget));
}
gadget.storageType = gadget.storageType || 0;
if (options.page === "playlist") {
if (options.id === "offline") {
gadget.storageType = 0;
gadget.__element.getElementsByClassName("addMusic")[0].style.display = "";
} else if (options.id === "localhost") {
gadget.storageType = 1;
gadget.__element.getElementsByClassName("addMusic")[0].style.display = "none";
} else if (options.id === "online") {
gadget.storageType = 2;
gadget.__element.getElementsByClassName("addMusic")[0].style.display = "none";
}
}
return gadget.declareGadget(gadget_list[options.page][gadget.storageType]).push(function(g) {
disablePage(gadget);
page_gadget = g;
return page_gadget.getElement();
}).push(function(result) {
page_element = result;
while (element.firstChild) {
element.removeChild(element.firstChild);
}
element.appendChild(page_element);
$(element).trigger("create");
if (page_gadget.render !== undefined) {
return page_gadget.render(options);
}
}).push(function() {
// XXX RenderJS hack to start sub gadget services
// Only work if this gadget has no parent.
if (page_gadget.startService !== undefined) {
return page_gadget.startService(options);
}
});
});
})(window, rJS, jQuery, RSVP);
\ No newline at end of file
<!DOCTYPE html>
<!--html manifest="audioPlayer.appcache"-->
<head>
<!-- renderjs -->
<script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script>
<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../lib/jquerymobile.js"></script>
<link rel="stylesheet" href="../lib/jquerymobile.css">
<!-- custom script -->
<script src="./audioplayer.js" type="text/javascript"></script>
<link rel="stylesheet" href="./audioplayer.css" media="screen" ></link>
</head>
<body>
<div data-role="page" class="ui-page" >
<div class="nav" data-role="header" data-theme="b">
<h1>music player</h1>
<a class="addMusic" data-icon="plus" href="#page=upload">add</a>
<a data-icon="grid" href="#page=playlist" >playlist</a>
</div>
<div class="page">
</div>
<div class="offline" data-gadget-url="../audioplayer_bridge/index.html" data-gadget-scope="offline" >
</div>
<div class="localhost" data-gadget-url="../audioplayer_bridge/index.html" data-gadget-scope="localhost" >
</div>
<div class="online" data-gadget-url="../audioplayer_bridge/index.html" data-gadget-scope="online" >
</div>
<article class="gadget_container"></article>
</div>
</body>
</html>
/*global rJS, jIO, console, RSVP, encodeURI */
/*jslint nomen: true*/
(function(rJS, jIO) {
"use strict";
rJS(window).ready(function(gadget) {
// Initialize the gadget local parameters
gadget.state_parameter_dict = {};
gadget.save = {};
}).declareMethod("createJio", function(jio_options) {
this.state_parameter_dict.jio_storage = jIO.createJIO(jio_options);
this.save = {};
}).declareMethod("allDocs", function(options) {
var storage = this.state_parameter_dict.jio_storage, that = this;
if (that.save.data !== undefined) {
return that.save;
}
return storage.allDocs(options).then(function(result) {
if (options.save) {
that.save = result;
}
return result;
});
}).declareMethod("get", function(param) {
var storage = this.state_parameter_dict.jio_storage, result = this.save, length, i;
if (result.data !== undefined) {
length = result.data.rows.length;
for (i = 0; i < length; i += 1) {
if (result.data.rows[i].id === encodeURI(param._id) || result.data.rows[i].id === param._id) {
return {
data: {
title: result.data.rows[i].doc.title
}
};
}
}
}
return storage.get.apply(storage, arguments);
}).declareMethod("getAttachment", function() {
var storage = this.state_parameter_dict.jio_storage;
return storage.getAttachment.apply(storage, arguments).then(function(response) {
return response.data;
});
}).declareMethod("putAttachment", function() {
var storage = this.state_parameter_dict.jio_storage;
return storage.putAttachment.apply(storage, arguments);
}).declareMethod("post", function() {
var storage = this.state_parameter_dict.jio_storage;
return storage.post.apply(storage, arguments);
}).declareMethod("remove", function() {
var storage = this.state_parameter_dict.jio_storage;
return storage.remove.apply(storage, arguments);
}).declareMethod("put", function() {
var storage = this.state_parameter_dict.jio_storage;
return storage.put.apply(storage, arguments);
});
})(rJS, jIO);
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>Jio Gadget</title>
<!-- renderjs -->
<script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/uritemplate.min.js" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script>
<script src="../lib/URI.js" type="text/javascript"></script>
<script src="../lib/jio.js" type="text/javascript"></script>
<!-- custom script -->
<script src="audiogadget.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
button.loop{width:10em}#visualizer{text-align:center}canvas#can{width:50%;height:20%}progress.bar{position:inherit;display:block;height:1em;width:100%;-moz-border-radius:.5em;-webkit-border-radius:.5em;border-radius:.5em;-moz-box-shadow:0 .1em .5em #000 inset,0 .1em 0 #444;-webkit-box-shadow:0 .1em .5em #000 inset,0 .1em 0 #444;box-shadow:0 .1em .5em #000 inset,0 .1em 0 #444}
\ No newline at end of file
This diff is collapsed.
<!DOCTYPE html>
<html lang="en">
<head>
<title>audio control</title>
<!-- renderjs -->
<script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script>
<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../lib/URI.js" type="text/javascript"></script>
<script src="../lib/uritemplate.min.js" type="text/javascript"></script>
<script src="../lib/jio.js" type="text/javascript"></script>
<script src="http://git.erp5.org/gitweb/dream.git/blob_plain/refs/heads/renderjs2:/dream/platform/src2/dream/mixin_promise.js" type="text/javascript"></script>
<!-- custom script -->
<script src="./control.js" type="text/javascript"></script>
<link rel="stylesheet" href="./control.css" media="screen" ></link>
</head>
<body>
<progress class="bar" style="width: 100%;">
</progress>
<div class="box" style="display:none;position:absolute;">
</div>
<div class="time" style="position:relative;">
</div>
<button type="button" data-icon="refresh" class="loop" ></button>
<div id="visualizer">
<canvas id="can" width="800" height="350">
!Canvas not supported by your browser
</canvas>
</div>
<audio controls>
<type="audio/mpeg">
</audio>
<div data-role="collapsible" data-collapsed-icon="gear" data-expanded-icon="minus">
<h1>Equalizer</h1>
<div data-role="fieldcontain">
<select name="type" class="type">
<option value="0">lowpass</option>
<option value="1">highpass</option>
<option value="2">bandpass</option>
<option value="3">lowshelf</option>
<option value="4">highself</option>
<option value="5">peaking</option>
<option value="6">notch</option>
<option value="7">allpass</option>
</select>
</div>
<div data-role="fieldcontain">
<input type="range" class="filter" value="5000" max="20000" min="0">
</div>
</div>
<!-- data-position="fixed" -->
<div data-role="footer" data-position="fixed" data-theme="b">
<div data-role="navbar">
<ul>
<li><a data-role="button" class="mute" data-icon="info" >mute off</a></li>
<li><a data-role="button" class="command" data-icon="gear">stop</a></li>
<li><a data-role="button" class="next" data-icon="arrow-r">next</a></li>
<li><a data-role="button" class="share" data-icon="star" target="_blank">share</a></li>
</ul>
</div><!-- /navbar -->
</div><!-- /footer -->
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- renderjs -->
<script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script>
<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../lib/handlebars.min.js"></script>
<script src="http://git.erp5.org/gitweb/dream.git/blob_plain/refs/heads/renderjs2:/dream/platform/src2/dream/mixin_promise.js" type="text/javascript"></script>
<script id="network" type="text/x-handlebars-template">
{{#each rows}}
<li>
<a href=#page=control&id={{this.id}}&action=localhost>
{{this.doc.title}}
</a>
</li>
{{/each}}
</script>
<!-- custom script -->
<script src="./playlist.js" type="text/javascript"></script>
<body>
<input type="search" class="research" placeholder="research..."/>
<div data-role="content">
<ul data-role="listview" data-split-icon="delete" data-split-theme="d">
</ul>
</div>
<div class="info">
</div>
<div data-role="footer" data-position="fixed" data-theme="b">
<div data-role="navbar" >
<ul>
<li><a data-role="button" class="offline" data-icon="search">offline</a></li>
<li><a data-role="button" class="online" data-icon="search">online</a></li>
</ul>
</div><!-- /navbar -->
</div><!-- /footer -->
</body>
</html>
/*global window, rJS, RSVP, console, jQuery, $, JSON, Handlebars,
loopEventListener, RegExp */
/*jslint maxlen:80, nomen: true */
(function(window, rJS, $, Handlebars, loopEventListener) {
"use strict";
var gk = rJS(window), network_source = gk.__template_element.getElementById("network").innerHTML, network = Handlebars.compile(network_source);
gk.declareAcquiredMethod("allDocs", "allDocs").declareAcquiredMethod("displayThisPage", "displayThisPage").declareAcquiredMethod("displayThisTitle", "displayThisTitle").declareAcquiredMethod("plEnablePage", "plEnablePage").declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").declareMethod("render", function(options) {
var gadget = this, list = gadget.__element.getElementsByTagName("ul")[0];
return new RSVP.Queue().push(function() {
return RSVP.all([ gadget.displayThisPage({
page: "playlist",
id: "offline"
}), gadget.displayThisPage({
page: "playlist",
id: "online"
}) ]);
}).push(function(param_list) {
gadget.__element.getElementsByClassName("offline")[0].href = param_list[0];
gadget.__element.getElementsByClassName("online")[0].href = param_list[1];
}).push(function() {
return gadget.allDocs({
include_docs: true
});
}).push(function(e) {
var tmp = e.data.rows, i, j, exp;
if (options.id !== undefined && options.id !== "localhost") {
tmp = [];
for (i = 0, j = 0; i < e.data.rows.length; i += 1) {
exp = new RegExp(options.id, "i");
if (e.data.rows[i].doc.title.search(exp) !== -1) {
tmp[j] = e.data.rows[i];
j += 1;
}
}
gadget.id = options.id;
}
list.innerHTML = network({
rows: tmp
});
$(list).listview("refresh");
return gadget.displayThisTitle("localhost playlist: " + tmp.length + " music");
}).fail(function(error) {
if (!(error instanceof RSVP.CancellationError)) {
gadget.__element.getElementsByClassName("info")[0].innerHTML = "please enable local server";
}
});
}).declareMethod("startService", function() {
var g = this, research = g.__element.getElementsByClassName("research")[0];
if (g.id !== undefined) {
research.value = g.id;
}
return new RSVP.Queue().push(function() {
return g.plEnablePage();
}).push(function() {
return loopEventListener(research, "change", false, function() {
return new RSVP.Queue().push(function() {
return g.displayThisPage({
page: "playlist",
id: research.value
});
}).push(function(url) {
window.location = url;
});
});
});
});
})(window, rJS, jQuery, Handlebars, loopEventListener);
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<!-- renderjs -->
<script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script>
<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../lib/handlebars.min.js"></script>
<script src="http://git.erp5.org/gitweb/dream.git/blob_plain/refs/heads/renderjs2:/dream/platform/src2/dream/mixin_promise.js" type="text/javascript"></script>
<script id="rows-template" type="text/x-handlebars-template">
{{#each rows}}
<li>
<a href=#page=control&id={{this.id}}&action=offline>
{{this.doc.title}}
</a>
<a href=#page=playlist&id={{this.id}}&action=delete>
data-rel=popup
data-position-to=window
</a>
</li>
{{/each}}
</script>
<!-- custom script -->
<script src="./playlist.js" type="text/javascript"></script>
<body>
<input type="search" class="research" placeholder="research..."/>
<div data-role="content">
<ul data-role="listview" data-split-icon="delete" data-split-theme="d">
</ul>
</div>
<div data-role="footer" data-position="fixed" data-theme="b">
<div data-role="navbar" >
<ul>
<li><a data-role="button" class="localhost" data-icon="search">localhost</a></li>
<li><a data-role="button" class="online" data-icon="search">online</a></li>
</ul>
</div><!-- /navbar -->
</div><!-- /footer -->
</body>
</html>
/*global window, rJS, RSVP, console, jQuery, $, JSON, Handlebars,
loopEventListener, RegExp */
/*jslint maxlen:80, nomen: true */
(function(window, rJS, $, Handlebars, loopEventListener) {
"use strict";
var gk = rJS(window), rows_template_source = gk.__template_element.getElementById("rows-template").innerHTML, rows_template = Handlebars.compile(rows_template_source);
gk.declareAcquiredMethod("allDocs", "allDocs").declareAcquiredMethod("jio_remove", "jio_remove").declareAcquiredMethod("displayThisPage", "displayThisPage").declareAcquiredMethod("displayThisTitle", "displayThisTitle").declareAcquiredMethod("plEnablePage", "plEnablePage").declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").declareMethod("render", function(options) {
var gadget = this, list = gadget.__element.getElementsByTagName("ul")[0];
return new RSVP.Queue().push(function() {
return RSVP.all([ gadget.displayThisPage({
page: "playlist",
id: "localhost"
}), gadget.displayThisPage({
page: "playlist",
id: "online"
}) ]);
}).push(function(param_list) {
gadget.__element.getElementsByClassName("localhost")[0].href = param_list[0];
gadget.__element.getElementsByClassName("online")[0].href = param_list[1];
}).push(function() {
var id = options.id;
if (options.action === "delete") {
delete options.id;
return gadget.jio_remove({
_id: id
});
}
}).push(function() {
return gadget.allDocs({
include_docs: true
});
}).push(function(e) {
var tmp = e.data.rows, i, j, exp;
if (options.id !== undefined && options.id !== "offline") {
tmp = [];
for (i = 0, j = 0; i < e.data.rows.length; i += 1) {
exp = new RegExp(options.id, "i");
if (e.data.rows[i].doc.title.search(exp) !== -1) {
tmp[j] = e.data.rows[i];
j += 1;
}
}
gadget.id = options.id;
}
list.innerHTML = rows_template({
rows: tmp
});
$(list).listview("refresh");
return gadget.displayThisTitle("offline playlist: " + tmp.length + " music");
}).fail(function(error) {
if (!(error instanceof RSVP.CancellationError)) {
console.log("error");
}
});
}).declareMethod("startService", function() {
var g = this, research = g.__element.getElementsByClassName("research")[0];
if (g.id !== undefined) {
research.value = g.id;
}
return new RSVP.Queue().push(function() {
return g.plEnablePage();
}).push(function() {
return loopEventListener(research, "change", false, function() {
return new RSVP.Queue().push(function() {
return g.displayThisPage({
page: "playlist",
id: research.value
});
}).push(function(url) {
window.location = url;
});
});
});
});
})(window, rJS, jQuery, Handlebars, loopEventListener);
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<!-- renderjs -->
<script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script>
<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../lib/handlebars.min.js"></script>
<script src="http://git.erp5.org/gitweb/dream.git/blob_plain/refs/heads/renderjs2:/dream/platform/src2/dream/mixin_promise.js" type="text/javascript"></script>
<script id="network" type="text/x-handlebars-template">
{{#each rows}}
<li>
<a href=#page=control&id={{this.id}}&action=online>
{{this.doc.title}}
</a>
</li>
{{/each}}
</script>
<!-- custom script -->
<script src="./playlist.js" type="text/javascript"></script>
<body>
<input type="text" class="inputIp" placeholder="input ip: http://xxx.xxx.xxx.xxx:port/(xxx is between 0 ~ 255) or url"/>
<input type="search" class="research" placeholder="research..."/>
<div data-role="content">
<ul data-role="listview" data-split-icon="delete" data-split-theme="d">
</ul>
</div>
<div class="info">
</div>
<div data-role="footer" data-position="fixed" data-theme="b">
<div data-role="navbar" >
<ul>
<li><a data-role="button" class="offline" data-icon="search">offline</a></li>
<li><a data-role="button" class="localhost" data-icon="search">localhost</a></li>
</ul>
</div><!-- /navbar -->
</div><!-- /footer -->
</body>
</html>
/*global window, rJS, RSVP, console, jQuery, $, JSON, Handlebars,
loopEventListener, RegExp, alert, promiseEventListener */
/*jslint maxlen:180, nomen: true, regexp: true */
(function(window, rJS, $, Handlebars, loopEventListener) {
"use strict";
var gk = rJS(window), network_source = gk.__template_element.getElementById("network").innerHTML, network = Handlebars.compile(network_source);
function endWith(str, end) {
return str.indexOf(end, str.length - end.length) !== -1;
}
function contain(str, s) {
return str.indexOf(s) !== -1;
}
function checkUrl(url) {
return contain(url, ".com") || contain(url, ".net") || contain(url, ".fr");
}
function checkIp(ip) {
var re = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
return re.test(ip);
}
function check(value) {
var g = this, info = g.__element.getElementsByClassName("info")[0], http, port, portEnd, ipValue = value;
g.__element.getElementsByTagName("ul")[0].innerHTML = " ";
http = ipValue.indexOf("http");
if (ipValue.indexOf("www.") !== -1) {
if (http === -1) {
info.innerHTML = "please start with http:// or https://";
return;
}
if (!checkUrl(ipValue)) {
info.innerHTML = "url invalide";
return;
}
} else {
ipValue = ipValue.substring(ipValue.indexOf("//") + 2);
port = ipValue.indexOf(":");
portEnd = ipValue.indexOf(":/");
if (port !== -1) {
ipValue = ipValue.substring(0, port);
}
if (http === -1) {
info.innerHTML = "please start ip with http:// or https://";
return;
}
if (port === -1 || portEnd !== -1) {
info.innerHTML = "input port number";
return;
}
if (checkIp(ipValue) === false) {
info.innerHTML = "invalide ip: ip should like xxx.xxx.xxx.xxx(xxx is between 0 ~ 255)";
return;
}
if (!endWith(value, "/")) {
info.innerHTML = "not end with /";
return;
}
}
return new RSVP.Queue().push(function() {
return g.plSave({
ip: value
});
}).push(function() {
return g.displayThisPage({
page: "playlist",
action: value
});
}).push(function(url) {
window.location = url;
});
}
gk.declareAcquiredMethod("allDocs", "allDocs").declareAcquiredMethod("plSave", "plSave").declareAcquiredMethod("plGive", "plGive").declareAcquiredMethod("displayThisPage", "displayThisPage").declareAcquiredMethod("displayThisTitle", "displayThisTitle").declareAcquiredMethod("plCreateHttpStorage", "plCreateHttpStorage").declareAcquiredMethod("plEnablePage", "plEnablePage").declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").declareMethod("render", function(options) {
var gadget = this, ipValue, ip_context = gadget.__element.getElementsByClassName("inputIp")[0], list = gadget.__element.getElementsByTagName("ul")[0];
return new RSVP.Queue().push(function() {
return RSVP.all([ gadget.displayThisPage({
page: "playlist",
id: "offline"
}), gadget.displayThisPage({
page: "playlist",
id: "localhost"
}) ]);
}).push(function(param_list) {
gadget.__element.getElementsByClassName("offline")[0].href = param_list[0];
gadget.__element.getElementsByClassName("localhost")[0].href = param_list[1];
}).push(function() {
if (options.action) {
return options.action;
}
return gadget.plGive("ip");
}).push(function(value) {
if (value !== undefined) {
ipValue = value;
ip_context.value = value;
if (options.action) {
return gadget.plCreateHttpStorage(value);
}
}
}).push(function() {
return RSVP.any([ gadget.allDocs({
include_docs: true
}), promiseEventListener(ip_context, "change", false) ]);
}).push(function(e) {
if (e.data) {
var tmp = e.data.rows, i, j, exp;
if (options.id !== undefined && options.id !== "online") {
tmp = [];
for (i = 0, j = 0; i < e.data.rows.length; i += 1) {
exp = new RegExp(options.id, "i");
if (e.data.rows[i].doc.title.search(exp) !== -1) {
tmp[j] = e.data.rows[i];
j += 1;
}
}
gadget.id = options.id;
}
list.innerHTML = network({
rows: tmp
});
$(list).listview("refresh");
return gadget.displayThisTitle("online playlist: " + tmp.length + " music");
}
return check.call(gadget, ip_context.value);
}).fail(function(error) {
if (ipValue) {
gadget.__element.getElementsByClassName("info")[0].innerHTML = "network error";
}
return gadget.displayThisTitle("online playlist: " + "0 music");
});
}).declareMethod("startService", function() {
var g = this, research = g.__element.getElementsByClassName("research")[0], ip = g.__element.getElementsByClassName("inputIp")[0];
if (g.id !== undefined) {
research.value = g.id;
}
return new RSVP.Queue().push(function() {
return g.plEnablePage();
}).push(function() {
return RSVP.any([ loopEventListener(research, "change", false, function() {
return new RSVP.Queue().push(function() {
return g.displayThisPage({
page: "playlist",
id: research.value
});
}).push(function(url) {
window.location = url;
});
}), loopEventListener(ip, "change", false, function() {
return check.call(g, ip.value);
}) ]);
});
});
})(window, rJS, jQuery, Handlebars, loopEventListener);
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<title>audioplayer io</title>
<!-- renderjs -->
<script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script>
<!-- jio core dependencies -->
<script src="../lib/URI.js" type="text/javascript"></script>
<script src="../lib/uritemplate.min.js" type="text/javascript"></script>
<script src="../lib/jio.js" type="text/javascript"></script>
<script src="http://git.erp5.org/gitweb/dream.git/blob_plain/refs/heads/renderjs2:/dream/platform/src2/dream/mixin_promise.js" type="text/javascript"></script>
<!-- custom script -->
<script src="./upload.js" type="text/javascript"></script>
</head>
<body>
<h1> the music uploaded is duplicated in browser, using of localhost or online is recommmended </h1>
<input type="file" multiple />
<ul class="info">
</ul>
</body>
</html>
/*global window, rJS, RSVP, jIO, JSON, promiseEventListener, console,
Error*/
/*jslint nomen: true*/
(function(window, jIO, rJS) {
"use strict";
var gk = rJS(window);
gk.declareAcquiredMethod("jio_post", "jio_post").declareAcquiredMethod("jio_putAttachment", "jio_putAttachment").declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").declareAcquiredMethod("displayThisPage", "displayThisPage").declareAcquiredMethod("displayThisTitle", "displayThisTitle").declareAcquiredMethod("plEnablePage", "plEnablePage").declareAcquiredMethod("plDisablePage", "plDisablePage").declareMethod("render", function() {
return this.displayThisTitle("upload");
}).declareMethod("startService", function() {
var g = this, input_context = g.__element.getElementsByTagName("input")[0], info_context = g.__element.getElementsByClassName("info")[0], queue, uploaded = 0, length;
function post() {
if (uploaded === length) {
return;
}
var now = new Date();
return g.jio_post({
title: input_context.files[uploaded].name,
type: "file",
format: input_context.files[uploaded].type,
size: input_context.files[uploaded].size,
modified: now.toUTCString(),
date: now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate()
}, 0).then(function(res) {
return g.jio_putAttachment({
_id: res.id,
_attachment: "enclosure",
_blob: input_context.files[uploaded]
}, 0);
}).then(function() {
uploaded += 1;
info_context.innerHTML += "<li>" + input_context.files[uploaded - 1].name + " " + uploaded + "/" + length + "</li>";
if (uploaded === length) {
return g.plEnablePage();
}
queue.push(post);
}).fail(function(error) {
if (!(error instanceof RSVP.CancellationError)) {
info_context.innerHTML += input_context.files[uploaded].name + " failed : storage maybe insufficient";
return g.plEnablePage();
}
document.getElementsByTagName("body")[0].textContent = JSON.stringify(error);
});
}
queue = new RSVP.Queue();
queue.push(function() {
return g.plEnablePage();
}).push(function() {
return promiseEventListener(input_context, "change", false);
}).push(function() {
return g.plDisablePage();
}).push(function() {
length = input_context.files.length;
queue.push(post);
});
return queue;
});
})(window, jIO, rJS);
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
!function(e){"use strict";function t(e){var n;if(null===e||void 0===e)return!1;if(r.isArray(e))return e.length>0;if("string"==typeof e||"number"==typeof e||"boolean"==typeof e)return!0;for(n in e)if(e.hasOwnProperty(n)&&t(e[n]))return!0;return!1}var n=function(){function e(e){this.options=e}return e.prototype.toString=function(){return JSON&&JSON.stringify?JSON.stringify(this.options):this.options},e}(),r=function(){function e(e){return"[object Array]"===Object.prototype.toString.apply(e)}function t(e){return"[object String]"===Object.prototype.toString.apply(e)}function n(e){return"[object Number]"===Object.prototype.toString.apply(e)}function r(e){return"[object Boolean]"===Object.prototype.toString.apply(e)}function i(e,t){var n,r="",i=!0;for(n=0;n<e.length;n+=1)i?i=!1:r+=t,r+=e[n];return r}function o(e,t){for(var n=[],r=0;r<e.length;r+=1)n.push(t(e[r]));return n}function s(e,t){for(var n=[],r=0;r<e.length;r+=1)t(e[r])&&n.push(e[r]);return n}function a(e){if("object"!=typeof e||null===e)return e;Object.freeze(e);var t,n;for(n in e)e.hasOwnProperty(n)&&(t=e[n],"object"==typeof t&&u(t));return e}function u(e){return"function"==typeof Object.freeze?a(e):e}return{isArray:e,isString:t,isNumber:n,isBoolean:r,join:i,map:o,filter:s,deepFreeze:u}}(),i=function(){function e(e){return e>="a"&&"z">=e||e>="A"&&"Z">=e}function t(e){return e>="0"&&"9">=e}function n(e){return t(e)||e>="a"&&"f">=e||e>="A"&&"F">=e}return{isAlpha:e,isDigit:t,isHexDigit:n}}(),o=function(){function e(e){var t,n,r="",i=s.encode(e);for(n=0;n<i.length;n+=1)t=i.charCodeAt(n),r+="%"+(16>t?"0":"")+t.toString(16).toUpperCase();return r}function t(e,t){return"%"===e.charAt(t)&&i.isHexDigit(e.charAt(t+1))&&i.isHexDigit(e.charAt(t+2))}function n(e,t){return parseInt(e.substr(t,2),16)}function r(e){if(!t(e,0))return!1;var r=n(e,1),i=s.numBytes(r);if(0===i)return!1;for(var o=1;i>o;o+=1)if(!t(e,3*o)||!s.isValidFollowingCharCode(n(e,3*o+1)))return!1;return!0}function o(e,r){var i=e.charAt(r);if(!t(e,r))return i;var o=n(e,r+1),a=s.numBytes(o);if(0===a)return i;for(var u=1;a>u;u+=1)if(!t(e,r+3*u)||!s.isValidFollowingCharCode(n(e,r+3*u+1)))return i;return e.substr(r,3*a)}var s={encode:function(e){return unescape(encodeURIComponent(e))},numBytes:function(e){return 127>=e?1:e>=194&&223>=e?2:e>=224&&239>=e?3:e>=240&&244>=e?4:0},isValidFollowingCharCode:function(e){return e>=128&&191>=e}};return{encodeCharacter:e,isPctEncoded:r,pctCharAt:o}}(),s=function(){function e(e){return i.isAlpha(e)||i.isDigit(e)||"_"===e||o.isPctEncoded(e)}function t(e){return i.isAlpha(e)||i.isDigit(e)||"-"===e||"."===e||"_"===e||"~"===e}function n(e){return":"===e||"/"===e||"?"===e||"#"===e||"["===e||"]"===e||"@"===e||"!"===e||"$"===e||"&"===e||"("===e||")"===e||"*"===e||"+"===e||","===e||";"===e||"="===e||"'"===e}return{isVarchar:e,isUnreserved:t,isReserved:n}}(),a=function(){function e(e,t){var n,r="",i="";for(("number"==typeof e||"boolean"==typeof e)&&(e=e.toString()),n=0;n<e.length;n+=i.length)i=e.charAt(n),r+=s.isUnreserved(i)||t&&s.isReserved(i)?i:o.encodeCharacter(i);return r}function t(t){return e(t,!0)}function n(e,t){var n=o.pctCharAt(e,t);return n.length>1?n:s.isReserved(n)||s.isUnreserved(n)?n:o.encodeCharacter(n)}function r(e){var t,n="",r="";for(t=0;t<e.length;t+=r.length)r=o.pctCharAt(e,t),n+=r.length>1?r:s.isReserved(r)||s.isUnreserved(r)?r:o.encodeCharacter(r);return n}return{encode:e,encodePassReserved:t,encodeLiteral:r,encodeLiteralCharacter:n}}(),u=function(){function e(e){t[e]={symbol:e,separator:"?"===e?"&":""===e||"+"===e||"#"===e?",":e,named:";"===e||"&"===e||"?"===e,ifEmpty:"&"===e||"?"===e?"=":"",first:"+"===e?"":e,encode:"+"===e||"#"===e?a.encodePassReserved:a.encode,toString:function(){return this.symbol}}}var t={};return e(""),e("+"),e("#"),e("."),e("/"),e(";"),e("?"),e("&"),{valueOf:function(e){return t[e]?t[e]:"=,!@|".indexOf(e)>=0?null:t[""]}}}(),p=function(){function e(e){this.literal=a.encodeLiteral(e)}return e.prototype.expand=function(){return this.literal},e.prototype.toString=e.prototype.expand,e}(),f=function(){function e(e){function t(){var t=e.substring(h,p);if(0===t.length)throw new n({expressionText:e,message:"a varname must be specified",position:p});c={varname:t,exploded:!1,maxLength:null},h=null}function r(){if(d===p)throw new n({expressionText:e,message:"after a ':' you have to specify the length",position:p});c.maxLength=parseInt(e.substring(d,p),10),d=null}var a,p,f=[],c=null,h=null,d=null,g="";for(a=function(t){var r=u.valueOf(t);if(null===r)throw new n({expressionText:e,message:"illegal use of reserved operator",position:p,operator:t});return r}(e.charAt(0)),p=a.symbol.length,h=p;p<e.length;p+=g.length){if(g=o.pctCharAt(e,p),null!==h){if("."===g){if(h===p)throw new n({expressionText:e,message:"a varname MUST NOT start with a dot",position:p});continue}if(s.isVarchar(g))continue;t()}if(null!==d){if(p===d&&"0"===g)throw new n({expressionText:e,message:"A :prefix must not start with digit 0",position:p});if(i.isDigit(g)){if(p-d>=4)throw new n({expressionText:e,message:"A :prefix must have max 4 digits",position:p});continue}r()}if(":"!==g)if("*"!==g){if(","!==g)throw new n({expressionText:e,message:"illegal character",character:g,position:p});f.push(c),c=null,h=p+1}else{if(null===c)throw new n({expressionText:e,message:"exploded without varspec",position:p});if(c.exploded)throw new n({expressionText:e,message:"exploded twice",position:p});if(c.maxLength)throw new n({expressionText:e,message:"an explode (*) MUST NOT follow to a prefix",position:p});c.exploded=!0}else{if(null!==c.maxLength)throw new n({expressionText:e,message:"only one :maxLength is allowed per varspec",position:p});if(c.exploded)throw new n({expressionText:e,message:"an exploeded varspec MUST NOT be varspeced",position:p});d=p+1}}return null!==h&&t(),null!==d&&r(),f.push(c),new l(e,a,f)}function t(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function r(r){var i,o,s,a=[],u=null,f="",l=!0,h=0;for(i=0;i<r.length;i+=1)if(o=r.charAt(i),null===h){if(null===u)throw new Error("reached unreachable code");if("{"===o)throw new n({templateText:r,message:"brace already opened",position:i});if("}"===o){if(u+1===i)throw new n({templateText:r,message:"empty braces",position:u});try{s=e(r.substring(u+1,i))}catch(d){if(d.prototype===n.prototype)throw new n({templateText:r,message:d.options.message,position:u+d.options.position,details:d.options});throw d}a.push(s),0===s.operator.symbol.length?f+="([^/]+)":l=!1,u=null,h=i+1}}else{if("}"===o)throw new n({templateText:r,message:"unopened brace closed",position:i});"{"===o&&(i>h&&(s=new p(r.substring(h,i)),a.push(s),f+=t(s.literal)),h=null,u=i)}if(null!==u)throw new n({templateText:r,message:"unclosed brace",position:u});return h<r.length&&(s=new p(r.substring(h)),a.push(s),f+=t(s.literal)),l===!1&&(f=void 0),new c(r,a,f)}return r}(),l=function(){function e(e){return JSON&&JSON.stringify?JSON.stringify(e):e}function n(e){if(!t(e))return!0;if(r.isString(e))return""===e;if(r.isNumber(e)||r.isBoolean(e))return!1;if(r.isArray(e))return 0===e.length;for(var n in e)if(e.hasOwnProperty(n))return!1;return!0}function i(e){var t,n=[];for(t in e)e.hasOwnProperty(t)&&n.push({name:t,value:e[t]});return n}function o(e,t,n){this.templateText=e,this.operator=t,this.varspecs=n}function s(e,t,n){var r="";if(n=n.toString(),t.named){if(r+=a.encodeLiteral(e.varname),""===n)return r+=t.ifEmpty;r+="="}return null!==e.maxLength&&(n=n.substr(0,e.maxLength)),r+=t.encode(n)}function u(e){return t(e.value)}function p(e,o,s){var p=[],f="";if(o.named){if(f+=a.encodeLiteral(e.varname),n(s))return f+=o.ifEmpty;f+="="}return r.isArray(s)?(p=s,p=r.filter(p,t),p=r.map(p,o.encode),f+=r.join(p,",")):(p=i(s),p=r.filter(p,u),p=r.map(p,function(e){return o.encode(e.name)+","+o.encode(e.value)}),f+=r.join(p,",")),f}function f(e,o,s){var p=r.isArray(s),f=[];return p?(f=s,f=r.filter(f,t),f=r.map(f,function(t){var r=a.encodeLiteral(e.varname);return r+=n(t)?o.ifEmpty:"="+o.encode(t)})):(f=i(s),f=r.filter(f,u),f=r.map(f,function(e){var t=a.encodeLiteral(e.name);return t+=n(e.value)?o.ifEmpty:"="+o.encode(e.value)})),r.join(f,o.separator)}function l(e,n){var o=[],s="";return r.isArray(n)?(o=n,o=r.filter(o,t),o=r.map(o,e.encode),s+=r.join(o,e.separator)):(o=i(n),o=r.filter(o,function(e){return t(e.value)}),o=r.map(o,function(t){return e.encode(t.name)+"="+e.encode(t.value)}),s+=r.join(o,e.separator)),s}return o.prototype.toString=function(){return this.templateText},o.prototype.expand=function(i){var o,a,u,c,h=[],d=!1,g=this.operator;for(o=0;o<this.varspecs.length;o+=1)if(a=this.varspecs[o],u=i[a.varname],null!==u&&void 0!==u)if(a.exploded&&(d=!0),c=r.isArray(u),"string"==typeof u||"number"==typeof u||"boolean"==typeof u)h.push(s(a,g,u));else{if(a.maxLength&&t(u))throw new Error("Prefix modifiers are not applicable to variables that have composite values. You tried to expand "+this+" with "+e(u));a.exploded?t(u)&&(g.named?h.push(f(a,g,u)):h.push(l(g,u))):(g.named||!n(u))&&h.push(p(a,g,u))}return 0===h.length?"":g.first+r.join(h,g.separator)},o}(),c=function(){function e(e,t,n){this.templateText=e,this.expressions=t,void 0!==n&&(this.regexp=new RegExp("^"+n+"$")),r.deepFreeze(this)}return e.prototype.toString=function(){return this.templateText},e.prototype.expand=function(e){var t,n="";for(t=0;t<this.expressions.length;t+=1)n+=this.expressions[t].expand(e);return n},e.prototype.extract=function(e){var t,n,r,i,o=1,s=!0,a={};if(void 0!==this.regexp&&this.regexp.test(e)){for(i=this.regexp.exec(e),t=0;t<this.expressions.length;t+=1)n=this.expressions[t],void 0===n.literal&&(void 0!==n.operator&&0===n.operator.symbol.length&&1===n.varspecs.length?(r=n.varspecs[0],r.exploded===!1&&null===r.maxLength?-1===i[o].indexOf(",")?(a[r.varname]=decodeURIComponent(i[o]),o+=1):s=!1:s=!1):s=!1);if(s)return a}return!1},e.parse=f,e.UriTemplateError=n,e}();e(c)}(function(e){"use strict";"undefined"!=typeof module?module.exports=e:"function"==typeof define?define([],function(){return e}):"undefined"!=typeof window?window.UriTemplate=e:global.UriTemplate=e});
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment