Re: using tinymce in cl-http
Rainer Joswig <[email protected]> Tue, 17 Feb 2009 11:33:53 +0100
| Newsgroups | gmane.lisp.cl-http |
|---|---|
| Message-ID | <[email protected]> |
Am 16.02.2009 um 21:47 schrieb Mark Klein:
>
> Rainer,
>
> Thanks! That works! I really appreciate your help, I was stuck.
>
> Do you know whether the tinymce javascript code gets loaded into the
> browser every time you load a page that uses it, or does the browser
> cache the code? There's a perceptible delay every time a text area
> appears. Is there a way to reduce load times by ensuring the code is
> cached?
Hi Mark,
you can look at the log to see what your server/proxy/browser
combination is doing.
Usually the browser has three ways to answer the request (simplified):
1) to look at its cache and take the result
2) to see whether the resource is still fresh. You will see a 304
response code from the server if it is.
The server does not answer with the data, just tells the browser
the response code.
There is a request which takes time, but there is no data to be
transferred if the data is not changed.
3) get the resource (the server answers with a 200 response code and
the data)
So, you can see what happens by looking at the log.
If you look at the rather long documentation for HTTP:EXPORT-URL, you
will find
the description how to control this. The file http:examples;example-
exports.lisp
shows a few ways to use HTTP:EXPORT-UR.
For example you can add an EXPIRATION date:
(http:export-url #u"/js/tiny_mce/"
:directory
:pathname (pathname "/Lisp/software/CL-HTTP-archive/
tinymce/jscripts/tiny_mce/")
:recursive-p t
:expiration `(:interval ,(* 15. 60.)))
If you look at the EXPORT-URL documentation you will see that
the :INTERVAL means
now + 15 minutes.
>
>
> I had another question, if you have the time. I'd like to have a
> popup menu appear when a user clicks on an icon in a cl-http
> generated page. The menu should appear near the icon, and the items
> in the menu should be hotlinked text that (if possible) *are
> determined when the icon is clicked, rather than when the page is
> loaded*. Have you done something like this and/or do you have any
> thoughts about how to achieve it?
Any Javascript experts here who can answer this question?
Regards,
Rainer Joswig
>
>
> Thanks,
>
> Mark
>
>>
>> Am 13.02.2009 um 20:00 schrieb Mark Klein:
>>
>>>
>>> Has anyone had any success using a javascript HTML editor (e.g.
>>> tinymce) in a page generated by cl-http? I've had no luck, and I'd
>>> appreciate any pointers people may have.
>>
>> Hi Mark,
>>
>> the following example works for me.
>>
>> I have changed the WITH-SCRIPT macro so that it does not put the
>> script into comments.
>> Then I have also added the .js file extension to javascript files.
>>
>> You might need to change the directories and URLs. I've downloaded a
>> copy of tinymce,
>> extracted the files and exported the javascript directory.
>>
>> The form function generates the form and puts a string into a
>> textarea.
>> The response function saves that string back into a global variable.
>>
>> I can then edit the text with styles and get HTML back on submit.
>>
>> Regards,
>>
>> Rainer
>>
>>
>> (in-package "HTML4.0")
>>
>> (define-macro with-script ((media-type &key script-location no-
>> content
>> charset language (stream '*output-stream*)) &body body)
>> "Provides an environment for emitting a client-side script with
>> MEDIA-TYPE on STREAM.
>>
>> MEDIA-TYPE is required and must be the content type for the scripting
>> language, like:
>>
>> (:text :javascript) -- JavaScript script
>> (:text :tcl) -- TCL script
>> (:text :vbscript) -- Visual Basic script
>>
>> MEDIA-TYPE overrides any default scripting language declarations in
>> the document preamble.
>>
>> BODY executes code that emit the script the source on STREAM, or
>> alternatively
>> SCRIPT-LOCATION may used to designate a URI that loads the script
>> text
>> into the client.
>>
>> NO-CONTENT is a boolean that informs the browser that the script
>> emitted within BODY or
>> loaded from SCRIPT-LOCATION will not display content, and so, the
>> browser may handle
>> this asynchronously and continue rendering the document.
>>
>> CHARSET is the character encoding of the script text (see ISO 10646).
>>
>> LANGUAGE (deprecated) is keyword or string identifying the scripting
>> language."
>> `(%with-environment
>> ("script" :stream ,stream)
>> (%write-with-script-arguments ,stream ,media-type ,script-
>> location ,no-content ,charset ,language)
>> (fresh-line stream)
>>
>> ,@body))
>>
>> ;;; Example
>>
>> (in-package "HTTP-USER")
>>
>> (http:define-url-export-type :java-script-file :javascript
>> (:text :javascript)
>> :copy-mode #.http::+standard-text-copy-
>> mode+
>> :data-type :text
>> :alternate-extensions (:js))
>>
>> (http:export-url #u"/js/tiny_mce/"
>> :directory
>> :pathname (pathname "/Lisp/software/CL-HTTP-archive/
>> tinymce/jscripts/tiny_mce/")
>> :recursive-p t)
>>
>> (defparameter *mytext* "Hi there from CL-HTTP.")
>>
>> (defun generate-tinymce-example (url stream)
>> (declare (ignore url))
>> (with-successful-response (stream :html)
>> (with-html-document (:stream stream)
>> (with-document-preamble (:stream stream)
>> (declare-title "tinymce example" :stream stream)
>> (with-script ('(:text :javascript) :script-location "/js/
>> tiny_mce/tiny_mce.js" :stream stream))
>> (with-script ('(:text :javascript) :stream stream)
>> (princ "tinyMCE.init({mode : \"textareas\" });" stream)))
>> (with-document-body (:stream stream)
>> (html:with-fillout-form (:post #u"/tinymceexample" :stream
>> stream)
>> (html:accept-input 'html:multi-line-text "content"
>> :default *mytext*
>> :stream stream)
>> (html2:break-line :stream stream)
>> (html:with-rendition (:bold :stream stream)
>> (html:accept-input 'html:submit-button "Submit" :stream
>> stream)))))))
>>
>> (defun generate-tinymce-example-response (url stream query-alist)
>> (http:bind-query-values (content) (url query-alist)
>> (setf *mytext* content)
>> (generate-tinymce-example url stream)))
>>
>> (http:export-url #u"/tinymceexample"
>> :computed-form
>> :form-function 'generate-tinymce-example
>> :response-function 'generate-tinymce-example-
>> response)
>>
>>
>>
>>
>>
>>>
>>>
>>> Mark
>>>
>>> -----------------
>>> Mark Klein
>>> Principal Research Scientist
>>> MIT Center for Collective Intelligence
>>> http://cci.mit.edu/klein/
>>>
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> WWW-CL mailing list
>>> [email protected]
>>> https://lists.csail.mit.edu/mailman/listinfo/www-cl
>>
>> Rainer Joswig, Hamburg, Germany
>> http://lispm.dyndns.org/
>> mailto:[email protected]
>>
>>
>>
>>
>> _______________________________________________
>> WWW-CL mailing list
>> [email protected]
>> https://lists.csail.mit.edu/mailman/listinfo/www-cl
>
> -----------------
> Mark Klein
> Principal Research Scientist
> MIT Center for Collective Intelligence
> http://cci.mit.edu/klein/
>
>
>
Rainer Joswig, Hamburg, Germany
http://lispm.dyndns.org/
mailto:[email protected]
_______________________________________________
WWW-CL mailing list
[email protected]
https://lists.csail.mit.edu/mailman/listinfo/www-cl