Commit 3473b0878c24c591a4aa2b4f5a077dab5a1783dd

Authored by AntonioTerceiro
1 parent 9ec083f6

ActionItem152: moving javascript code to application.js



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1195 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/views/layouts/application.rhtml
... ... @@ -24,10 +24,7 @@
24 24 <% end %>
25 25 </head>
26 26  
27   - <body class='category<%= category_color %>'>
28   - <script type="text/javascript">
29   - if ( navigator.appName.indexOf("Microsoft") > -1 ) document.body.className += " msie";
30   - </script>
  27 + <body class='category<%= category_color %>' onload='noosfero_init();'>
31 28  
32 29 <% unless flash[:notice].nil? %>
33 30 <div id='notice' onclick="Element.hide('notice');">
... ...
public/javascripts/application.js
1 1 // Place your application-specific JavaScript functions and classes here
2 2 // This file is automatically included by javascript_include_tag :defaults
  3 +
  4 +function noosfero_init() {
  5 + focus_first_field();
  6 + detect_internet_explorer();
  7 +}
  8 +
  9 +/* Adds a class to "msie" to the body element if a Microsoft browser is
  10 + * detected. This is needed to workaround several of their limitations.
  11 + */
  12 +function detect_internet_explorer() {
  13 + if ( navigator.appName.indexOf("Microsoft") > -1 ) {
  14 + document.body.className += " msie";
  15 + }
  16 +}
  17 +
  18 +/* If applicable, find the first field in which the user can type and move the
  19 + * keyboard focus to it.
  20 + */
  21 +function focus_first_field() {
  22 + form = document.forms[0];
  23 + if (form == undefined) {
  24 + return;
  25 + }
  26 +
  27 + for (var i = 0; i < form.elements.length; i++) {
  28 + field = form.elements[i];
  29 + if (field.type == 'text' || field.type == 'textarea') {
  30 + field.focus();
  31 + return;
  32 + }
  33 + }
  34 +}
... ...