Method: Nitro::JavascriptHelper#emit_script

Defined in:
lib/nitro/helper/javascript.rb

#emit_scriptObject Also known as: helper_script

Call this in your template/page to include the javascript statements that link your HTML to the javascript libraries. Must be called after the HTML elements involved, i.e., at the bottom of the page. – FIXME: refactor this! ++



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/nitro/helper/javascript.rb', line 384

def emit_script
  code = %|<script type="text/javascript">\n<!--\n|
  unless @_behaviours.empty?
    code << %|var _behaviours = {\n|
    compo = []
    for id, js in @_behaviours
      compo << %|'#{id}': function(el) { #{js} \n }|
    end
    code << compo.join(',')
    code << %|
    }
    Behaviour.register(_behaviours);    
    |
  end
  code << %|
      #{@_script.join("\n")}
  | if @_script
  code << %|
    //-->
    </script>
  |
end