Module: NotificationServer::ActionView::ScriptHelper

Included in:
NotificationServer::ActionView
Defined in:
lib/notification_server/action_view/script_helper.rb

Instance Method Summary collapse

Instance Method Details

#javascript_include_async_notification_serverObject

Generate async javascript embeddable code

If you use this method remember you can’t get “now” variable immediately you have to wait for “now” variable.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/notification_server/action_view/script_helper.rb', line 26

def javascript_include_async_notification_server
  html = <<HTML
<script type='text/javascript' id='__notification_server'></script>
<script type="text/javascript">
(function() {
  if (typeof(jQuery) != 'undefined') {
    setTimeout(function() {
jQuery('head').append(jQuery('<script />', {
  type: "text/javascript",
  src: "#{NotificationServer::Configuration.script_path}"
}));
    } , 1000);
  } else {
    document.getElementById('__notification_server').src = "#{NotificationServer::Configuration.script_path}";
  }
})();
</script>
HTML
  _safe html
end

#javascript_include_notification_serverObject

Generate script tag for including notification server script



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/notification_server/action_view/script_helper.rb', line 7

def javascript_include_notification_server
  html = if defined?()
     'script', '',
                src: NotificationServer::Configuration.script_path,
                type: 'text/javascript'
  else
    "<script type='text/javascript' " +
        " src=\"#{NotificationServer::Configuration.script_path}\">" +
        "</script>"
  end

  _safe html
end