Skip to content

Commit 31d10f0

Browse files
committed
- Converted all javascript stuff in dragonfly.js to using jQuery
- Improved the ajax functions and demo to use jQuery - Separated "User Guide" into "User Guide" and "Examples"
1 parent 3528dab commit 31d10f0

13 files changed

+222
-174
lines changed

CHANGES

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Version 0.50
2+
3+
* massive rewrite. too many changes to list, if you want to see them look through the mercurial change log:
4+
http://code.google.com/p/dragonfly-newlisp/source/list
5+
or the updates list (similar to the other link, but with fewer details):
6+
http://code.google.com/p/dragonfly-newlisp/updates/list
7+
18
Version 0.20
29

310
* changed license from MIT to GNU (GPL v3)

UPGRADE_GUIDE

+10-12
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,16 @@ Purpose:
1717
are user-customizable and which are not, and to make naming
1818
conflicts more difficult.
1919

20-
* To avoid having too many constants all over the place, possibly
21-
causing confusion and conflicts with other similarly named variables,
22-
and to avoid cluttering the code, all environment variables have simply
23-
been placed into the PHP-like env map. Some constants still
24-
exist, namely those starting with 'dragonfly'
20+
* Environment variables are now global constants and therefore
21+
the ones formerly in Dragonfly context should be converted like this:
2522

26-
Dragonfly:host => (env "HTTP_HOST")
27-
Dragonfly:useragent => (env "HTTP_USER_AGENT")
28-
Dragonfly:server => (env "SERVER_SOFTWARE")
29-
Dragonfly:programfiles => (env "PROGRAMFILES")
30-
Dragonfly:proxy => (env "HTTP_PROXY")
23+
Dragonfly:host => HTTP_HOST
24+
Dragonfly:useragent => HTTP_USER_AGENT
25+
Dragonfly:server => SERVER_SOFTWARE
26+
Dragonfly:programfiles => PROGRAMFILES
27+
Dragonfly:proxy => HTTP_PROXY
3128

32-
You can also use the new PHP-like symbol $SERVER instead of env.
29+
Alternatively you can use 'env' or '$SERVER' to access them:
3330

34-
Example: ($SERVER "HTTP_HOST")
31+
Example: ($SERVER "HTTP_HOST")
32+

example-site/dragonfly-framework/plugins-active/dragonfly_basic.lsp

+35-46
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
1414
;;
1515
;; @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>
1717
;; @version 0.20
1818
;;
1919
;; @location http://code.google.com/p/dragonfly-newlisp/
@@ -29,16 +29,6 @@
2929

3030
(context 'Dragonfly)
3131

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-
4232
;; @syntax (Dragonfly:benchmark-start)
4333
;; <p>Sets the start point for benchmarking.</p>
4434
;;
@@ -99,7 +89,6 @@
9989
<h2>REQUEST METHOD</h2>"REQUEST_METHOD"
10090
<h2>DEFAULT VIEW</h2>"DEFAULT_VIEW"
10191
<h2>CURRENT VIEW</h2>"viewname"
102-
<h2>VIEW ACTION</h2>"action"
10392
<h2>USER-AGENT</h2>"HTTP_USER_AGENT"
10493
<h2>Proxy</h2>"HTTP_PROXY"
10594
<h2>SERVER</h2>"SERVER_SOFTWARE"
@@ -201,18 +190,18 @@
201190
;; <p>Writes the Google Analytics tracking code.</p>
202191
;;
203192
(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"));
208197
</script>
209-
<script type=\"text/javascript\">
198+
<script type="text/javascript">
210199
try {
211-
var pageTracker = _gat._getTracker(\""analytics-id"\");
200+
var pageTracker = _gat._getTracker("[/text] analytics-id [text]");
212201
pageTracker._trackPageview();
213202
} catch(err) {}
214203
</script>
215-
")
204+
[/text])
216205
)
217206

218207

@@ -261,18 +250,15 @@
261250
;; @param <view> a string containing the view
262251
;; <p>Writes a internal link</p>
263252
;;
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
267255
; use .htaccess, so we've to write the "?" into the url
268256
; else we miss it
269-
(if (true? (find "newLISP" SERVER_SOFTWARE))
257+
(if (find "newLISP" SERVER_SOFTWARE)
270258
(set 'link-url (string "?" view))
271259
(set 'link-url (string "/" view))
272260
)
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>")
276262
)
277263

278264
;; @syntax (Dragonfly:link_to <link_name> <url>)
@@ -281,9 +267,7 @@
281267
;; <p>Writes a standard HTML link</p>
282268
;;
283269
(define (link_to_external link-name url)
284-
285270
(print "<a href='"url"'>"link-name"</a>")
286-
287271
)
288272

289273
;; @syntax (Dragonfly:link_mailto <link_name> <options>)
@@ -292,40 +276,45 @@
292276
;; <p>Writes a standard HTML mailto link</p>
293277
;;
294278
(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>")
296280
)
297281

298282

299283
;===============================================================================
300284
; !AJAX Functions
301285
;===============================================================================
302286

303-
;; @syntax (Dragonfly:ajax-updater <html-elementid> <request-url> <params-url> <timeout>)
287+
;; @syntax (Dragonfly:ajax-updater <html-elementid> <request-url> <str-params> <timeout>)
304288
;; @param <html-elementid> a string containing the elementID
305289
;; @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
308292
;; <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"'>&nbsp;</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)
319294
; check for newLISP as webSERVER_SOFTWARE, then we've to use a ? before request-url, because there's no working .htaccess
320295
(when (find "newLISP" SERVER_SOFTWARE)
321296
(if (starts-with request-url "/") (pop request-url))
322297
(push "/?" request-url)
323298
)
324299
(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">&nbsp;</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+
)
329318
)
330319

331320
(context Dragonfly)

example-site/dragonfly-framework/plugins-active/dragonfly_nldb.lsp

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
(context 'Dragonfly)
3131

32+
(constant 'databases-path (string DOCUMENT_ROOT "/databases/"))
33+
3234
;===============================================================================
3335
; !nldb Wrapper for a pure newLISP Database (flat)
3436
;===============================================================================

example-site/includes/css/screen.css

+7-7
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ body img {
281281

282282
/* Dragonfly User Guide Menu */
283283

284-
#menu {
284+
.menu {
285285
width: 470px;
286286
display: block;
287287
background: #000000;
@@ -296,22 +296,22 @@ body img {
296296
padding-bottom:10px;
297297
}
298298

299-
#menu dt {
299+
.menu dt {
300300
font-weight: bold;
301301
font-size: 13px;
302302
color:#00aeef;
303303
}
304304

305-
#menu dd {
305+
.menu dd {
306306
padding-left:5px;
307307
font-weight: normal;
308308
font-size: 11px;
309309
}
310310

311-
#menu dt { padding:0; margin:8px 0 0 0;}
312-
#menu a { color: #ffffff; background: none !important;}
313-
#menu .L, #menu .R {float: left; width: 50%; margin: 0; padding: 0;}
314-
#menu .R { float: right; }
311+
.menu dt { padding:0; margin:8px 0 0 0;}
312+
.menu a { color: #ffffff; background: none !important;}
313+
.menu .L, .menu .R {float: left; width: 50%; margin: 0; padding: 0;}
314+
.menu .R { float: right; }
315315

316316
/* Dragonfly Styles */
317317

example-site/includes/js/dragonfly.js

+7-55
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,8 @@
1-
/* scrollTo function for iPhone support */
2-
window.onload = function () {
3-
this.scrollTo(0, 1);
4-
};
5-
6-
/* toggleMenu function for Dragonfly User Guide Menu */
7-
function toggleMenu() {
8-
9-
/* very basic without animation */
10-
if ($('#menu').is(':visible')) {
11-
$('#menu').hide();
12-
} else {
13-
$('#menu').show();
14-
}
15-
16-
}
17-
18-
19-
/* simple AJAX Request */
20-
21-
function AjaxRequest(url, completeFunction) {
22-
var request = this;
23-
var request_url = url;
24-
25-
this.callback = completeFunction || function () { };
26-
this.post = function(params) {
27-
request.http = null;
28-
if (window.XMLHttpRequest) {
29-
request.http = new XMLHttpRequest();
30-
} else {
31-
request.http = new ActiveXObject("Microsoft.XMLHTTP");
32-
}
33-
34-
if (request.http == null) {
1+
$(document).ready(function () {
2+
window.scrollTo(0, 1); // scrollTo function for iPhone support
3+
$("a.menu_toggle").click(function () {
4+
$(this).parent().siblings().children("div.menu:visible").hide(); // hide the other visible menus
5+
$(this).next().toggle(); // toggle our menu
356
return false;
36-
} else {
37-
request.http.onreadystatechange = function() {
38-
if (request.http.readyState == 4 && request.http.status == 200) {
39-
request.callback(request.http.responseText, request.http.status, request.http.responseXML);
40-
request.http = null;
41-
}
42-
}
43-
44-
request.http.open("POST", request_url, true);
45-
request.http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
46-
request.http.setRequestHeader("Content-Length", params.length);
47-
request.http.send(params);
48-
return true;
49-
}
50-
51-
}
52-
}
53-
54-
55-
56-
7+
});
8+
});

example-site/views/dragonfly_ajax.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ <h1>AJAX calls</h1>
1919
<p class="extract">Dragonfly provides some simple AJAX functions. With AJAX, web applications can retrieve data from the server asynchronously in the background without interfering with the display and behavior of the existing page. The use of AJAX techniques has led to an increase in interactive or dynamic interfaces on web pages and better quality of Web services due to the asynchronous mode. Data is usually retrieved using the XMLHttpRequest object. (source: wikipedia.org)
2020
</p>
2121
<h2>Current time</h2>
22-
<p><% (ajax-updater "timer" "/dragonfly_ajax-date" "gettime" "1000") %></p>
22+
<% (ajax-updater "timer" "/dragonfly_ajax-date" "gettime" 1000) %>
2323

2424
<h2>Real-time tweets for 'michael jackson'</h2>
25-
<p><% (ajax-updater "twitter" "/dragonfly_ajax-twitter" "gettweets" "1000") %></p>
25+
<% (ajax-updater "twitter" "/dragonfly_ajax-twitter" "gettweets" 5000) %>
2626

2727
<div class="line-dotted"></div>
2828

example-site/views/dragonfly_routes.html

-24
Original file line numberDiff line numberDiff line change
@@ -85,30 +85,6 @@ <h3 class="code">Example of wings.lsp in /resources</h3>
8585

8686
<p class="config"><b>Configuration</b><br/>Set Your resource directory to whatever You want by changing the constant RESOURCES_PATH in config.lsp. Default is set to "/resources".</p>
8787

88-
89-
<h2>Using views</h2>
90-
<p class="extract">A view is simply a web page, or a page fragment, like a header or footer. In fact, views can flexibly be embedded within other views. In that case we call them partials.</p>
91-
92-
<h3 class="code">How to load a view</h3>
93-
<p>Example: open Your favorite text-editor and enter the following:</p>
94-
<pre class="code">Hello World</pre>
95-
<p>Save the file as "hello" into Your views directory. Now open Your browser and navigate to <a href="http://www.example-site.com/hello">example-site.com/hello</a>. That's it!</p>
96-
<p class="info"><b>Information</b><br/>You can put nearly everything into views: (X)HTML, Javascript, newLISP code.</p>
97-
<p class="config"><b>Configuration</b><br/>If VIEW_EXTENSION is ".html" for example, then when example-site.com/hello is called Dragonfly will search for a "hello.html" file in the VIEWS_PATH. It also applies to the partials, too.</p>
98-
99-
<h3 class="code">How to call functions inside a view</h3>
100-
<pre class="code">&lt;% (benchmark-result) %&gt;</pre>
101-
102-
<p>Put Your function call inside our open and close brackets and there You go! That will display some stats about rendering time and memory consumption.</p>
103-
104-
<p class="info"><b>Information</b><br/>You can use all functions from newLISP and Dragonfly. Additionally You may write Your own functions inside a plugin and just put the file into the "plugins-active" directory.</p>
105-
106-
<h3 class="code">How to load a partial view</h3>
107-
<pre class="code">&lt;% (display-partial "header") %&gt;</pre>
108-
109-
<p>This simple argument would load the "header"-partial from the partials directory.</p>
110-
111-
11288
<div class="line-dotted"></div>
11389

11490
<% (benchmark-result) %>

0 commit comments

Comments
 (0)