Fixed Rico.Corner.round to be compatible with latest browsers/CSS3 - in both Rico2...
[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 transDir\r
24 Public ricoLib,ricoTheme,ricoLogging\r
25 Public grid_striping     ' apply row striping to LiveGrids?\r
26 Public LoadBaseLib       ' load base Javascript library (prototype, jQuery, etc)?\r
27 Public jQuery_theme_path\r
28 Public SupportedLangs    ' comma-separated list of 2-character codes, representing the files that can be found in js/translations directory\r
29 \r
30 ' Constructor\r
31 \r
32 Private Sub Class_Initialize\r
33   ricoLib="proto_min"         ' default base library\r
34   ricoTheme="j-ui-lightness"  ' jquery themes start with j-, rico themes start with r-\r
35   ricoLogging=false\r
36   grid_striping = true\r
37   LoadBaseLib = true\r
38   SupportedLangs = "de,es,fr,it,ja,ko,pt,ru,uk,zh"\r
39   jQuery_theme_path = "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/"\r
40 End Sub\r
41 \r
42 \r
43 Public Sub SetRicoClientPaths(ByVal jsPath, cssPath, imgPath)\r
44   jsDir = jsPath\r
45   cssDir= cssPath\r
46   imgDir= imgPath\r
47   transDir=jsDir & "translations/"\r
48 End Sub\r
49 \r
50 \r
51 Public Sub SetRicoClientParentPath(ByVal clientDir)\r
52   if mid(clientDir,len(clientDir),1) <> "/" then clientDir=clientDir & "/"\r
53   SetRicoClientPaths clientDir & "js/", clientDir & "css/", clientDir & "images/"\r
54 End Sub\r
55 \r
56 \r
57 ' Used by demo to switch libraries & themes\r
58 ' Do no call in production\r
59 Public Sub CheckQueryString()\r
60   ricoLib=LCase(Request.QueryString("lib"))\r
61   ricoTheme=trim(Request.QueryString("theme"))\r
62   ricoLogging=CBool(trim(Request.QueryString("log")) <> "")\r
63 end Sub\r
64 \r
65 \r
66 ' This is the main method, which creates the Javscript and CSS links\r
67 Public Sub CreateLinks()\r
68   SetConfig\r
69   LoadLib ricoLib, LoadBaseLib\r
70   setLang\r
71   if ricoTheme<>"" then\r
72     LoadTheme ricoTheme\r
73   end if\r
74 End sub\r
75 \r
76 \r
77 ' Create Rico client initialization object\r
78 sub SetConfig()\r
79   Response.Write vbLf & "<script type='text/javascript'>"\r
80   Response.Write vbLf & "Rico_CONFIG = {"\r
81   if ricoLogging then Response.Write vbLf & "enableLogging: true,"\r
82   Response.Write vbLf & "jsDir: '" & jsDir & "',"\r
83   Response.Write vbLf & "cssDir: '" & cssDir & "',"\r
84   Response.Write vbLf & "imgDir: '" & imgDir & "'"\r
85   Response.Write vbLf & "};"\r
86   Response.Write vbLf & "</script>"\r
87 end sub\r
88 \r
89 \r
90 sub LoadLib(baseLib, baseLoadFlag)\r
91   if baseLoadFlag then\r
92     if InStr(baseLib,"/") > 0 then\r
93       Response.Write vbLf & "<script src='http://ajax.googleapis.com/ajax/libs/" & baseLib & "' type='text/javascript'></script>"\r
94     else\r
95       Response.Write vbLf & "<script src='" & jsDir & baseLib & "' type='text/javascript'></script>"\r
96     end if\r
97   end if\r
98   requireRicoJS ""\r
99   requireRicoJS "2" & left(baseLib,3)\r
100   requireRicoCSS "rico"\r
101   requireRicoJS "_min"\r
102 end sub\r
103 \r
104 \r
105 ' -------------------------------------------------------------\r
106 ' Check languages accepted by browser\r
107 ' and see if there is a match\r
108 ' -------------------------------------------------------------\r
109 sub setLang()\r
110   dim fso,lang,lang2,fname,i\r
111 \r
112   lang=lcase(Request.ServerVariables("HTTP_ACCEPT_LANGUAGE"))\r
113   arLang=split(lang,",")\r
114   for i=0 to ubound(arLang)\r
115     lang2=lcase(left(trim(arLang(i)),2))\r
116     if lang2="en" then exit for\r
117     If InStr(SupportedLangs, lang2) > 0 Then\r
118       fname=transDir & "ricoLocale_" & lang2 & ".js"\r
119       Response.Write "<script src='" & fname & "' type='text/javascript'></script>"\r
120       exit for\r
121     end if\r
122   next\r
123 end sub\r
124 \r
125 \r
126 ' set theme\r
127 ' "j-ui-lightness" for a Themeroller theme\r
128 ' "r-greenHdg" for a native Rico theme\r
129 sub LoadTheme(theme)\r
130   dim prefix,themeFile\r
131   prefix=left(theme,1)\r
132   themeFile=mid(theme,3)\r
133   select case prefix\r
134     case "j":\r
135       requireRicoJS "Themeroller"\r
136       Response.Write vbLf & "<link type='text/css' rel='Stylesheet' href='" & jQuery_theme_path & themeFile & "/jquery-ui.css' />"\r
137     case "r":\r
138       requireRicoCSS themeFile\r
139   end select\r
140   if grid_striping then Response.Write vbLf & "<link type='text/css' rel='stylesheet' href='" & cssDir & "striping_" & themeFile & ".css' />"\r
141 end sub\r
142 \r
143 \r
144 sub requireRicoJS(filename)\r
145   Response.Write vbLf & "<script src='" & jsDir & "rico" & filename & ".js' type='text/javascript'></script>"\r
146 end sub\r
147 \r
148 \r
149 sub requireRicoCSS(filename)\r
150   Response.Write vbLf & "<link href='" & cssDir & filename & ".css' type='text/css' rel='stylesheet' />"\r
151 end sub\r
152 \r
153 End Class\r
154 \r
155 %>\r