update for m2
[opensuse:software-o-o.git] / app / helpers / application_helper.rb
1 # Methods added to this helper will be available to all templates in the application.
2 module ApplicationHelper
3
4   @@theme_prefix = nil
5
6   def theme_prefix
7     return @@theme_prefix if @@theme_prefix
8     @@theme_prefix = '/themes'
9     if ActionController::Base.relative_url_root
10       @@theme_prefix = ActionController::Base.relative_url_root + @@theme_prefix
11     end
12     @@theme_prefix
13   end
14
15   def compute_asset_host(source)
16     if defined? USE_STATIC
17       if source.slice(0, theme_prefix.length) == theme_prefix
18         return "https://static.opensuse.org"
19       end
20       return "https://static.opensuse.org/hosts/#{USE_STATIC}"
21     end
22     super(source)
23   end
24
25   def setup_baseproject
26     if @baseproject
27       scr = "setCookie('search_baseproject','#{@baseproject}');\n"
28     else
29       scr = "var p = getCookie('search_baseproject'); if (p) { $(\"#baseproject option[value='\" + p + \"']\").attr('selected', 'selected'); }\n"
30     end
31     "<script type=\"text/javascript\">\n" +
32     "//<![CDATA[\n" +
33     scr +
34     "//]]>\n" +
35     "</script>\n"
36   end
37
38 end