26
|
1 ;;; w3-script.el --- Scripting support
|
|
2 ;; Author: wmperry
|
38
|
3 ;; Created: 1997/03/20 14:22:28
|
|
4 ;; Version: 1.7
|
26
|
5 ;; Keywords: hypermedia, scripting
|
|
6
|
|
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
8 ;;; Copyright (c) 1997 Free Software Foundation, Inc.
|
|
9 ;;;
|
|
10 ;;; This file is part of GNU Emacs.
|
|
11 ;;;
|
|
12 ;;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
13 ;;; it under the terms of the GNU General Public License as published by
|
|
14 ;;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;;; any later version.
|
|
16 ;;;
|
|
17 ;;; GNU Emacs is distributed in the hope that it will be useful,
|
|
18 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20 ;;; GNU General Public License for more details.
|
|
21 ;;;
|
|
22 ;;; You should have received a copy of the GNU General Public License
|
|
23 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
24 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
25 ;;; Boston, MA 02111-1307, USA.
|
|
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
27
|
|
28 (require 'cl)
|
|
29 (require 'w3-elisp)
|
|
30 (require 'w3-jscript)
|
|
31
|
|
32 ;; Event Handlers
|
|
33 ;; onclick ; It was clicked on
|
|
34 ;; onchange ; Text area was changed
|
|
35 ;; onselect ; Menu choice changed
|
|
36 ;; onmouseover ; Mouse is over us
|
|
37 ;; onmouseout ; Mouse left us
|
|
38 ;; onblur ; We lost focus
|
|
39 ;; onfocus ; We gained focus
|
|
40 ;; onload ; We got loaded
|
|
41 ;; onunload ; We got unloaded
|
|
42 ;; onreset ; Form got reset
|
|
43 ;; onsubmit ; From is about to be submitted
|
|
44 ;; onabort ; User cancelled loading an image
|
|
45 ;; onerror ; Error occurred loading an image
|
|
46
|
38
|
47 (defgroup w3-scripting nil
|
|
48 "When, where, how, and why to enable client-side scripting."
|
|
49 :group 'w3)
|
|
50
|
|
51 (defcustom w3-do-scripting nil
|
26
|
52 "*Whether to handle client-side scripting or not.
|
38
|
53 If you are adventurous, set this to `t'"
|
|
54 :group 'w3-scripting
|
|
55 :type 'boolean)
|
26
|
56
|
|
57 (defvar w3-current-scripting-language 'elisp)
|
|
58 (make-variable-buffer-local 'w3-current-scripting-language)
|
|
59
|
|
60 (put 'form 'w3-event-handlers
|
|
61 '(onclick onchange onselect onblur onfocus onreset onsubmit))
|
|
62
|
|
63 (put 'mouse 'w3-event-handlers '(onmouseover onmouseout))
|
|
64
|
|
65 (put 'misc 'w3-event-handlers '(onload onunload))
|
|
66
|
|
67 (put 'all 'w3-event-handlers (append (get 'form 'w3-event-handlers)
|
|
68 (get 'mouse 'w3-event-handlers)))
|
|
69
|
|
70 (defun w3-script-find-event-handlers (pt type)
|
|
71 (if w3-do-scripting
|
|
72 (let* ((html-stack (get-text-property pt 'html-stack))
|
|
73 (args nil)
|
|
74 (rval nil)
|
|
75 (cur nil))
|
|
76 (while html-stack
|
|
77 (setq args (cdr (pop html-stack)))
|
|
78 (while (setq cur (pop args))
|
|
79 (if (memq (car cur) (get type 'w3-event-handlers))
|
|
80 (setq rval (cons cur rval)))))
|
|
81 (nreverse rval))))
|
|
82
|
|
83 (defun w3-script-evaluate-form (f)
|
|
84 (if w3-do-scripting
|
|
85 (case w3-current-scripting-language
|
|
86 (elisp
|
|
87 (let ((st 0)
|
|
88 (form nil)
|
|
89 (max (length f)))
|
32
|
90 (condition-case ()
|
|
91 (while (and (< st max) (setq form (read-from-string f st)))
|
|
92 (setq st (cdr form)
|
|
93 form (car form))
|
|
94 (w3-elisp-safe-eval form))
|
|
95 (error nil))))
|
26
|
96 (otherwise
|
30
|
97 (message "Unimplemented scripting language: %S"
|
|
98 w3-current-scripting-language)))))
|
26
|
99
|
|
100 (provide 'w3-script)
|