- 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.sendEvent = function(event) { event.session_id = '#{RubyApp::Session.session_id}'; event.now = new Date().toString(); request = $.post(location.href, event); 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}); } ) }, this.alert = function(message) { alert(message); }, this.refresh = function() { location.assign(location.pathname); }, this.confirm_refresh = function(message) { if (confirm(message)) { RubyApp.refresh(); } }, this.go = function(url) { location.assign(url); }, this.show = function(id) { response = $.get('/#{RubyApp::Language.locale.code}/elements/' + id + '.html'); response .success( function(dialog) { var overlay = $('body div.overlay'); overlay.append(dialog); overlay.show(); centerOverlay = function() { var overlay = $('body div.overlay'); var _document = $(document); overlay.css('width', '0px'); overlay.css('height', '0px'); overlay.css('width', _document.width() + 'px'); overlay.css('height', _document.height() + 'px'); }; centerDialog = function(id) { var dialog = $('#'+id); var _window = $(window); dialog.css('top', _window.scrollTop() + (_window.height() - dialog.outerHeight(true)) / 2 + 'px'); dialog.css('left', _window.scrollLeft() + (_window.width() - dialog.outerWidth(true)) / 2 + 'px'); }; centerOverlay(); centerDialog(id); $(window).bind('resize', function() { centerOverlay(); centerDialog(id); } ); $(window).bind('scroll', function() { centerDialog(id); } ); RubyApp.sendEvent({_class:'RubyApp::Elements::Dialog::ShownEvent', source_id:id}); } ); }, this.hide = function(id) { $(window).unbind('scroll'); $(window).unbind('resize'); $('body div.overlay').hide(); $('#'+id).remove(); RubyApp.sendEvent({_class:'RubyApp::Elements::Dialog::HiddenEvent', source_id:id}); }, this.updateElement = function(id) { response = $.get('/#{RubyApp::Language.locale.code}/elements/' + id + '.html'); response .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(); } }; $(window).load(function() { RubyApp.sendEvent({_class:'RubyApp::Elements::Page::LoadedEvent', source_id:$('html').attr('id')}); if ( RubyApp.interval > 0 ) { RubyApp._interval = window.setInterval(function() { RubyApp.sendEvent({_class:'RubyApp::Elements::Page::TriggeredEvent', source_id:$('html').attr('id')}); }, RubyApp.interval); } }); $(window).unload(function() { if ( RubyApp.interval > 0 ) { window.clearInterval(RubyApp._interval); } // RubyApp.sendEvent({_class:'RubyApp::Elements::Page::UnloadedEvent', source_id:$('html').attr('id')}); }); = yield