|
13 | 13 | ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
14 | 14 | ;;
|
15 | 15 | ;; @module Dragonfly
|
16 |
| -;; @author Marc Hildmann <marc.hildmann at gmail.com> |
| 16 | +;; @author Marc Hildmann <marc.hildmann at gmail.com>, Greg Slepak <greg at taoeffect.com> |
17 | 17 | ;; @version 0.20
|
18 | 18 | ;;
|
19 | 19 | ;; @location http://code.google.com/p/dragonfly-newlisp/
|
|
29 | 29 |
|
30 | 30 | (context 'Dragonfly)
|
31 | 31 |
|
32 |
| -; TODO: these are copied from dragonfly.lsp, and they're probably going to be |
33 |
| -; moved or deleted further. |
34 |
| -(constant 'databases-path (string DOCUMENT_ROOT"/databases/")) |
35 |
| - |
36 |
| -; init symbols for Dragonfly listener |
37 |
| -(set 'viewname "") |
38 |
| -(set 'action "") |
39 |
| -(set 'params "") |
40 |
| -(set 'selector "") |
41 |
| - |
42 | 32 | ;; @syntax (Dragonfly:benchmark-start)
|
43 | 33 | ;; <p>Sets the start point for benchmarking.</p>
|
44 | 34 | ;;
|
|
99 | 89 | <h2>REQUEST METHOD</h2>"REQUEST_METHOD"
|
100 | 90 | <h2>DEFAULT VIEW</h2>"DEFAULT_VIEW"
|
101 | 91 | <h2>CURRENT VIEW</h2>"viewname"
|
102 |
| - <h2>VIEW ACTION</h2>"action" |
103 | 92 | <h2>USER-AGENT</h2>"HTTP_USER_AGENT"
|
104 | 93 | <h2>Proxy</h2>"HTTP_PROXY"
|
105 | 94 | <h2>SERVER</h2>"SERVER_SOFTWARE"
|
|
201 | 190 | ;; <p>Writes the Google Analytics tracking code.</p>
|
202 | 191 | ;;
|
203 | 192 | (define (google-analytics analytics-id)
|
204 |
| - (print " |
205 |
| - <script type=\"text/javascript\"> |
206 |
| - var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\"); |
207 |
| - document.write(unescape(\"%3Cscript src='\" + gaJsHost + \"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\")); |
| 193 | + (print [text] |
| 194 | + <script type="text/javascript"> |
| 195 | + var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); |
| 196 | + document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); |
208 | 197 | </script>
|
209 |
| - <script type=\"text/javascript\"> |
| 198 | + <script type="text/javascript"> |
210 | 199 | try {
|
211 |
| - var pageTracker = _gat._getTracker(\""analytics-id"\"); |
| 200 | + var pageTracker = _gat._getTracker("[/text] analytics-id [text]"); |
212 | 201 | pageTracker._trackPageview();
|
213 | 202 | } catch(err) {}
|
214 | 203 | </script>
|
215 |
| - ") |
| 204 | + [/text]) |
216 | 205 | )
|
217 | 206 |
|
218 | 207 |
|
|
261 | 250 | ;; @param <view> a string containing the view
|
262 | 251 | ;; <p>Writes a internal link</p>
|
263 | 252 | ;;
|
264 |
| -(define (link_to link-name view action) |
265 |
| - |
266 |
| - ; if Dragonfly runs on newLISP webSERVER_SOFTWARE, we cannot |
| 253 | +(define (link_to link-name view , link-url) |
| 254 | + ; if Dragonfly runs on newLISP SERVER_SOFTWARE, we cannot |
267 | 255 | ; use .htaccess, so we've to write the "?" into the url
|
268 | 256 | ; else we miss it
|
269 |
| - (if (true? (find "newLISP" SERVER_SOFTWARE)) |
| 257 | + (if (find "newLISP" SERVER_SOFTWARE) |
270 | 258 | (set 'link-url (string "?" view))
|
271 | 259 | (set 'link-url (string "/" view))
|
272 | 260 | )
|
273 |
| - (if action (write-buffer link-url (string "/" action))) |
274 |
| - |
275 |
| - (print "<a href='"(web-root link-url)"'>"link-name"</a>") |
| 261 | + (print "<a href=\"" (web-root link-url) "\">" link-name "</a>") |
276 | 262 | )
|
277 | 263 |
|
278 | 264 | ;; @syntax (Dragonfly:link_to <link_name> <url>)
|
|
281 | 267 | ;; <p>Writes a standard HTML link</p>
|
282 | 268 | ;;
|
283 | 269 | (define (link_to_external link-name url)
|
284 |
| - |
285 | 270 | (print "<a href='"url"'>"link-name"</a>")
|
286 |
| - |
287 | 271 | )
|
288 | 272 |
|
289 | 273 | ;; @syntax (Dragonfly:link_mailto <link_name> <options>)
|
|
292 | 276 | ;; <p>Writes a standard HTML mailto link</p>
|
293 | 277 | ;;
|
294 | 278 | (define (link_mailto link-name link-url)
|
295 |
| - (print "<a href='mailto:"link-url"'>"link-name"</a>") |
| 279 | + (print "<a href='mailto:"link-url"'>"link-name"</a>") |
296 | 280 | )
|
297 | 281 |
|
298 | 282 |
|
299 | 283 | ;===============================================================================
|
300 | 284 | ; !AJAX Functions
|
301 | 285 | ;===============================================================================
|
302 | 286 |
|
303 |
| -;; @syntax (Dragonfly:ajax-updater <html-elementid> <request-url> <params-url> <timeout>) |
| 287 | +;; @syntax (Dragonfly:ajax-updater <html-elementid> <request-url> <str-params> <timeout>) |
304 | 288 | ;; @param <html-elementid> a string containing the elementID
|
305 | 289 | ;; @param <request-url> a string containing the url which is called frequently
|
306 |
| -;; @param <params-url> a string containing params which are POSTED against request-url |
307 |
| -;; @param <timeout> an integer containing the number of microseconds after recalling the request-url |
| 290 | +;; @param <str-params> a string containing params which are POSTED against request-url |
| 291 | +;; @param <int-timeout> an integer containing the number of microseconds after recalling the request-url |
308 | 292 | ;; <p>Writes a simple AJAX-updater, e.g. for displaying the time on a website.</p>
|
309 |
| -;; |
310 |
| -(define (ajax-updater html-elementid request-url params-url timeout) |
311 |
| - (print "<div id='"html-elementid"'> </div>") |
312 |
| - (print "<script language='javascript'>") |
313 |
| - (print "function responseFunction(responseText, responseStatus) {") |
314 |
| - (print "var response = responseText;") |
315 |
| - (print "document.getElementById('"html-elementid"').innerHTML = response;") |
316 |
| - (print "setTimeout(\"ajax"html-elementid".post('"params-url"');\","timeout");") |
317 |
| - (print "}") |
318 |
| - |
| 293 | +(define (ajax-updater html-elementid request-url str-params timeout) |
319 | 294 | ; check for newLISP as webSERVER_SOFTWARE, then we've to use a ? before request-url, because there's no working .htaccess
|
320 | 295 | (when (find "newLISP" SERVER_SOFTWARE)
|
321 | 296 | (if (starts-with request-url "/") (pop request-url))
|
322 | 297 | (push "/?" request-url)
|
323 | 298 | )
|
324 | 299 | (set 'request-url (web-root request-url))
|
325 |
| - (print "var ajax"html-elementid" = new AjaxRequest(\""request-url"\", responseFunction);") |
326 |
| - |
327 |
| - (print "ajax"html-elementid".post(\""params-url"\");") |
328 |
| - (print "</script>") |
| 300 | + ; 'fetcher' is prevented from entering the global scope because |
| 301 | + ; of the surrounding parenthesis. Meaning, this code won't conflict if |
| 302 | + ; it's listed multiple times on the page. The parenthesis play two roles: |
| 303 | + ; to protect it from entering the global scope, and to call the function. |
| 304 | + (print (format [text] |
| 305 | + <div id="%s"> </div> |
| 306 | + <script type="text/javascript"> |
| 307 | + (function fetcher() { |
| 308 | + $.post("%s", "%s", |
| 309 | + function (data, status) { |
| 310 | + $("#%s").html(data); |
| 311 | + setTimeout(fetcher, %d); |
| 312 | + } |
| 313 | + ); |
| 314 | + })(); |
| 315 | + </script> |
| 316 | + [/text] html-elementid request-url str-params html-elementid timeout) |
| 317 | + ) |
329 | 318 | )
|
330 | 319 |
|
331 | 320 | (context Dragonfly)
|
0 commit comments