3f35828b2e7b4ccdbba14f5dca485d8c49b18146
[infodrom/rico3] / plugins / asp / LoadRicoClient.asp
1 <%\r
2 \r
3 ' ----------------------------------------------------------------------\r
4 '\r
5 ' Page        : LoadRicoClient.asp\r
6 ' Description : Class to load Rico client-side Javascript and CSS\r
7 ' Author      : Matt Brown (dowdybrown@yahoo.com)\r
8 ' Copyright (C) 2006-2011 Matt Brown\r
9 '\r
10 ' Rico is licensed under the Apache License, Version 2.0 (the "License"); you may not use this\r
11 ' file except in compliance with the License. You may obtain a copy of the License at\r
12 ' http://www.apache.org/licenses/LICENSE-2.0\r
13 '\r
14 ' ----------------------------------------------------------------------\r
15 \r
16 class LoadRicoClient\r
17 \r
18 ' Properties\r
19 \r
20 Public jsDir      ' directory containing Rico's javascript files\r
21 Public cssDir     ' directory containing Rico's css files\r
22 Public imgDir     ' directory containing Rico's image files\r
23 Public imgHeading ' background image for grid headings and window titles, used in grayedout theme\r
24 Public BaseLib    ' base library - prototype, jquery, etc\r
25 Public ricoLogging       ' enable console logging?\r
26 Public grid_striping     ' apply row striping to LiveGrids?\r
27 Public LoadBaseLib       ' load base Javascript library (prototype, jQuery, etc)?\r
28 Public jQuery_theme_path ' url to jqueryui themes\r
29 Public SupportedLangs    ' comma-separated list of 2-character codes, representing the files that can be found in jsDir directory. Defaults to ones delivered with Rico.\r
30 \r
31 ' Constructor\r
32 \r
33 Private Sub Class_Initialize\r
34   BaseLib="proto_min"         ' default base library\r
35   jTheme="ui-lightness"\r
36   ricoLogging=false\r
37   grid_striping = true\r
38   LoadBaseLib = true\r
39   SupportedLangs = "de,es,fr,it,ja,ko,pt,ru,uk,zh"\r
40   jQuery_theme_path = "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/"\r
41 End Sub\r
42 \r
43 \r
44 ' jquery themes start with j-, rico themes start with r-\r
45 Private theme         \r
46 Public Property Let ricoTheme(ThemeName)\r
47   theme = "r-" & ThemeName\r
48   if ThemeName="grayedout" then imgHeading="grayedout.gif"\r
49 End Property \r
50 Public Property Let jTheme(ThemeName)\r
51   theme = "j-" & ThemeName\r
52 End Property \r
53 \r
54 \r
55 Public Sub SetRicoClientPaths(ByVal jsPath, cssPath, imgPath)\r
56   jsDir = jsPath\r
57   cssDir= cssPath\r
58   imgDir= imgPath\r
59 End Sub\r
60 \r
61 \r
62 Public Sub SetRicoClientParentPath(ByVal clientDir)\r
63   if mid(clientDir,len(clientDir),1) <> "/" then clientDir=clientDir & "/"\r
64   SetRicoClientPaths clientDir & "js/", clientDir & "css/", clientDir & "images/"\r
65 End Sub\r
66 \r
67 \r
68 ' Used by demo to switch libraries & themes\r
69 ' Do no call in production\r
70 Public Sub CheckQueryString()\r
71   BaseLib=LCase(Request.QueryString("lib"))\r
72   theme=trim(Request.QueryString("theme"))\r
73   ricoLogging=CBool(trim(Request.QueryString("log")) <> "")\r
74 end Sub\r
75 \r
76 \r
77 ' This is the main method, which creates the Javscript and CSS links\r
78 Public Sub CreateLinks()\r
79   SetConfig\r
80   if LoadBaseLib then\r
81     if InStr(baseLib,"/") > 0 then\r
82       Response.Write vbLf & "<script src='http://ajax.googleapis.com/ajax/libs/" & baseLib & "' type='text/javascript'></script>"\r
83     else\r
84       Response.Write vbLf & "<script src='" & jsDir & baseLib & "' type='text/javascript'></script>"\r
85     end if\r
86   end if\r
87   requireRicoJS ""\r
88   requireRicoJS "2" & left(baseLib,3)\r
89   requireRicoCSS "rico"\r
90   requireRicoJS "_min"\r
91   setLang\r
92   if theme<>"" then LoadTheme\r
93 End sub\r
94 \r
95 \r
96 ' Create Rico client initialization object\r
97 Private sub SetConfig()\r
98   Response.Write vbLf & "<script type='text/javascript'>"\r
99   Response.Write vbLf & "Rico_CONFIG = {"\r
100   if ricoLogging then Response.Write vbLf & "enableLogging: true,"\r
101   Response.Write vbLf & "jsDir: '" & jsDir & "',"\r
102   if not IsEmpty(imgHeading) then Response.Write vbLf & "imgHeading: '" & imgDir & imgHeading & "',"\r
103   Response.Write vbLf & "imgResize: '" & imgDir & "resize.gif',"\r
104   Response.Write vbLf & "imgIcons: '" & imgDir & "ricoIcons.gif'"\r
105   Response.Write vbLf & "};"\r
106   Response.Write vbLf & "</script>"\r
107 end sub\r
108 \r
109 \r
110 ' -------------------------------------------------------------\r
111 ' Check languages accepted by browser\r
112 ' and see if there is a match\r
113 ' -------------------------------------------------------------\r
114 sub setLang()\r
115   dim fso,lang,lang2,fname,i\r
116 \r
117   lang=lcase(Request.ServerVariables("HTTP_ACCEPT_LANGUAGE"))\r
118   arLang=split(lang,",")\r
119   for i=0 to ubound(arLang)\r
120     lang2=lcase(left(trim(arLang(i)),2))\r
121     if lang2="en" then exit for\r
122     If InStr(SupportedLangs, lang2) > 0 Then\r
123       requireRicoJS "Locale_" & lang2\r
124       exit for\r
125     end if\r
126   next\r
127 end sub\r
128 \r
129 \r
130 ' set theme\r
131 ' "j-ui-lightness" for a Themeroller theme\r
132 ' "r-greenHdg" for a native Rico theme\r
133 Private sub LoadTheme()\r
134   dim prefix,themeFile\r
135   prefix=left(theme,1)\r
136   themeFile=mid(theme,3)\r
137   select case prefix\r
138     case "j":\r
139       requireRicoJS "Themeroller"\r
140       Response.Write vbLf & "<link type='text/css' rel='Stylesheet' href='" & jQuery_theme_path & themeFile & "/jquery-ui.css' />"\r
141     case "r":\r
142       requireRicoCSS themeFile\r
143   end select\r
144   if grid_striping then Response.Write vbLf & "<link type='text/css' rel='stylesheet' href='" & cssDir & "striping_" & themeFile & ".css' />"\r
145 end sub\r
146 \r
147 \r
148 Public sub requireRicoJS(filename)\r
149   Response.Write vbLf & "<script src='" & jsDir & "rico" & filename & ".js' type='text/javascript'></script>"\r
150 end sub\r
151 \r
152 \r
153 Public sub requireRicoCSS(filename)\r
154   Response.Write vbLf & "<link href='" & cssDir & filename & ".css' type='text/css' rel='stylesheet' />"\r
155 end sub\r
156 \r
157 End Class\r
158 \r
159 %>\r