1100f693745ebffd77d9e8d6d471ea5e04c8dc7e
[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.js"         ' default base library\r
35   theme=""\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   SetTheme "r-" & ThemeName\r
48 End Property \r
49 Public Property Let jTheme(ThemeName)\r
50   SetTheme "j-" & ThemeName\r
51 End Property\r
52 \r
53 \r
54 Private Sub SetTheme(ByVal PrefixedTheme)\r
55   theme = PrefixedTheme\r
56   If PrefixedTheme = "r-grayedout" Then imgHeading = "grayedout.gif"\r
57 End Sub\r
58 \r
59 \r
60 Public Sub SetRicoClientPaths(ByVal jsPath, cssPath, imgPath)\r
61   jsDir = jsPath\r
62   cssDir= cssPath\r
63   imgDir= imgPath\r
64 End Sub\r
65 \r
66 \r
67 Public Sub SetRicoClientParentPath(ByVal clientDir)\r
68   if mid(clientDir,len(clientDir),1) <> "/" then clientDir=clientDir & "/"\r
69   SetRicoClientPaths clientDir & "js/", clientDir & "css/", clientDir & "images/"\r
70 End Sub\r
71 \r
72 \r
73 ' Used by demo to switch libraries & themes\r
74 ' Do no call in production\r
75 Public Sub CheckQueryString()\r
76   BaseLib=LCase(Request.QueryString("lib"))\r
77   SetTheme trim(Request.QueryString("theme"))\r
78   ricoLogging=CBool(trim(Request.QueryString("log")) <> "")\r
79 end Sub\r
80 \r
81 \r
82 ' This is the main method, which creates the Javscript and CSS links\r
83 Public Sub CreateLinks()\r
84   SetConfig\r
85   if LoadBaseLib then\r
86     if InStr(baseLib,"/") > 0 then\r
87       Response.Write vbLf & "<script src='http://ajax.googleapis.com/ajax/libs/" & baseLib & "' type='text/javascript'></script>"\r
88     else\r
89       Response.Write vbLf & "<script src='" & jsDir & baseLib & "' type='text/javascript'></script>"\r
90     end if\r
91   end if\r
92   requireRicoJS "2" & left(baseLib,3)\r
93   requireRicoJS "_min"\r
94   setLang\r
95   requireRicoCSS "rico"\r
96   if theme<>"" then LoadTheme\r
97 End sub\r
98 \r
99 \r
100 ' Create Rico client initialization object\r
101 Private sub SetConfig()\r
102   Response.Write vbLf & "<script type='text/javascript'>"\r
103   Response.Write vbLf & "Rico_CONFIG = {"\r
104   if ricoLogging then Response.Write vbLf & "enableLogging: true,"\r
105   if not IsEmpty(imgHeading) then Response.Write vbLf & "imgHeading: '" & imgDir & imgHeading & "',"\r
106   Response.Write vbLf & "imgResize: '" & imgDir & "resize.gif',"\r
107   Response.Write vbLf & "imgIcons: '" & imgDir & "ricoIcons.gif'"\r
108   Response.Write vbLf & "};"\r
109   Response.Write vbLf & "</script>"\r
110 end sub\r
111 \r
112 \r
113 ' -------------------------------------------------------------\r
114 ' Check languages accepted by browser\r
115 ' and see if there is a match\r
116 ' -------------------------------------------------------------\r
117 sub setLang()\r
118   dim fso,lang,lang2,fname,i\r
119 \r
120   lang=lcase(Request.ServerVariables("HTTP_ACCEPT_LANGUAGE"))\r
121   arLang=split(lang,",")\r
122   for i=0 to ubound(arLang)\r
123     lang2=lcase(left(trim(arLang(i)),2))\r
124     if lang2="en" then exit for\r
125     If InStr(SupportedLangs, lang2) > 0 Then\r
126       requireRicoJS "Locale_" & lang2\r
127       exit for\r
128     end if\r
129   next\r
130 end sub\r
131 \r
132 \r
133 ' set theme\r
134 ' "j-ui-lightness" for a Themeroller theme\r
135 ' "r-greenHdg" for a native Rico theme\r
136 Private sub LoadTheme()\r
137   dim prefix,themeFile\r
138   prefix=left(theme,1)\r
139   themeFile=mid(theme,3)\r
140   select case prefix\r
141     case "j":\r
142       requireRicoJS "Themeroller"\r
143       Response.Write vbLf & "<link type='text/css' rel='Stylesheet' href='" & jQuery_theme_path & themeFile & "/jquery-ui.css' />"\r
144     case "r":\r
145       requireRicoCSS themeFile\r
146   end select\r
147   if grid_striping then Response.Write vbLf & "<link type='text/css' rel='stylesheet' href='" & cssDir & "striping_" & themeFile & ".css' />"\r
148 end sub\r
149 \r
150 \r
151 Public sub requireRicoJS(filename)\r
152   Response.Write vbLf & "<script src='" & jsDir & "rico" & filename & ".js' type='text/javascript'></script>"\r
153 end sub\r
154 \r
155 \r
156 Public sub requireRicoCSS(filename)\r
157   Response.Write vbLf & "<link href='" & cssDir & filename & ".css' type='text/css' rel='stylesheet' />"\r
158 end sub\r
159 \r
160 End Class\r
161 \r
162 %>\r