summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-06-25 22:37:26 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-06-25 22:38:05 (GMT)
commitb9786455d28bf9dff37a5c88276513549a8be14d (patch)
tree0c6a3aff752a8f1016b26884bcc36c959cf039db
parent64bde3d495236f6f72c618ebc5004656c0fc67cc (diff)
max lenght of show list can now be configured
-rw-r--r--www/js/nextshows.js17
-rw-r--r--www/js/utils.js49
2 files changed, 63 insertions, 3 deletions
diff --git a/www/js/nextshows.js b/www/js/nextshows.js
index 6d85f55..f0f732b 100644
--- a/www/js/nextshows.js
+++ b/www/js/nextshows.js
@@ -69,9 +69,9 @@ rh.Show = function(show) {
var showListView = null;
-rh.ShowListView = function(model, len) {
+rh.ShowListView = function(model, maxlen) {
this.model = model;
- this.len = len;
+ this.maxlen = maxlen;
this.showViews = [];
@@ -97,6 +97,9 @@ rh.ShowListView.prototype.render = function() {
this.showViews.push(showView);
showView.render();
list.append(showView.$el);
+ if(this.showViews.length >= this.maxlen) {
+ break;
+ }
}
};
@@ -128,8 +131,16 @@ rh.ShowView.prototype.render = function() {
/***************** controller *****************/
function nextshows_init() {
+ var url = parseLocationHref();
+ var maxlen = 5;
+ if(url.path.length > 1) {
+ var tmp = parseInt(url.path[1], 10);
+ if(!isNaN(tmp) && tmp > 0) {
+ maxlen = tmp;
+ }
+ }
shows = new rh.ShowList();
- showListView = new rh.ShowListView(shows, 10);
+ showListView = new rh.ShowListView(shows, maxlen);
setInterval("shows.fetch()", 5000);
clock.addCallback(function() {
diff --git a/www/js/utils.js b/www/js/utils.js
index 86c369b..c09628c 100644
--- a/www/js/utils.js
+++ b/www/js/utils.js
@@ -118,3 +118,52 @@ function get_rd_week(msEpoch) {
var week = Math.floor((((sEpoch + 259200)/604800) + 2) % 4) + 1;
return week;
}
+
+function parseLocationHref() {
+ var matches = window.location.href.match(/(https?):\/\/(.*)/);
+ if(matches === null) {
+ return null;
+ }
+
+ var uri = {};
+ uri.scheme = matches[1];
+ uri.servername = '';
+ uri.path = [];
+ uri.query = [];
+ uri.fragment = '';
+
+ if(matches[2].indexOf('/') < 0) {
+ uri.servername = parts[2];
+ return uri;
+ }
+
+ var parts = matches[2].split('/');
+ uri.servername = parts[0];
+ uri.path = parts.slice(1);
+
+ var tmp = uri.path[uri.path.length-1];
+ if(tmp.length > 0) {
+ var qidx = tmp.indexOf('?');
+ var fidx = tmp.indexOf('#');
+
+ var query = '';
+ if(qidx >= 0 && fidx >= 0) {
+ uri.path[uri.path.length-1] = tmp.substring(0, qidx);
+ if(qidx < fidx) {
+ query = tmp.substring(qidx+1, fidx);
+ }
+ uri.fragment = tmp.substring(fidx+1);
+ } else if (qidx >= 0 && fidx < 0) {
+ uri.path[uri.path.length-1] = tmp.substring(0, qidx);
+ query = tmp.substring(qidx+1);
+ } else if (qidx < 0 && fidx >= 0) {
+ uri.path[uri.path.length-1] = tmp.substring(0, fidx);
+ uri.fragment = tmp.substring(fidx+1);
+ }
+ if(query.length > 0) {
+ uri.query = query.split('&');
+ }
+ }
+
+ return uri
+}