- self.rendered?(__FILE__) do
:plain
// #{__FILE__}
var RubyApp = new function() {
this.translation = {code:'#{RubyApp::Language.locale.code}', title:'#{RubyApp::Language.locale.title}'},
this.interval = #{self.interval * 1000},
this._interval = 0,
this._waitCount = 0,
this.maximize = function(selector) {
var element = $(selector);
var _document = $(document);
element.css('width', '0px');
element.css('height', '0px');
element.css('width', _document.width() + 'px');
element.css('height', _document.height() + 'px');
},
this.center = function(selector) {
var element = $(selector);
var _window = $(window);
element.css('top', _window.scrollTop() + (_window.height() - element.outerHeight(true)) / 2 + 'px');
element.css('left', _window.scrollLeft() + (_window.width() - element.outerWidth(true)) / 2 + 'px');
},
this.maximizeWait = function() {
RubyApp.maximize('body div.wait');
},
this.centerWaitImage = function() {
RubyApp.center('body div.wait > div.image');
},
this.maximizeOverlay = function() {
RubyApp.maximize('body div.overlay');
},
this.centerDialog = function(id) {
RubyApp.center('#'+id);
},
this.log = function(message) {
$('ul.log').append('
' + message + '');
},
this.queueEvent = function(event, wait) {
event.session_id = '#{RubyApp::Session.session_id}';
event.now = new Date().toString();
RubyApp.log('RubyApp.queueEvent ENQUEUE event.class=' + event._class + ' wait=' + wait);
$(window).queue( function() {
RubyApp.log('RubyApp.queueEvent DEQUEUE event.class=' + event._class + ' wait=' + wait);
request = $.ajax({type:'POST', url:location.href, data:event, wait:wait});
request
.success( function(event) {
$.each(event.statements, function(index, statement) {
eval(statement);
} );
} )
.error( function(request, message, exception) {
RubyApp.confirm_refresh(#{RubyApp::Elements::Base::BasePage.translate.error.to_json}, true);
} )
.complete( function() {
$(window).dequeue();
} )
} );
},
this.alert = function(message) {
alert(message);
},
this.refresh = function() {
RubyApp.showWait();
$(window).clearQueue();
location.assign(location.pathname);
},
this.confirm_refresh = function(message) {
if (confirm(message))
{
RubyApp.refresh();
}
},
this.go = function(url) {
RubyApp.showWait();
$(window).clearQueue();
location.assign(url);
},
this.showWait = function() {
if (RubyApp._waitCount <= 0)
{
var wait = $('body div.wait');
wait.show();
RubyApp.maximizeWait();
RubyApp.centerWaitImage();
$(window).bind('resize.wait', function() {
RubyApp.maximizeWait();
RubyApp.centerWaitImage();
} );
$(window).bind('scroll.wait', function() {
RubyApp.centerWaitImage();
} );
}
RubyApp._waitCount ++;
},
this.hideWait = function() {
if (RubyApp._waitCount == 1)
{
$(window).unbind('.wait');
$('body div.wait').hide();
}
RubyApp._waitCount --;
},
this.showDialog = function(id) {
//request = $.get('/#{RubyApp::Language.locale.code}/elements/' + id + '.html');
request = $.ajax({type:'GET', url:'/#{RubyApp::Language.locale.code}/elements/' + id + '.html', wait:true});
request
.success( function(dialog) {
var overlay = $('body div.overlay');
overlay.append(dialog);
overlay.show();
RubyApp.maximizeOverlay();
RubyApp.centerDialog(id);
$(window).bind('resize.dialog', function() {
RubyApp.maximizeOverlay();
RubyApp.centerDialog(id);
} );
$(window).bind('scroll.dialog', function() {
RubyApp.centerDialog(id);
} );
RubyApp.queueEvent({_class:'RubyApp::Elements::Dialog::ShownEvent', source_id:id}, false);
} );
},
this.hideDialog = function(id) {
$(window).unbind('.dialog');
$('body div.overlay').hide();
$('#'+id).remove();
RubyApp.queueEvent({_class:'RubyApp::Elements::Dialog::HiddenEvent', source_id:id}, false);
},
this.updateElement = function(id) {
//request = $.get('/#{RubyApp::Language.locale.code}/elements/' + id + '.html');
request = $.ajax({type:'GET', url:'/#{RubyApp::Language.locale.code}/elements/' + id + '.html', wait:true});
request
.success( function(content) {
$('#'+id).replaceWith(content);
} );
},
this.addClass = function(selector, _class) {
$(selector).addClass(_class);
},
this.removeClass = function(selector, _class) {
$(selector).removeClass(_class);
},
this.updateText = function(selector, value) {
$(selector).text(value);
},
this.updateValue = function(selector, value) {
$(selector).val(value);
},
this.setCookie = function(name, value, expires) {
document.cookie = name + '=' + value + '; expires=' + expires.toUTCString();
}
};
$(document).ready(function() {
$('body div.wait')
.bind('ajaxSend', function(event, request, options) {
if (options.wait)
RubyApp.showWait();
} )
.bind('ajaxComplete', function(event, request, options) {
if (options.wait)
RubyApp.hideWait();
} );
});
$(window).load(function() {
RubyApp.queueEvent({_class:'RubyApp::Elements::Page::LoadedEvent', source_id:$('html').attr('id')}, false);
if ( RubyApp.interval > 0 ) {
RubyApp._interval = window.setInterval(function() {
RubyApp.queueEvent({_class:'RubyApp::Elements::Page::TriggeredEvent', source_id:$('html').attr('id')}, false);
}, RubyApp.interval);
}
});
$(window).unload(function() {
if ( RubyApp.interval > 0 ) {
window.clearInterval(RubyApp._interval);
$(window).clearQueue();
}
});
= yield