4 function ucwords (str
) {
5 return (str
+ '').replace(/^([a-z])|\s+([a-z])/g, function ($1) {
6 return $1.toUpperCase();
10 function arrayRemoveValue(arr
){
11 var what
, a
= arguments
, L
= a
.length
, ax
;
12 while(L
> 1 && arr
.length
){
14 while((ax
= arr
.indexOf(what
))!= -1){
21 var STATUS_PAUSED
= 0,
24 var RotationalView = function () {
26 var self
= Object
.create(RotationalView
.prototype);
30 basepath
: _site_domain
+ _index_page
,
34 interval_increment
: 1000,
40 self
.status
= STATUS_PAUSED
;
43 self
.frame
= $('#rotation-frame');
44 self
.help
= $('#page-rotation-initial');
53 $.ajax(self
.config
.basepath
+ '/ajax/get_setting', {
56 'type': 'rotation_queue',
57 'page': 'page_rotation'
62 success: function (obj
) {
64 var pages
= obj
['rotation_queue'] || [];
66 if (pages
.length
>= 1) {
67 $('#page-rotation-play').css('opacity','1.0');
70 for (var i
= 0; i
< pages
.length
; i
+= 1) {
83 RotationalView
.prototype = {
86 return this.pages
[this.current
];
89 hoisting
: function hoisting (frame
) {
93 frame
.load(function () {
95 var contents
= frame
.contents().find('body').children(),
97 scripts
= frame
.contents().find('script'),
98 css
= frame
.contents().find('link[rel="stylesheet"]'),
100 cscripts
= $('head').find('script'),
101 ccss
= $('head').find('link[rel="stylesheet"]');
103 scripts
.each(function () {
105 var i
= cscripts
.length
,
111 insert
= (this.src
== cscripts
[0].src
) ? false : insert
;
114 $('head').prepend($(this));
115 addedscripts
.push($(this));
121 css
.each(function () {
129 insert
= (this.href
== ccss
[i
].href
) ? false : insert
;
132 $('head').prepend($(this));
133 addedcss
.push($(this));
142 css({'margin': '1% auto'}).
143 animate({'opacity': 'show'}, 1000);
145 clearTimeout(self
.timer
);
146 self
.timer
= setTimeout(function () {
148 }, self
.config
.interval
);
153 interpret
: function interpret (request
) {
155 var tmp
= document
.implementation
.createHTMLDocument("tmp"),
159 tmp
.documentElement
.innerHTML
= request
.responseText
;
162 for (var i
= 0; i
< this.x_scripts
.length
; i
+= 1)
163 this.x_scripts
[i
].remove();
165 for (var i
= 0; i
< this.x_css
.length
; i
+= 1)
166 this.x_css
[i
].remove();
172 if (this.page().indexOf('widget') > 0) {
174 var name
= this.page().split(' ')[0];
175 widget
= doc
.find("[id*=" + name
+ "]");
178 this.frame
.append(widget
.children());
180 this.frame
.html('Could not resolve widget ' + name
);
186 doc
.find('.content').children()
189 var frame
= this.frame
.find('iframe');
191 if (frame
.length
> 0) {
193 this.hoisting(frame
);
197 this.frame
.css({'margin': '0'});
198 this.frame
.animate({'opacity': 'show'}, 1000);
200 clearTimeout(this.timer
);
201 this.timer
= setTimeout(function () {
203 }, this.config
.interval
);
210 rotate
: function rotate () {
213 callback = function (request
) {
214 if (request
.status
!= 200) {
215 self
.note('The requested frame did not return status 200, ' +
216 'jumping to next in 3 seconds', self
.rotate
);
218 self
.interpret(request
);
222 this.help
.css('display', 'none');
223 this.current
= (this.current
=== this.pages
.length
- 1) ? 0 : this.current
+ 1;
224 this.frame
.animate({'opacity': 'hide'}, 400);
226 if (this.page().indexOf('widget') > 0) {
227 path
= this.config
.basepath
+ '/tac';
229 path
= this.config
.basepath
+ this.pages
[this.current
];
239 note
: function note (message
, ref
) {
240 if (typeof(ref
) == 'function') {
241 $('#page-rotation-note').html(message
).fadeIn(500).delay(2000).fadeOut(1000, ref
);
243 $('#page-rotation-note').html(message
).fadeIn(500).delay(2000).fadeOut(1000);
248 $('#page-rotation-opts').fadeOut(400);
249 $('#page-rotation-views').fadeOut(400);
250 $('#content').animate({'margin-top': '0px'}, {'duration': 800, 'queue': false});
251 $('#header').fadeOut(400, function () {
257 $('#page-rotation-opts').fadeIn(400);
258 $('#page-rotation-views').fadeIn(400);
259 $('#content').animate({'margin-top': '48px'}, {'duration': 200, 'queue': false});
260 $('#header').fadeIn(400);
263 add
: function add (uri
) {
268 if (value
.indexOf('widget') > 0) {
270 // Holder for widgets
274 if (value
.indexOf('index.php') > 0)
275 value
= value
.split('index.php')[1];
280 value
+= ( value
.indexOf('rotation_token') > 0 ) ? "" :
281 ( value
.indexOf('?') > 0 ) ?
282 '&rotation_token=' + (new Date()).getTime() :
283 '?rotation_token=' + (new Date()).getTime();
285 $.ajax(this.config
.basepath
+ value
, {
288 complete: function (request
) {
290 var title
= request
.responseText
,
291 i1
= title
.indexOf('<title>') + 7,
292 i2
= title
.indexOf('</title>') - i1
;
294 title
= title
.substr(i1
, i2
);
296 if (request
.status
== 200) {
298 $('#page-rotation-fields-list').append(
300 $('<input type="checkbox" checked="true" value="' + value
+ '" />').bind('click', function (e
) {
301 arrayRemoveValue(self
.pages
, $(e
.target
).val());
304 $('<span>').text(' ' + title
)
308 self
.pages
.push(value
);
312 self
.note('HEAD test of the given URI could not be resolved!<br /><br />' +
313 'This is either due to a faulty URI or the request is targetting a ' +
314 'page outside of Op5 Monitors Web Interface.<br />' +
315 'Try copying URI\'s from existing pages in Op5 Monitors Web Interface.');
325 save
: function save () {
327 var button
= $('#page-rotation-save');
328 button
.css('opacity', '0.4');
330 $.ajax(this.config
.basepath
+ '/ajax/save_page_setting', {
332 'type': 'rotation_queue',
333 'page': 'page_rotation',
334 'setting': JSON
.stringify(this.pages
)
337 complete: function (request
) {
338 button
.css('opacity', '1.0');
344 gotoPage: function () {
345 if (this.page().indexOf('widget') > 0) {
346 window
.location
.href
= this.config
.basepath
+ '/tac';
348 window
.location
.href
= this.config
.basepath
+ this.page();
352 element: function (btn
) {
353 return $('#page-rotation-' + btn
);
356 events: function () {
360 reveal = function () {
368 clearTimeout(self
.hideTimer
);
369 self
.hideTimer
= setTimeout(function () {
371 self
.showing
= false;
378 $('#page-rotation-add').bind('click', function () {self
.add($('#page-rotation-new').attr('value'));});
379 $('#page-rotation-save').bind('click', function () {self
.save();});
381 $('#page-rotation-prev').bind('click', function () {
383 self
.current
= (self
.current
< -1) ? self
.pages
.length
- 2 : self
.current
;
387 $('#page-rotation-next').bind('click', function () {
391 $('#page-rotation-play').bind('click', function () {
393 self
.status
= STATUS_PLAYING
;
396 clearTimeout(self
.hideTimer
);
397 $(window
).unbind('mousemove', reveal
);
398 $(window
).bind('mousemove', reveal
);
400 $('#page-rotation-play').css('display', 'none');
401 $('#page-rotation-pause').css('display', 'inline-block');
404 $('#page-rotation-pause').bind('click', function () {
406 self
.status
= STATUS_PAUSED
;
407 clearTimeout(self
.timer
);
409 clearTimeout(self
.hideTimer
);
410 $(window
).unbind('mousemove', reveal
);
412 $('#page-rotation-play').css('display', 'inline-block');
413 $('#page-rotation-pause').css('display', 'none');
416 self
.element('goto').bind('click', function () {
420 self
.element('slower').bind('click', function () {
421 if (self
.config
.interval
+ self
.config
.interval_increment
<= self
.config
.max_interval
)
422 self
.config
.interval
+= self
.config
.interval_increment
;
423 self
.element('speed').val(self
.config
.interval
/ 1000);
426 self
.element('faster').bind('click', function () {
427 if (self
.config
.interval
- self
.config
.interval_increment
>= self
.config
.min_interval
)
428 self
.config
.interval
-= self
.config
.interval_increment
;
429 self
.element('speed').val(self
.config
.interval
/ 1000);
436 $(window
).bind('load', function onmainload () {