├── .gitignore ├── license.txt ├── src ├── .gitignore ├── widgets │ ├── .gitignore │ ├── login-maybe.lisp │ ├── post.lisp │ └── blog.lisp ├── init-session.lisp ├── model │ ├── user.lisp │ └── post.lisp ├── views │ ├── presentations │ │ └── action-link.lisp │ └── post-views.lisp └── layout.lisp ├── pub ├── images │ ├── reset.png │ ├── progress.gif │ ├── bubblehead.png │ ├── dialog │ │ ├── close.gif │ │ ├── question.png │ │ └── information.png │ ├── header │ │ ├── logo.png │ │ ├── background.png │ │ ├── top_left.png │ │ ├── top_right.png │ │ ├── bottom_left.png │ │ └── bottom_right.png │ ├── menu │ │ ├── arrow.png │ │ ├── top_left.png │ │ ├── top_right.png │ │ ├── bottom_left.png │ │ ├── bottom_right.png │ │ ├── selected_arrow.png │ │ ├── top_background.png │ │ └── bottom_background.png │ ├── widget │ │ ├── arrow.png │ │ ├── flash │ │ │ ├── flag.png │ │ │ ├── top_left.png │ │ │ ├── top_right.png │ │ │ ├── bottom_left.png │ │ │ ├── bottom_right.png │ │ │ ├── top_background.png │ │ │ └── bottom_background.png │ │ ├── top_left.png │ │ ├── top_right.png │ │ ├── bottom_left.png │ │ ├── bottom_right.png │ │ ├── top_background.png │ │ ├── bottom_background.png │ │ ├── datagrid │ │ │ ├── up_arrow.png │ │ │ ├── down_arrow.png │ │ │ ├── sort_bg_asc.png │ │ │ └── sort_bg_desc.png │ │ ├── datalist │ │ │ ├── up_arrow.png │ │ │ ├── down_arrow.png │ │ │ ├── up_arrow_link.png │ │ │ └── down_arrow_link.png │ │ ├── table_border_top.png │ │ └── dataseq │ │ │ └── flash │ │ │ ├── bottom_left.png │ │ │ └── bottom_right.png │ ├── bubble-310x310.png │ ├── page │ │ ├── top_left.png │ │ ├── top_right.png │ │ ├── background.png │ │ ├── bottom_left.png │ │ ├── bottom_right.png │ │ ├── hor_border.png │ │ └── hor_border_bottom.png │ ├── footer │ │ ├── valid-css.png │ │ └── valid-xhtml11.png │ └── horizontal_line.png ├── stylesheets │ ├── isearch.css │ ├── dataform.css │ ├── blog-widget.css │ ├── suggest.css │ ├── navigation.css │ ├── debug-toolbar.css │ ├── table.css │ ├── flash.css │ ├── datagrid.css │ ├── pagination.css │ ├── menu.css │ ├── dialog.css │ ├── post-widget.css │ ├── dataseq.css │ ├── layout.css │ ├── form.css │ ├── datalist.css │ └── main.css └── scripts │ ├── weblocks-debug.js │ ├── sound.js │ ├── scriptaculous.js │ ├── datagrid.js │ ├── dialog.js │ ├── builder.js │ ├── shortcut.js │ ├── weblocks.js │ ├── slider.js │ ├── unittest.js │ ├── controls.js │ └── dragdrop.js ├── conf └── stores.lisp ├── simple-blog.lisp ├── simple-blog.asd └── ChangeLog /.gitignore: -------------------------------------------------------------------------------- 1 | data/* 2 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | LLGPL 2 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | /*.fasl 2 | -------------------------------------------------------------------------------- /src/widgets/.gitignore: -------------------------------------------------------------------------------- 1 | /*.fasl 2 | -------------------------------------------------------------------------------- /pub/images/reset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/reset.png -------------------------------------------------------------------------------- /pub/images/progress.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/progress.gif -------------------------------------------------------------------------------- /pub/images/bubblehead.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/bubblehead.png -------------------------------------------------------------------------------- /pub/images/dialog/close.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/dialog/close.gif -------------------------------------------------------------------------------- /pub/images/header/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/header/logo.png -------------------------------------------------------------------------------- /pub/images/menu/arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/menu/arrow.png -------------------------------------------------------------------------------- /pub/images/widget/arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/arrow.png -------------------------------------------------------------------------------- /pub/images/bubble-310x310.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/bubble-310x310.png -------------------------------------------------------------------------------- /pub/images/menu/top_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/menu/top_left.png -------------------------------------------------------------------------------- /pub/images/menu/top_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/menu/top_right.png -------------------------------------------------------------------------------- /pub/images/page/top_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/page/top_left.png -------------------------------------------------------------------------------- /pub/images/page/top_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/page/top_right.png -------------------------------------------------------------------------------- /pub/images/dialog/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/dialog/question.png -------------------------------------------------------------------------------- /pub/images/footer/valid-css.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/footer/valid-css.png -------------------------------------------------------------------------------- /pub/images/header/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/header/background.png -------------------------------------------------------------------------------- /pub/images/header/top_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/header/top_left.png -------------------------------------------------------------------------------- /pub/images/header/top_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/header/top_right.png -------------------------------------------------------------------------------- /pub/images/horizontal_line.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/horizontal_line.png -------------------------------------------------------------------------------- /pub/images/menu/bottom_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/menu/bottom_left.png -------------------------------------------------------------------------------- /pub/images/menu/bottom_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/menu/bottom_right.png -------------------------------------------------------------------------------- /pub/images/page/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/page/background.png -------------------------------------------------------------------------------- /pub/images/page/bottom_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/page/bottom_left.png -------------------------------------------------------------------------------- /pub/images/page/bottom_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/page/bottom_right.png -------------------------------------------------------------------------------- /pub/images/page/hor_border.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/page/hor_border.png -------------------------------------------------------------------------------- /pub/images/widget/flash/flag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/flash/flag.png -------------------------------------------------------------------------------- /pub/images/widget/top_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/top_left.png -------------------------------------------------------------------------------- /pub/images/widget/top_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/top_right.png -------------------------------------------------------------------------------- /pub/images/dialog/information.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/dialog/information.png -------------------------------------------------------------------------------- /pub/images/header/bottom_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/header/bottom_left.png -------------------------------------------------------------------------------- /pub/images/header/bottom_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/header/bottom_right.png -------------------------------------------------------------------------------- /pub/images/menu/selected_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/menu/selected_arrow.png -------------------------------------------------------------------------------- /pub/images/menu/top_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/menu/top_background.png -------------------------------------------------------------------------------- /pub/images/widget/bottom_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/bottom_left.png -------------------------------------------------------------------------------- /pub/images/widget/bottom_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/bottom_right.png -------------------------------------------------------------------------------- /pub/stylesheets/isearch.css: -------------------------------------------------------------------------------- 1 | 2 | .isearch input.submit 3 | { 4 | margin-right: 0; 5 | margin-left: 0.5em; 6 | } 7 | -------------------------------------------------------------------------------- /pub/images/footer/valid-xhtml11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/footer/valid-xhtml11.png -------------------------------------------------------------------------------- /pub/images/menu/bottom_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/menu/bottom_background.png -------------------------------------------------------------------------------- /pub/images/page/hor_border_bottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/page/hor_border_bottom.png -------------------------------------------------------------------------------- /pub/images/widget/flash/top_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/flash/top_left.png -------------------------------------------------------------------------------- /pub/images/widget/flash/top_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/flash/top_right.png -------------------------------------------------------------------------------- /pub/images/widget/top_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/top_background.png -------------------------------------------------------------------------------- /pub/images/widget/bottom_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/bottom_background.png -------------------------------------------------------------------------------- /pub/images/widget/datagrid/up_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/datagrid/up_arrow.png -------------------------------------------------------------------------------- /pub/images/widget/datalist/up_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/datalist/up_arrow.png -------------------------------------------------------------------------------- /pub/images/widget/flash/bottom_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/flash/bottom_left.png -------------------------------------------------------------------------------- /pub/images/widget/table_border_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/table_border_top.png -------------------------------------------------------------------------------- /pub/images/widget/datagrid/down_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/datagrid/down_arrow.png -------------------------------------------------------------------------------- /pub/images/widget/datagrid/sort_bg_asc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/datagrid/sort_bg_asc.png -------------------------------------------------------------------------------- /pub/images/widget/datalist/down_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/datalist/down_arrow.png -------------------------------------------------------------------------------- /pub/images/widget/flash/bottom_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/flash/bottom_right.png -------------------------------------------------------------------------------- /pub/images/widget/flash/top_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/flash/top_background.png -------------------------------------------------------------------------------- /pub/images/widget/datagrid/sort_bg_desc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/datagrid/sort_bg_desc.png -------------------------------------------------------------------------------- /pub/images/widget/datalist/up_arrow_link.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/datalist/up_arrow_link.png -------------------------------------------------------------------------------- /pub/images/widget/datalist/down_arrow_link.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/datalist/down_arrow_link.png -------------------------------------------------------------------------------- /pub/images/widget/dataseq/flash/bottom_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/dataseq/flash/bottom_left.png -------------------------------------------------------------------------------- /pub/images/widget/flash/bottom_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/flash/bottom_background.png -------------------------------------------------------------------------------- /pub/images/widget/dataseq/flash/bottom_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/simple-blog/master/pub/images/widget/dataseq/flash/bottom_right.png -------------------------------------------------------------------------------- /pub/stylesheets/dataform.css: -------------------------------------------------------------------------------- 1 | /* @import url(/weblocks-common/pub/stylesheets/data.css); */ 2 | @import url(/weblocks-common/pub/stylesheets/form.css); 3 | 4 | -------------------------------------------------------------------------------- /pub/scripts/weblocks-debug.js: -------------------------------------------------------------------------------- 1 | 2 | function onActionFailure(transport) { 3 | document.body.innerHTML= 4 | '
' + 5 | transport.responseText 6 | + '
'; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /pub/stylesheets/blog-widget.css: -------------------------------------------------------------------------------- 1 | div.blog-widget.blog-mode #bubblehead 2 | { 3 | position: relative; 4 | margin-left: 40%; 5 | margin-right: auto; 6 | margin-bottom: -20px; 7 | z-index: 50; 8 | } -------------------------------------------------------------------------------- /src/init-session.lisp: -------------------------------------------------------------------------------- 1 | 2 | (in-package :simple-blog) 3 | 4 | ;; Define callback function to initialize new sessions 5 | (defun init-user-session (comp) 6 | (setf (widget-children comp) 7 | (make-main-page))) 8 | -------------------------------------------------------------------------------- /conf/stores.lisp: -------------------------------------------------------------------------------- 1 | 2 | (in-package :simple-blog) 3 | 4 | ;;; Multiple stores may be defined. The last defined store will be the 5 | ;;; default. 6 | (defstore *blog-store* :prevalence 7 | (merge-pathnames (make-pathname :directory '(:relative "data")) 8 | (asdf-system-directory :simple-blog))) 9 | 10 | -------------------------------------------------------------------------------- /pub/stylesheets/suggest.css: -------------------------------------------------------------------------------- 1 | 2 | div.suggest 3 | { 4 | border: solid 1px; 5 | background-color: #F6FBFD; 6 | } 7 | 8 | div.suggest ul 9 | { 10 | margin: 0; 11 | padding: 0; 12 | } 13 | 14 | div.suggest ul li 15 | { 16 | list-style-type: none; 17 | margin: 0; 18 | padding: 2px; 19 | display: block; 20 | } 21 | 22 | div.suggest ul li.selected 23 | { 24 | background-color: #D8EAF8; 25 | } 26 | -------------------------------------------------------------------------------- /src/model/user.lisp: -------------------------------------------------------------------------------- 1 | ;;;; mode: common-lisp; mode: paredit; mode: slime 2 | (in-package :simple-blog) 3 | 4 | (defclass user () 5 | ((id) 6 | (name :accessor user-name 7 | :initarg :name 8 | :initform "" 9 | :type string) 10 | (email :accessor user-email 11 | :initarg :email 12 | :initform "") 13 | (pw-hash :accessor user-pw-hash 14 | :initarg :pw-hash 15 | :initform nil))) 16 | 17 | (defun all-users (&rest args) 18 | (declare (ignore args)) 19 | (find-persistent-objects (class-store 'user) 'user)) 20 | -------------------------------------------------------------------------------- /pub/stylesheets/navigation.css: -------------------------------------------------------------------------------- 1 | #MENU-navigation 2 | { 3 | width: auto; 4 | float: right; 5 | position: absolute; 6 | top: 0px; 7 | right: 1px; 8 | } 9 | 10 | #MENU-navigation h1 11 | { 12 | display: none; 13 | } 14 | 15 | #MENU-navigation ul li 16 | { 17 | display: inline; 18 | } 19 | 20 | #MENU-navigation a 21 | { 22 | display: inline; 23 | } 24 | 25 | #MENU-navigation li span span 26 | { 27 | width: auto; 28 | padding-right: 2px; 29 | padding-left: 2px; 30 | text-align: center; 31 | } 32 | 33 | #MENU-navigation li.selected-item 34 | { 35 | background: none; 36 | } 37 | #MENU-navigation li.selected-item span 38 | { 39 | background: none; 40 | } -------------------------------------------------------------------------------- /pub/stylesheets/debug-toolbar.css: -------------------------------------------------------------------------------- 1 | 2 | .debug-toolbar 3 | { 4 | background-color: #d0d0d0; 5 | border-top: #f5f5f5 1px solid; 6 | 7 | width: 100%; 8 | text-align: left; 9 | } 10 | 11 | /* 'position: fixed' for all modern browsers */ 12 | body > .debug-toolbar 13 | { 14 | position: fixed; 15 | left: 0; 16 | bottom: 0; 17 | } 18 | 19 | /* IE 6 specific fix for lack of 'position: fixed' implementation */ 20 | * html .debug-toolbar 21 | { 22 | position: absolute; 23 | /* in case JS is turned off */ 24 | left: 0; 25 | /* in case JS is on */ 26 | left: expression((documentElement.scrollLeft) + 'px'); 27 | top: expression((documentElement.scrollTop 28 | + (documentElement.clientHeight - this.clientHeight - 1)) 29 | + 'px'); 30 | width: expression((document.documentElement.clientWidth) + 'px'); 31 | } 32 | 33 | .debug-toolbar img 34 | { 35 | border: none; 36 | } 37 | -------------------------------------------------------------------------------- /src/views/presentations/action-link.lisp: -------------------------------------------------------------------------------- 1 | ;;;; mode: common-lisp; mode: paredit; mode: slime 2 | (in-package :simple-blog) 3 | 4 | (defclass action-link-presentation (text-presentation) 5 | ((action :initform nil 6 | :initarg :action-fn 7 | :accessor action-link-presentation-body 8 | :documentation "This needs to be a function that accepts at 9 | least the first six arguments passed to 10 | render-view-field-value in order to get access to the 11 | object being rendered."))) 12 | 13 | (defmethod render-view-field-value (value (presentation action-link-presentation) 14 | field view widget obj &rest args 15 | &key highlight &allow-other-keys) 16 | (declare (ignore highlight args)) 17 | (if (null value) 18 | (call-next-method) ;; just render as text 19 | (render-link (lambda (&rest args) 20 | (funcall (action-link-presentation-body presentation) 21 | widget)) 22 | value))) -------------------------------------------------------------------------------- /simple-blog.lisp: -------------------------------------------------------------------------------- 1 | 2 | (defpackage #:simple-blog 3 | (:use :cl :weblocks :cl-who 4 | :metabang.utilities) 5 | (:import-from :weblocks-stores :class-store :find-persistent-objects) 6 | (:import-from :weblocks-util :safe-apply) 7 | (:documentation 8 | "A web application based on Weblocks.")) 9 | 10 | (in-package :simple-blog) 11 | 12 | (export '(start-simple-blog stop-simple-blog)) 13 | 14 | (defwebapp simple-blog 15 | :prefix "/" 16 | :description "simple-blog: An example application" 17 | :init-user-session 'simple-blog::init-user-session 18 | :autostart nil ;; have to start the app manually 19 | :dependencies '((:stylesheet "navigation")) 20 | :ignore-default-dependencies nil 21 | :debug t) ;; accept the defaults 22 | 23 | (defvar *msg-log-path* 24 | #p"/tmp/simple-blog-msg.log") 25 | (defvar *access-log-path* 26 | #p"/tmp/simple-blog-access.log") 27 | 28 | (defun start-simple-blog (&rest args) 29 | "Starts the application by calling 'start-weblocks' with appropriate 30 | arguments." 31 | (apply #'start-weblocks args) 32 | (start-webapp 'simple-blog)) 33 | 34 | (defun stop-simple-blog () 35 | "Stops the application by calling 'stop-weblocks'." 36 | (stop-webapp 'simple-blog) 37 | (stop-weblocks)) 38 | 39 | -------------------------------------------------------------------------------- /src/widgets/login-maybe.lisp: -------------------------------------------------------------------------------- 1 | ;; mode: common-lisp; mode: paredit; mode: slime; 2 | (in-package :simple-blog) 3 | 4 | (defwidget login-maybe (login) 5 | ((child-widget :accessor login-maybe-child-widget 6 | :initarg :child-widget 7 | :documentation "The widget to render if we are already logged in.") 8 | (dom-id :initform "login")) 9 | (:documentation "Render login form only if not logged in.")) 10 | 11 | (defmethod initialize-instance ((self login-maybe) &key &allow-other-keys) 12 | (call-next-method) 13 | (setf (widget-continuation self) 14 | (lambda (&optional auth) 15 | (declare (ignore auth)) 16 | (mark-dirty self)))) 17 | 18 | (defmethod render-widget-body((self login-maybe) &key &allow-other-keys) 19 | (cond 20 | ((authenticatedp) 21 | (hunchentoot:log-message* :debug "=== authenticated! ===") 22 | (render-widget (login-maybe-child-widget self) :inlinep t)) 23 | (t 24 | (hunchentoot:log-message* :debug "=== not authenticated! ==") 25 | (call-next-method)))) 26 | 27 | (defun check-login (login-widget credentials-obj) 28 | "Check the user's login credentials" 29 | (declare (ignore login-widget)) 30 | credentials-obj) 31 | 32 | (defun login-success (lw cred-obj) 33 | (declare (ignore cred-obj)) 34 | (render-widget (login-maybe-child-widget lw))) 35 | -------------------------------------------------------------------------------- /simple-blog.asd: -------------------------------------------------------------------------------- 1 | ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*- 2 | (defpackage #:simple-blog-asd 3 | (:use :cl :asdf)) 4 | 5 | (in-package :simple-blog-asd) 6 | 7 | (defsystem simple-blog 8 | :name "simple-blog" 9 | :version "0.0.3" 10 | :maintainer "" 11 | :author "" 12 | :licence "" 13 | :description "simple blog" 14 | :depends-on (:weblocks) 15 | :components ((:file "simple-blog") 16 | (:module conf 17 | :components ((:file "stores")) 18 | :depends-on ("simple-blog")) 19 | (:module src 20 | :components 21 | ((:file "init-session" 22 | :depends-on ("layout")) 23 | (:file "layout" 24 | :depends-on ("model" "views")) 25 | (:module model 26 | :components 27 | ((:file "post" 28 | :depends-on ("user")) 29 | (:file "user"))) 30 | (:module views 31 | :components 32 | ((:file "post-views" 33 | :depends-on ("presentations")) 34 | (:module presentations 35 | :components 36 | ((:file "action-link")))) 37 | :depends-on ("model")) 38 | (:module widgets 39 | :components 40 | ((:file "post") 41 | (:file "blog" 42 | :depends-on ("post")) 43 | (:file "login-maybe")) 44 | :depends-on ("model" "views"))) 45 | :depends-on ("simple-blog" conf)))) 46 | -------------------------------------------------------------------------------- /src/views/post-views.lisp: -------------------------------------------------------------------------------- 1 | (in-package :simple-blog) 2 | 3 | (defview user-table-view (:type table :inherit-from '(:scaffold user)) 4 | (pw-hash :hidep t)) 5 | 6 | (defview user-data-view (:type data :inherit-from '(:scaffold user)) 7 | (pw-hash :hidep t)) 8 | 9 | (defview user-form-view (:type form :inherit-from '(:scaffold user)) 10 | (pw-hash )) 11 | 12 | (defview post-table-view (:type table :inherit-from '(:scaffold post))) 13 | 14 | (defview post-data-view (:type data :inherit-from '(:scaffold post)) 15 | (author :reader #'post-author-name) 16 | (time :reader #'post-formatted-time)) 17 | 18 | (defview post-form-view (:type form :inherit-from '(:scaffold post)) 19 | (time :hidep t) 20 | ;; POST-AUTHOR-ID and ALL-USERS will be defined below 21 | (author :reader #'post-author-id 22 | :present-as (dropdown :choices #'all-users 23 | :label-key #'user-name) 24 | :parse-as (object-id :class-name 'user) 25 | :requiredp t) 26 | (short-text :present-as textarea 27 | :requiredp t) 28 | (text :present-as (textarea :cols 30) 29 | :requiredp t)) 30 | 31 | (defview post-short-view (:type data :inherit-from 'post-data-view) 32 | (title :present-as (action-link 33 | :action-fn (lambda (w) 34 | (setf (mode w) :full) 35 | (let ((blog (blog-widget w))) 36 | (setf (mode blog) :post)) 37 | (safe-funcall (on-select w) w)))) 38 | (text :hidep t)) 39 | 40 | (defview post-full-view (:type data :inherit-from 'post-data-view) 41 | (short-text :hidep t)) 42 | -------------------------------------------------------------------------------- /pub/stylesheets/table.css: -------------------------------------------------------------------------------- 1 | 2 | .table 3 | { 4 | min-width: 42em; 5 | } 6 | 7 | .table table 8 | { 9 | width: 100%; 10 | } 11 | 12 | .table table thead tr th 13 | { 14 | text-align: left; 15 | } 16 | 17 | .table table thead tr th, .table table tbody tr td 18 | { 19 | padding-left: 0.5em; 20 | } 21 | 22 | .table table tbody tr td strong 23 | { 24 | background: #fe4631; 25 | color: white; 26 | font-weight: normal; 27 | } 28 | 29 | .view table tbody tr td 30 | { 31 | border-bottom: 1px solid #dbeac1; 32 | padding-top: 1px; 33 | background-image: url(/weblocks-common/pub/images/widget/table_border_top.png); 34 | background-repeat: repeat-x; 35 | background-position: top; 36 | } 37 | 38 | /* Hover on table */ 39 | .table table tbody tr:hover, 40 | .datagrid table tbody tr.drilled-down, 41 | .table table tr.hover 42 | { 43 | background: #dbeac1; 44 | } 45 | 46 | /* IE specific border behavior (no support for border-spacing) */ 47 | .table table 48 | { 49 | border-collapse: collapse; 50 | } 51 | 52 | /* Border behavior for other browsers (can't use border-collapse 53 | because of incosistent behavior between Opera, Mozilla, IE, and 54 | Safari). Note, comment is necessary to hide from IE7. */ 55 | .table >/**/table 56 | { 57 | border-spacing: 0; 58 | border-collapse: separate; 59 | } 60 | 61 | /* Safari and WebKit specific caption fix */ 62 | html[xmlns*=""] body:last-child .table table caption 63 | { 64 | width: 100%; 65 | } 66 | 67 | @media all and (min-width: 0px) 68 | { 69 | body:not(:root:root) .table table caption 70 | { 71 | width: 100%; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /pub/stylesheets/flash.css: -------------------------------------------------------------------------------- 1 | 2 | .flash .view 3 | { 4 | width: 100%; 5 | background: #f8e9d8 url(/weblocks-common/pub/images/widget/flash/top_background.png) repeat-x; 6 | } 7 | 8 | .flash .view .extra-top-1 9 | { 10 | background: url(/weblocks-common/pub/images/widget/flash/top_left.png) no-repeat top left; 11 | } 12 | 13 | .flash .view .extra-top-2 14 | { 15 | background: url(/weblocks-common/pub/images/widget/flash/top_right.png) no-repeat top right; 16 | border-bottom-color: #ead8c2; 17 | } 18 | 19 | .flash .view ul.messages p 20 | { 21 | padding: 0; 22 | margin: 0; 23 | } 24 | 25 | .flash .view ul.messages 26 | { 27 | border-left-color: #ead8c2; 28 | border-right-color: #ead8c2; 29 | } 30 | 31 | .flash .view ul.messages li 32 | { 33 | padding-left: 32px; 34 | min-height: 16px; 35 | border-top-color: #fef9f6; 36 | border-bottom-color: #ead8c2; 37 | list-style-image: none; 38 | background: url(/weblocks-common/pub/images/widget/flash/flag.png) no-repeat top left; 39 | } 40 | 41 | /* Fake min-height for IE 6 */ 42 | * html .flash .view ul.messages li 43 | { 44 | height: 16px; 45 | } 46 | 47 | .flash .view .extra-bottom-1 48 | { 49 | background: url(/weblocks-common/pub/images/widget/flash/bottom_background.png) repeat-x top; 50 | border-top-color: #fef9f6; 51 | } 52 | 53 | .flash .view .extra-bottom-2 54 | { 55 | background: url(/weblocks-common/pub/images/widget/flash/bottom_left.png) no-repeat top left; 56 | } 57 | 58 | .flash .view .extra-bottom-3 59 | { 60 | background: url(/weblocks-common/pub/images/widget/flash/bottom_right.png) no-repeat top right; 61 | } 62 | 63 | -------------------------------------------------------------------------------- /src/layout.lisp: -------------------------------------------------------------------------------- 1 | (in-package :simple-blog) 2 | 3 | (defun make-main-page () 4 | (hunchentoot:log-message* :debug "creating main page") 5 | (let ((blog (make-blog-widget))) 6 | (make-navigation 'navigation 7 | (list nil blog) 8 | (list 'main blog) 9 | (list 'admin (make-instance 'login-maybe 10 | :on-login #'check-login 11 | :on-success #'login-success 12 | :child-widget (make-admin-page)))))) 13 | 14 | (defun make-users-gridedit () 15 | (make-instance 'gridedit 16 | :name 'users-grid 17 | :data-class 'user 18 | :view 'user-table-view 19 | :widget-prefix-fn (lambda (&rest args) 20 | (declare (ignore args)) 21 | (with-html (:h1 "Users"))) 22 | :item-data-view 'user-data-view 23 | :item-form-view 'user-form-view)) 24 | 25 | (defun make-posts-gridedit () 26 | (make-instance 'gridedit 27 | :name 'posts-grid 28 | :data-class 'post 29 | :widget-prefix-fn (lambda (&rest args) 30 | (declare (ignore args)) 31 | (with-html (:h1 "Posts"))) 32 | :view 'post-table-view 33 | :item-data-view 'post-data-view 34 | :item-form-view 'post-form-view)) 35 | 36 | (defun make-admin-page () 37 | (make-instance 'widget 38 | :children 39 | (list (make-users-gridedit) 40 | (lambda () 41 | ;; gridedit widgets were probably not intended to be put 2 42 | ;; on the same page, so I add an HR tag between the two 43 | (with-html (:div (:hr :style "margin: 2em;")))) 44 | (make-posts-gridedit)))) 45 | 46 | (defun make-blog-widget () 47 | (make-instance 'blog-widget 48 | :post-short-view 'post-short-view 49 | :post-full-view 'post-full-view)) 50 | -------------------------------------------------------------------------------- /pub/stylesheets/datagrid.css: -------------------------------------------------------------------------------- 1 | @import url(/weblocks-common/pub/stylesheets/table.css); 2 | 3 | /* Body */ 4 | .datagrid 5 | { 6 | margin-bottom: 1em; 7 | position: relative; 8 | _height: 1%; /* IE 6 fix */ 9 | } 10 | 11 | /* Sorting */ 12 | .sort-asc span 13 | { 14 | background: url(/weblocks-common/pub/images/widget/datagrid/sort_bg_asc.png) repeat-x bottom; 15 | } 16 | 17 | .sort-asc span a 18 | { 19 | background: url(/weblocks-common/pub/images/widget/datagrid/up_arrow.png) no-repeat right center; 20 | } 21 | 22 | .sort-desc span 23 | { 24 | background: url(/weblocks-common/pub/images/widget/datagrid/sort_bg_desc.png) repeat-x top; 25 | } 26 | 27 | .sort-desc span a 28 | { 29 | background: url(/weblocks-common/pub/images/widget/datagrid/down_arrow.png) no-repeat right center; 30 | } 31 | 32 | 33 | .sort-asc span a, .sort-desc span a, 34 | .sort-asc span, .sort-desc span 35 | { 36 | display: block; 37 | text-decoration: underline; 38 | } 39 | 40 | /* Selecting */ 41 | p.datagrid-select-bar 42 | { 43 | padding: 0; 44 | margin: 0; 45 | font-size: x-small; 46 | position: absolute; 47 | bottom: 0; 48 | left: 0; 49 | } 50 | 51 | p.datagrid-select-bar strong 52 | { 53 | color: gray; 54 | font-family: Garamond, New York, serif; 55 | font-weight: normal; 56 | } 57 | 58 | .datagrid form .select 59 | { 60 | text-align: right; 61 | width: 1em; 62 | } 63 | 64 | .datagrid table tbody tr.drilled-down td.select input 65 | { 66 | visibility: hidden; 67 | } 68 | 69 | .datagrid table tbody tr.drilled-down td.select div 70 | { 71 | background: url(/weblocks-common/pub/images/widget/arrow.png) no-repeat center center; 72 | } 73 | 74 | /* We need to adjust margins to properly style pagination and item 75 | operations */ 76 | .datagrid .datagrid-body .view.table 77 | { 78 | margin-bottom: 0; 79 | } 80 | 81 | -------------------------------------------------------------------------------- /src/widgets/post.lisp: -------------------------------------------------------------------------------- 1 | (in-package :simple-blog) 2 | 3 | (defwidget post-widget () 4 | ((blog :accessor blog-widget 5 | :initarg :blog) 6 | (post :accessor post 7 | :initarg :post 8 | :initform nil) 9 | (mode :accessor mode 10 | :initarg :mode 11 | :initform :short 12 | :documentation "The post can be displayed in two 13 | versions, :SHORT and :FULL.") 14 | (short-view :accessor short-view 15 | :initarg :short-view 16 | :initform nil 17 | :documentation "View to determine how the post is 18 | displayed when in :SHORT mode.") 19 | (full-view :accessor full-view 20 | :initarg :full-view 21 | :initform nil 22 | :documentation "View to determine how the post is 23 | displayed when in :SHORT mode.") 24 | (on-select :accessor on-select 25 | :initarg :on-select 26 | :initform nil 27 | :documentation "Function to be called when this post is 28 | selected. It accepts POST-WIDGET as argument.")) 29 | (:documentation "widget to handle a blog post")) 30 | 31 | (defmethod with-widget-header ((obj post-widget) body-fn &rest args &key 32 | widget-prefix-fn widget-suffix-fn 33 | &allow-other-keys) 34 | (with-html 35 | (:div :class (dom-classes obj) :id (dom-id obj) 36 | :style (when (eql (mode obj) :short) 37 | (format nil "margin-left: ~A%;" (random 60))) 38 | (safe-apply widget-prefix-fn obj args) 39 | (apply body-fn obj args) 40 | (safe-apply widget-suffix-fn obj args)))) 41 | 42 | (defmethod render-widget-body ((obj post-widget) &key) 43 | (ecase (mode obj) 44 | (:short 45 | (when (short-view obj) 46 | (render-object-view (post obj) (short-view obj) :widget obj))) 47 | (:full 48 | (when (full-view obj) 49 | (render-object-view (post obj) (full-view obj) :widget obj))))) 50 | -------------------------------------------------------------------------------- /pub/stylesheets/pagination.css: -------------------------------------------------------------------------------- 1 | 2 | .pagination .current-page, 3 | .pagination .total-pages 4 | { 5 | font-weight: bolder; 6 | font-size: small; 7 | } 8 | 9 | .pagination .page-info 10 | { 11 | margin-top: 4px; 12 | } 13 | 14 | .pagination .viewing-label 15 | { 16 | display: none; 17 | } 18 | 19 | .pagination form fieldset 20 | { 21 | vertical-align: middle; 22 | } 23 | 24 | .pagination form, 25 | .pagination fieldset 26 | { 27 | display: inline; 28 | border: none; 29 | margin: 0; 30 | padding: 0; 31 | } 32 | 33 | .pagination fieldset 34 | { 35 | margin-left: 0.75em; 36 | } 37 | 38 | .pagination form fieldset input.page-number 39 | { 40 | width: 2em; 41 | margin-right: 0.5em; 42 | } 43 | 44 | /* We need to increate input width on Safari */ 45 | html[xmlns*=""] body:last-child .pagination form fieldset input.page-number 46 | { 47 | width: 2.5em; 48 | } 49 | 50 | .pagination form fieldset input.item-not-validated 51 | { 52 | border: solid 1px red; 53 | } 54 | 55 | .pagination div.extra-top-1, 56 | .pagination div.extra-top-2, 57 | .pagination div.extra-top-3, 58 | .pagination div.extra-bottom-1, 59 | .pagination div.extra-bottom-2, 60 | .pagination div.extra-bottom-3 61 | { 62 | display: none; 63 | } 64 | 65 | .pagination form label span 66 | { 67 | color: gray; 68 | } 69 | 70 | /* Fix the vertical alignment issue for IE 6 */ 71 | * html .pagination form label span 72 | { 73 | display: inline-block; 74 | padding-bottom: 3px; 75 | } 76 | 77 | /* Fix the vertical alignment issue for IE 7 */ 78 | *:first-child+html .pagination form label span 79 | { 80 | display: inline-block; 81 | padding-bottom: 3px; 82 | } 83 | 84 | /* Normalize alignment for all modern browsers (without IE 7) */ 85 | html>/**/body .pagination .page-info, 86 | html>/**/body .pagination a 87 | { 88 | vertical-align: middle; 89 | } 90 | 91 | .pagination .total-items 92 | { 93 | display: block; 94 | } 95 | 96 | -------------------------------------------------------------------------------- /pub/stylesheets/menu.css: -------------------------------------------------------------------------------- 1 | 2 | .menu 3 | { 4 | width: 15em; 5 | background: #d8eaf8 url(/weblocks-common/pub/images/menu/top_background.png) repeat-x; 6 | } 7 | 8 | .menu h1 9 | { 10 | background: #d8eaf8; 11 | } 12 | 13 | .menu .extra-top-1 14 | { 15 | background: url(/weblocks-common/pub/images/menu/top_left.png) no-repeat top left; 16 | } 17 | 18 | .menu .extra-top-2 19 | { 20 | background: url(/weblocks-common/pub/images/menu/top_right.png) no-repeat top right; 21 | border-bottom-color: #bfd9ec; 22 | } 23 | 24 | .empty-menu 25 | { 26 | padding-left: 0.5em; 27 | } 28 | 29 | .selected-item 30 | { 31 | color: #606060; 32 | background-color: #bfd9ec; 33 | } 34 | 35 | .menu ul li 36 | { 37 | padding-left: 0; 38 | } 39 | 40 | .menu ul li.selected-item 41 | { 42 | padding-left: 0.5em; 43 | } 44 | 45 | .menu ul li.selected-item span 46 | { 47 | background: url(/weblocks-common/pub/images/menu/arrow.png) no-repeat center left; 48 | padding-left: 1em; 49 | } 50 | 51 | .menu h1, .view .empty-menu, .menu ul li 52 | { 53 | border-top-color: #f6fbfd; 54 | border-bottom-color: #bfd9ec; 55 | } 56 | 57 | .menu h1, .menu .empty-menu, .menu ul 58 | { 59 | border-left-color: #bfd9ec; 60 | border-right-color: #bfd9ec; 61 | } 62 | 63 | .menu .extra-bottom-1 64 | { 65 | background: url(/weblocks-common/pub/images/menu/bottom_background.png) repeat-x top; 66 | border-top-color: #f6fbfd; 67 | } 68 | 69 | .menu .extra-bottom-2 70 | { 71 | background: url(/weblocks-common/pub/images/menu/bottom_left.png) no-repeat top left; 72 | } 73 | 74 | .menu .extra-bottom-3 75 | { 76 | background: url(/weblocks-common/pub/images/menu/bottom_right.png) no-repeat top right; 77 | } 78 | 79 | .menu a 80 | { 81 | display: block; 82 | } 83 | 84 | /* IE 6 and 7 hover hack */ 85 | *:first-child+html {} * html {} .menu a 86 | { 87 | height: 1%; 88 | } 89 | 90 | .menu a:hover 91 | { 92 | background-color: #bfd9ec; 93 | } 94 | 95 | -------------------------------------------------------------------------------- /src/model/post.lisp: -------------------------------------------------------------------------------- 1 | ;;;; mode: common-lisp; mode: paredit; mode: slime 2 | (in-package :simple-blog) 3 | 4 | (defclass post () 5 | ((id) 6 | (title :accessor post-title 7 | :initarg :title 8 | :initform "" 9 | :type string 10 | :documentation "a title for the post, to be displayed on 11 | both the blog page and on the post page.") 12 | (short-text :accessor post-short-text 13 | :initarg :short-text 14 | :initform "" 15 | :type string 16 | :documentation "short text of the post, to be shown on 17 | the main page of the blog") 18 | (text :accessor post-text 19 | :initarg :text 20 | :initform "" 21 | :type string 22 | :documentation "long text of the post, shown when the user 23 | clicks on the link after the short text") 24 | (time :accessor post-time 25 | :initarg :time 26 | :initform (get-universal-time) 27 | :documentation "time at which the post was created") 28 | (author :accessor post-author 29 | :initarg :author 30 | :initform nil 31 | :type user))) 32 | 33 | (defgeneric post-author-id (post) 34 | (:method ((post post)) 35 | (when (post-author post) 36 | (object-id (post-author post))))) 37 | 38 | (defgeneric post-author-name (post) 39 | (:method ((post post)) 40 | (when (post-author post) 41 | (user-name (post-author post))))) 42 | 43 | (defun post-formatted-time (post) 44 | (multiple-value-bind (sec min hr dom mo year dow daylight-p zone) 45 | (decode-universal-time (post-time post)) 46 | (declare (ignore sec daylight-p zone dom)) 47 | (format nil "~d-~d-~d ~d:~d" year mo dow hr min))) 48 | 49 | (defun all-posts (&rest args) 50 | "return all objects of class POST. Args is an added argument that 51 | is ignored (needed for use in dropdown lists in views" 52 | (declare (ignore args)) 53 | (find-persistent-objects (class-store 'post) 'post)) 54 | 55 | (defun post-by-id (id) 56 | (first 57 | (remove-if-not (lambda (post) 58 | (when (slot-boundp post 'id) 59 | (= id (slot-value post 'id)))) 60 | (all-posts)))) 61 | 62 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | 2008-03-08 Evan Monroig 2 | 3 | blog-v4 4 | 5 | * blog.asd (blog): add new file 6 | 7 | * src/models.lisp (post-author-name, post-formatted-time): backend 8 | functions 9 | 10 | * src/layout.lisp (make-blog-widget): make a BLOG-WIDGET instead 11 | of POST-WIDGET 12 | (make-blog-widget): use new views for the post 13 | 14 | * src/views.lisp (post-data-view): modify to display formatted 15 | time, and user name instead of "User" 16 | (post-short-view, post-full-view): new views for used the two 17 | states POST-WIDGET 18 | 19 | * src/widgets/post.lisp (post-widget): add ON-SELECT slot so that 20 | BLOG-WIDGET can set a call-back 21 | (post-action-select): return an action that selects POST-WIDGET 22 | (render-widget-body): modify to add a link to see the full post 23 | [and call the ON-SELECT function if defined] 24 | 25 | * src/widgets/blog.lisp: 26 | (blog-action-blog-mode, blog-make-post-widget, reset-blog) 27 | (render-blog, initialize-instance, render-widget-body): new blog 28 | widget 29 | 30 | * src/specials.lisp (*blog-title*): blog title 31 | 32 | blog-v3 33 | 34 | * blog.asd (blog): updated for new files 35 | 36 | * src/layout.lisp (make-blog-widget): create a composite widget 37 | with a post widget and a link 38 | (make-admin-page): add a link to MAKE-BLOG-WIDGET 39 | 40 | * src/models.lisp (all-posts, post-by-id): backend functions 41 | 42 | * src/widgets/post.lisp (post-widget): simple post widget 43 | (render-widget-body): specialized method to render the post 44 | 45 | blog-v2 46 | 47 | * src/models.lisp (post-author-id, all-users): functions used by 48 | the views 49 | 50 | * src/views.lisp (post-form-view): override some fields - textarea 51 | for the texts, and dropdown list for the author 52 | 53 | blog-v1: 54 | 55 | * src/views.lisp (user-grid-view, user-data-view, user-form-view) 56 | (post-grid-view, post-data-view, post-form-view): scaffolded views 57 | for the gridedit interface 58 | 59 | * src/init-session.lisp (init-user-session): call MAKE-ADMIN-PAGE 60 | 61 | * src/layout.lisp (make-users-gridedit, make-posts-gridedit) 62 | (make-admin-page): add simple gridedit interface for the two 63 | models 64 | 65 | * src/models.lisp (user, post): USER and POST models 66 | -------------------------------------------------------------------------------- /pub/scripts/sound.js: -------------------------------------------------------------------------------- 1 | // script.aculo.us sound.js v1.7.1_beta3, Fri May 25 17:19:41 +0200 2007 2 | 3 | // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 4 | // 5 | // Based on code created by Jules Gravinese (http://www.webveteran.com/) 6 | // 7 | // script.aculo.us is freely distributable under the terms of an MIT-style license. 8 | // For details, see the script.aculo.us web site: http://script.aculo.us/ 9 | 10 | Sound = { 11 | tracks: {}, 12 | _enabled: true, 13 | template: 14 | new Template(''), 15 | enable: function(){ 16 | Sound._enabled = true; 17 | }, 18 | disable: function(){ 19 | Sound._enabled = false; 20 | }, 21 | play: function(url){ 22 | if(!Sound._enabled) return; 23 | var options = Object.extend({ 24 | track: 'global', url: url, replace: false 25 | }, arguments[1] || {}); 26 | 27 | if(options.replace && this.tracks[options.track]) { 28 | $R(0, this.tracks[options.track].id).each(function(id){ 29 | var sound = $('sound_'+options.track+'_'+id); 30 | sound.Stop && sound.Stop(); 31 | sound.remove(); 32 | }) 33 | this.tracks[options.track] = null; 34 | } 35 | 36 | if(!this.tracks[options.track]) 37 | this.tracks[options.track] = { id: 0 } 38 | else 39 | this.tracks[options.track].id++; 40 | 41 | options.id = this.tracks[options.track].id; 42 | if (Prototype.Browser.IE) { 43 | var sound = document.createElement('bgsound'); 44 | sound.setAttribute('id','sound_'+options.track+'_'+options.id); 45 | sound.setAttribute('src',options.url); 46 | sound.setAttribute('loop','1'); 47 | sound.setAttribute('autostart','true'); 48 | $$('body')[0].appendChild(sound); 49 | } 50 | else 51 | new Insertion.Bottom($$('body')[0], Sound.template.evaluate(options)); 52 | } 53 | }; 54 | 55 | if(Prototype.Browser.Gecko && navigator.userAgent.indexOf("Win") > 0){ 56 | if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('QuickTime') != -1 })) 57 | Sound.template = new Template('') 58 | else 59 | Sound.play = function(){} 60 | } 61 | -------------------------------------------------------------------------------- /pub/stylesheets/dialog.css: -------------------------------------------------------------------------------- 1 | 2 | .graybox 3 | { 4 | position: fixed; 5 | top: 0; 6 | left: 0; 7 | bottom: 0; 8 | right: 0; 9 | background-color: black; 10 | z-index: 500; 11 | 12 | filter: alpha(opacity=30); 13 | -moz-opacity: 0.3; 14 | opacity: 0.3; 15 | } 16 | 17 | /* IE 6 specific fix for lack of 'position: fixed' implementation */ 18 | * html .graybox 19 | { 20 | position: absolute; 21 | left: expression(documentElement.scrollLeft + 'px'); 22 | top: expression(documentElement.scrollTop + 'px'); 23 | width: expression(document.documentElement.clientWidth + 'px'); 24 | height: expression(document.documentElement.clientHeight + 'px'); 25 | } 26 | 27 | .dialog 28 | { 29 | position: fixed; 30 | _position: absolute; /* Degrade to this in IE for now */ 31 | z-index: 725; 32 | width: 10em; 33 | } 34 | 35 | .dialog-body 36 | { 37 | padding: 1em; 38 | _height: 1%; /* hasLayout */ 39 | background-color: white; 40 | } 41 | 42 | /* Style choice dialog */ 43 | .choice .dialog-body, .modal .choice 44 | { 45 | background: white url(/weblocks-common/pub/images/dialog/question.png) no-repeat 0.5em center; 46 | } 47 | 48 | .dialog h1, .modal h1 49 | { 50 | background-color: white; 51 | padding: 0; 52 | margin: 0; 53 | text-align: left; 54 | } 55 | 56 | .dialog h1 span, .modal h1 span 57 | { 58 | background: url(/weblocks-common/pub/images/horizontal_line.png) repeat-x bottom; 59 | display: block; 60 | } 61 | 62 | .dialog h1 span 63 | { 64 | margin-left: 0.5em; 65 | margin-right: 0.5em; 66 | } 67 | 68 | .choice 69 | { 70 | text-align: center; 71 | } 72 | 73 | .choice form, .choice form fieldset, .choice p 74 | { 75 | border: none; 76 | margin: 0; 77 | padding: 0; 78 | } 79 | 80 | .choice p 81 | { 82 | margin-bottom: 1em; 83 | } 84 | 85 | .choice input 86 | { 87 | margin-left: 0.25em; 88 | margin-right: 0.25em; 89 | } 90 | 91 | /* Style information dialog */ 92 | .information .dialog-body, .modal .information 93 | { 94 | background-image: url(/weblocks-common/pub/images/dialog/information.png); 95 | } 96 | 97 | /* Modal interaction */ 98 | .modal 99 | { 100 | background: url(/weblocks-common/pub/images/horizontal_line.png) repeat-x bottom; 101 | padding-bottom: 2px; 102 | } 103 | 104 | .modal h1 105 | { 106 | border: none; 107 | margin: 0; 108 | } 109 | 110 | .modal .choice 111 | { 112 | min-height: 48px; 113 | _height: 48px; 114 | background-position: left center; 115 | padding-top: 1em; 116 | padding-bottom: 1em; 117 | } 118 | 119 | -------------------------------------------------------------------------------- /pub/scripts/scriptaculous.js: -------------------------------------------------------------------------------- 1 | // script.aculo.us scriptaculous.js v1.7.1_beta3, Fri May 25 17:19:41 +0200 2007 2 | 3 | // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining 6 | // a copy of this software and associated documentation files (the 7 | // "Software"), to deal in the Software without restriction, including 8 | // without limitation the rights to use, copy, modify, merge, publish, 9 | // distribute, sublicense, and/or sell copies of the Software, and to 10 | // permit persons to whom the Software is furnished to do so, subject to 11 | // the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | // 24 | // For details, see the script.aculo.us web site: http://script.aculo.us/ 25 | 26 | var Scriptaculous = { 27 | Version: '1.7.1_beta3', 28 | require: function(libraryName) { 29 | // inserting via DOM fails in Safari 2.0, so brute force approach 30 | document.write(''); 31 | }, 32 | REQUIRED_PROTOTYPE: '1.5.1', 33 | load: function() { 34 | function convertVersionString(versionString){ 35 | var r = versionString.split('.'); 36 | return parseInt(r[0])*100000 + parseInt(r[1])*1000 + parseInt(r[2]); 37 | } 38 | 39 | if((typeof Prototype=='undefined') || 40 | (typeof Element == 'undefined') || 41 | (typeof Element.Methods=='undefined') || 42 | (convertVersionString(Prototype.Version) < 43 | convertVersionString(Scriptaculous.REQUIRED_PROTOTYPE))) 44 | throw("script.aculo.us requires the Prototype JavaScript framework >= " + 45 | Scriptaculous.REQUIRED_PROTOTYPE); 46 | 47 | $A(document.getElementsByTagName("script")).findAll( function(s) { 48 | return (s.src && s.src.match(/scriptaculous\.js(\?.*)?$/)) 49 | }).each( function(s) { 50 | var path = s.src.replace(/scriptaculous\.js(\?.*)?$/,''); 51 | var includes = s.src.match(/\?.*load=([a-z,]*)/); 52 | (includes ? includes[1] : 'builder,effects,dragdrop,controls,slider,sound').split(',').each( 53 | function(include) { Scriptaculous.require(path+include+'.js') }); 54 | }); 55 | } 56 | } 57 | 58 | Scriptaculous.load(); -------------------------------------------------------------------------------- /pub/stylesheets/post-widget.css: -------------------------------------------------------------------------------- 1 | div.blog-widget div.post-widget .view, 2 | div.blog-widget div.post-widget .view .extra-top-2, 3 | div.blog-widget div.post-widget .view .extra-top-1, 4 | div.blog-widget div.post-widget .view .extra-bottom-2, 5 | div.blog-widget div.post-widget .view .extra-bottom-3, 6 | div.blog-widget div.post-widget .view .extra-bottom-1 7 | { 8 | border: none; 9 | background: none; 10 | width: 100%; 11 | } 12 | 13 | div.blog-widget div.post-widget .view h1 14 | { display: none; } 15 | 16 | div.blog-widget div.post-widget .view li span.label 17 | { display: none; } 18 | 19 | div.blog-widget div.post-widget .view li.title 20 | { 21 | font-variant: small-caps; 22 | font-style: bold; 23 | font-size: large; 24 | } 25 | 26 | div.blog-widget div.post-widget .view li.time 27 | { 28 | font-style: oblique; 29 | } 30 | 31 | div.blog-widget div.post-widget .view li.author 32 | { 33 | font-style: italic; 34 | } 35 | 36 | /***********************************************************************/ 37 | 38 | div.blog-widget.blog-mode div.post-widget 39 | { 40 | width: 310px; 41 | height: 310px; 42 | background-image: url('../images/bubble-310x310.png'); 43 | } 44 | 45 | div.blog-widget.blog-mode div.post-widget .view 46 | { 47 | position: relative; 48 | top: 13%; 49 | } 50 | 51 | div.blog-widget.blog-mode div.post-widget .view ul 52 | { 53 | border: none; 54 | text-align: center; 55 | } 56 | 57 | div.blog-widget.blog-mode div.post-widget .view li 58 | { 59 | margin-left: auto; 60 | margin-right: auto; 61 | padding-left: 0; 62 | text-align: center; 63 | border: none; 64 | } 65 | 66 | div.blog-widget.blog-mode div.post-widget .view li.title 67 | { 68 | width: 60%; 69 | } 70 | 71 | div.blog-widget.blog-mode div.post-widget .view li.title a 72 | { 73 | color: #79cdcd; 74 | padding-left: none; 75 | } 76 | 77 | div.blog-widget.blog-mode div.post-widget .view li.short-text 78 | { 79 | margin-top: 5%; 80 | width: 85%; 81 | height: 150px; 82 | } 83 | 84 | /***********************************************************************/ 85 | 86 | div.blog-widget.post-mode div.post-widget .view ul 87 | { 88 | border: none; 89 | } 90 | 91 | div.blog-widget.post-mode div.post-widget .view li 92 | { 93 | border-bottom: none; 94 | } 95 | 96 | div.blog-widget.post-mode div.post-widget .view li.title 97 | { 98 | border-bottom: 1px solid black; 99 | text-align: center; 100 | } 101 | 102 | div.blog-widget.post-mode div.post-widget .view li.text 103 | { 104 | margin-top: 30px; 105 | margin-bottom: 30px; 106 | } 107 | 108 | div.blog-widget.post-mode div.post-widget .view li.author 109 | { 110 | float: left; 111 | margin-right: 150px; 112 | } 113 | 114 | div.blog-widget.post-mode div.post-widget .view li.time 115 | { 116 | width: 100px; 117 | float: right; 118 | } -------------------------------------------------------------------------------- /pub/scripts/datagrid.js: -------------------------------------------------------------------------------- 1 | 2 | // These styles need to be added dynamically because we only want them 3 | // when JS is turned on 4 | addCss(".datagrid td.drilldown, .datagrid th.drilldown { display: none; }"); 5 | 6 | // We should only invoke datagrid actions when selection is empty 7 | function initiateActionOnEmptySelection(actionCode, sessionString) { 8 | if(selectionEmpty()) { 9 | initiateAction(actionCode, sessionString); 10 | return false; 11 | } 12 | } 13 | 14 | // Keyboard 15 | function clearNavigatableHighlight() { 16 | if(selectedNavigatableRowIndex != undefined) { 17 | var row = navigatableTableRows[selectedNavigatableRowIndex]; 18 | if(row) { 19 | if(!row.hasClassName('drilled-down')) { 20 | row.removeClassName('hover'); 21 | } 22 | } else { 23 | selectedNavigatableRowIndex = undefined; 24 | } 25 | } 26 | } 27 | 28 | function setNavigatableHighlight() { 29 | if(selectedNavigatableRowIndex != undefined) { 30 | var row = navigatableTableRows[selectedNavigatableRowIndex]; 31 | if(row) { 32 | row.addClassName('hover'); 33 | } 34 | } 35 | } 36 | 37 | function initializeNavigatableRows() { 38 | navigatableTableRows = $$('tr').select(function(e) { return e.readAttribute('onclick'); }); 39 | selectedNavigatableRowIndex = undefined; 40 | for(var i = 0; i < navigatableTableRows.length; i++) { 41 | if(navigatableTableRows[i].hasClassName('drilled-down')) { 42 | selectedNavigatableRowIndex = i; 43 | break; 44 | } 45 | } 46 | navigatableTableRows.each(function(row) { 47 | Event.observe(row, 'mouseover', function(event) { 48 | clearNavigatableHighlight(); 49 | selectedNavigatableRowIndex = undefined; 50 | }); 51 | }); 52 | } 53 | 54 | Event.observe(window, 'load', initializeNavigatableRows); 55 | 56 | Ajax.Responders.register({ 57 | onComplete: function() { 58 | clearNavigatableHighlight(); 59 | initializeNavigatableRows(); 60 | } 61 | }); 62 | 63 | shortcut.add("j", function() { 64 | if(selectedNavigatableRowIndex == undefined) { 65 | selectedNavigatableRowIndex = 0; 66 | } else { 67 | clearNavigatableHighlight(); 68 | selectedNavigatableRowIndex++; 69 | if(selectedNavigatableRowIndex == navigatableTableRows.length) { 70 | selectedNavigatableRowIndex = undefined; 71 | } 72 | } 73 | setNavigatableHighlight(); 74 | }, 75 | { 'disable_in_input' : true }); 76 | 77 | shortcut.add("k", function() { 78 | if(selectedNavigatableRowIndex == undefined) { 79 | selectedNavigatableRowIndex = navigatableTableRows.length - 1; 80 | } else { 81 | clearNavigatableHighlight(); 82 | selectedNavigatableRowIndex--; 83 | if(selectedNavigatableRowIndex == -1) { 84 | selectedNavigatableRowIndex = undefined; 85 | } 86 | } 87 | setNavigatableHighlight(); 88 | }, 89 | { 'disable_in_input' : true }) 90 | 91 | shortcut.add("Return", function() { 92 | if(selectedNavigatableRowIndex != undefined) { 93 | navigatableTableRows[selectedNavigatableRowIndex].onclick(); 94 | } 95 | }, 96 | { 'disable_in_input' : true }) 97 | 98 | -------------------------------------------------------------------------------- /pub/stylesheets/dataseq.css: -------------------------------------------------------------------------------- 1 | 2 | /* Body */ 3 | .dataseq form.dataseq-form fieldset 4 | { 5 | border: none; 6 | margin: 0; 7 | padding: 0; 8 | } 9 | 10 | .dataseq form.dataseq-form 11 | { 12 | margin: 0; 13 | padding: 0; 14 | } 15 | 16 | .dataseq form.dataseq-form 17 | { 18 | margin-bottom: 1em; 19 | } 20 | 21 | /* Mining Bar */ 22 | .dataseq .data-mining-bar 23 | { 24 | position: relative; 25 | margin-bottom: 0.25em; 26 | height: 1em; 27 | } 28 | 29 | .dataseq > .data-mining-bar 30 | { 31 | height: auto; 32 | min-height: 1em; 33 | } 34 | 35 | .dataseq .data-mining-bar .total-items 36 | { 37 | position: absolute; 38 | right: 0; 39 | bottom: 0; 40 | } 41 | 42 | /* Operations */ 43 | .dataseq form .operations 44 | { 45 | position: absolute; 46 | right: 0; 47 | margin-top: 0.25em; 48 | } 49 | 50 | .dataseq form.operations-form .operations input.submit, 51 | .dataseq form.dataseq-form .operations input.submit 52 | { 53 | margin-left: 0.5em; 54 | } 55 | 56 | .dataseq form.operations-form, 57 | .dataseq form.operations-form fieldset 58 | { 59 | border: none; 60 | margin: 0; 61 | padding: 0; 62 | } 63 | 64 | /* Datagrid specific pagination styles */ 65 | .dataseq div.pagination 66 | { 67 | margin-top: -1em; 68 | } 69 | 70 | .dataseq div.pagination, 71 | .dataseq div.pagination form fieldset input 72 | { 73 | font-size: x-small; 74 | } 75 | 76 | /* Flash */ 77 | div.dataseq .flash 78 | { 79 | position: relative; 80 | _height: 1%; /* hasLayout IE 6 fix */ 81 | } 82 | 83 | div.dataseq .flash .view .extra-top-1 84 | { 85 | position: absolute; 86 | z-index: 10; 87 | left: 0; 88 | width: 5px; 89 | overflow: hidden; 90 | } 91 | 92 | div.dataseq .flash .view .extra-top-2 93 | { 94 | right: 0; 95 | width: 5px; 96 | border: none; 97 | position: absolute; 98 | margin-top: 0; 99 | z-index: 10; 100 | overflow: hidden; 101 | } 102 | 103 | div.dataseq .flash .view .extra-top-3 104 | { 105 | height: 2px; 106 | background: url(/weblocks-common/pub/images/widget/flash/top_background.png) repeat-x; 107 | display: block; 108 | overflow: hidden; 109 | } 110 | 111 | div.dataseq .flash .view 112 | { 113 | margin-bottom: 0.25em; 114 | background-image: url(/weblocks-common/pub/images/widget/dataseq/flash/vertical_border.png); 115 | background-repeat: repeat-y; 116 | background-position: left; 117 | } 118 | 119 | div.dataseq .flash .view ul.messages 120 | { 121 | background: url(/weblocks-common/pub/images/widget/dataseq/flash/vertical_border.png) repeat-y right; 122 | border: none; 123 | margin-bottom: 5px; 124 | } 125 | 126 | div.dataseq .flash .view ul.messages li 127 | { 128 | background-image: none; 129 | border: none; 130 | padding-left: 0; 131 | } 132 | 133 | div.dataseq .flash .view ul.messages p 134 | { 135 | text-align: center; 136 | font-size: x-small; 137 | padding-top: 1px; 138 | } 139 | 140 | div.dataseq .flash .view .extra-bottom-1 141 | { 142 | background-image: none; 143 | border-bottom: solid 2px #ead8c2; 144 | margin-top: -14px; 145 | } 146 | 147 | div.dataseq .flash .view .extra-bottom-2 148 | { 149 | background: url(/weblocks-common/pub/images/widget/dataseq/flash/bottom_left.png) no-repeat top left; 150 | margin-top: -7px; 151 | } 152 | 153 | div.dataseq .flash .view .extra-bottom-3 154 | { 155 | background: url(/weblocks-common/pub/images/widget/dataseq/flash/bottom_right.png) no-repeat top right; 156 | margin-top: -7px; 157 | } 158 | 159 | -------------------------------------------------------------------------------- /pub/scripts/dialog.js: -------------------------------------------------------------------------------- 1 | 2 | Position.GetViewportSize = function() { 3 | var w = window; 4 | var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth); 5 | var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight); 6 | return [width, height] 7 | } 8 | Position.EyeLevel = function(element, parent) { 9 | var w, h, pw, ph; 10 | var d = Element.getDimensions(element); 11 | w = d.width; 12 | h = d.height; 13 | Position.prepare(); 14 | if (!parent) { 15 | var ws = Position.GetViewportSize(); 16 | pw = ws[0]; 17 | ph = ws[1]; 18 | } else { 19 | pw = parent.offsetWidth; 20 | ph = parent.offsetHeight; 21 | } 22 | var eyeLevel = ph - (ph/4*3) - (h/2); 23 | var screenCenter = (ph/2) - (h/2); 24 | var scrollX = 0, scrollY = 0; 25 | if(!window.XMLHttpRequest) { 26 | // IE 6 only, as we can't use position: fixed 27 | scrollX = Position.deltaX; 28 | scrollY = Position.deltaY; 29 | } 30 | element.style.top = (eyeLevel < (ph / 10) ? screenCenter : eyeLevel) + scrollY + "px"; 31 | element.style.left = (pw/2) - (w/2) + scrollX + "px"; 32 | } 33 | 34 | function showDialog(title, body, cssClass) { 35 | showDialog(title, body, cssClass, null); 36 | } 37 | 38 | 39 | function showDialog(title, body, cssClass, close) { 40 | // Find or create a graybox 41 | var graybox = $$('.graybox')[0]; 42 | if(!graybox) { 43 | graybox = Builder.node('div', { className : 'graybox' }); 44 | } else { 45 | Element.show(graybox); 46 | } 47 | $$('body')[0].appendChild(graybox); 48 | // Create a dialog 49 | var dialogBody = Builder.node('div', { className : 'dialog-body' }); 50 | dialogBody.innerHTML = body; 51 | 52 | var titleTextCell = Builder.node('td', {className : 'title-text-cell'}, 53 | [ Builder.node('h1', {className : 'title-text'}, [title])]); 54 | 55 | var titleButtonCell = null; 56 | var titleRow = null; 57 | if (close != null) { 58 | var buttonDiv = Builder.node('div', { className : 'title-button' }); 59 | buttonDiv.innerHTML = close; 60 | titleButtonCell = Builder.node('td', {className : 'title-button-cell'}, [ buttonDiv ]); 61 | 62 | titleRow = Builder.node('tr', [ titleTextCell, titleButtonCell ]); 63 | } 64 | else { 65 | titleRow = Builder.node('tr', [ titleTextCell ]); 66 | } 67 | 68 | var titleBar = Builder.node('table', {className : 'title-bar'}, [titleRow]); 69 | 70 | var dialog = Builder.node('div', { className : ('dialog ' + cssClass) }, 71 | [ Builder.node('div', { className : 'dialog-extra-top-1' }), 72 | Builder.node('div', { className : 'dialog-extra-top-2' }), 73 | Builder.node('div', { className : 'dialog-extra-top-3' }), 74 | titleBar, 75 | dialogBody, 76 | Builder.node('div', { className : 'dialog-extra-bottom-1' }), 77 | Builder.node('div', { className : 'dialog-extra-bottom-2' }), 78 | Builder.node('div', { className : 'dialog-extra-bottom-3' }) ]); 79 | if(!Prototype.Browser.IE) { 80 | // Everything but IE, due to z-index issues 81 | // Necessary to avoid flicker if rendering is slow 82 | $(dialog).hide(); 83 | } 84 | $$('div.page-wrapper')[0].appendChild(dialog); 85 | Position.EyeLevel(dialog); 86 | if(!Prototype.Browser.IE) { 87 | // Everything but IE, due to z-index issues 88 | // Necessary to avoid flicker if rendering is slow 89 | $(dialog).show(); 90 | } 91 | } 92 | 93 | function removeDialog() { 94 | Element.remove($$('.dialog')[0]); 95 | Element.hide($$('.graybox')[0]); 96 | } 97 | 98 | -------------------------------------------------------------------------------- /src/widgets/blog.lisp: -------------------------------------------------------------------------------- 1 | (in-package :simple-blog) 2 | 3 | (defwidget blog-widget () 4 | ((current-post :accessor current-post 5 | :initarg :current-post 6 | :initform nil 7 | :documentation "POST-WIDGET containing the current 8 | post when the blog is in :POST mode") 9 | (posts :accessor posts 10 | :initarg :posts 11 | :initform (make-instance 'widget) 12 | :documentation "widget that contains a POST-WIDGET 13 | for each post of the blog") 14 | (mode :accessor mode 15 | :initarg :mode 16 | :initform :blog 17 | :documentation "The blog can be in two modes, :BLOG 18 | and :POST. In :BLOG mode to display a list of posts, and 19 | in :POST mode to display an individual post.") 20 | (post-short-view :accessor post-short-view 21 | :initarg :post-short-view 22 | :initform nil 23 | :documentation "see SHORT-VIEW slot of POST-WIDGET") 24 | (post-full-view :accessor post-full-view 25 | :initarg :post-full-view 26 | :initform nil 27 | :documentation "see FULL-VIEW slot of POST-WIDGET")) 28 | (:documentation "widget to handle a blog")) 29 | 30 | (defgeneric blog-action-blog-mode (blog-widget) 31 | (:documentation "return an action that will switch BLOG-WIDGET into :BLOG 32 | mode") 33 | (:method ((blog-widget blog-widget)) 34 | (make-action 35 | (lambda (&rest args) 36 | (declare (ignore args)) 37 | (when (current-post blog-widget) 38 | (setf (mode (current-post blog-widget)) :short)) 39 | (setf (mode blog-widget) :blog) 40 | (reset-blog blog-widget))))) 41 | 42 | (defgeneric blog-make-post-widget (blog-widget post) 43 | (:documentation "make a POST-WIDGET containing POST. (called by 44 | RESET-BLOG)") 45 | (:method ((blog-widget blog-widget) (post post)) 46 | (make-instance 'post-widget 47 | :blog blog-widget 48 | :post post 49 | :short-view (post-short-view blog-widget) 50 | :full-view (post-full-view blog-widget) 51 | :on-select (lambda (post-widget) 52 | (setf (current-post blog-widget) post-widget) 53 | (setf (mode blog-widget) :post))))) 54 | 55 | (defgeneric reset-blog (blog-widget) 56 | (:documentation "Reset the list of post widgets from the posts in 57 | the database. This function is called by BLOG-ACTION-BLOG-MODE.") 58 | (:method ((blog-widget blog-widget)) 59 | (setf (widget-children (posts blog-widget)) 60 | (mapcar (lambda (post) 61 | (blog-make-post-widget blog-widget post)) 62 | (all-posts))))) 63 | 64 | (defmethod initialize-instance :after ((obj blog-widget) &key) 65 | (reset-blog obj)) 66 | 67 | (defgeneric render-blog (blog-widget mode) 68 | (:documentation "render a blog widget in mode MODE. This function 69 | is called by RENDER-WIDGET-BODY.")) 70 | 71 | (defmethod render-blog ((blog-widget blog-widget) (mode (eql :blog))) 72 | (with-html (:h1 "Simple Blog")) 73 | (render-widget (posts blog-widget))) 74 | 75 | (defmethod render-blog ((blog-widget blog-widget) (mode (eql :post))) 76 | (with-html 77 | (:h1 78 | ;; link to come back to the blog 79 | (render-link (blog-action-blog-mode blog-widget) 80 | "Simple Blog"))) 81 | (render-widget (current-post blog-widget))) 82 | 83 | (defmethod with-widget-header ((obj blog-widget) body-fn &rest args) 84 | (with-html 85 | (:div :class (format nil "~A ~A-mode" 86 | (dom-classes obj) 87 | (remove #\: (write-to-string (mode obj) :case :downcase))) 88 | :id (dom-id obj) 89 | (apply body-fn obj args) 90 | (when (eql (mode obj) :blog) 91 | (htm 92 | (:img :id "bubblehead" 93 | :src "/pub/images/bubblehead.png")))))) 94 | 95 | (defmethod render-widget-body ((obj blog-widget) &key) 96 | (hunchentoot:log-message* :debug "rendering blog widget") 97 | (render-blog obj (mode obj))) 98 | -------------------------------------------------------------------------------- /pub/stylesheets/layout.css: -------------------------------------------------------------------------------- 1 | body 2 | { 3 | background: url(/weblocks-common/pub/images/page/background.png); 4 | text-align: center; 5 | } 6 | 7 | div.page-wrapper 8 | { 9 | max-width: 70em; 10 | min-width: 60em; 11 | 12 | margin: 0 auto; 13 | text-align: left; 14 | } 15 | 16 | /* IE 6 specific hacks (has layout and min-width)*/ 17 | * html div.page-wrapper 18 | { 19 | width: 70em; 20 | } 21 | 22 | .page-wrapper .page-extra-top-1, 23 | .dialog .dialog-extra-top-1 24 | { 25 | height: 5px; 26 | background: url(/weblocks-common/pub/images/page/top_left.png) no-repeat top left; 27 | overflow: hidden; 28 | } 29 | 30 | .page-wrapper .page-extra-top-2, 31 | .dialog .dialog-extra-top-2 32 | { 33 | height: 5px; 34 | margin-top: -5px; 35 | background: url(/weblocks-common/pub/images/page/top_right.png) no-repeat top right; 36 | overflow: hidden; 37 | } 38 | 39 | .page-wrapper .page-extra-top-3, 40 | .dialog .dialog-extra-top-3 41 | { 42 | height: 5px; 43 | margin-top: -5px; 44 | margin-left: 5px; 45 | margin-right: 5px; 46 | background: url(/weblocks-common/pub/images/page/hor_border.png) repeat-x top; 47 | overflow: hidden; 48 | } 49 | 50 | div#root, .dialog-body, .dialog h1 51 | { 52 | border-left: 1px solid black; 53 | border-right: 1px solid black; 54 | } 55 | 56 | div#root 57 | { 58 | padding: 1em; 59 | min-height: 60em; 60 | background-color: white; 61 | } 62 | 63 | /* IE 6 specific hacks (has layout and min-height)*/ 64 | * html div#root 65 | { 66 | height: 60em; 67 | } 68 | 69 | div#main-menu 70 | { 71 | position: relative; 72 | } 73 | 74 | div#main-menu div.composite 75 | { 76 | margin-left: 16em; 77 | } 78 | 79 | div#main-menu div.menu 80 | { 81 | position: absolute; 82 | top: 0; 83 | } 84 | 85 | .page-wrapper .page-extra-bottom-1, 86 | .dialog .dialog-extra-bottom-1 87 | { 88 | height: 5px; 89 | background: url(/weblocks-common/pub/images/page/bottom_left.png) no-repeat top left; 90 | overflow: hidden; 91 | } 92 | 93 | .page-wrapper .page-extra-bottom-2, 94 | .dialog .dialog-extra-bottom-2 95 | { 96 | height: 5px; 97 | margin-top: -5px; 98 | background: url(/weblocks-common/pub/images/page/bottom_right.png) no-repeat top right; 99 | overflow: hidden; 100 | } 101 | 102 | .page-wrapper .page-extra-bottom-3, 103 | .dialog .dialog-extra-bottom-3 104 | { 105 | height: 5px; 106 | margin-top: -5px; 107 | margin-left: 5px; 108 | margin-right: 5px; 109 | background: url(/weblocks-common/pub/images/page/hor_border_bottom.png) repeat-x top; 110 | overflow: hidden; 111 | } 112 | 113 | .header 114 | { 115 | height: 52px; 116 | background: url(/weblocks-common/pub/images/header/background.png) repeat-x; 117 | margin-top: -5px; 118 | margin-bottom: 1em; 119 | } 120 | 121 | .header .extra-top-1 122 | { 123 | height: 5px; 124 | background: url(/weblocks-common/pub/images/header/top_left.png) no-repeat top left; 125 | overflow: hidden; 126 | } 127 | 128 | .header .extra-top-2 129 | { 130 | height: 5px; 131 | margin-top: -5px; 132 | background: url(/weblocks-common/pub/images/header/top_right.png) no-repeat top right; 133 | overflow: hidden; 134 | } 135 | 136 | .header .extra-top-3 137 | { 138 | height: 42px; 139 | margin-left: 5px; 140 | background: url(/weblocks-common/pub/images/header/logo.png) no-repeat center left; 141 | } 142 | 143 | .header .extra-bottom-1 144 | { 145 | height: 5px; 146 | background: url(/weblocks-common/pub/images/header/bottom_left.png) no-repeat top left; 147 | overflow: hidden; 148 | } 149 | 150 | .header .extra-bottom-2 151 | { 152 | height: 5px; 153 | margin-top: -5px; 154 | background: url(/weblocks-common/pub/images/header/bottom_right.png) no-repeat top right; 155 | overflow: hidden; 156 | } 157 | 158 | .footer 159 | { 160 | margin-top: 1em; 161 | } 162 | 163 | .footer p#system-info 164 | { 165 | margin-bottom: 0; 166 | } 167 | 168 | .footer p#contact-info 169 | { 170 | margin-top: 0; 171 | } 172 | 173 | -------------------------------------------------------------------------------- /pub/stylesheets/form.css: -------------------------------------------------------------------------------- 1 | 2 | .form 3 | { 4 | margin-top: 0; 5 | } 6 | 7 | form fieldset 8 | { 9 | border: none; 10 | padding: 0; 11 | margin: 0; 12 | } 13 | 14 | .form fieldset .validation-errors-summary .error-count, 15 | .form fieldset .validation-errors-summary .field-validation-errors 16 | { 17 | display: none; 18 | } 19 | 20 | /* For long forms, change display of validation summary back */ 21 | .long-form fieldset .validation-errors-summary .error-count, 22 | .long-form fieldset .validation-errors-summary .field-validation-errors 23 | { 24 | display: block; 25 | } 26 | 27 | .form fieldset .validation-errors-summary h2.error-count, 28 | .form fieldset .validation-errors-summary ul li 29 | { 30 | color: red; 31 | } 32 | 33 | .form fieldset .validation-errors-summary ul li, 34 | .long-form fieldset .validation-errors-summary .non-field-validation-errors 35 | { 36 | font-style: italic; 37 | border-top: none; 38 | border-bottom: none; 39 | } 40 | 41 | .form fieldset .form-fields-title 42 | { 43 | display: none; 44 | } 45 | 46 | form.view fieldset ul li label em.required-slot, 47 | form.view fieldset ul li span.label em.required-slot 48 | { 49 | font-weight: normal; 50 | display: inline; 51 | font-size: x-small; 52 | font-style: normal; 53 | color: red; 54 | } 55 | 56 | form.view fieldset ul li label input, 57 | form.view fieldset ul li label select, 58 | form.view fieldset ul li label textarea 59 | { 60 | margin-top: 2px; 61 | margin-bottom: 2px; 62 | width: 12em; 63 | } 64 | 65 | /* Target firefox */ 66 | html>/**/body form.view fieldset ul li label textarea, x:-moz-any-link 67 | { 68 | width: auto; 69 | } 70 | 71 | /* IE6 font size hacks */ 72 | * html form.view fieldset ul li label input, 73 | * html form.view fieldset ul li label textarea 74 | { 75 | font-size: 1em; 76 | } 77 | * html form.view fieldset ul li label select 78 | { 79 | font-size: small; 80 | } 81 | 82 | /* Target Safari */ 83 | /* Safari and WebKit specific caption fix */ 84 | html[xmlns*=""] form.view fieldset ul li label input, 85 | html[xmlns*=""] form.view fieldset ul li label select, 86 | html[xmlns*=""] form.view fieldset ul li label textarea 87 | { 88 | font-size: 1em; 89 | } 90 | 91 | form.view fieldset ul li label input 92 | { 93 | padding: 0; 94 | } 95 | 96 | form.view fieldset ul li label input.checkbox, 97 | form.view fieldset ul li label.radio input.radio 98 | { 99 | width: auto; 100 | /* A hack for IE to line up the checkbox and radio button */ 101 | margin-left: -4px; 102 | } 103 | 104 | /* Set normal margin for other browsers (comment is necessary to hide 105 | from IE7) */ 106 | form.view >/**/fieldset ul li label input.checkbox, 107 | form.view >/**/fieldset ul li label.radio input.radio 108 | 109 | { 110 | margin-left: 0; 111 | } 112 | 113 | form.view fieldset div.submit input.submit 114 | { 115 | margin-top: 2px; 116 | margin-bottom: 2px; 117 | margin-right: 0.5em; 118 | } 119 | 120 | p.validation-error 121 | { 122 | color: red; 123 | font-weight: normal; 124 | font-style: italic; 125 | margin-top: 0; 126 | margin-bottom: 0; 127 | } 128 | 129 | p.validation-error span.validation-error-heading 130 | { 131 | display: none; 132 | } 133 | 134 | /* Radio buttons */ 135 | form.view fieldset ul li label.radio 136 | { 137 | display: block; 138 | margin-left: 12em; 139 | } 140 | 141 | form.view >/**/fieldset ul li label.radio 142 | { 143 | /* We only need this for non-IE browsers */ 144 | margin-top: 0.25em; 145 | } 146 | 147 | form.view fieldset ul li label.radio.first 148 | { 149 | display: inline; 150 | margin-left: 0; 151 | margin-top: 0; 152 | } 153 | 154 | form.view fieldset ul li label.radio input.radio 155 | { 156 | width: auto; 157 | vertical-align: middle; 158 | margin-top: 0; 159 | margin-bottom: 0; 160 | } 161 | 162 | form.view fieldset ul li label.radio span 163 | { 164 | vertical-align: middle; 165 | } 166 | 167 | /* Text area label alignment */ 168 | form fieldset ul li label.textarea span.slot-name 169 | { 170 | vertical-align: top; 171 | } 172 | 173 | -------------------------------------------------------------------------------- /pub/stylesheets/datalist.css: -------------------------------------------------------------------------------- 1 | 2 | .datalist .data-mining-bar form, 3 | .datalist .data-mining-bar form fieldset 4 | { 5 | border: none; 6 | margin: 0; 7 | padding: 0; 8 | } 9 | 10 | .datalist form.datalist-sort-bar, 11 | .datalist form.datalist-sort-bar fieldset select, 12 | .datalist form.datalist-sort-bar fieldset input 13 | { 14 | font-size: x-small; 15 | margin-right: 0.5em; 16 | } 17 | 18 | .datalist form.datalist-sort-bar span, 19 | .datalist form.datalist-sort-bar input, 20 | .datalist form.datalist-sort-bar select 21 | { 22 | vertical-align: middle; 23 | } 24 | 25 | /* Replacing sort direction with an arrow */ 26 | .datalist form.datalist-sort-bar a 27 | { 28 | text-decoration: none; 29 | cursor: pointer; 30 | } 31 | 32 | .datalist form.datalist-sort-bar a span.direction, 33 | .datalist form.datalist-sort-bar span span.direction 34 | { 35 | display: none; 36 | } 37 | 38 | .datalist form.datalist-sort-bar a.sort-asc:before 39 | { 40 | content: url(/weblocks-common/pub/images/widget/datalist/up_arrow_link.png); 41 | } 42 | 43 | .datalist form.datalist-sort-bar a.sort-desc:before 44 | { 45 | content: url(/weblocks-common/pub/images/widget/datalist/down_arrow_link.png); 46 | } 47 | 48 | /* Replacing sort direction with an arrow on IE browsers */ 49 | *:first-child+html .datalist form.datalist-sort-bar a span.direction 50 | { 51 | display: inline; 52 | } 53 | 54 | * html .datalist form.datalist-sort-bar a span.direction 55 | { 56 | display: inline; 57 | } 58 | 59 | *:first-child+html form.datalist-sort-bar a.sort-asc, 60 | *:first-child+html .datalist form.datalist-sort-bar a.sort-desc 61 | { 62 | display: inline-block; 63 | text-indent: -1000em; 64 | cursor: pointer; 65 | width: 11px; 66 | } 67 | 68 | * html .datalist form.datalist-sort-bar a.sort-asc, 69 | * html .datalist form.datalist-sort-bar a.sort-desc, 70 | .datalist form.datalist-sort-bar span.sort-asc, 71 | .datalist form.datalist-sort-bar span.sort-desc 72 | { 73 | display: -moz-inline-box; 74 | display: inline-block; 75 | text-indent: -1000em; 76 | cursor: pointer; 77 | width: 11px; 78 | height: 6px; 79 | } 80 | 81 | * html .datalist form.datalist-sort-bar a.sort-asc, 82 | * html .datalist form.datalist-sort-bar a.sort-desc 83 | { 84 | cursor: pointer; 85 | } 86 | 87 | *:first-child+html .datalist form.datalist-sort-bar a.sort-asc 88 | { 89 | background: url(/weblocks-common/pub/images/widget/datalist/up_arrow_link.png) no-repeat right center; 90 | } 91 | 92 | * html .datalist form.datalist-sort-bar a.sort-asc 93 | { 94 | background: url(/weblocks-common/pub/images/widget/datalist/up_arrow_link.png) no-repeat right center; 95 | } 96 | 97 | *:first-child+html .datalist form.datalist-sort-bar a.sort-desc 98 | { 99 | background: url(/weblocks-common/pub/images/widget/datalist/down_arrow_link.png) no-repeat right center; 100 | } 101 | 102 | * html .datalist form.datalist-sort-bar a.sort-desc 103 | { 104 | background: url(/weblocks-common/pub/images/widget/datalist/down_arrow_link.png) no-repeat right center; 105 | } 106 | 107 | .datalist form.datalist-sort-bar span.sort-asc, 108 | .datalist form.datalist-sort-bar span.sort-desc 109 | { 110 | cursor: default; 111 | } 112 | 113 | /* No Script Arrow */ 114 | .datalist form.datalist-sort-bar span.sort-desc 115 | { 116 | background: url(/weblocks-common/pub/images/widget/datalist/down_arrow.png) no-repeat right center; 117 | } 118 | 119 | .datalist form.datalist-sort-bar span.sort-asc 120 | { 121 | background: url(/weblocks-common/pub/images/widget/datalist/up_arrow.png) no-repeat right center; 122 | } 123 | 124 | /* Some colors */ 125 | .datalist form.datalist-sort-bar span 126 | { 127 | color: gray; 128 | } 129 | 130 | /* Lists */ 131 | .datalist ol, .datalist ul 132 | { 133 | margin: 0; 134 | padding: 0; 135 | list-style-type: none; 136 | } 137 | 138 | .datalist .datalist-body .view 139 | { 140 | width: 100%; 141 | } 142 | 143 | .datalist form.operations-form fieldset .operations 144 | { 145 | margin-top: -0.75em; 146 | } 147 | 148 | /* IE6 and IE7 fix for gaps between list items Note, once we set 149 | element to inline, we need to reset inner elements to block */ 150 | .datalist .datalist-body ol li, 151 | .datalist .datalist-body ul li 152 | { 153 | display: inline; 154 | } 155 | 156 | .datalist .datalist-body ol li li, 157 | .datalist .datalist-body ul li li 158 | { 159 | display: block; 160 | } 161 | 162 | /* Remove view headers in the body */ 163 | .datalist .datalist-body .view h1 164 | { 165 | display: none; 166 | } 167 | 168 | -------------------------------------------------------------------------------- /pub/scripts/builder.js: -------------------------------------------------------------------------------- 1 | // script.aculo.us builder.js v1.7.1_beta3, Fri May 25 17:19:41 +0200 2007 2 | 3 | // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 4 | // 5 | // script.aculo.us is freely distributable under the terms of an MIT-style license. 6 | // For details, see the script.aculo.us web site: http://script.aculo.us/ 7 | 8 | var Builder = { 9 | NODEMAP: { 10 | AREA: 'map', 11 | CAPTION: 'table', 12 | COL: 'table', 13 | COLGROUP: 'table', 14 | LEGEND: 'fieldset', 15 | OPTGROUP: 'select', 16 | OPTION: 'select', 17 | PARAM: 'object', 18 | TBODY: 'table', 19 | TD: 'table', 20 | TFOOT: 'table', 21 | TH: 'table', 22 | THEAD: 'table', 23 | TR: 'table' 24 | }, 25 | // note: For Firefox < 1.5, OPTION and OPTGROUP tags are currently broken, 26 | // due to a Firefox bug 27 | node: function(elementName) { 28 | elementName = elementName.toUpperCase(); 29 | 30 | // try innerHTML approach 31 | var parentTag = this.NODEMAP[elementName] || 'div'; 32 | var parentElement = document.createElement(parentTag); 33 | try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707 34 | parentElement.innerHTML = "<" + elementName + ">"; 35 | } catch(e) {} 36 | var element = parentElement.firstChild || null; 37 | 38 | // see if browser added wrapping tags 39 | if(element && (element.tagName.toUpperCase() != elementName)) 40 | element = element.getElementsByTagName(elementName)[0]; 41 | 42 | // fallback to createElement approach 43 | if(!element) element = document.createElement(elementName); 44 | 45 | // abort if nothing could be created 46 | if(!element) return; 47 | 48 | // attributes (or text) 49 | if(arguments[1]) 50 | if(this._isStringOrNumber(arguments[1]) || 51 | (arguments[1] instanceof Array) || 52 | arguments[1].tagName) { 53 | this._children(element, arguments[1]); 54 | } else { 55 | var attrs = this._attributes(arguments[1]); 56 | if(attrs.length) { 57 | try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707 58 | parentElement.innerHTML = "<" +elementName + " " + 59 | attrs + ">"; 60 | } catch(e) {} 61 | element = parentElement.firstChild || null; 62 | // workaround firefox 1.0.X bug 63 | if(!element) { 64 | element = document.createElement(elementName); 65 | for(attr in arguments[1]) 66 | element[attr == 'class' ? 'className' : attr] = arguments[1][attr]; 67 | } 68 | if(element.tagName.toUpperCase() != elementName) 69 | element = parentElement.getElementsByTagName(elementName)[0]; 70 | } 71 | } 72 | 73 | // text, or array of children 74 | if(arguments[2]) 75 | this._children(element, arguments[2]); 76 | 77 | return element; 78 | }, 79 | _text: function(text) { 80 | return document.createTextNode(text); 81 | }, 82 | 83 | ATTR_MAP: { 84 | 'className': 'class', 85 | 'htmlFor': 'for' 86 | }, 87 | 88 | _attributes: function(attributes) { 89 | var attrs = []; 90 | for(attribute in attributes) 91 | attrs.push((attribute in this.ATTR_MAP ? this.ATTR_MAP[attribute] : attribute) + 92 | '="' + attributes[attribute].toString().escapeHTML().gsub(/"/,'"') + '"'); 93 | return attrs.join(" "); 94 | }, 95 | _children: function(element, children) { 96 | if(children.tagName) { 97 | element.appendChild(children); 98 | return; 99 | } 100 | if(typeof children=='object') { // array can hold nodes and text 101 | children.flatten().each( function(e) { 102 | if(typeof e=='object') 103 | element.appendChild(e) 104 | else 105 | if(Builder._isStringOrNumber(e)) 106 | element.appendChild(Builder._text(e)); 107 | }); 108 | } else 109 | if(Builder._isStringOrNumber(children)) 110 | element.appendChild(Builder._text(children)); 111 | }, 112 | _isStringOrNumber: function(param) { 113 | return(typeof param=='string' || typeof param=='number'); 114 | }, 115 | build: function(html) { 116 | var element = this.node('div'); 117 | $(element).update(html.strip()); 118 | return element.down(); 119 | }, 120 | dump: function(scope) { 121 | if(typeof scope != 'object' && typeof scope != 'function') scope = window; //global scope 122 | 123 | var tags = ("A ABBR ACRONYM ADDRESS APPLET AREA B BASE BASEFONT BDO BIG BLOCKQUOTE BODY " + 124 | "BR BUTTON CAPTION CENTER CITE CODE COL COLGROUP DD DEL DFN DIR DIV DL DT EM FIELDSET " + 125 | "FONT FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HR HTML I IFRAME IMG INPUT INS ISINDEX "+ 126 | "KBD LABEL LEGEND LI LINK MAP MENU META NOFRAMES NOSCRIPT OBJECT OL OPTGROUP OPTION P "+ 127 | "PARAM PRE Q S SAMP SCRIPT SELECT SMALL SPAN STRIKE STRONG STYLE SUB SUP TABLE TBODY TD "+ 128 | "TEXTAREA TFOOT TH THEAD TITLE TR TT U UL VAR").split(/\s+/); 129 | 130 | tags.each( function(tag){ 131 | scope[tag] = function() { 132 | return Builder.node.apply(Builder, [tag].concat($A(arguments))); 133 | } 134 | }); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /pub/stylesheets/main.css: -------------------------------------------------------------------------------- 1 | 2 | body 3 | { 4 | font-size: small; 5 | font-family: arial, helvetica, sans-serif; 6 | } 7 | 8 | a 9 | { 10 | color: #A61E2E; 11 | } 12 | 13 | #root { position: relative; } 14 | 15 | .view 16 | { 17 | background: #ecf8d7 url(/weblocks-common/pub/images/widget/top_background.png) repeat-x; 18 | margin-bottom: 1em; 19 | _height: 0; /* IE specific hasLayout fix */ 20 | } 21 | 22 | .view h1, .view fieldset h1 23 | { 24 | background-color: #ecf8d7; 25 | } 26 | 27 | .view .extra-top-1 28 | { 29 | height: 7px; 30 | background: url(/weblocks-common/pub/images/widget/top_left.png) no-repeat top left; 31 | overflow: hidden; 32 | } 33 | 34 | .view .extra-top-2 35 | { 36 | height: 7px; 37 | margin-top: -7px; 38 | background: url(/weblocks-common/pub/images/widget/top_right.png) no-repeat top right; 39 | border-bottom: 1px solid #dbeac1; 40 | overflow: hidden; 41 | } 42 | 43 | .view h1, .view fieldset h1, 44 | .long-form fieldset .validation-errors-summary h2.error-count 45 | { 46 | margin: 0; 47 | padding: 0; 48 | padding-left: 0.4em; 49 | } 50 | 51 | .view h1, .view fieldset h1, .table table caption, div.empty p, 52 | .view .empty-navigation, .view ul li, .view fieldset ul li, 53 | .view table thead tr th, 54 | .view fieldset div.submit, .view div.submit, 55 | .long-form fieldset .validation-errors-summary h2.error-count, 56 | .form fieldset .validation-errors-summary .non-field-validation-errors 57 | { 58 | border-top: 1px solid #fcfef6; 59 | } 60 | 61 | .view h1, .view fieldset h1, .table table caption, div.empty p, 62 | .view .empty-navigation, .view ul li, .view fieldset ul li, 63 | .view table thead tr th, 64 | .view fieldset div.submit, .view div.submit, 65 | .long-form fieldset .validation-errors-summary, 66 | .form fieldset .validation-errors-summary .non-field-validation-errors 67 | { 68 | border-bottom: 1px solid #dbeac1; 69 | } 70 | 71 | .view h1, .view fieldset h1, .table table caption, div.empty p, 72 | .view .empty-navigation, .view ul, .view fieldset ul, .table table, 73 | .view fieldset div.submit, .view div.submit, 74 | .long-form fieldset .validation-errors-summary h2.error-count 75 | { 76 | border-left: 2px solid #dbeac1; 77 | border-right: 2px solid #dbeac1; 78 | } 79 | 80 | h1, h2 81 | { 82 | font-size: large; 83 | color: #29364F; 84 | font-weight: bold; 85 | font-family: Garamond, New York, serif; 86 | } 87 | 88 | .view h1 .action, .view fieldset h1 .action 89 | { 90 | display: none; 91 | } 92 | 93 | .view ul, .view fieldset ul, .table table, .view fieldset div.submit, 94 | .view div.submit 95 | { 96 | padding-left: 0; 97 | margin: 0; 98 | } 99 | 100 | .view ul li, .view fieldset ul li, .menu ul li a 101 | { 102 | list-style: none; 103 | padding-left: 1.5em; 104 | } 105 | 106 | .view div.submit, .form fieldset div.submit 107 | { 108 | padding-left: 13.5em; 109 | } 110 | 111 | .view ul li .label, .view fieldset ul li label span.slot-name, 112 | .table table thead 113 | { 114 | color: #808080; 115 | font-weight: bold; 116 | } 117 | 118 | .view ul li .label, .view fieldset ul li label span.slot-name 119 | { 120 | display: -moz-inline-box; 121 | display: inline-block; 122 | width: 12em; 123 | } 124 | 125 | .view .extra-bottom-1 126 | { 127 | height: 7px; 128 | background: url(/weblocks-common/pub/images/widget/bottom_background.png) repeat-x top; 129 | overflow: hidden; 130 | } 131 | 132 | .view .extra-bottom-2 133 | { 134 | height: 7px; 135 | margin-top: -7px; 136 | background: url(/weblocks-common/pub/images/widget/bottom_left.png) no-repeat top left; 137 | overflow: hidden; 138 | } 139 | 140 | .view .extra-bottom-3 141 | { 142 | height: 7px; 143 | margin-top: -7px; 144 | background: url(/weblocks-common/pub/images/widget/bottom_right.png) no-repeat top right; 145 | overflow: hidden; 146 | } 147 | 148 | .missing 149 | { 150 | font-style: italic; 151 | color: #808080; 152 | } 153 | 154 | input[type=hidden] 155 | { 156 | visibility: hidden; 157 | } 158 | 159 | #ajax-progress 160 | { 161 | position: fixed; 162 | right: 0; 163 | top: 0; 164 | z-index: 1000; 165 | } 166 | 167 | /* IE 6 specific progress bar fix */ 168 | * html #ajax-progress 169 | { 170 | position: absolute; 171 | left: expression((documentElement.scrollLeft 172 | + (documentElement.clientWidth - this.clientWidth)) 173 | + 'px') 174 | top: expression(documentElement.scrollTop + 'px'); 175 | } 176 | 177 | /* Common styles for form, and data */ 178 | .data, .form 179 | { 180 | width: 27em; 181 | } 182 | 183 | /* Close button */ 184 | span.close-button 185 | { 186 | display: block; 187 | width: 15px; 188 | height: 15px; 189 | overflow: hidden; 190 | } 191 | 192 | span.close-button a 193 | { 194 | /* background: url(/weblocks-common/pub/images/close.png) no-repeat top left; */ 195 | padding-left: 1000em; 196 | } 197 | 198 | span.close-button a:hover 199 | { 200 | /* background: url(/weblocks-common/pub/images/close_hl.png) no-repeat top left; */ 201 | } 202 | 203 | /* Total Items */ 204 | span.total-items 205 | { 206 | color: gray; 207 | font-size: x-small; 208 | } 209 | 210 | /* Text */ 211 | .ellipsis 212 | { 213 | color: gray; 214 | font-weight: bold; 215 | } 216 | 217 | p.text 218 | { 219 | margin: 0; 220 | } 221 | 222 | .view ul li p.text 223 | { 224 | margin-left: 0.5em; 225 | } 226 | 227 | /* No elements */ 228 | div.empty p 229 | { 230 | padding-left: 0.5em; 231 | margin: 0; 232 | } 233 | 234 | div.empty p span.caption 235 | { 236 | color: #29364F; 237 | font-weight: bold; 238 | font-family: Garamond, New York, serif; 239 | } 240 | 241 | -------------------------------------------------------------------------------- /pub/scripts/shortcut.js: -------------------------------------------------------------------------------- 1 | /** 2 | * http://www.openjs.com/scripts/events/keyboard_shortcuts/ 3 | * Version : 2.01.A 4 | * By Binny V A 5 | * License : BSD 6 | */ 7 | shortcut = { 8 | 'all_shortcuts':{},//All the shortcuts are stored in this array 9 | 'add': function(shortcut_combination,callback,opt) { 10 | //Provide a set of default options 11 | var default_options = { 12 | 'type':'keydown', 13 | 'propagate':false, 14 | 'disable_in_input':false, 15 | 'target':document, 16 | 'keycode':false 17 | } 18 | if(!opt) opt = default_options; 19 | else { 20 | for(var dfo in default_options) { 21 | if(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo]; 22 | } 23 | } 24 | 25 | var ele = opt.target 26 | if(typeof opt.target == 'string') ele = document.getElementById(opt.target); 27 | var ths = this; 28 | shortcut_combination = shortcut_combination.toLowerCase(); 29 | 30 | //The function to be called at keypress 31 | var func = function(e) { 32 | e = e || window.event; 33 | 34 | if(opt['disable_in_input']) { //Don't enable shortcut keys in Input, Textarea fields 35 | var element; 36 | if(e.target) element=e.target; 37 | else if(e.srcElement) element=e.srcElement; 38 | if(element.nodeType==3) element=element.parentNode; 39 | 40 | if(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA' 41 | || element.tagName == 'SELECT') return; 42 | } 43 | 44 | //Find Which key is pressed 45 | if (e.keyCode) code = e.keyCode; 46 | else if (e.which) code = e.which; 47 | var character = String.fromCharCode(code).toLowerCase(); 48 | 49 | if(code == 188) character=","; //If the user presses , when the type is onkeydown 50 | if(code == 190) character="."; //If the user presses , when the type is onkeydown 51 | 52 | var keys = shortcut_combination.split("+"); 53 | //Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked 54 | var kp = 0; 55 | 56 | //Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken 57 | var shift_nums = { 58 | "`":"~", 59 | "1":"!", 60 | "2":"@", 61 | "3":"#", 62 | "4":"$", 63 | "5":"%", 64 | "6":"^", 65 | "7":"&", 66 | "8":"*", 67 | "9":"(", 68 | "0":")", 69 | "-":"_", 70 | "=":"+", 71 | ";":":", 72 | "'":"\"", 73 | ",":"<", 74 | ".":">", 75 | "/":"?", 76 | "\\":"|" 77 | } 78 | //Special Keys - and their codes 79 | var special_keys = { 80 | 'esc':27, 81 | 'escape':27, 82 | 'tab':9, 83 | 'space':32, 84 | 'return':13, 85 | 'enter':13, 86 | 'backspace':8, 87 | 88 | 'scrolllock':145, 89 | 'scroll_lock':145, 90 | 'scroll':145, 91 | 'capslock':20, 92 | 'caps_lock':20, 93 | 'caps':20, 94 | 'numlock':144, 95 | 'num_lock':144, 96 | 'num':144, 97 | 98 | 'pause':19, 99 | 'break':19, 100 | 101 | 'insert':45, 102 | 'home':36, 103 | 'delete':46, 104 | 'end':35, 105 | 106 | 'pageup':33, 107 | 'page_up':33, 108 | 'pu':33, 109 | 110 | 'pagedown':34, 111 | 'page_down':34, 112 | 'pd':34, 113 | 114 | 'left':37, 115 | 'up':38, 116 | 'right':39, 117 | 'down':40, 118 | 119 | 'f1':112, 120 | 'f2':113, 121 | 'f3':114, 122 | 'f4':115, 123 | 'f5':116, 124 | 'f6':117, 125 | 'f7':118, 126 | 'f8':119, 127 | 'f9':120, 128 | 'f10':121, 129 | 'f11':122, 130 | 'f12':123 131 | } 132 | 133 | var modifiers = { 134 | shift: { wanted:false, pressed:false}, 135 | ctrl : { wanted:false, pressed:false}, 136 | alt : { wanted:false, pressed:false}, 137 | meta : { wanted:false, pressed:false} //Meta is Mac specific 138 | }; 139 | 140 | if(e.ctrlKey) modifiers.ctrl.pressed = true; 141 | if(e.shiftKey) modifiers.shift.pressed = true; 142 | if(e.altKey) modifiers.alt.pressed = true; 143 | if(e.metaKey) modifiers.meta.pressed = true; 144 | 145 | for(var i=0; k=keys[i],i 1) { //If it is a special key 162 | if(special_keys[k] == code) kp++; 163 | 164 | } else if(opt['keycode']) { 165 | if(opt['keycode'] == code) kp++; 166 | 167 | } else { //The special keys did not match 168 | if(character == k) kp++; 169 | else { 170 | if(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase 171 | character = shift_nums[character]; 172 | if(character == k) kp++; 173 | } 174 | } 175 | } 176 | } 177 | 178 | if(kp == keys.length && 179 | modifiers.ctrl.pressed == modifiers.ctrl.wanted && 180 | modifiers.shift.pressed == modifiers.shift.wanted && 181 | modifiers.alt.pressed == modifiers.alt.wanted && 182 | modifiers.meta.pressed == modifiers.meta.wanted) { 183 | callback(e); 184 | 185 | if(!opt['propagate']) { //Stop the event 186 | //e.cancelBubble is supported by IE - this will kill the bubbling process. 187 | e.cancelBubble = true; 188 | e.returnValue = false; 189 | 190 | //e.stopPropagation works in Firefox. 191 | if (e.stopPropagation) { 192 | e.stopPropagation(); 193 | e.preventDefault(); 194 | } 195 | return false; 196 | } 197 | } 198 | } 199 | this.all_shortcuts[shortcut_combination] = { 200 | 'callback':func, 201 | 'target':ele, 202 | 'event': opt['type'] 203 | }; 204 | //Attach the function with the event 205 | if(ele.addEventListener) ele.addEventListener(opt['type'], func, false); 206 | else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func); 207 | else ele['on'+opt['type']] = func; 208 | }, 209 | 210 | //Remove the shortcut - just specify the shortcut and I will remove the binding 211 | 'remove':function(shortcut_combination) { 212 | shortcut_combination = shortcut_combination.toLowerCase(); 213 | var binding = this.all_shortcuts[shortcut_combination]; 214 | delete(this.all_shortcuts[shortcut_combination]) 215 | if(!binding) return; 216 | var type = binding['event']; 217 | var ele = binding['target']; 218 | var callback = binding['callback']; 219 | 220 | if(ele.detachEvent) ele.detachEvent('on'+type, callback); 221 | else if(ele.removeEventListener) ele.removeEventListener(type, callback, false); 222 | else ele['on'+type] = false; 223 | } 224 | } 225 | -------------------------------------------------------------------------------- /pub/scripts/weblocks.js: -------------------------------------------------------------------------------- 1 | 2 | // Utilities 3 | function updateElementBody(element, newBody) { 4 | element.update(newBody); 5 | } 6 | 7 | function updateElement(element, newElement) { 8 | var parent = element.parentNode; 9 | parent.replaceChild(newElement[0], element); 10 | 11 | if(element.next()){ 12 | var next = element.next(); 13 | var insertMethod = function(newEl){ 14 | parent.insertBefore(newEl, next); 15 | }; 16 | }else{ 17 | var insertMethod = function(newEl){ 18 | parent.appendChild(newEl); 19 | }; 20 | } 21 | 22 | for(var i=1;i < newElement.length - 1;i++){ 23 | insertMethod(newElement[i]); 24 | } 25 | } 26 | 27 | function selectionEmpty() { 28 | if(document.getSelection) { 29 | return document.getSelection() == ""; 30 | } else if(document.selection && document.selection.createRange) { 31 | return document.selection.createRange().text == ""; 32 | } else { 33 | return true; 34 | } 35 | } 36 | 37 | function addCss(cssCode) { 38 | var styleElement = document.createElement("style"); 39 | styleElement.type = "text/css"; 40 | if (styleElement.styleSheet) { 41 | styleElement.styleSheet.cssText = cssCode; 42 | } else { 43 | styleElement.appendChild(document.createTextNode(cssCode)); 44 | } 45 | document.getElementsByTagName("head")[0].appendChild(styleElement); 46 | } 47 | 48 | function stopPropagation(event) { 49 | if(event.preventDefault) { 50 | event.stopPropagation(); 51 | } else { 52 | event.cancelBubble = true; 53 | }; 54 | } 55 | 56 | // Register global AJAX handlers to show progress 57 | Ajax.Responders.register({ 58 | onCreate: function() { 59 | $('ajax-progress').innerHTML = ""; 60 | }, 61 | onComplete: function() { 62 | $('ajax-progress').innerHTML = ""; 63 | } 64 | }); 65 | 66 | function onActionSuccess(transport) { 67 | // Grab json value 68 | var json; 69 | 70 | json = transport.responseText.evalJSON(false); 71 | 72 | // See if there are redirects 73 | var redirect = json['redirect']; 74 | if (redirect) 75 | { 76 | window.location.href = redirect; 77 | return; 78 | } 79 | 80 | execJsonCalls(json['before-load']); 81 | 82 | // Update dirty widgets 83 | var dirtyWidgets = json['widgets']; 84 | var minTopOffset = document.documentElement.getHeight(); 85 | 86 | for(var i in dirtyWidgets) { 87 | var widget = $(i); 88 | if(widget) { 89 | //console.log("updating widget %s", i); 90 | var el = (new Element('div')).update(dirtyWidgets[i]).childElements(); 91 | updateElement(widget, el); 92 | 93 | el.each(function(th){ 94 | var offsetTop = th.cumulativeOffset().top; 95 | if(offsetTop < minTopOffset){ 96 | minTopOffset = offsetTop; 97 | } 98 | }); 99 | } 100 | } 101 | 102 | // Scroll top if some of updated elements is above area viewed by user 103 | if(minTopOffset < window.scrollY){ 104 | new Effect.ScrollTo(document, { duration:0.2 }); 105 | } 106 | 107 | execJsonCalls(json['on-load']); 108 | } 109 | 110 | function execJsonCalls (calls) { 111 | if(calls) { 112 | calls.each(function(item) 113 | { 114 | try { 115 | item.evalScripts(); 116 | } catch(e) { 117 | //console.log("Error evaluating AJAX script %o: %s", item, e); 118 | } 119 | }); 120 | } 121 | } 122 | 123 | function onActionFailure() { 124 | alert('Oops, we could not complete your request because of an internal error.'); 125 | } 126 | 127 | function getActionUrl(actionCode, sessionString, isPure) { 128 | if (!sessionString) sessionString = ""; 129 | var scriptName = location.protocol + "//" 130 | + location.hostname 131 | + (location.port ? ":" + location.port : "") 132 | + location.pathname; 133 | var query = location.search; 134 | var url = scriptName + query + (query ? "&" : "?") 135 | + sessionString + (sessionString ? "&" : "") + "action=" + actionCode; 136 | 137 | if(isPure) 138 | url += '&pure=true'; 139 | 140 | return url; 141 | } 142 | 143 | function initiateActionWithArgs(actionCode, sessionString, args, method, url) { 144 | if (!method) method = 'get'; 145 | if (!url) url = getActionUrl(actionCode, sessionString); 146 | new Ajax.Request(url, 147 | { 148 | method: method, 149 | onSuccess: onActionSuccess, 150 | onFailure: onActionFailure, 151 | parameters: args 152 | }); 153 | 154 | } 155 | 156 | /* convenience/compatibility function */ 157 | function initiateAction(actionCode, sessionString) { 158 | initiateActionWithArgs(actionCode, sessionString); 159 | } 160 | 161 | function initiateFormAction(actionCode, form, sessionString) { 162 | // Hidden "action" field should not be serialized on AJAX 163 | var serializedForm = form.serialize(true); 164 | delete(serializedForm['action']); 165 | 166 | initiateActionWithArgs(actionCode, sessionString, serializedForm, form.method); 167 | } 168 | 169 | function disableIrrelevantButtons(currentButton) { 170 | $(currentButton.form).getInputs('submit').each(function(obj) 171 | { 172 | obj.disable(); 173 | currentButton.enable(); 174 | }); 175 | } 176 | 177 | // Fix IE6 flickering issue 178 | if(Prototype.Browser.IE) { 179 | try { 180 | document.execCommand("BackgroundImageCache", false, true); 181 | } catch(err) {} 182 | } 183 | 184 | // Table hovering for IE (can't use CSS expressions because 185 | // Event.observe isn't available there and we can't overwrite events 186 | // using assignment 187 | if(!window.XMLHttpRequest) { 188 | // IE6 only 189 | Event.observe(window, 'load', function() { 190 | var tableRows = $$('.table table tbody tr'); 191 | tableRows.each(function(row) { 192 | Event.observe(row, 'mouseover', function() { 193 | row.addClassName('hover'); 194 | }); 195 | Event.observe(row, 'mouseout', function() { 196 | row.removeClassName('hover'); 197 | }); 198 | }); 199 | }); 200 | } 201 | 202 | // Support suggest control 203 | function declareSuggest(inputId, choicesId, resultSet, sessionString) { 204 | if(resultSet instanceof Array) { 205 | new Autocompleter.Local(inputId, choicesId, resultSet, {}); 206 | } else { 207 | new Ajax.Autocompleter(inputId, choicesId, getActionUrl(resultSet, sessionString, true), {}); 208 | } 209 | } 210 | 211 | function replaceDropdownWithSuggest(ignoreWelcomeMsg, inputId, inputName, choicesId, value) { 212 | var dropdownOptions = $(inputId).childElements(); 213 | var suggestOptions = []; 214 | dropdownOptions.each(function(i) 215 | { 216 | if(!(i == dropdownOptions[0] && ignoreWelcomeMsg)) { 217 | suggestOptions.push(i.innerHTML); 218 | } 219 | }); 220 | 221 | var inputBox = ''; 228 | $(inputId).replace(suggestHTML); 229 | 230 | declareSuggest(inputId, choicesId, suggestOptions); 231 | } 232 | 233 | function include_css(css_file) { 234 | var html_doc = document.getElementsByTagName('head').item(0); 235 | var css = document.createElement('link'); 236 | css.setAttribute('rel', 'stylesheet'); 237 | css.setAttribute('type', 'text/css'); 238 | css.setAttribute('href', css_file); 239 | html_doc.appendChild(css); 240 | return false; 241 | } 242 | 243 | function include_dom(script_filename) { 244 | var html_doc = document.getElementsByTagName('head').item(0); 245 | var js = document.createElement('script'); 246 | js.setAttribute('language', 'javascript'); 247 | js.setAttribute('type', 'text/javascript'); 248 | js.setAttribute('src', script_filename); 249 | html_doc.appendChild(js); 250 | return false; 251 | } 252 | 253 | -------------------------------------------------------------------------------- /pub/scripts/slider.js: -------------------------------------------------------------------------------- 1 | // script.aculo.us slider.js v1.7.1_beta3, Fri May 25 17:19:41 +0200 2007 2 | 3 | // Copyright (c) 2005-2007 Marty Haught, Thomas Fuchs 4 | // 5 | // script.aculo.us is freely distributable under the terms of an MIT-style license. 6 | // For details, see the script.aculo.us web site: http://script.aculo.us/ 7 | 8 | if(!Control) var Control = {}; 9 | Control.Slider = Class.create(); 10 | 11 | // options: 12 | // axis: 'vertical', or 'horizontal' (default) 13 | // 14 | // callbacks: 15 | // onChange(value) 16 | // onSlide(value) 17 | Control.Slider.prototype = { 18 | initialize: function(handle, track, options) { 19 | var slider = this; 20 | 21 | if(handle instanceof Array) { 22 | this.handles = handle.collect( function(e) { return $(e) }); 23 | } else { 24 | this.handles = [$(handle)]; 25 | } 26 | 27 | this.track = $(track); 28 | this.options = options || {}; 29 | 30 | this.axis = this.options.axis || 'horizontal'; 31 | this.increment = this.options.increment || 1; 32 | this.step = parseInt(this.options.step || '1'); 33 | this.range = this.options.range || $R(0,1); 34 | 35 | this.value = 0; // assure backwards compat 36 | this.values = this.handles.map( function() { return 0 }); 37 | this.spans = this.options.spans ? this.options.spans.map(function(s){ return $(s) }) : false; 38 | this.options.startSpan = $(this.options.startSpan || null); 39 | this.options.endSpan = $(this.options.endSpan || null); 40 | 41 | this.restricted = this.options.restricted || false; 42 | 43 | this.maximum = this.options.maximum || this.range.end; 44 | this.minimum = this.options.minimum || this.range.start; 45 | 46 | // Will be used to align the handle onto the track, if necessary 47 | this.alignX = parseInt(this.options.alignX || '0'); 48 | this.alignY = parseInt(this.options.alignY || '0'); 49 | 50 | this.trackLength = this.maximumOffset() - this.minimumOffset(); 51 | 52 | this.handleLength = this.isVertical() ? 53 | (this.handles[0].offsetHeight != 0 ? 54 | this.handles[0].offsetHeight : this.handles[0].style.height.replace(/px$/,"")) : 55 | (this.handles[0].offsetWidth != 0 ? this.handles[0].offsetWidth : 56 | this.handles[0].style.width.replace(/px$/,"")); 57 | 58 | this.active = false; 59 | this.dragging = false; 60 | this.disabled = false; 61 | 62 | if(this.options.disabled) this.setDisabled(); 63 | 64 | // Allowed values array 65 | this.allowedValues = this.options.values ? this.options.values.sortBy(Prototype.K) : false; 66 | if(this.allowedValues) { 67 | this.minimum = this.allowedValues.min(); 68 | this.maximum = this.allowedValues.max(); 69 | } 70 | 71 | this.eventMouseDown = this.startDrag.bindAsEventListener(this); 72 | this.eventMouseUp = this.endDrag.bindAsEventListener(this); 73 | this.eventMouseMove = this.update.bindAsEventListener(this); 74 | 75 | // Initialize handles in reverse (make sure first handle is active) 76 | this.handles.each( function(h,i) { 77 | i = slider.handles.length-1-i; 78 | slider.setValue(parseFloat( 79 | (slider.options.sliderValue instanceof Array ? 80 | slider.options.sliderValue[i] : slider.options.sliderValue) || 81 | slider.range.start), i); 82 | Element.makePositioned(h); // fix IE 83 | Event.observe(h, "mousedown", slider.eventMouseDown); 84 | }); 85 | 86 | Event.observe(this.track, "mousedown", this.eventMouseDown); 87 | Event.observe(document, "mouseup", this.eventMouseUp); 88 | Event.observe(document, "mousemove", this.eventMouseMove); 89 | 90 | this.initialized = true; 91 | }, 92 | dispose: function() { 93 | var slider = this; 94 | Event.stopObserving(this.track, "mousedown", this.eventMouseDown); 95 | Event.stopObserving(document, "mouseup", this.eventMouseUp); 96 | Event.stopObserving(document, "mousemove", this.eventMouseMove); 97 | this.handles.each( function(h) { 98 | Event.stopObserving(h, "mousedown", slider.eventMouseDown); 99 | }); 100 | }, 101 | setDisabled: function(){ 102 | this.disabled = true; 103 | }, 104 | setEnabled: function(){ 105 | this.disabled = false; 106 | }, 107 | getNearestValue: function(value){ 108 | if(this.allowedValues){ 109 | if(value >= this.allowedValues.max()) return(this.allowedValues.max()); 110 | if(value <= this.allowedValues.min()) return(this.allowedValues.min()); 111 | 112 | var offset = Math.abs(this.allowedValues[0] - value); 113 | var newValue = this.allowedValues[0]; 114 | this.allowedValues.each( function(v) { 115 | var currentOffset = Math.abs(v - value); 116 | if(currentOffset <= offset){ 117 | newValue = v; 118 | offset = currentOffset; 119 | } 120 | }); 121 | return newValue; 122 | } 123 | if(value > this.range.end) return this.range.end; 124 | if(value < this.range.start) return this.range.start; 125 | return value; 126 | }, 127 | setValue: function(sliderValue, handleIdx){ 128 | if(!this.active) { 129 | this.activeHandleIdx = handleIdx || 0; 130 | this.activeHandle = this.handles[this.activeHandleIdx]; 131 | this.updateStyles(); 132 | } 133 | handleIdx = handleIdx || this.activeHandleIdx || 0; 134 | if(this.initialized && this.restricted) { 135 | if((handleIdx>0) && (sliderValuethis.values[handleIdx+1])) 138 | sliderValue = this.values[handleIdx+1]; 139 | } 140 | sliderValue = this.getNearestValue(sliderValue); 141 | this.values[handleIdx] = sliderValue; 142 | this.value = this.values[0]; // assure backwards compat 143 | 144 | this.handles[handleIdx].style[this.isVertical() ? 'top' : 'left'] = 145 | this.translateToPx(sliderValue); 146 | 147 | this.drawSpans(); 148 | if(!this.dragging || !this.event) this.updateFinished(); 149 | }, 150 | setValueBy: function(delta, handleIdx) { 151 | this.setValue(this.values[handleIdx || this.activeHandleIdx || 0] + delta, 152 | handleIdx || this.activeHandleIdx || 0); 153 | }, 154 | translateToPx: function(value) { 155 | return Math.round( 156 | ((this.trackLength-this.handleLength)/(this.range.end-this.range.start)) * 157 | (value - this.range.start)) + "px"; 158 | }, 159 | translateToValue: function(offset) { 160 | return ((offset/(this.trackLength-this.handleLength) * 161 | (this.range.end-this.range.start)) + this.range.start); 162 | }, 163 | getRange: function(range) { 164 | var v = this.values.sortBy(Prototype.K); 165 | range = range || 0; 166 | return $R(v[range],v[range+1]); 167 | }, 168 | minimumOffset: function(){ 169 | return(this.isVertical() ? this.alignY : this.alignX); 170 | }, 171 | maximumOffset: function(){ 172 | return(this.isVertical() ? 173 | (this.track.offsetHeight != 0 ? this.track.offsetHeight : 174 | this.track.style.height.replace(/px$/,"")) - this.alignY : 175 | (this.track.offsetWidth != 0 ? this.track.offsetWidth : 176 | this.track.style.width.replace(/px$/,"")) - this.alignY); 177 | }, 178 | isVertical: function(){ 179 | return (this.axis == 'vertical'); 180 | }, 181 | drawSpans: function() { 182 | var slider = this; 183 | if(this.spans) 184 | $R(0, this.spans.length-1).each(function(r) { slider.setSpan(slider.spans[r], slider.getRange(r)) }); 185 | if(this.options.startSpan) 186 | this.setSpan(this.options.startSpan, 187 | $R(0, this.values.length>1 ? this.getRange(0).min() : this.value )); 188 | if(this.options.endSpan) 189 | this.setSpan(this.options.endSpan, 190 | $R(this.values.length>1 ? this.getRange(this.spans.length-1).max() : this.value, this.maximum)); 191 | }, 192 | setSpan: function(span, range) { 193 | if(this.isVertical()) { 194 | span.style.top = this.translateToPx(range.start); 195 | span.style.height = this.translateToPx(range.end - range.start + this.range.start); 196 | } else { 197 | span.style.left = this.translateToPx(range.start); 198 | span.style.width = this.translateToPx(range.end - range.start + this.range.start); 199 | } 200 | }, 201 | updateStyles: function() { 202 | this.handles.each( function(h){ Element.removeClassName(h, 'selected') }); 203 | Element.addClassName(this.activeHandle, 'selected'); 204 | }, 205 | startDrag: function(event) { 206 | if(Event.isLeftClick(event)) { 207 | if(!this.disabled){ 208 | this.active = true; 209 | 210 | var handle = Event.element(event); 211 | var pointer = [Event.pointerX(event), Event.pointerY(event)]; 212 | var track = handle; 213 | if(track==this.track) { 214 | var offsets = Position.cumulativeOffset(this.track); 215 | this.event = event; 216 | this.setValue(this.translateToValue( 217 | (this.isVertical() ? pointer[1]-offsets[1] : pointer[0]-offsets[0])-(this.handleLength/2) 218 | )); 219 | var offsets = Position.cumulativeOffset(this.activeHandle); 220 | this.offsetX = (pointer[0] - offsets[0]); 221 | this.offsetY = (pointer[1] - offsets[1]); 222 | } else { 223 | // find the handle (prevents issues with Safari) 224 | while((this.handles.indexOf(handle) == -1) && handle.parentNode) 225 | handle = handle.parentNode; 226 | 227 | if(this.handles.indexOf(handle)!=-1) { 228 | this.activeHandle = handle; 229 | this.activeHandleIdx = this.handles.indexOf(this.activeHandle); 230 | this.updateStyles(); 231 | 232 | var offsets = Position.cumulativeOffset(this.activeHandle); 233 | this.offsetX = (pointer[0] - offsets[0]); 234 | this.offsetY = (pointer[1] - offsets[1]); 235 | } 236 | } 237 | } 238 | Event.stop(event); 239 | } 240 | }, 241 | update: function(event) { 242 | if(this.active) { 243 | if(!this.dragging) this.dragging = true; 244 | this.draw(event); 245 | if(Prototype.Browser.WebKit) window.scrollBy(0,0); 246 | Event.stop(event); 247 | } 248 | }, 249 | draw: function(event) { 250 | var pointer = [Event.pointerX(event), Event.pointerY(event)]; 251 | var offsets = Position.cumulativeOffset(this.track); 252 | pointer[0] -= this.offsetX + offsets[0]; 253 | pointer[1] -= this.offsetY + offsets[1]; 254 | this.event = event; 255 | this.setValue(this.translateToValue( this.isVertical() ? pointer[1] : pointer[0] )); 256 | if(this.initialized && this.options.onSlide) 257 | this.options.onSlide(this.values.length>1 ? this.values : this.value, this); 258 | }, 259 | endDrag: function(event) { 260 | if(this.active && this.dragging) { 261 | this.finishDrag(event, true); 262 | Event.stop(event); 263 | } 264 | this.active = false; 265 | this.dragging = false; 266 | }, 267 | finishDrag: function(event, success) { 268 | this.active = false; 269 | this.dragging = false; 270 | this.updateFinished(); 271 | }, 272 | updateFinished: function() { 273 | if(this.initialized && this.options.onChange) 274 | this.options.onChange(this.values.length>1 ? this.values : this.value, this); 275 | this.event = null; 276 | } 277 | } -------------------------------------------------------------------------------- /pub/scripts/unittest.js: -------------------------------------------------------------------------------- 1 | // script.aculo.us unittest.js v1.7.1_beta3, Fri May 25 17:19:41 +0200 2007 2 | 3 | // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 4 | // (c) 2005-2007 Jon Tirsen (http://www.tirsen.com) 5 | // (c) 2005-2007 Michael Schuerig (http://www.schuerig.de/michael/) 6 | // 7 | // script.aculo.us is freely distributable under the terms of an MIT-style license. 8 | // For details, see the script.aculo.us web site: http://script.aculo.us/ 9 | 10 | // experimental, Firefox-only 11 | Event.simulateMouse = function(element, eventName) { 12 | var options = Object.extend({ 13 | pointerX: 0, 14 | pointerY: 0, 15 | buttons: 0, 16 | ctrlKey: false, 17 | altKey: false, 18 | shiftKey: false, 19 | metaKey: false 20 | }, arguments[2] || {}); 21 | var oEvent = document.createEvent("MouseEvents"); 22 | oEvent.initMouseEvent(eventName, true, true, document.defaultView, 23 | options.buttons, options.pointerX, options.pointerY, options.pointerX, options.pointerY, 24 | options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, 0, $(element)); 25 | 26 | if(this.mark) Element.remove(this.mark); 27 | this.mark = document.createElement('div'); 28 | this.mark.appendChild(document.createTextNode(" ")); 29 | document.body.appendChild(this.mark); 30 | this.mark.style.position = 'absolute'; 31 | this.mark.style.top = options.pointerY + "px"; 32 | this.mark.style.left = options.pointerX + "px"; 33 | this.mark.style.width = "5px"; 34 | this.mark.style.height = "5px;"; 35 | this.mark.style.borderTop = "1px solid red;" 36 | this.mark.style.borderLeft = "1px solid red;" 37 | 38 | if(this.step) 39 | alert('['+new Date().getTime().toString()+'] '+eventName+'/'+Test.Unit.inspect(options)); 40 | 41 | $(element).dispatchEvent(oEvent); 42 | }; 43 | 44 | // Note: Due to a fix in Firefox 1.0.5/6 that probably fixed "too much", this doesn't work in 1.0.6 or DP2. 45 | // You need to downgrade to 1.0.4 for now to get this working 46 | // See https://bugzilla.mozilla.org/show_bug.cgi?id=289940 for the fix that fixed too much 47 | Event.simulateKey = function(element, eventName) { 48 | var options = Object.extend({ 49 | ctrlKey: false, 50 | altKey: false, 51 | shiftKey: false, 52 | metaKey: false, 53 | keyCode: 0, 54 | charCode: 0 55 | }, arguments[2] || {}); 56 | 57 | var oEvent = document.createEvent("KeyEvents"); 58 | oEvent.initKeyEvent(eventName, true, true, window, 59 | options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, 60 | options.keyCode, options.charCode ); 61 | $(element).dispatchEvent(oEvent); 62 | }; 63 | 64 | Event.simulateKeys = function(element, command) { 65 | for(var i=0; i' + 116 | '' + 117 | '' + 118 | '' + 119 | '
StatusTestMessage
'; 120 | this.logsummary = $('logsummary') 121 | this.loglines = $('loglines'); 122 | }, 123 | _toHTML: function(txt) { 124 | return txt.escapeHTML().replace(/\n/g,"
"); 125 | }, 126 | addLinksToResults: function(){ 127 | $$("tr.failed .nameCell").each( function(td){ // todo: limit to children of this.log 128 | td.title = "Run only this test" 129 | Event.observe(td, 'click', function(){ window.location.search = "?tests=" + td.innerHTML;}); 130 | }); 131 | $$("tr.passed .nameCell").each( function(td){ // todo: limit to children of this.log 132 | td.title = "Run all tests" 133 | Event.observe(td, 'click', function(){ window.location.search = "";}); 134 | }); 135 | } 136 | } 137 | 138 | Test.Unit.Runner = Class.create(); 139 | Test.Unit.Runner.prototype = { 140 | initialize: function(testcases) { 141 | this.options = Object.extend({ 142 | testLog: 'testlog' 143 | }, arguments[1] || {}); 144 | this.options.resultsURL = this.parseResultsURLQueryParameter(); 145 | this.options.tests = this.parseTestsQueryParameter(); 146 | if (this.options.testLog) { 147 | this.options.testLog = $(this.options.testLog) || null; 148 | } 149 | if(this.options.tests) { 150 | this.tests = []; 151 | for(var i = 0; i < this.options.tests.length; i++) { 152 | if(/^test/.test(this.options.tests[i])) { 153 | this.tests.push(new Test.Unit.Testcase(this.options.tests[i], testcases[this.options.tests[i]], testcases["setup"], testcases["teardown"])); 154 | } 155 | } 156 | } else { 157 | if (this.options.test) { 158 | this.tests = [new Test.Unit.Testcase(this.options.test, testcases[this.options.test], testcases["setup"], testcases["teardown"])]; 159 | } else { 160 | this.tests = []; 161 | for(var testcase in testcases) { 162 | if(/^test/.test(testcase)) { 163 | this.tests.push( 164 | new Test.Unit.Testcase( 165 | this.options.context ? ' -> ' + this.options.titles[testcase] : testcase, 166 | testcases[testcase], testcases["setup"], testcases["teardown"] 167 | )); 168 | } 169 | } 170 | } 171 | } 172 | this.currentTest = 0; 173 | this.logger = new Test.Unit.Logger(this.options.testLog); 174 | setTimeout(this.runTests.bind(this), 1000); 175 | }, 176 | parseResultsURLQueryParameter: function() { 177 | return window.location.search.parseQuery()["resultsURL"]; 178 | }, 179 | parseTestsQueryParameter: function(){ 180 | if (window.location.search.parseQuery()["tests"]){ 181 | return window.location.search.parseQuery()["tests"].split(','); 182 | }; 183 | }, 184 | // Returns: 185 | // "ERROR" if there was an error, 186 | // "FAILURE" if there was a failure, or 187 | // "SUCCESS" if there was neither 188 | getResult: function() { 189 | var hasFailure = false; 190 | for(var i=0;i 0) { 192 | return "ERROR"; 193 | } 194 | if (this.tests[i].failures > 0) { 195 | hasFailure = true; 196 | } 197 | } 198 | if (hasFailure) { 199 | return "FAILURE"; 200 | } else { 201 | return "SUCCESS"; 202 | } 203 | }, 204 | postResults: function() { 205 | if (this.options.resultsURL) { 206 | new Ajax.Request(this.options.resultsURL, 207 | { method: 'get', parameters: 'result=' + this.getResult(), asynchronous: false }); 208 | } 209 | }, 210 | runTests: function() { 211 | var test = this.tests[this.currentTest]; 212 | if (!test) { 213 | // finished! 214 | this.postResults(); 215 | this.logger.summary(this.summary()); 216 | return; 217 | } 218 | if(!test.isWaiting) { 219 | this.logger.start(test.name); 220 | } 221 | test.run(); 222 | if(test.isWaiting) { 223 | this.logger.message("Waiting for " + test.timeToWait + "ms"); 224 | setTimeout(this.runTests.bind(this), test.timeToWait || 1000); 225 | } else { 226 | this.logger.finish(test.status(), test.summary()); 227 | this.currentTest++; 228 | // tail recursive, hopefully the browser will skip the stackframe 229 | this.runTests(); 230 | } 231 | }, 232 | summary: function() { 233 | var assertions = 0; 234 | var failures = 0; 235 | var errors = 0; 236 | var messages = []; 237 | for(var i=0;i 0) return 'failed'; 282 | if (this.errors > 0) return 'error'; 283 | return 'passed'; 284 | }, 285 | assert: function(expression) { 286 | var message = arguments[1] || 'assert: got "' + Test.Unit.inspect(expression) + '"'; 287 | try { expression ? this.pass() : 288 | this.fail(message); } 289 | catch(e) { this.error(e); } 290 | }, 291 | assertEqual: function(expected, actual) { 292 | var message = arguments[2] || "assertEqual"; 293 | try { (expected == actual) ? this.pass() : 294 | this.fail(message + ': expected "' + Test.Unit.inspect(expected) + 295 | '", actual "' + Test.Unit.inspect(actual) + '"'); } 296 | catch(e) { this.error(e); } 297 | }, 298 | assertInspect: function(expected, actual) { 299 | var message = arguments[2] || "assertInspect"; 300 | try { (expected == actual.inspect()) ? this.pass() : 301 | this.fail(message + ': expected "' + Test.Unit.inspect(expected) + 302 | '", actual "' + Test.Unit.inspect(actual) + '"'); } 303 | catch(e) { this.error(e); } 304 | }, 305 | assertEnumEqual: function(expected, actual) { 306 | var message = arguments[2] || "assertEnumEqual"; 307 | try { $A(expected).length == $A(actual).length && 308 | expected.zip(actual).all(function(pair) { return pair[0] == pair[1] }) ? 309 | this.pass() : this.fail(message + ': expected ' + Test.Unit.inspect(expected) + 310 | ', actual ' + Test.Unit.inspect(actual)); } 311 | catch(e) { this.error(e); } 312 | }, 313 | assertNotEqual: function(expected, actual) { 314 | var message = arguments[2] || "assertNotEqual"; 315 | try { (expected != actual) ? this.pass() : 316 | this.fail(message + ': got "' + Test.Unit.inspect(actual) + '"'); } 317 | catch(e) { this.error(e); } 318 | }, 319 | assertIdentical: function(expected, actual) { 320 | var message = arguments[2] || "assertIdentical"; 321 | try { (expected === actual) ? this.pass() : 322 | this.fail(message + ': expected "' + Test.Unit.inspect(expected) + 323 | '", actual "' + Test.Unit.inspect(actual) + '"'); } 324 | catch(e) { this.error(e); } 325 | }, 326 | assertNotIdentical: function(expected, actual) { 327 | var message = arguments[2] || "assertNotIdentical"; 328 | try { !(expected === actual) ? this.pass() : 329 | this.fail(message + ': expected "' + Test.Unit.inspect(expected) + 330 | '", actual "' + Test.Unit.inspect(actual) + '"'); } 331 | catch(e) { this.error(e); } 332 | }, 333 | assertNull: function(obj) { 334 | var message = arguments[1] || 'assertNull' 335 | try { (obj==null) ? this.pass() : 336 | this.fail(message + ': got "' + Test.Unit.inspect(obj) + '"'); } 337 | catch(e) { this.error(e); } 338 | }, 339 | assertMatch: function(expected, actual) { 340 | var message = arguments[2] || 'assertMatch'; 341 | var regex = new RegExp(expected); 342 | try { (regex.exec(actual)) ? this.pass() : 343 | this.fail(message + ' : regex: "' + Test.Unit.inspect(expected) + ' did not match: ' + Test.Unit.inspect(actual) + '"'); } 344 | catch(e) { this.error(e); } 345 | }, 346 | assertHidden: function(element) { 347 | var message = arguments[1] || 'assertHidden'; 348 | this.assertEqual("none", element.style.display, message); 349 | }, 350 | assertNotNull: function(object) { 351 | var message = arguments[1] || 'assertNotNull'; 352 | this.assert(object != null, message); 353 | }, 354 | assertType: function(expected, actual) { 355 | var message = arguments[2] || 'assertType'; 356 | try { 357 | (actual.constructor == expected) ? this.pass() : 358 | this.fail(message + ': expected "' + Test.Unit.inspect(expected) + 359 | '", actual "' + (actual.constructor) + '"'); } 360 | catch(e) { this.error(e); } 361 | }, 362 | assertNotOfType: function(expected, actual) { 363 | var message = arguments[2] || 'assertNotOfType'; 364 | try { 365 | (actual.constructor != expected) ? this.pass() : 366 | this.fail(message + ': expected "' + Test.Unit.inspect(expected) + 367 | '", actual "' + (actual.constructor) + '"'); } 368 | catch(e) { this.error(e); } 369 | }, 370 | assertInstanceOf: function(expected, actual) { 371 | var message = arguments[2] || 'assertInstanceOf'; 372 | try { 373 | (actual instanceof expected) ? this.pass() : 374 | this.fail(message + ": object was not an instance of the expected type"); } 375 | catch(e) { this.error(e); } 376 | }, 377 | assertNotInstanceOf: function(expected, actual) { 378 | var message = arguments[2] || 'assertNotInstanceOf'; 379 | try { 380 | !(actual instanceof expected) ? this.pass() : 381 | this.fail(message + ": object was an instance of the not expected type"); } 382 | catch(e) { this.error(e); } 383 | }, 384 | assertRespondsTo: function(method, obj) { 385 | var message = arguments[2] || 'assertRespondsTo'; 386 | try { 387 | (obj[method] && typeof obj[method] == 'function') ? this.pass() : 388 | this.fail(message + ": object doesn't respond to [" + method + "]"); } 389 | catch(e) { this.error(e); } 390 | }, 391 | assertReturnsTrue: function(method, obj) { 392 | var message = arguments[2] || 'assertReturnsTrue'; 393 | try { 394 | var m = obj[method]; 395 | if(!m) m = obj['is'+method.charAt(0).toUpperCase()+method.slice(1)]; 396 | m() ? this.pass() : 397 | this.fail(message + ": method returned false"); } 398 | catch(e) { this.error(e); } 399 | }, 400 | assertReturnsFalse: function(method, obj) { 401 | var message = arguments[2] || 'assertReturnsFalse'; 402 | try { 403 | var m = obj[method]; 404 | if(!m) m = obj['is'+method.charAt(0).toUpperCase()+method.slice(1)]; 405 | !m() ? this.pass() : 406 | this.fail(message + ": method returned true"); } 407 | catch(e) { this.error(e); } 408 | }, 409 | assertRaise: function(exceptionName, method) { 410 | var message = arguments[2] || 'assertRaise'; 411 | try { 412 | method(); 413 | this.fail(message + ": exception expected but none was raised"); } 414 | catch(e) { 415 | ((exceptionName == null) || (e.name==exceptionName)) ? this.pass() : this.error(e); 416 | } 417 | }, 418 | assertElementsMatch: function() { 419 | var expressions = $A(arguments), elements = $A(expressions.shift()); 420 | if (elements.length != expressions.length) { 421 | this.fail('assertElementsMatch: size mismatch: ' + elements.length + ' elements, ' + expressions.length + ' expressions'); 422 | return false; 423 | } 424 | elements.zip(expressions).all(function(pair, index) { 425 | var element = $(pair.first()), expression = pair.last(); 426 | if (element.match(expression)) return true; 427 | this.fail('assertElementsMatch: (in index ' + index + ') expected ' + expression.inspect() + ' but got ' + element.inspect()); 428 | }.bind(this)) && this.pass(); 429 | }, 430 | assertElementMatches: function(element, expression) { 431 | this.assertElementsMatch([element], expression); 432 | }, 433 | benchmark: function(operation, iterations) { 434 | var startAt = new Date(); 435 | (iterations || 1).times(operation); 436 | var timeTaken = ((new Date())-startAt); 437 | this.info((arguments[2] || 'Operation') + ' finished ' + 438 | iterations + ' iterations in ' + (timeTaken/1000)+'s' ); 439 | return timeTaken; 440 | }, 441 | _isVisible: function(element) { 442 | element = $(element); 443 | if(!element.parentNode) return true; 444 | this.assertNotNull(element); 445 | if(element.style && Element.getStyle(element, 'display') == 'none') 446 | return false; 447 | 448 | return this._isVisible(element.parentNode); 449 | }, 450 | assertNotVisible: function(element) { 451 | this.assert(!this._isVisible(element), Test.Unit.inspect(element) + " was not hidden and didn't have a hidden parent either. " + ("" || arguments[1])); 452 | }, 453 | assertVisible: function(element) { 454 | this.assert(this._isVisible(element), Test.Unit.inspect(element) + " was not visible. " + ("" || arguments[1])); 455 | }, 456 | benchmark: function(operation, iterations) { 457 | var startAt = new Date(); 458 | (iterations || 1).times(operation); 459 | var timeTaken = ((new Date())-startAt); 460 | this.info((arguments[2] || 'Operation') + ' finished ' + 461 | iterations + ' iterations in ' + (timeTaken/1000)+'s' ); 462 | return timeTaken; 463 | } 464 | } 465 | 466 | Test.Unit.Testcase = Class.create(); 467 | Object.extend(Object.extend(Test.Unit.Testcase.prototype, Test.Unit.Assertions.prototype), { 468 | initialize: function(name, test, setup, teardown) { 469 | Test.Unit.Assertions.prototype.initialize.bind(this)(); 470 | this.name = name; 471 | 472 | if(typeof test == 'string') { 473 | test = test.gsub(/(\.should[^\(]+\()/,'#{0}this,'); 474 | test = test.gsub(/(\.should[^\(]+)\(this,\)/,'#{1}(this)'); 475 | this.test = function() { 476 | eval('with(this){'+test+'}'); 477 | } 478 | } else { 479 | this.test = test || function() {}; 480 | } 481 | 482 | this.setup = setup || function() {}; 483 | this.teardown = teardown || function() {}; 484 | this.isWaiting = false; 485 | this.timeToWait = 1000; 486 | }, 487 | wait: function(time, nextPart) { 488 | this.isWaiting = true; 489 | this.test = nextPart; 490 | this.timeToWait = time; 491 | }, 492 | run: function() { 493 | try { 494 | try { 495 | if (!this.isWaiting) this.setup.bind(this)(); 496 | this.isWaiting = false; 497 | this.test.bind(this)(); 498 | } finally { 499 | if(!this.isWaiting) { 500 | this.teardown.bind(this)(); 501 | } 502 | } 503 | } 504 | catch(e) { this.error(e); } 505 | } 506 | }); 507 | 508 | // *EXPERIMENTAL* BDD-style testing to please non-technical folk 509 | // This draws many ideas from RSpec http://rspec.rubyforge.org/ 510 | 511 | Test.setupBDDExtensionMethods = function(){ 512 | var METHODMAP = { 513 | shouldEqual: 'assertEqual', 514 | shouldNotEqual: 'assertNotEqual', 515 | shouldEqualEnum: 'assertEnumEqual', 516 | shouldBeA: 'assertType', 517 | shouldNotBeA: 'assertNotOfType', 518 | shouldBeAn: 'assertType', 519 | shouldNotBeAn: 'assertNotOfType', 520 | shouldBeNull: 'assertNull', 521 | shouldNotBeNull: 'assertNotNull', 522 | 523 | shouldBe: 'assertReturnsTrue', 524 | shouldNotBe: 'assertReturnsFalse', 525 | shouldRespondTo: 'assertRespondsTo' 526 | }; 527 | Test.BDDMethods = {}; 528 | for(m in METHODMAP) { 529 | Test.BDDMethods[m] = eval( 530 | 'function(){'+ 531 | 'var args = $A(arguments);'+ 532 | 'var scope = args.shift();'+ 533 | 'scope.'+METHODMAP[m]+'.apply(scope,(args || []).concat([this])); }'); 534 | } 535 | [Array.prototype, String.prototype, Number.prototype].each( 536 | function(p){ Object.extend(p, Test.BDDMethods) } 537 | ); 538 | } 539 | 540 | Test.context = function(name, spec, log){ 541 | Test.setupBDDExtensionMethods(); 542 | 543 | var compiledSpec = {}; 544 | var titles = {}; 545 | for(specName in spec) { 546 | switch(specName){ 547 | case "setup": 548 | case "teardown": 549 | compiledSpec[specName] = spec[specName]; 550 | break; 551 | default: 552 | var testName = 'test'+specName.gsub(/\s+/,'-').camelize(); 553 | var body = spec[specName].toString().split('\n').slice(1); 554 | if(/^\{/.test(body[0])) body = body.slice(1); 555 | body.pop(); 556 | body = body.map(function(statement){ 557 | return statement.strip() 558 | }); 559 | compiledSpec[testName] = body.join('\n'); 560 | titles[testName] = specName; 561 | } 562 | } 563 | new Test.Unit.Runner(compiledSpec, { titles: titles, testLog: log || 'testlog', context: name }); 564 | }; -------------------------------------------------------------------------------- /pub/scripts/controls.js: -------------------------------------------------------------------------------- 1 | // script.aculo.us controls.js v1.7.1_beta3, Fri May 25 17:19:41 +0200 2007 2 | 3 | // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 4 | // (c) 2005-2007 Ivan Krstic (http://blogs.law.harvard.edu/ivan) 5 | // (c) 2005-2007 Jon Tirsen (http://www.tirsen.com) 6 | // Contributors: 7 | // Richard Livsey 8 | // Rahul Bhargava 9 | // Rob Wills 10 | // 11 | // script.aculo.us is freely distributable under the terms of an MIT-style license. 12 | // For details, see the script.aculo.us web site: http://script.aculo.us/ 13 | 14 | // Autocompleter.Base handles all the autocompletion functionality 15 | // that's independent of the data source for autocompletion. This 16 | // includes drawing the autocompletion menu, observing keyboard 17 | // and mouse events, and similar. 18 | // 19 | // Specific autocompleters need to provide, at the very least, 20 | // a getUpdatedChoices function that will be invoked every time 21 | // the text inside the monitored textbox changes. This method 22 | // should get the text for which to provide autocompletion by 23 | // invoking this.getToken(), NOT by directly accessing 24 | // this.element.value. This is to allow incremental tokenized 25 | // autocompletion. Specific auto-completion logic (AJAX, etc) 26 | // belongs in getUpdatedChoices. 27 | // 28 | // Tokenized incremental autocompletion is enabled automatically 29 | // when an autocompleter is instantiated with the 'tokens' option 30 | // in the options parameter, e.g.: 31 | // new Ajax.Autocompleter('id','upd', '/url/', { tokens: ',' }); 32 | // will incrementally autocomplete with a comma as the token. 33 | // Additionally, ',' in the above example can be replaced with 34 | // a token array, e.g. { tokens: [',', '\n'] } which 35 | // enables autocompletion on multiple tokens. This is most 36 | // useful when one of the tokens is \n (a newline), as it 37 | // allows smart autocompletion after linebreaks. 38 | 39 | if(typeof Effect == 'undefined') 40 | throw("controls.js requires including script.aculo.us' effects.js library"); 41 | 42 | var Autocompleter = {} 43 | Autocompleter.Base = function() {}; 44 | Autocompleter.Base.prototype = { 45 | baseInitialize: function(element, update, options) { 46 | element = $(element) 47 | this.element = element; 48 | this.update = $(update); 49 | this.hasFocus = false; 50 | this.changed = false; 51 | this.active = false; 52 | this.index = 0; 53 | this.entryCount = 0; 54 | 55 | if(this.setOptions) 56 | this.setOptions(options); 57 | else 58 | this.options = options || {}; 59 | 60 | this.options.paramName = this.options.paramName || this.element.name; 61 | this.options.tokens = this.options.tokens || []; 62 | this.options.frequency = this.options.frequency || 0.4; 63 | this.options.minChars = this.options.minChars || 1; 64 | this.options.onShow = this.options.onShow || 65 | function(element, update){ 66 | if(!update.style.position || update.style.position=='absolute') { 67 | update.style.position = 'absolute'; 68 | Position.clone(element, update, { 69 | setHeight: false, 70 | offsetTop: element.offsetHeight 71 | }); 72 | } 73 | Effect.Appear(update,{duration:0.15}); 74 | }; 75 | this.options.onHide = this.options.onHide || 76 | function(element, update){ new Effect.Fade(update,{duration:0.15}) }; 77 | 78 | if(typeof(this.options.tokens) == 'string') 79 | this.options.tokens = new Array(this.options.tokens); 80 | 81 | this.observer = null; 82 | 83 | this.element.setAttribute('autocomplete','off'); 84 | 85 | Element.hide(this.update); 86 | 87 | Event.observe(this.element, 'blur', this.onBlur.bindAsEventListener(this)); 88 | Event.observe(this.element, 'keypress', this.onKeyPress.bindAsEventListener(this)); 89 | 90 | // Turn autocomplete back on when the user leaves the page, so that the 91 | // field's value will be remembered on Mozilla-based browsers. 92 | Event.observe(window, 'beforeunload', function(){ 93 | element.setAttribute('autocomplete', 'on'); 94 | }); 95 | }, 96 | 97 | show: function() { 98 | if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update); 99 | if(!this.iefix && 100 | (Prototype.Browser.IE) && 101 | (Element.getStyle(this.update, 'position')=='absolute')) { 102 | new Insertion.After(this.update, 103 | ''); 106 | this.iefix = $(this.update.id+'_iefix'); 107 | } 108 | if(this.iefix) setTimeout(this.fixIEOverlapping.bind(this), 50); 109 | }, 110 | 111 | fixIEOverlapping: function() { 112 | Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)}); 113 | this.iefix.style.zIndex = 1; 114 | this.update.style.zIndex = 2; 115 | Element.show(this.iefix); 116 | }, 117 | 118 | hide: function() { 119 | this.stopIndicator(); 120 | if(Element.getStyle(this.update, 'display')!='none') this.options.onHide(this.element, this.update); 121 | if(this.iefix) Element.hide(this.iefix); 122 | }, 123 | 124 | startIndicator: function() { 125 | if(this.options.indicator) Element.show(this.options.indicator); 126 | }, 127 | 128 | stopIndicator: function() { 129 | if(this.options.indicator) Element.hide(this.options.indicator); 130 | }, 131 | 132 | onKeyPress: function(event) { 133 | if(this.active) 134 | switch(event.keyCode) { 135 | case Event.KEY_TAB: 136 | case Event.KEY_RETURN: 137 | this.selectEntry(); 138 | Event.stop(event); 139 | case Event.KEY_ESC: 140 | this.hide(); 141 | this.active = false; 142 | Event.stop(event); 143 | return; 144 | case Event.KEY_LEFT: 145 | case Event.KEY_RIGHT: 146 | return; 147 | case Event.KEY_UP: 148 | this.markPrevious(); 149 | this.render(); 150 | if(Prototype.Browser.WebKit) Event.stop(event); 151 | return; 152 | case Event.KEY_DOWN: 153 | this.markNext(); 154 | this.render(); 155 | if(Prototype.Browser.WebKit) Event.stop(event); 156 | return; 157 | } 158 | else 159 | if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN || 160 | (Prototype.Browser.WebKit > 0 && event.keyCode == 0)) return; 161 | 162 | this.changed = true; 163 | this.hasFocus = true; 164 | 165 | if(this.observer) clearTimeout(this.observer); 166 | this.observer = 167 | setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000); 168 | }, 169 | 170 | activate: function() { 171 | this.changed = false; 172 | this.hasFocus = true; 173 | this.getUpdatedChoices(); 174 | }, 175 | 176 | onHover: function(event) { 177 | var element = Event.findElement(event, 'LI'); 178 | if(this.index != element.autocompleteIndex) 179 | { 180 | this.index = element.autocompleteIndex; 181 | this.render(); 182 | } 183 | Event.stop(event); 184 | }, 185 | 186 | onClick: function(event) { 187 | var element = Event.findElement(event, 'LI'); 188 | this.index = element.autocompleteIndex; 189 | this.selectEntry(); 190 | this.hide(); 191 | }, 192 | 193 | onBlur: function(event) { 194 | // needed to make click events working 195 | setTimeout(this.hide.bind(this), 250); 196 | this.hasFocus = false; 197 | this.active = false; 198 | }, 199 | 200 | render: function() { 201 | if(this.entryCount > 0) { 202 | for (var i = 0; i < this.entryCount; i++) 203 | this.index==i ? 204 | Element.addClassName(this.getEntry(i),"selected") : 205 | Element.removeClassName(this.getEntry(i),"selected"); 206 | if(this.hasFocus) { 207 | this.show(); 208 | this.active = true; 209 | } 210 | } else { 211 | this.active = false; 212 | this.hide(); 213 | } 214 | }, 215 | 216 | markPrevious: function() { 217 | if(this.index > 0) this.index-- 218 | else this.index = this.entryCount-1; 219 | this.getEntry(this.index).scrollIntoView(true); 220 | }, 221 | 222 | markNext: function() { 223 | if(this.index < this.entryCount-1) this.index++ 224 | else this.index = 0; 225 | this.getEntry(this.index).scrollIntoView(false); 226 | }, 227 | 228 | getEntry: function(index) { 229 | return this.update.firstChild.childNodes[index]; 230 | }, 231 | 232 | getCurrentEntry: function() { 233 | return this.getEntry(this.index); 234 | }, 235 | 236 | selectEntry: function() { 237 | this.active = false; 238 | this.updateElement(this.getCurrentEntry()); 239 | }, 240 | 241 | updateElement: function(selectedElement) { 242 | if (this.options.updateElement) { 243 | this.options.updateElement(selectedElement); 244 | return; 245 | } 246 | var value = ''; 247 | if (this.options.select) { 248 | var nodes = document.getElementsByClassName(this.options.select, selectedElement) || []; 249 | if(nodes.length>0) value = Element.collectTextNodes(nodes[0], this.options.select); 250 | } else 251 | value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal'); 252 | 253 | var lastTokenPos = this.findLastToken(); 254 | if (lastTokenPos != -1) { 255 | var newValue = this.element.value.substr(0, lastTokenPos + 1); 256 | var whitespace = this.element.value.substr(lastTokenPos + 1).match(/^\s+/); 257 | if (whitespace) 258 | newValue += whitespace[0]; 259 | this.element.value = newValue + value; 260 | } else { 261 | this.element.value = value; 262 | } 263 | this.element.focus(); 264 | 265 | if (this.options.afterUpdateElement) 266 | this.options.afterUpdateElement(this.element, selectedElement); 267 | }, 268 | 269 | updateChoices: function(choices) { 270 | if(!this.changed && this.hasFocus) { 271 | this.update.innerHTML = choices; 272 | Element.cleanWhitespace(this.update); 273 | Element.cleanWhitespace(this.update.down()); 274 | 275 | if(this.update.firstChild && this.update.down().childNodes) { 276 | this.entryCount = 277 | this.update.down().childNodes.length; 278 | for (var i = 0; i < this.entryCount; i++) { 279 | var entry = this.getEntry(i); 280 | entry.autocompleteIndex = i; 281 | this.addObservers(entry); 282 | } 283 | } else { 284 | this.entryCount = 0; 285 | } 286 | 287 | this.stopIndicator(); 288 | this.index = 0; 289 | 290 | if(this.entryCount==1 && this.options.autoSelect) { 291 | this.selectEntry(); 292 | this.hide(); 293 | } else { 294 | this.render(); 295 | } 296 | } 297 | }, 298 | 299 | addObservers: function(element) { 300 | Event.observe(element, "mouseover", this.onHover.bindAsEventListener(this)); 301 | Event.observe(element, "click", this.onClick.bindAsEventListener(this)); 302 | }, 303 | 304 | onObserverEvent: function() { 305 | this.changed = false; 306 | if(this.getToken().length>=this.options.minChars) { 307 | this.getUpdatedChoices(); 308 | } else { 309 | this.active = false; 310 | this.hide(); 311 | } 312 | }, 313 | 314 | getToken: function() { 315 | var tokenPos = this.findLastToken(); 316 | if (tokenPos != -1) 317 | var ret = this.element.value.substr(tokenPos + 1).replace(/^\s+/,'').replace(/\s+$/,''); 318 | else 319 | var ret = this.element.value; 320 | 321 | return /\n/.test(ret) ? '' : ret; 322 | }, 323 | 324 | findLastToken: function() { 325 | var lastTokenPos = -1; 326 | 327 | for (var i=0; i lastTokenPos) 330 | lastTokenPos = thisTokenPos; 331 | } 332 | return lastTokenPos; 333 | } 334 | } 335 | 336 | Ajax.Autocompleter = Class.create(); 337 | Object.extend(Object.extend(Ajax.Autocompleter.prototype, Autocompleter.Base.prototype), { 338 | initialize: function(element, update, url, options) { 339 | this.baseInitialize(element, update, options); 340 | this.options.asynchronous = true; 341 | this.options.onComplete = this.onComplete.bind(this); 342 | this.options.defaultParams = this.options.parameters || null; 343 | this.url = url; 344 | }, 345 | 346 | getUpdatedChoices: function() { 347 | this.startIndicator(); 348 | 349 | var entry = encodeURIComponent(this.options.paramName) + '=' + 350 | encodeURIComponent(this.getToken()); 351 | 352 | this.options.parameters = this.options.callback ? 353 | this.options.callback(this.element, entry) : entry; 354 | 355 | if(this.options.defaultParams) 356 | this.options.parameters += '&' + this.options.defaultParams; 357 | 358 | new Ajax.Request(this.url, this.options); 359 | }, 360 | 361 | onComplete: function(request) { 362 | this.updateChoices(request.responseText); 363 | } 364 | 365 | }); 366 | 367 | // The local array autocompleter. Used when you'd prefer to 368 | // inject an array of autocompletion options into the page, rather 369 | // than sending out Ajax queries, which can be quite slow sometimes. 370 | // 371 | // The constructor takes four parameters. The first two are, as usual, 372 | // the id of the monitored textbox, and id of the autocompletion menu. 373 | // The third is the array you want to autocomplete from, and the fourth 374 | // is the options block. 375 | // 376 | // Extra local autocompletion options: 377 | // - choices - How many autocompletion choices to offer 378 | // 379 | // - partialSearch - If false, the autocompleter will match entered 380 | // text only at the beginning of strings in the 381 | // autocomplete array. Defaults to true, which will 382 | // match text at the beginning of any *word* in the 383 | // strings in the autocomplete array. If you want to 384 | // search anywhere in the string, additionally set 385 | // the option fullSearch to true (default: off). 386 | // 387 | // - fullSsearch - Search anywhere in autocomplete array strings. 388 | // 389 | // - partialChars - How many characters to enter before triggering 390 | // a partial match (unlike minChars, which defines 391 | // how many characters are required to do any match 392 | // at all). Defaults to 2. 393 | // 394 | // - ignoreCase - Whether to ignore case when autocompleting. 395 | // Defaults to true. 396 | // 397 | // It's possible to pass in a custom function as the 'selector' 398 | // option, if you prefer to write your own autocompletion logic. 399 | // In that case, the other options above will not apply unless 400 | // you support them. 401 | 402 | Autocompleter.Local = Class.create(); 403 | Autocompleter.Local.prototype = Object.extend(new Autocompleter.Base(), { 404 | initialize: function(element, update, array, options) { 405 | this.baseInitialize(element, update, options); 406 | this.options.array = array; 407 | }, 408 | 409 | getUpdatedChoices: function() { 410 | this.updateChoices(this.options.selector(this)); 411 | }, 412 | 413 | setOptions: function(options) { 414 | this.options = Object.extend({ 415 | choices: 10, 416 | partialSearch: true, 417 | partialChars: 2, 418 | ignoreCase: true, 419 | fullSearch: false, 420 | selector: function(instance) { 421 | var ret = []; // Beginning matches 422 | var partial = []; // Inside matches 423 | var entry = instance.getToken(); 424 | var count = 0; 425 | 426 | for (var i = 0; i < instance.options.array.length && 427 | ret.length < instance.options.choices ; i++) { 428 | 429 | var elem = instance.options.array[i]; 430 | var foundPos = instance.options.ignoreCase ? 431 | elem.toLowerCase().indexOf(entry.toLowerCase()) : 432 | elem.indexOf(entry); 433 | 434 | while (foundPos != -1) { 435 | if (foundPos == 0 && elem.length != entry.length) { 436 | ret.push("
  • " + elem.substr(0, entry.length) + "" + 437 | elem.substr(entry.length) + "
  • "); 438 | break; 439 | } else if (entry.length >= instance.options.partialChars && 440 | instance.options.partialSearch && foundPos != -1) { 441 | if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) { 442 | partial.push("
  • " + elem.substr(0, foundPos) + "" + 443 | elem.substr(foundPos, entry.length) + "" + elem.substr( 444 | foundPos + entry.length) + "
  • "); 445 | break; 446 | } 447 | } 448 | 449 | foundPos = instance.options.ignoreCase ? 450 | elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) : 451 | elem.indexOf(entry, foundPos + 1); 452 | 453 | } 454 | } 455 | if (partial.length) 456 | ret = ret.concat(partial.slice(0, instance.options.choices - ret.length)) 457 | return "
      " + ret.join('') + "
    "; 458 | } 459 | }, options || {}); 460 | } 461 | }); 462 | 463 | // AJAX in-place editor 464 | // 465 | // see documentation on http://wiki.script.aculo.us/scriptaculous/show/Ajax.InPlaceEditor 466 | 467 | // Use this if you notice weird scrolling problems on some browsers, 468 | // the DOM might be a bit confused when this gets called so do this 469 | // waits 1 ms (with setTimeout) until it does the activation 470 | Field.scrollFreeActivate = function(field) { 471 | setTimeout(function() { 472 | Field.activate(field); 473 | }, 1); 474 | } 475 | 476 | Ajax.InPlaceEditor = Class.create(); 477 | Ajax.InPlaceEditor.defaultHighlightColor = "#FFFF99"; 478 | Ajax.InPlaceEditor.prototype = { 479 | initialize: function(element, url, options) { 480 | this.url = url; 481 | this.element = $(element); 482 | 483 | this.options = Object.extend({ 484 | paramName: "value", 485 | okButton: true, 486 | okLink: false, 487 | okText: "ok", 488 | cancelButton: false, 489 | cancelLink: true, 490 | cancelText: "cancel", 491 | textBeforeControls: '', 492 | textBetweenControls: '', 493 | textAfterControls: '', 494 | savingText: "Saving...", 495 | clickToEditText: "Click to edit", 496 | okText: "ok", 497 | rows: 1, 498 | onComplete: function(transport, element) { 499 | new Effect.Highlight(element, {startcolor: this.options.highlightcolor}); 500 | }, 501 | onFailure: function(transport) { 502 | alert("Error communicating with the server: " + transport.responseText.stripTags()); 503 | }, 504 | callback: function(form) { 505 | return Form.serialize(form); 506 | }, 507 | handleLineBreaks: true, 508 | loadingText: 'Loading...', 509 | savingClassName: 'inplaceeditor-saving', 510 | loadingClassName: 'inplaceeditor-loading', 511 | formClassName: 'inplaceeditor-form', 512 | highlightcolor: Ajax.InPlaceEditor.defaultHighlightColor, 513 | highlightendcolor: "#FFFFFF", 514 | externalControl: null, 515 | submitOnBlur: false, 516 | ajaxOptions: {}, 517 | evalScripts: false 518 | }, options || {}); 519 | 520 | if(!this.options.formId && this.element.id) { 521 | this.options.formId = this.element.id + "-inplaceeditor"; 522 | if ($(this.options.formId)) { 523 | // there's already a form with that name, don't specify an id 524 | this.options.formId = null; 525 | } 526 | } 527 | 528 | if (this.options.externalControl) { 529 | this.options.externalControl = $(this.options.externalControl); 530 | } 531 | 532 | this.originalBackground = Element.getStyle(this.element, 'background-color'); 533 | if (!this.originalBackground) { 534 | this.originalBackground = "transparent"; 535 | } 536 | 537 | this.element.title = this.options.clickToEditText; 538 | 539 | this.onclickListener = this.enterEditMode.bindAsEventListener(this); 540 | this.mouseoverListener = this.enterHover.bindAsEventListener(this); 541 | this.mouseoutListener = this.leaveHover.bindAsEventListener(this); 542 | Event.observe(this.element, 'click', this.onclickListener); 543 | Event.observe(this.element, 'mouseover', this.mouseoverListener); 544 | Event.observe(this.element, 'mouseout', this.mouseoutListener); 545 | if (this.options.externalControl) { 546 | Event.observe(this.options.externalControl, 'click', this.onclickListener); 547 | Event.observe(this.options.externalControl, 'mouseover', this.mouseoverListener); 548 | Event.observe(this.options.externalControl, 'mouseout', this.mouseoutListener); 549 | } 550 | }, 551 | enterEditMode: function(evt) { 552 | if (this.saving) return; 553 | if (this.editing) return; 554 | this.editing = true; 555 | this.onEnterEditMode(); 556 | if (this.options.externalControl) { 557 | Element.hide(this.options.externalControl); 558 | } 559 | Element.hide(this.element); 560 | this.createForm(); 561 | this.element.parentNode.insertBefore(this.form, this.element); 562 | if (!this.options.loadTextURL) Field.scrollFreeActivate(this.editField); 563 | // stop the event to avoid a page refresh in Safari 564 | if (evt) { 565 | Event.stop(evt); 566 | } 567 | return false; 568 | }, 569 | createForm: function() { 570 | this.form = document.createElement("form"); 571 | this.form.id = this.options.formId; 572 | Element.addClassName(this.form, this.options.formClassName) 573 | this.form.onsubmit = this.onSubmit.bind(this); 574 | 575 | this.createEditField(); 576 | 577 | if (this.options.textarea) { 578 | var br = document.createElement("br"); 579 | this.form.appendChild(br); 580 | } 581 | 582 | if (this.options.textBeforeControls) 583 | this.form.appendChild(document.createTextNode(this.options.textBeforeControls)); 584 | 585 | if (this.options.okButton) { 586 | var okButton = document.createElement("input"); 587 | okButton.type = "submit"; 588 | okButton.value = this.options.okText; 589 | okButton.className = 'editor_ok_button'; 590 | this.form.appendChild(okButton); 591 | } 592 | 593 | if (this.options.okLink) { 594 | var okLink = document.createElement("a"); 595 | okLink.href = "#"; 596 | okLink.appendChild(document.createTextNode(this.options.okText)); 597 | okLink.onclick = this.onSubmit.bind(this); 598 | okLink.className = 'editor_ok_link'; 599 | this.form.appendChild(okLink); 600 | } 601 | 602 | if (this.options.textBetweenControls && 603 | (this.options.okLink || this.options.okButton) && 604 | (this.options.cancelLink || this.options.cancelButton)) 605 | this.form.appendChild(document.createTextNode(this.options.textBetweenControls)); 606 | 607 | if (this.options.cancelButton) { 608 | var cancelButton = document.createElement("input"); 609 | cancelButton.type = "submit"; 610 | cancelButton.value = this.options.cancelText; 611 | cancelButton.onclick = this.onclickCancel.bind(this); 612 | cancelButton.className = 'editor_cancel_button'; 613 | this.form.appendChild(cancelButton); 614 | } 615 | 616 | if (this.options.cancelLink) { 617 | var cancelLink = document.createElement("a"); 618 | cancelLink.href = "#"; 619 | cancelLink.appendChild(document.createTextNode(this.options.cancelText)); 620 | cancelLink.onclick = this.onclickCancel.bind(this); 621 | cancelLink.className = 'editor_cancel editor_cancel_link'; 622 | this.form.appendChild(cancelLink); 623 | } 624 | 625 | if (this.options.textAfterControls) 626 | this.form.appendChild(document.createTextNode(this.options.textAfterControls)); 627 | }, 628 | hasHTMLLineBreaks: function(string) { 629 | if (!this.options.handleLineBreaks) return false; 630 | return string.match(/
    /i); 631 | }, 632 | convertHTMLLineBreaks: function(string) { 633 | return string.replace(/
    /gi, "\n").replace(//gi, "\n").replace(/<\/p>/gi, "\n").replace(/

    /gi, ""); 634 | }, 635 | createEditField: function() { 636 | var text; 637 | if(this.options.loadTextURL) { 638 | text = this.options.loadingText; 639 | } else { 640 | text = this.getText(); 641 | } 642 | 643 | var obj = this; 644 | 645 | if (this.options.rows == 1 && !this.hasHTMLLineBreaks(text)) { 646 | this.options.textarea = false; 647 | var textField = document.createElement("input"); 648 | textField.obj = this; 649 | textField.type = "text"; 650 | textField.name = this.options.paramName; 651 | textField.value = text; 652 | textField.style.backgroundColor = this.options.highlightcolor; 653 | textField.className = 'editor_field'; 654 | var size = this.options.size || this.options.cols || 0; 655 | if (size != 0) textField.size = size; 656 | if (this.options.submitOnBlur) 657 | textField.onblur = this.onSubmit.bind(this); 658 | this.editField = textField; 659 | } else { 660 | this.options.textarea = true; 661 | var textArea = document.createElement("textarea"); 662 | textArea.obj = this; 663 | textArea.name = this.options.paramName; 664 | textArea.value = this.convertHTMLLineBreaks(text); 665 | textArea.rows = this.options.rows; 666 | textArea.cols = this.options.cols || 40; 667 | textArea.className = 'editor_field'; 668 | if (this.options.submitOnBlur) 669 | textArea.onblur = this.onSubmit.bind(this); 670 | this.editField = textArea; 671 | } 672 | 673 | if(this.options.loadTextURL) { 674 | this.loadExternalText(); 675 | } 676 | this.form.appendChild(this.editField); 677 | }, 678 | getText: function() { 679 | return this.element.innerHTML; 680 | }, 681 | loadExternalText: function() { 682 | Element.addClassName(this.form, this.options.loadingClassName); 683 | this.editField.disabled = true; 684 | new Ajax.Request( 685 | this.options.loadTextURL, 686 | Object.extend({ 687 | asynchronous: true, 688 | onComplete: this.onLoadedExternalText.bind(this) 689 | }, this.options.ajaxOptions) 690 | ); 691 | }, 692 | onLoadedExternalText: function(transport) { 693 | Element.removeClassName(this.form, this.options.loadingClassName); 694 | this.editField.disabled = false; 695 | this.editField.value = transport.responseText.stripTags(); 696 | Field.scrollFreeActivate(this.editField); 697 | }, 698 | onclickCancel: function() { 699 | this.onComplete(); 700 | this.leaveEditMode(); 701 | return false; 702 | }, 703 | onFailure: function(transport) { 704 | this.options.onFailure(transport); 705 | if (this.oldInnerHTML) { 706 | this.element.innerHTML = this.oldInnerHTML; 707 | this.oldInnerHTML = null; 708 | } 709 | return false; 710 | }, 711 | onSubmit: function() { 712 | // onLoading resets these so we need to save them away for the Ajax call 713 | var form = this.form; 714 | var value = this.editField.value; 715 | 716 | // do this first, sometimes the ajax call returns before we get a chance to switch on Saving... 717 | // which means this will actually switch on Saving... *after* we've left edit mode causing Saving... 718 | // to be displayed indefinitely 719 | this.onLoading(); 720 | 721 | if (this.options.evalScripts) { 722 | new Ajax.Request( 723 | this.url, Object.extend({ 724 | parameters: this.options.callback(form, value), 725 | onComplete: this.onComplete.bind(this), 726 | onFailure: this.onFailure.bind(this), 727 | asynchronous:true, 728 | evalScripts:true 729 | }, this.options.ajaxOptions)); 730 | } else { 731 | new Ajax.Updater( 732 | { success: this.element, 733 | // don't update on failure (this could be an option) 734 | failure: null }, 735 | this.url, Object.extend({ 736 | parameters: this.options.callback(form, value), 737 | onComplete: this.onComplete.bind(this), 738 | onFailure: this.onFailure.bind(this) 739 | }, this.options.ajaxOptions)); 740 | } 741 | // stop the event to avoid a page refresh in Safari 742 | if (arguments.length > 1) { 743 | Event.stop(arguments[0]); 744 | } 745 | return false; 746 | }, 747 | onLoading: function() { 748 | this.saving = true; 749 | this.removeForm(); 750 | this.leaveHover(); 751 | this.showSaving(); 752 | }, 753 | showSaving: function() { 754 | this.oldInnerHTML = this.element.innerHTML; 755 | this.element.innerHTML = this.options.savingText; 756 | Element.addClassName(this.element, this.options.savingClassName); 757 | this.element.style.backgroundColor = this.originalBackground; 758 | Element.show(this.element); 759 | }, 760 | removeForm: function() { 761 | if(this.form) { 762 | if (this.form.parentNode) Element.remove(this.form); 763 | this.form = null; 764 | } 765 | }, 766 | enterHover: function() { 767 | if (this.saving) return; 768 | this.element.style.backgroundColor = this.options.highlightcolor; 769 | if (this.effect) { 770 | this.effect.cancel(); 771 | } 772 | Element.addClassName(this.element, this.options.hoverClassName) 773 | }, 774 | leaveHover: function() { 775 | if (this.options.backgroundColor) { 776 | this.element.style.backgroundColor = this.oldBackground; 777 | } 778 | Element.removeClassName(this.element, this.options.hoverClassName) 779 | if (this.saving) return; 780 | this.effect = new Effect.Highlight(this.element, { 781 | startcolor: this.options.highlightcolor, 782 | endcolor: this.options.highlightendcolor, 783 | restorecolor: this.originalBackground 784 | }); 785 | }, 786 | leaveEditMode: function() { 787 | Element.removeClassName(this.element, this.options.savingClassName); 788 | this.removeForm(); 789 | this.leaveHover(); 790 | this.element.style.backgroundColor = this.originalBackground; 791 | Element.show(this.element); 792 | if (this.options.externalControl) { 793 | Element.show(this.options.externalControl); 794 | } 795 | this.editing = false; 796 | this.saving = false; 797 | this.oldInnerHTML = null; 798 | this.onLeaveEditMode(); 799 | }, 800 | onComplete: function(transport) { 801 | this.leaveEditMode(); 802 | this.options.onComplete.bind(this)(transport, this.element); 803 | }, 804 | onEnterEditMode: function() {}, 805 | onLeaveEditMode: function() {}, 806 | dispose: function() { 807 | if (this.oldInnerHTML) { 808 | this.element.innerHTML = this.oldInnerHTML; 809 | } 810 | this.leaveEditMode(); 811 | Event.stopObserving(this.element, 'click', this.onclickListener); 812 | Event.stopObserving(this.element, 'mouseover', this.mouseoverListener); 813 | Event.stopObserving(this.element, 'mouseout', this.mouseoutListener); 814 | if (this.options.externalControl) { 815 | Event.stopObserving(this.options.externalControl, 'click', this.onclickListener); 816 | Event.stopObserving(this.options.externalControl, 'mouseover', this.mouseoverListener); 817 | Event.stopObserving(this.options.externalControl, 'mouseout', this.mouseoutListener); 818 | } 819 | } 820 | }; 821 | 822 | Ajax.InPlaceCollectionEditor = Class.create(); 823 | Object.extend(Ajax.InPlaceCollectionEditor.prototype, Ajax.InPlaceEditor.prototype); 824 | Object.extend(Ajax.InPlaceCollectionEditor.prototype, { 825 | createEditField: function() { 826 | if (!this.cached_selectTag) { 827 | var selectTag = document.createElement("select"); 828 | var collection = this.options.collection || []; 829 | var optionTag; 830 | collection.each(function(e,i) { 831 | optionTag = document.createElement("option"); 832 | optionTag.value = (e instanceof Array) ? e[0] : e; 833 | if((typeof this.options.value == 'undefined') && 834 | ((e instanceof Array) ? this.element.innerHTML == e[1] : e == optionTag.value)) optionTag.selected = true; 835 | if(this.options.value==optionTag.value) optionTag.selected = true; 836 | optionTag.appendChild(document.createTextNode((e instanceof Array) ? e[1] : e)); 837 | selectTag.appendChild(optionTag); 838 | }.bind(this)); 839 | this.cached_selectTag = selectTag; 840 | } 841 | 842 | this.editField = this.cached_selectTag; 843 | if(this.options.loadTextURL) this.loadExternalText(); 844 | this.form.appendChild(this.editField); 845 | this.options.callback = function(form, value) { 846 | return "value=" + encodeURIComponent(value); 847 | } 848 | } 849 | }); 850 | 851 | // Delayed observer, like Form.Element.Observer, 852 | // but waits for delay after last key input 853 | // Ideal for live-search fields 854 | 855 | Form.Element.DelayedObserver = Class.create(); 856 | Form.Element.DelayedObserver.prototype = { 857 | initialize: function(element, delay, callback) { 858 | this.delay = delay || 0.5; 859 | this.element = $(element); 860 | this.callback = callback; 861 | this.timer = null; 862 | this.lastValue = $F(this.element); 863 | Event.observe(this.element,'keyup',this.delayedListener.bindAsEventListener(this)); 864 | }, 865 | delayedListener: function(event) { 866 | if(this.lastValue == $F(this.element)) return; 867 | if(this.timer) clearTimeout(this.timer); 868 | this.timer = setTimeout(this.onTimerEvent.bind(this), this.delay * 1000); 869 | this.lastValue = $F(this.element); 870 | }, 871 | onTimerEvent: function() { 872 | this.timer = null; 873 | this.callback(this.element, $F(this.element)); 874 | } 875 | }; 876 | -------------------------------------------------------------------------------- /pub/scripts/dragdrop.js: -------------------------------------------------------------------------------- 1 | // script.aculo.us dragdrop.js v1.7.1_beta3, Fri May 25 17:19:41 +0200 2007 2 | 3 | // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 4 | // (c) 2005-2007 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz) 5 | // 6 | // script.aculo.us is freely distributable under the terms of an MIT-style license. 7 | // For details, see the script.aculo.us web site: http://script.aculo.us/ 8 | 9 | if(typeof Effect == 'undefined') 10 | throw("dragdrop.js requires including script.aculo.us' effects.js library"); 11 | 12 | var Droppables = { 13 | drops: [], 14 | 15 | remove: function(element) { 16 | this.drops = this.drops.reject(function(d) { return d.element==$(element) }); 17 | }, 18 | 19 | add: function(element) { 20 | element = $(element); 21 | var options = Object.extend({ 22 | greedy: true, 23 | hoverclass: null, 24 | tree: false 25 | }, arguments[1] || {}); 26 | 27 | // cache containers 28 | if(options.containment) { 29 | options._containers = []; 30 | var containment = options.containment; 31 | if((typeof containment == 'object') && 32 | (containment.constructor == Array)) { 33 | containment.each( function(c) { options._containers.push($(c)) }); 34 | } else { 35 | options._containers.push($(containment)); 36 | } 37 | } 38 | 39 | if(options.accept) options.accept = [options.accept].flatten(); 40 | 41 | Element.makePositioned(element); // fix IE 42 | options.element = element; 43 | 44 | this.drops.push(options); 45 | }, 46 | 47 | findDeepestChild: function(drops) { 48 | deepest = drops[0]; 49 | 50 | for (i = 1; i < drops.length; ++i) 51 | if (Element.isParent(drops[i].element, deepest.element)) 52 | deepest = drops[i]; 53 | 54 | return deepest; 55 | }, 56 | 57 | isContained: function(element, drop) { 58 | var containmentNode; 59 | if(drop.tree) { 60 | containmentNode = element.treeNode; 61 | } else { 62 | containmentNode = element.parentNode; 63 | } 64 | return drop._containers.detect(function(c) { return containmentNode == c }); 65 | }, 66 | 67 | isAffected: function(point, element, drop) { 68 | return ( 69 | (drop.element!=element) && 70 | ((!drop._containers) || 71 | this.isContained(element, drop)) && 72 | ((!drop.accept) || 73 | (Element.classNames(element).detect( 74 | function(v) { return drop.accept.include(v) } ) )) && 75 | Position.within(drop.element, point[0], point[1]) ); 76 | }, 77 | 78 | deactivate: function(drop) { 79 | if(drop.hoverclass) 80 | Element.removeClassName(drop.element, drop.hoverclass); 81 | this.last_active = null; 82 | }, 83 | 84 | activate: function(drop) { 85 | if(drop.hoverclass) 86 | Element.addClassName(drop.element, drop.hoverclass); 87 | this.last_active = drop; 88 | }, 89 | 90 | show: function(point, element) { 91 | if(!this.drops.length) return; 92 | var affected = []; 93 | 94 | if(this.last_active) this.deactivate(this.last_active); 95 | this.drops.each( function(drop) { 96 | if(Droppables.isAffected(point, element, drop)) 97 | affected.push(drop); 98 | }); 99 | 100 | if(affected.length>0) { 101 | drop = Droppables.findDeepestChild(affected); 102 | Position.within(drop.element, point[0], point[1]); 103 | if(drop.onHover) 104 | drop.onHover(element, drop.element, Position.overlap(drop.overlap, drop.element)); 105 | 106 | Droppables.activate(drop); 107 | } 108 | }, 109 | 110 | fire: function(event, element) { 111 | if(!this.last_active) return; 112 | Position.prepare(); 113 | 114 | if (this.isAffected([Event.pointerX(event), Event.pointerY(event)], element, this.last_active)) 115 | if (this.last_active.onDrop) { 116 | this.last_active.onDrop(element, this.last_active.element, event); 117 | return true; 118 | } 119 | }, 120 | 121 | reset: function() { 122 | if(this.last_active) 123 | this.deactivate(this.last_active); 124 | } 125 | } 126 | 127 | var Draggables = { 128 | drags: [], 129 | observers: [], 130 | 131 | register: function(draggable) { 132 | if(this.drags.length == 0) { 133 | this.eventMouseUp = this.endDrag.bindAsEventListener(this); 134 | this.eventMouseMove = this.updateDrag.bindAsEventListener(this); 135 | this.eventKeypress = this.keyPress.bindAsEventListener(this); 136 | 137 | Event.observe(document, "mouseup", this.eventMouseUp); 138 | Event.observe(document, "mousemove", this.eventMouseMove); 139 | Event.observe(document, "keypress", this.eventKeypress); 140 | } 141 | this.drags.push(draggable); 142 | }, 143 | 144 | unregister: function(draggable) { 145 | this.drags = this.drags.reject(function(d) { return d==draggable }); 146 | if(this.drags.length == 0) { 147 | Event.stopObserving(document, "mouseup", this.eventMouseUp); 148 | Event.stopObserving(document, "mousemove", this.eventMouseMove); 149 | Event.stopObserving(document, "keypress", this.eventKeypress); 150 | } 151 | }, 152 | 153 | activate: function(draggable) { 154 | if(draggable.options.delay) { 155 | this._timeout = setTimeout(function() { 156 | Draggables._timeout = null; 157 | window.focus(); 158 | Draggables.activeDraggable = draggable; 159 | }.bind(this), draggable.options.delay); 160 | } else { 161 | window.focus(); // allows keypress events if window isn't currently focused, fails for Safari 162 | this.activeDraggable = draggable; 163 | } 164 | }, 165 | 166 | deactivate: function() { 167 | this.activeDraggable = null; 168 | }, 169 | 170 | updateDrag: function(event) { 171 | if(!this.activeDraggable) return; 172 | var pointer = [Event.pointerX(event), Event.pointerY(event)]; 173 | // Mozilla-based browsers fire successive mousemove events with 174 | // the same coordinates, prevent needless redrawing (moz bug?) 175 | if(this._lastPointer && (this._lastPointer.inspect() == pointer.inspect())) return; 176 | this._lastPointer = pointer; 177 | 178 | this.activeDraggable.updateDrag(event, pointer); 179 | }, 180 | 181 | endDrag: function(event) { 182 | if(this._timeout) { 183 | clearTimeout(this._timeout); 184 | this._timeout = null; 185 | } 186 | if(!this.activeDraggable) return; 187 | this._lastPointer = null; 188 | this.activeDraggable.endDrag(event); 189 | this.activeDraggable = null; 190 | }, 191 | 192 | keyPress: function(event) { 193 | if(this.activeDraggable) 194 | this.activeDraggable.keyPress(event); 195 | }, 196 | 197 | addObserver: function(observer) { 198 | this.observers.push(observer); 199 | this._cacheObserverCallbacks(); 200 | }, 201 | 202 | removeObserver: function(element) { // element instead of observer fixes mem leaks 203 | this.observers = this.observers.reject( function(o) { return o.element==element }); 204 | this._cacheObserverCallbacks(); 205 | }, 206 | 207 | notify: function(eventName, draggable, event) { // 'onStart', 'onEnd', 'onDrag' 208 | if(this[eventName+'Count'] > 0) 209 | this.observers.each( function(o) { 210 | if(o[eventName]) o[eventName](eventName, draggable, event); 211 | }); 212 | if(draggable.options[eventName]) draggable.options[eventName](draggable, event); 213 | }, 214 | 215 | _cacheObserverCallbacks: function() { 216 | ['onStart','onEnd','onDrag'].each( function(eventName) { 217 | Draggables[eventName+'Count'] = Draggables.observers.select( 218 | function(o) { return o[eventName]; } 219 | ).length; 220 | }); 221 | } 222 | } 223 | 224 | /*--------------------------------------------------------------------------*/ 225 | 226 | var Draggable = Class.create(); 227 | Draggable._dragging = {}; 228 | 229 | Draggable.prototype = { 230 | initialize: function(element) { 231 | var defaults = { 232 | handle: false, 233 | reverteffect: function(element, top_offset, left_offset) { 234 | var dur = Math.sqrt(Math.abs(top_offset^2)+Math.abs(left_offset^2))*0.02; 235 | new Effect.Move(element, { x: -left_offset, y: -top_offset, duration: dur, 236 | queue: {scope:'_draggable', position:'end'} 237 | }); 238 | }, 239 | endeffect: function(element) { 240 | var toOpacity = typeof element._opacity == 'number' ? element._opacity : 1.0; 241 | new Effect.Opacity(element, {duration:0.2, from:0.7, to:toOpacity, 242 | queue: {scope:'_draggable', position:'end'}, 243 | afterFinish: function(){ 244 | Draggable._dragging[element] = false 245 | } 246 | }); 247 | }, 248 | zindex: 1000, 249 | revert: false, 250 | quiet: false, 251 | scroll: false, 252 | scrollSensitivity: 20, 253 | scrollSpeed: 15, 254 | snap: false, // false, or xy or [x,y] or function(x,y){ return [x,y] } 255 | delay: 0 256 | }; 257 | 258 | if(!arguments[1] || typeof arguments[1].endeffect == 'undefined') 259 | Object.extend(defaults, { 260 | starteffect: function(element) { 261 | element._opacity = Element.getOpacity(element); 262 | Draggable._dragging[element] = true; 263 | new Effect.Opacity(element, {duration:0.2, from:element._opacity, to:0.7}); 264 | } 265 | }); 266 | 267 | var options = Object.extend(defaults, arguments[1] || {}); 268 | 269 | this.element = $(element); 270 | 271 | if(options.handle && (typeof options.handle == 'string')) 272 | this.handle = this.element.down('.'+options.handle, 0); 273 | 274 | if(!this.handle) this.handle = $(options.handle); 275 | if(!this.handle) this.handle = this.element; 276 | 277 | if(options.scroll && !options.scroll.scrollTo && !options.scroll.outerHTML) { 278 | options.scroll = $(options.scroll); 279 | this._isScrollChild = Element.childOf(this.element, options.scroll); 280 | } 281 | 282 | Element.makePositioned(this.element); // fix IE 283 | 284 | this.delta = this.currentDelta(); 285 | this.options = options; 286 | this.dragging = false; 287 | 288 | this.eventMouseDown = this.initDrag.bindAsEventListener(this); 289 | Event.observe(this.handle, "mousedown", this.eventMouseDown); 290 | 291 | Draggables.register(this); 292 | }, 293 | 294 | destroy: function() { 295 | Event.stopObserving(this.handle, "mousedown", this.eventMouseDown); 296 | Draggables.unregister(this); 297 | }, 298 | 299 | currentDelta: function() { 300 | return([ 301 | parseInt(Element.getStyle(this.element,'left') || '0'), 302 | parseInt(Element.getStyle(this.element,'top') || '0')]); 303 | }, 304 | 305 | initDrag: function(event) { 306 | if(typeof Draggable._dragging[this.element] != 'undefined' && 307 | Draggable._dragging[this.element]) return; 308 | if(Event.isLeftClick(event)) { 309 | // abort on form elements, fixes a Firefox issue 310 | var src = Event.element(event); 311 | if((tag_name = src.tagName.toUpperCase()) && ( 312 | tag_name=='INPUT' || 313 | tag_name=='SELECT' || 314 | tag_name=='OPTION' || 315 | tag_name=='BUTTON' || 316 | tag_name=='TEXTAREA')) return; 317 | 318 | var pointer = [Event.pointerX(event), Event.pointerY(event)]; 319 | var pos = Position.cumulativeOffset(this.element); 320 | this.offset = [0,1].map( function(i) { return (pointer[i] - pos[i]) }); 321 | 322 | Draggables.activate(this); 323 | Event.stop(event); 324 | } 325 | }, 326 | 327 | startDrag: function(event) { 328 | this.dragging = true; 329 | 330 | if(this.options.zindex) { 331 | this.originalZ = parseInt(Element.getStyle(this.element,'z-index') || 0); 332 | this.element.style.zIndex = this.options.zindex; 333 | } 334 | 335 | if(this.options.ghosting) { 336 | this._clone = this.element.cloneNode(true); 337 | Position.absolutize(this.element); 338 | this.element.parentNode.insertBefore(this._clone, this.element); 339 | } 340 | 341 | if(this.options.scroll) { 342 | if (this.options.scroll == window) { 343 | var where = this._getWindowScroll(this.options.scroll); 344 | this.originalScrollLeft = where.left; 345 | this.originalScrollTop = where.top; 346 | } else { 347 | this.originalScrollLeft = this.options.scroll.scrollLeft; 348 | this.originalScrollTop = this.options.scroll.scrollTop; 349 | } 350 | } 351 | 352 | Draggables.notify('onStart', this, event); 353 | 354 | if(this.options.starteffect) this.options.starteffect(this.element); 355 | }, 356 | 357 | updateDrag: function(event, pointer) { 358 | if(!this.dragging) this.startDrag(event); 359 | 360 | if(!this.options.quiet){ 361 | Position.prepare(); 362 | Droppables.show(pointer, this.element); 363 | } 364 | 365 | Draggables.notify('onDrag', this, event); 366 | 367 | this.draw(pointer); 368 | if(this.options.change) this.options.change(this); 369 | 370 | if(this.options.scroll) { 371 | this.stopScrolling(); 372 | 373 | var p; 374 | if (this.options.scroll == window) { 375 | with(this._getWindowScroll(this.options.scroll)) { p = [ left, top, left+width, top+height ]; } 376 | } else { 377 | p = Position.page(this.options.scroll); 378 | p[0] += this.options.scroll.scrollLeft + Position.deltaX; 379 | p[1] += this.options.scroll.scrollTop + Position.deltaY; 380 | p.push(p[0]+this.options.scroll.offsetWidth); 381 | p.push(p[1]+this.options.scroll.offsetHeight); 382 | } 383 | var speed = [0,0]; 384 | if(pointer[0] < (p[0]+this.options.scrollSensitivity)) speed[0] = pointer[0]-(p[0]+this.options.scrollSensitivity); 385 | if(pointer[1] < (p[1]+this.options.scrollSensitivity)) speed[1] = pointer[1]-(p[1]+this.options.scrollSensitivity); 386 | if(pointer[0] > (p[2]-this.options.scrollSensitivity)) speed[0] = pointer[0]-(p[2]-this.options.scrollSensitivity); 387 | if(pointer[1] > (p[3]-this.options.scrollSensitivity)) speed[1] = pointer[1]-(p[3]-this.options.scrollSensitivity); 388 | this.startScrolling(speed); 389 | } 390 | 391 | // fix AppleWebKit rendering 392 | if(Prototype.Browser.WebKit) window.scrollBy(0,0); 393 | 394 | Event.stop(event); 395 | }, 396 | 397 | finishDrag: function(event, success) { 398 | this.dragging = false; 399 | 400 | if(this.options.quiet){ 401 | Position.prepare(); 402 | var pointer = [Event.pointerX(event), Event.pointerY(event)]; 403 | Droppables.show(pointer, this.element); 404 | } 405 | 406 | if(this.options.ghosting) { 407 | Position.relativize(this.element); 408 | Element.remove(this._clone); 409 | this._clone = null; 410 | } 411 | 412 | var dropped = false; 413 | if(success) { 414 | dropped = Droppables.fire(event, this.element); 415 | if (!dropped) dropped = false; 416 | } 417 | if(dropped && this.options.onDropped) this.options.onDropped(this.element); 418 | Draggables.notify('onEnd', this, event); 419 | 420 | var revert = this.options.revert; 421 | if(revert && typeof revert == 'function') revert = revert(this.element); 422 | 423 | var d = this.currentDelta(); 424 | if(revert && this.options.reverteffect) { 425 | if (dropped == 0 || revert != 'failure') 426 | this.options.reverteffect(this.element, 427 | d[1]-this.delta[1], d[0]-this.delta[0]); 428 | } else { 429 | this.delta = d; 430 | } 431 | 432 | if(this.options.zindex) 433 | this.element.style.zIndex = this.originalZ; 434 | 435 | if(this.options.endeffect) 436 | this.options.endeffect(this.element); 437 | 438 | Draggables.deactivate(this); 439 | Droppables.reset(); 440 | }, 441 | 442 | keyPress: function(event) { 443 | if(event.keyCode!=Event.KEY_ESC) return; 444 | this.finishDrag(event, false); 445 | Event.stop(event); 446 | }, 447 | 448 | endDrag: function(event) { 449 | if(!this.dragging) return; 450 | this.stopScrolling(); 451 | this.finishDrag(event, true); 452 | Event.stop(event); 453 | }, 454 | 455 | draw: function(point) { 456 | var pos = Position.cumulativeOffset(this.element); 457 | if(this.options.ghosting) { 458 | var r = Position.realOffset(this.element); 459 | pos[0] += r[0] - Position.deltaX; pos[1] += r[1] - Position.deltaY; 460 | } 461 | 462 | var d = this.currentDelta(); 463 | pos[0] -= d[0]; pos[1] -= d[1]; 464 | 465 | if(this.options.scroll && (this.options.scroll != window && this._isScrollChild)) { 466 | pos[0] -= this.options.scroll.scrollLeft-this.originalScrollLeft; 467 | pos[1] -= this.options.scroll.scrollTop-this.originalScrollTop; 468 | } 469 | 470 | var p = [0,1].map(function(i){ 471 | return (point[i]-pos[i]-this.offset[i]) 472 | }.bind(this)); 473 | 474 | if(this.options.snap) { 475 | if(typeof this.options.snap == 'function') { 476 | p = this.options.snap(p[0],p[1],this); 477 | } else { 478 | if(this.options.snap instanceof Array) { 479 | p = p.map( function(v, i) { 480 | return Math.round(v/this.options.snap[i])*this.options.snap[i] }.bind(this)) 481 | } else { 482 | p = p.map( function(v) { 483 | return Math.round(v/this.options.snap)*this.options.snap }.bind(this)) 484 | } 485 | }} 486 | 487 | var style = this.element.style; 488 | if((!this.options.constraint) || (this.options.constraint=='horizontal')) 489 | style.left = p[0] + "px"; 490 | if((!this.options.constraint) || (this.options.constraint=='vertical')) 491 | style.top = p[1] + "px"; 492 | 493 | if(style.visibility=="hidden") style.visibility = ""; // fix gecko rendering 494 | }, 495 | 496 | stopScrolling: function() { 497 | if(this.scrollInterval) { 498 | clearInterval(this.scrollInterval); 499 | this.scrollInterval = null; 500 | Draggables._lastScrollPointer = null; 501 | } 502 | }, 503 | 504 | startScrolling: function(speed) { 505 | if(!(speed[0] || speed[1])) return; 506 | this.scrollSpeed = [speed[0]*this.options.scrollSpeed,speed[1]*this.options.scrollSpeed]; 507 | this.lastScrolled = new Date(); 508 | this.scrollInterval = setInterval(this.scroll.bind(this), 10); 509 | }, 510 | 511 | scroll: function() { 512 | var current = new Date(); 513 | var delta = current - this.lastScrolled; 514 | this.lastScrolled = current; 515 | if(this.options.scroll == window) { 516 | with (this._getWindowScroll(this.options.scroll)) { 517 | if (this.scrollSpeed[0] || this.scrollSpeed[1]) { 518 | var d = delta / 1000; 519 | this.options.scroll.scrollTo( left + d*this.scrollSpeed[0], top + d*this.scrollSpeed[1] ); 520 | } 521 | } 522 | } else { 523 | this.options.scroll.scrollLeft += this.scrollSpeed[0] * delta / 1000; 524 | this.options.scroll.scrollTop += this.scrollSpeed[1] * delta / 1000; 525 | } 526 | 527 | Position.prepare(); 528 | Droppables.show(Draggables._lastPointer, this.element); 529 | Draggables.notify('onDrag', this); 530 | if (this._isScrollChild) { 531 | Draggables._lastScrollPointer = Draggables._lastScrollPointer || $A(Draggables._lastPointer); 532 | Draggables._lastScrollPointer[0] += this.scrollSpeed[0] * delta / 1000; 533 | Draggables._lastScrollPointer[1] += this.scrollSpeed[1] * delta / 1000; 534 | if (Draggables._lastScrollPointer[0] < 0) 535 | Draggables._lastScrollPointer[0] = 0; 536 | if (Draggables._lastScrollPointer[1] < 0) 537 | Draggables._lastScrollPointer[1] = 0; 538 | this.draw(Draggables._lastScrollPointer); 539 | } 540 | 541 | if(this.options.change) this.options.change(this); 542 | }, 543 | 544 | _getWindowScroll: function(w) { 545 | var T, L, W, H; 546 | with (w.document) { 547 | if (w.document.documentElement && documentElement.scrollTop) { 548 | T = documentElement.scrollTop; 549 | L = documentElement.scrollLeft; 550 | } else if (w.document.body) { 551 | T = body.scrollTop; 552 | L = body.scrollLeft; 553 | } 554 | if (w.innerWidth) { 555 | W = w.innerWidth; 556 | H = w.innerHeight; 557 | } else if (w.document.documentElement && documentElement.clientWidth) { 558 | W = documentElement.clientWidth; 559 | H = documentElement.clientHeight; 560 | } else { 561 | W = body.offsetWidth; 562 | H = body.offsetHeight 563 | } 564 | } 565 | return { top: T, left: L, width: W, height: H }; 566 | } 567 | } 568 | 569 | /*--------------------------------------------------------------------------*/ 570 | 571 | var SortableObserver = Class.create(); 572 | SortableObserver.prototype = { 573 | initialize: function(element, observer) { 574 | this.element = $(element); 575 | this.observer = observer; 576 | this.lastValue = Sortable.serialize(this.element); 577 | }, 578 | 579 | onStart: function() { 580 | this.lastValue = Sortable.serialize(this.element); 581 | }, 582 | 583 | onEnd: function() { 584 | Sortable.unmark(); 585 | if(this.lastValue != Sortable.serialize(this.element)) 586 | this.observer(this.element) 587 | } 588 | } 589 | 590 | var Sortable = { 591 | SERIALIZE_RULE: /^[^_\-](?:[A-Za-z0-9\-\_]*)[_](.*)$/, 592 | 593 | sortables: {}, 594 | 595 | _findRootElement: function(element) { 596 | while (element.tagName.toUpperCase() != "BODY") { 597 | if(element.id && Sortable.sortables[element.id]) return element; 598 | element = element.parentNode; 599 | } 600 | }, 601 | 602 | options: function(element) { 603 | element = Sortable._findRootElement($(element)); 604 | if(!element) return; 605 | return Sortable.sortables[element.id]; 606 | }, 607 | 608 | destroy: function(element){ 609 | var s = Sortable.options(element); 610 | 611 | if(s) { 612 | Draggables.removeObserver(s.element); 613 | s.droppables.each(function(d){ Droppables.remove(d) }); 614 | s.draggables.invoke('destroy'); 615 | 616 | delete Sortable.sortables[s.element.id]; 617 | } 618 | }, 619 | 620 | create: function(element) { 621 | element = $(element); 622 | var options = Object.extend({ 623 | element: element, 624 | tag: 'li', // assumes li children, override with tag: 'tagname' 625 | dropOnEmpty: false, 626 | tree: false, 627 | treeTag: 'ul', 628 | overlap: 'vertical', // one of 'vertical', 'horizontal' 629 | constraint: 'vertical', // one of 'vertical', 'horizontal', false 630 | containment: element, // also takes array of elements (or id's); or false 631 | handle: false, // or a CSS class 632 | only: false, 633 | delay: 0, 634 | hoverclass: null, 635 | ghosting: false, 636 | quiet: false, 637 | scroll: false, 638 | scrollSensitivity: 20, 639 | scrollSpeed: 15, 640 | format: this.SERIALIZE_RULE, 641 | 642 | // these take arrays of elements or ids and can be 643 | // used for better initialization performance 644 | elements: false, 645 | handles: false, 646 | 647 | onChange: Prototype.emptyFunction, 648 | onUpdate: Prototype.emptyFunction 649 | }, arguments[1] || {}); 650 | 651 | // clear any old sortable with same element 652 | this.destroy(element); 653 | 654 | // build options for the draggables 655 | var options_for_draggable = { 656 | revert: true, 657 | quiet: options.quiet, 658 | scroll: options.scroll, 659 | scrollSpeed: options.scrollSpeed, 660 | scrollSensitivity: options.scrollSensitivity, 661 | delay: options.delay, 662 | ghosting: options.ghosting, 663 | constraint: options.constraint, 664 | handle: options.handle }; 665 | 666 | if(options.starteffect) 667 | options_for_draggable.starteffect = options.starteffect; 668 | 669 | if(options.reverteffect) 670 | options_for_draggable.reverteffect = options.reverteffect; 671 | else 672 | if(options.ghosting) options_for_draggable.reverteffect = function(element) { 673 | element.style.top = 0; 674 | element.style.left = 0; 675 | }; 676 | 677 | if(options.endeffect) 678 | options_for_draggable.endeffect = options.endeffect; 679 | 680 | if(options.zindex) 681 | options_for_draggable.zindex = options.zindex; 682 | 683 | // build options for the droppables 684 | var options_for_droppable = { 685 | overlap: options.overlap, 686 | containment: options.containment, 687 | tree: options.tree, 688 | hoverclass: options.hoverclass, 689 | onHover: Sortable.onHover 690 | } 691 | 692 | var options_for_tree = { 693 | onHover: Sortable.onEmptyHover, 694 | overlap: options.overlap, 695 | containment: options.containment, 696 | hoverclass: options.hoverclass 697 | } 698 | 699 | // fix for gecko engine 700 | Element.cleanWhitespace(element); 701 | 702 | options.draggables = []; 703 | options.droppables = []; 704 | 705 | // drop on empty handling 706 | if(options.dropOnEmpty || options.tree) { 707 | Droppables.add(element, options_for_tree); 708 | options.droppables.push(element); 709 | } 710 | 711 | (options.elements || this.findElements(element, options) || []).each( function(e,i) { 712 | var handle = options.handles ? $(options.handles[i]) : 713 | (options.handle ? $(e).getElementsByClassName(options.handle)[0] : e); 714 | options.draggables.push( 715 | new Draggable(e, Object.extend(options_for_draggable, { handle: handle }))); 716 | Droppables.add(e, options_for_droppable); 717 | if(options.tree) e.treeNode = element; 718 | options.droppables.push(e); 719 | }); 720 | 721 | if(options.tree) { 722 | (Sortable.findTreeElements(element, options) || []).each( function(e) { 723 | Droppables.add(e, options_for_tree); 724 | e.treeNode = element; 725 | options.droppables.push(e); 726 | }); 727 | } 728 | 729 | // keep reference 730 | this.sortables[element.id] = options; 731 | 732 | // for onupdate 733 | Draggables.addObserver(new SortableObserver(element, options.onUpdate)); 734 | 735 | }, 736 | 737 | // return all suitable-for-sortable elements in a guaranteed order 738 | findElements: function(element, options) { 739 | return Element.findChildren( 740 | element, options.only, options.tree ? true : false, options.tag); 741 | }, 742 | 743 | findTreeElements: function(element, options) { 744 | return Element.findChildren( 745 | element, options.only, options.tree ? true : false, options.treeTag); 746 | }, 747 | 748 | onHover: function(element, dropon, overlap) { 749 | if(Element.isParent(dropon, element)) return; 750 | 751 | if(overlap > .33 && overlap < .66 && Sortable.options(dropon).tree) { 752 | return; 753 | } else if(overlap>0.5) { 754 | Sortable.mark(dropon, 'before'); 755 | if(dropon.previousSibling != element) { 756 | var oldParentNode = element.parentNode; 757 | element.style.visibility = "hidden"; // fix gecko rendering 758 | dropon.parentNode.insertBefore(element, dropon); 759 | if(dropon.parentNode!=oldParentNode) 760 | Sortable.options(oldParentNode).onChange(element); 761 | Sortable.options(dropon.parentNode).onChange(element); 762 | } 763 | } else { 764 | Sortable.mark(dropon, 'after'); 765 | var nextElement = dropon.nextSibling || null; 766 | if(nextElement != element) { 767 | var oldParentNode = element.parentNode; 768 | element.style.visibility = "hidden"; // fix gecko rendering 769 | dropon.parentNode.insertBefore(element, nextElement); 770 | if(dropon.parentNode!=oldParentNode) 771 | Sortable.options(oldParentNode).onChange(element); 772 | Sortable.options(dropon.parentNode).onChange(element); 773 | } 774 | } 775 | }, 776 | 777 | onEmptyHover: function(element, dropon, overlap) { 778 | var oldParentNode = element.parentNode; 779 | var droponOptions = Sortable.options(dropon); 780 | 781 | if(!Element.isParent(dropon, element)) { 782 | var index; 783 | 784 | var children = Sortable.findElements(dropon, {tag: droponOptions.tag, only: droponOptions.only}); 785 | var child = null; 786 | 787 | if(children) { 788 | var offset = Element.offsetSize(dropon, droponOptions.overlap) * (1.0 - overlap); 789 | 790 | for (index = 0; index < children.length; index += 1) { 791 | if (offset - Element.offsetSize (children[index], droponOptions.overlap) >= 0) { 792 | offset -= Element.offsetSize (children[index], droponOptions.overlap); 793 | } else if (offset - (Element.offsetSize (children[index], droponOptions.overlap) / 2) >= 0) { 794 | child = index + 1 < children.length ? children[index + 1] : null; 795 | break; 796 | } else { 797 | child = children[index]; 798 | break; 799 | } 800 | } 801 | } 802 | 803 | dropon.insertBefore(element, child); 804 | 805 | Sortable.options(oldParentNode).onChange(element); 806 | droponOptions.onChange(element); 807 | } 808 | }, 809 | 810 | unmark: function() { 811 | if(Sortable._marker) Sortable._marker.hide(); 812 | }, 813 | 814 | mark: function(dropon, position) { 815 | // mark on ghosting only 816 | var sortable = Sortable.options(dropon.parentNode); 817 | if(sortable && !sortable.ghosting) return; 818 | 819 | if(!Sortable._marker) { 820 | Sortable._marker = 821 | ($('dropmarker') || Element.extend(document.createElement('DIV'))). 822 | hide().addClassName('dropmarker').setStyle({position:'absolute'}); 823 | document.getElementsByTagName("body").item(0).appendChild(Sortable._marker); 824 | } 825 | var offsets = Position.cumulativeOffset(dropon); 826 | Sortable._marker.setStyle({left: offsets[0]+'px', top: offsets[1] + 'px'}); 827 | 828 | if(position=='after') 829 | if(sortable.overlap == 'horizontal') 830 | Sortable._marker.setStyle({left: (offsets[0]+dropon.clientWidth) + 'px'}); 831 | else 832 | Sortable._marker.setStyle({top: (offsets[1]+dropon.clientHeight) + 'px'}); 833 | 834 | Sortable._marker.show(); 835 | }, 836 | 837 | _tree: function(element, options, parent) { 838 | var children = Sortable.findElements(element, options) || []; 839 | 840 | for (var i = 0; i < children.length; ++i) { 841 | var match = children[i].id.match(options.format); 842 | 843 | if (!match) continue; 844 | 845 | var child = { 846 | id: encodeURIComponent(match ? match[1] : null), 847 | element: element, 848 | parent: parent, 849 | children: [], 850 | position: parent.children.length, 851 | container: $(children[i]).down(options.treeTag) 852 | } 853 | 854 | /* Get the element containing the children and recurse over it */ 855 | if (child.container) 856 | this._tree(child.container, options, child) 857 | 858 | parent.children.push (child); 859 | } 860 | 861 | return parent; 862 | }, 863 | 864 | tree: function(element) { 865 | element = $(element); 866 | var sortableOptions = this.options(element); 867 | var options = Object.extend({ 868 | tag: sortableOptions.tag, 869 | treeTag: sortableOptions.treeTag, 870 | only: sortableOptions.only, 871 | name: element.id, 872 | format: sortableOptions.format 873 | }, arguments[1] || {}); 874 | 875 | var root = { 876 | id: null, 877 | parent: null, 878 | children: [], 879 | container: element, 880 | position: 0 881 | } 882 | 883 | return Sortable._tree(element, options, root); 884 | }, 885 | 886 | /* Construct a [i] index for a particular node */ 887 | _constructIndex: function(node) { 888 | var index = ''; 889 | do { 890 | if (node.id) index = '[' + node.position + ']' + index; 891 | } while ((node = node.parent) != null); 892 | return index; 893 | }, 894 | 895 | sequence: function(element) { 896 | element = $(element); 897 | var options = Object.extend(this.options(element), arguments[1] || {}); 898 | 899 | return $(this.findElements(element, options) || []).map( function(item) { 900 | return item.id.match(options.format) ? item.id.match(options.format)[1] : ''; 901 | }); 902 | }, 903 | 904 | setSequence: function(element, new_sequence) { 905 | element = $(element); 906 | var options = Object.extend(this.options(element), arguments[2] || {}); 907 | 908 | var nodeMap = {}; 909 | this.findElements(element, options).each( function(n) { 910 | if (n.id.match(options.format)) 911 | nodeMap[n.id.match(options.format)[1]] = [n, n.parentNode]; 912 | n.parentNode.removeChild(n); 913 | }); 914 | 915 | new_sequence.each(function(ident) { 916 | var n = nodeMap[ident]; 917 | if (n) { 918 | n[1].appendChild(n[0]); 919 | delete nodeMap[ident]; 920 | } 921 | }); 922 | }, 923 | 924 | serialize: function(element) { 925 | element = $(element); 926 | var options = Object.extend(Sortable.options(element), arguments[1] || {}); 927 | var name = encodeURIComponent( 928 | (arguments[1] && arguments[1].name) ? arguments[1].name : element.id); 929 | 930 | if (options.tree) { 931 | return Sortable.tree(element, arguments[1]).children.map( function (item) { 932 | return [name + Sortable._constructIndex(item) + "[id]=" + 933 | encodeURIComponent(item.id)].concat(item.children.map(arguments.callee)); 934 | }).flatten().join('&'); 935 | } else { 936 | return Sortable.sequence(element, arguments[1]).map( function(item) { 937 | return name + "[]=" + encodeURIComponent(item); 938 | }).join('&'); 939 | } 940 | } 941 | } 942 | 943 | // Returns true if child is contained within element 944 | Element.isParent = function(child, element) { 945 | if (!child.parentNode || child == element) return false; 946 | if (child.parentNode == element) return true; 947 | return Element.isParent(child.parentNode, element); 948 | } 949 | 950 | Element.findChildren = function(element, only, recursive, tagName) { 951 | if(!element.hasChildNodes()) return null; 952 | tagName = tagName.toUpperCase(); 953 | if(only) only = [only].flatten(); 954 | var elements = []; 955 | $A(element.childNodes).each( function(e) { 956 | if(e.tagName && e.tagName.toUpperCase()==tagName && 957 | (!only || (Element.classNames(e).detect(function(v) { return only.include(v) })))) 958 | elements.push(e); 959 | if(recursive) { 960 | var grandchildren = Element.findChildren(e, only, recursive, tagName); 961 | if(grandchildren) elements.push(grandchildren); 962 | } 963 | }); 964 | 965 | return (elements.length>0 ? elements.flatten() : []); 966 | } 967 | 968 | Element.offsetSize = function (element, type) { 969 | return element['offset' + ((type=='vertical' || type=='height') ? 'Height' : 'Width')]; 970 | } 971 | --------------------------------------------------------------------------------