mywebtodo-20080329/0000755000175000000620000000000011014730207013170 5ustar trevorstaffmywebtodo-20080329/templates/0000755000175000000620000000000010773562065015206 5ustar trevorstaffmywebtodo-20080329/templates/base.html0000644000175000000620000000076210730535741017005 0ustar trevorstaff {% block title %}Trevor Caira's Development Server{% endblock %} {% block link %}{% endblock %} {% block content %} {% endblock %} mywebtodo-20080329/templates/404.html0000644000175000000620000000016710730535741016401 0ustar trevorstaff{% extends "base.html" %} {% block title %}404{% endblock %} {% block content %}

404 Not Found

{% endblock %} mywebtodo-20080329/templates/500.html0000644000175000000620000000020310730535741016365 0ustar trevorstaff{% extends "base.html" %} {% block title %}500{% endblock %} {% block content %}

500 Internal Server Error

{% endblock %} mywebtodo-20080329/templates/feeds/0000755000175000000620000000000010773562065016274 5ustar trevorstaffmywebtodo-20080329/templates/feeds/soonest_description.html0000644000175000000620000000011110730535741023242 0ustar trevorstaff{{ obj }} is due {{ obj.due|date:"F j, Y" }} at {{ obj.due|date:"H:i" }} mywebtodo-20080329/locale/0000755000175000000620000000000010773562065014447 5ustar trevorstaffmywebtodo-20080329/locale/zh_TW/0000755000175000000620000000000010773562065015502 5ustar trevorstaffmywebtodo-20080329/locale/zh_TW/LC_MESSAGES/0000755000175000000620000000000011014730023017243 5ustar trevorstaffmywebtodo-20080329/locale/zh_TW/LC_MESSAGES/django.mo0000644000175000000620000000175710730645240021066 0ustar trevorstaffxy{  :  5PT[ bov } -   .CategoryDoneDueNameSelectTask ListYour profileYour username and password didn't match. Please try again.categoriescategoryeditprofileprofilestaskProject-Id-Version: PACKAGE VERSION Report-Msgid-Bugs-To: POT-Creation-Date: 2007-12-07 13:39-0500 PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE Last-Translator: FULL NAME Language-Team: LANGUAGE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 。分類完成到期時間名稱選擇工作列表你的簡介使用者名稱和密碼不符。請再試。分類分類編輯簡介簡介工作mywebtodo-20080329/locale/zh_TW/LC_MESSAGES/djangojs.po0000644000175000000620000000216010730535737021424 0ustar trevorstaff# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2007-12-07 13:39-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" #: htdocs/js/todo.js:108 htdocs/js/todo.js.py:311 htdocs/js/todo.js.py:341 msgid "save" msgstr "儲存" #: htdocs/js/todo.js:137 msgid "edit" msgstr "編輯" #: htdocs/js/todo.js:207 msgid "saving..." msgstr "儲存中..." #: htdocs/js/todo.js:235 msgid "Create a new category..." msgstr "創造新分類..." #: htdocs/js/todo.js:264 msgid "Name of new category?" msgstr "新分類的名稱?" #: htdocs/js/todo.js:281 msgid "New name for category?" msgstr "分類的新名稱?" #: htdocs/js/todo.js:392 msgid "Delete this task?" msgstr "删除這個工作?" mywebtodo-20080329/locale/zh_TW/LC_MESSAGES/djangojs.mo0000644000175000000620000000133310730645240021411 0ustar trevorstaff\  !& +55k~ Create a new category...Delete this task?Name of new category?New name for category?editsavesaving...Project-Id-Version: PACKAGE VERSION Report-Msgid-Bugs-To: POT-Creation-Date: 2007-12-07 13:39-0500 PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE Last-Translator: FULL NAME Language-Team: LANGUAGE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 創造新分類...删除這個工作?新分類的名稱?分類的新名稱?編輯儲存儲存中...mywebtodo-20080329/locale/zh_TW/LC_MESSAGES/django.po0000644000175000000620000000626610730535737021102 0ustar trevorstaff# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2007-12-07 13:39-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" #: apps/accounts/models.py:14 msgid "profile" msgstr "簡介" #: apps/accounts/models.py:15 msgid "profiles" msgstr "簡介" #: apps/accounts/templates/registration/logged_out.html:8 msgid "Thanks for spending some quality time with the Web site today." msgstr "" #: apps/accounts/templates/registration/logged_out.html:10 msgid "." msgstr "。" #: apps/accounts/templates/registration/logged_out.html:10 msgid "Log in again" msgstr "" #: apps/accounts/templates/registration/login.html:3 #: apps/accounts/templates/registration/login.html:8 #: apps/todo/templates/todo/navbar.html:5 msgid "Log in" msgstr "" #: apps/accounts/templates/registration/login.html:11 msgid "Your username and password didn't match. Please try again." msgstr "使用者名稱和密碼不符。請再試。" #: apps/accounts/templates/registration/login.html:15 msgid "Username:" msgstr "" #: apps/accounts/templates/registration/login.html:19 msgid "Password:" msgstr "" #: apps/accounts/templates/registration/profile.html:3 msgid "Your profile" msgstr "你的簡介" #: apps/accounts/templates/registration/profile.html:8 msgid "Your account" msgstr "" #: apps/accounts/templates/registration/profile.html:10 #, python-format msgid "Hello, %(first_name)s." msgstr "" #: apps/accounts/templates/registration/profile.html:11 #, python-format msgid "Go to your task list." msgstr "" #: apps/todo/models.py:14 msgid "category" msgstr "分類" #: apps/todo/models.py:15 msgid "categories" msgstr "分類" #: apps/todo/models.py:34 apps/todo/models.py:35 msgid "task" msgstr "工作" #: apps/todo/templates/todo/index.html:3 #: apps/todo/templates/todo/index.html:10 msgid "Task List" msgstr "工作列表" #: apps/todo/templates/todo/index.html:5 msgid "Tasks due soonest" msgstr "" #: apps/todo/templates/todo/index.html:16 msgid "Done" msgstr "完成" #: apps/todo/templates/todo/index.html:17 #: apps/todo/templates/todo/view.html:15 msgid "Category" msgstr "分類" #: apps/todo/templates/todo/index.html:18 #: apps/todo/templates/todo/view.html:16 msgid "Name" msgstr "名稱" #: apps/todo/templates/todo/index.html:19 #: apps/todo/templates/todo/view.html:17 msgid "Due" msgstr "到期時間" #: apps/todo/templates/todo/index.html:30 #: apps/todo/templates/todo/view.html:24 msgid "Y-m-d H:i" msgstr "" #: apps/todo/templates/todo/index.html:32 msgid "edit" msgstr "編輯" #: apps/todo/templates/todo/navbar.html:7 msgid "Log out" msgstr "" #: apps/todo/templates/todo/navbar.html:19 msgid "Select" msgstr "選擇" #: apps/todo/templates/todo/view.html:3 apps/todo/templates/todo/view.html:9 #, python-format msgid "%(first_name)s's Task List" msgstr "" mywebtodo-20080329/urls.py0000644000175000000620000000134011014730104014521 0ustar trevorstafffrom django.conf.urls.defaults import * from django.views.i18n import javascript_catalog from django.views.generic.simple import redirect_to import settings _patterns = ( (r'^$', redirect_to, {'url': '/todo/'}), (r'^accounts/', include('apps.accounts.urls')), url(r'^jsi18n/$', javascript_catalog, {'packages': ''}, name='jsi18n'), (r'^todo/', include('apps.todo.urls')), ) if settings.DJANGO_DEVEL: _patterns += ( (r'^%s(?P.*)$' % settings.MEDIA_SERVER[1:], 'django.views.static.serve', { 'document_root': settings.PROJECT_ROOT + '/htdocs' } ), (r'^admin/', include('django.contrib.admin.urls')), ) urlpatterns = patterns('', *_patterns) mywebtodo-20080329/apps/0000755000175000000620000000000011014730207014133 5ustar trevorstaffmywebtodo-20080329/apps/accounts/0000755000175000000620000000000011014730207015752 5ustar trevorstaffmywebtodo-20080329/apps/accounts/models.py0000644000175000000620000000100310730535737017620 0ustar trevorstafffrom django.db import models from django.contrib.auth.models import User from django.utils.translation import ugettext_lazy as _ class Profile(models.Model): publish_calendar = models.BooleanField() user = models.ForeignKey(User, unique=True) name = models.CharField(max_length=128) class Admin: pass class Meta: verbose_name = _('profile') verbose_name_plural = _('profiles') ordering = ('name',) def __unicode__(self): return unicode(self.user) mywebtodo-20080329/apps/accounts/templates/0000755000175000000620000000000010773562064017767 5ustar trevorstaffmywebtodo-20080329/apps/accounts/templates/registration/0000755000175000000620000000000010773562064022501 5ustar trevorstaffmywebtodo-20080329/apps/accounts/templates/registration/login.html0000644000175000000620000000167710730535737024512 0ustar trevorstaff{% extends "base.html" %} {% load i18n %} {% block title %}{% trans "Log in" %}{% endblock %} {% block style %}accounts{% endblock %} {% block content %}

{% trans "Log in" %}

{% if form.has_errors %}

{% trans "Your username and password didn't match. Please try again." %}

{% endif %}
{{ form.username }}
{{ form.password }}
{% endblock %} mywebtodo-20080329/apps/accounts/templates/registration/profile.html0000644000175000000620000000100010730535737025016 0ustar trevorstaff{% extends "base.html" %} {% load i18n %} {% block title %}{% trans "Your profile" %}{% endblock %} {% block style %}accounts{% endblock %} {% block content %}

{% trans "Your account" %}

{% blocktrans with user.first_name as first_name %}Hello, {{ first_name }}.{% endblocktrans %} {% blocktrans %}Go to your task list.{% endblocktrans %}

{% endblock %} mywebtodo-20080329/apps/accounts/templates/registration/logged_out.html0000644000175000000620000000073010730535737025517 0ustar trevorstaff{% extends "base.html" %} {% load i18n %} {% block title %}{{ title }}{% endblock %} {% block style %}accounts{% endblock %} {% block content %}

{% trans "Thanks for spending some quality time with the Web site today." %}

{{ title }}{% trans "." %} {% trans "Log in again" %}{% trans "." %}

{% endblock %} mywebtodo-20080329/apps/accounts/urls.py0000644000175000000620000000124510730535737017332 0ustar trevorstafffrom django.conf.urls.defaults import * from django.contrib.auth.views import login, logout from django.core.urlresolvers import reverse from django.views.generic.simple import direct_to_template, redirect_to from django.views.i18n import set_language urlpatterns = patterns('', (r'^$', redirect_to, {'url': 'profile/'}), url(r'^i18n/$', set_language, name='accounts-i18n'), url(r'^login/', login, name='accounts-login'), url(r'^logout/$', logout, name='accounts-logout'), url(r'^profile/$', direct_to_template, { 'template': 'registration/profile.html', 'extra_context': {'todo': reverse('todo-index')}, }, name='accounts-profile'), ) mywebtodo-20080329/apps/accounts/__init__.py0000644000175000000620000000000010730535737020070 0ustar trevorstaffmywebtodo-20080329/apps/todo/0000755000175000000620000000000011014730207015100 5ustar trevorstaffmywebtodo-20080329/apps/todo/models.py0000644000175000000620000000174310730651521016747 0ustar trevorstafffrom django.db import models from django.contrib.auth.models import User from django.utils.translation import ugettext_lazy as _ class Category(models.Model): user = models.ForeignKey(User) name = models.CharField(max_length=256) class Admin: pass class Meta: verbose_name = _('category') verbose_name_plural = _('categories') ordering = ('name',) unique_together = ('user', 'name',) def __unicode__(self): return self.name class Task(models.Model): name = models.CharField(max_length=256) due = models.DateTimeField() done = models.BooleanField() user = models.ForeignKey(User) description = models.TextField(blank=True, null=True) category = models.ForeignKey(Category, blank=True, null=True) class Admin: pass class Meta: verbose_name = _('task') verbose_name_plural = _('task') ordering = ('name',) def __unicode__(self): return self.name mywebtodo-20080329/apps/todo/forms.py0000644000175000000620000000135510730651521016611 0ustar trevorstafffrom django import newforms as forms from apps.todo.models import Category, Task class SafeCharField(forms.CharField): import re _empty = re.compile(r'\s\+$').match _has_newlines = re.compile(r'[\n\r\v\f]').search def clean(self, value): super(SafeCharField, self).clean(value) if self._empty(value): raise forms.ValidationError(_('This field may not be empty.')) if self._has_newlines(value): raise forms.ValidationError(_('This field may not contain a \ newline.')) return value class CategoryForm(forms.ModelForm): name = SafeCharField(max_length=256) class Meta: model = Category class TaskForm(forms.ModelForm): class Meta: model = Task mywebtodo-20080329/apps/todo/templates/0000755000175000000620000000000010773562064017115 5ustar trevorstaffmywebtodo-20080329/apps/todo/templates/todo/0000755000175000000620000000000011014731320020040 5ustar trevorstaffmywebtodo-20080329/apps/todo/templates/todo/view.html0000644000175000000620000000316310730535740021717 0ustar trevorstaff{% extends "base.html" %} {% load i18n %} {% block title %}{% blocktrans with owner.first_name as first_name %}{{ first_name }}'s Task List{% endblocktrans %}{% endblock %} {% block style %}todo{% endblock %} {% block link %}{% endblock %} {% block content %}

{% blocktrans with owner.first_name as first_name %}{{ first_name }}'s Task List{% endblocktrans %}

{% include "todo/navbar.html" %}
{% for task in task_list %}
{% if task.category %}{{ task.category }}{% else %} {% endif %}
{{ task.name }}
{{ task.due|date:_("Y-m-d H:i") }}
{% endfor %}
Copyright © {% now "Y" %} Trevor Caira
{% endblock %} mywebtodo-20080329/apps/todo/templates/todo/index.html0000644000175000000620000000436511014731316022052 0ustar trevorstaff{% extends "base.html" %} {% load i18n %} {% block title %}{% trans "Task List" %}{% endblock %} {% block style %}todo{% endblock %} {% block link %} {% endblock %} {% block content %}

{% trans "Task List" %}

{% include "todo/navbar.html" %}
{% for task in task_list %}
{% if task.category %}{{ task.category }}{% else %}{% trans "uncategorized" %}{% endif %}
{{ task.name }}
{{ task.due|date:_("Y-m-d H:i") }}
{% endfor %}
Copyright © 2007-{% now "Y" %} Trevor Caira
{% include "todo/javascript.html" %} {% endblock %} mywebtodo-20080329/apps/todo/templates/todo/javascript.html0000644000175000000620000000070010730651521023101 0ustar trevorstaff{% load i18n %} mywebtodo-20080329/apps/todo/templates/todo/navbar.html0000644000175000000620000000130210730535740022207 0ustar trevorstaff{% load i18n %} mywebtodo-20080329/apps/todo/urls.py0000644000175000000620000000164010760263747016461 0ustar trevorstafffrom django.conf.urls.defaults import * from django.contrib.syndication.views import feed from apps.todo.models import Task from apps.todo.feeds import DueSoonest from apps.todo import views feeds = {'soonest': DueSoonest} username = r'(?P\w+)' urlpatterns = patterns('', url(r'^$', views.index, name='todo-index'), url(r'^view/%s/$' % username, views.view, name='todo-view'), url(r'^%s.xml$' % username, views.xml, name='todo-xml'), url(r'^%s.ics$' % username, views.icalendar, name='todo-ics'), url(r'^feeds/(?P.*)/$', feed, {'feed_dict': feeds}, name='todo-feed'), # Ajax url(r'^ajax/task/delete/$', views.delete_task, name='todo-ajax-task-delete'), url(r'^ajax/task/done/$', views.done_task, name='todo-ajax-task-done'), url(r'^ajax/task/edit/$', views.edit_task, name='todo-ajax-task-edit'), url(r'^ajax/task/new/$', views.new_task, name='todo-ajax-task-new'), ) mywebtodo-20080329/apps/todo/views.py0000644000175000000620000001275510730651521016626 0ustar trevorstafffrom django import http from django.contrib.auth.decorators import login_required from django.http import Http404, HttpResponse, HttpResponseRedirect from django.shortcuts import get_object_or_404 from django.views.generic.simple import direct_to_template from apps.todo.forms import CategoryForm, TaskForm from apps.todo.models import Category, Task from apps.accounts.models import Profile class FormError(Exception): pass def ajax(handler): def wrapper(request): from django.core.serializers.json import DjangoJSONEncoder from django.utils import simplejson if request.method != 'POST': return HttpResponseRedirect('/') try: json = simplejson.loads(request.raw_post_data) response = handler(request, json) if not response: response = {} status = 200 except (FormError, Http404), e: status = 400 response = e.args[:1] except Exception, e: status = 500 response = e.args return HttpResponse( simplejson.dumps(response, cls=DjangoJSONEncoder) + '\n', mimetype='application/json', status=status, ) return wrapper def public_access(handler): def wrapper(request, username): from django.contrib.auth.models import User task_list = Task.objects.filter( user__username=username, ).order_by('done', 'due') owner = get_object_or_404(User, username=username) profile = get_object_or_404(Profile, user__username=username) if not ((request.user.is_authenticated() and request.user.is_staff) or (request.user.id == owner.id) or profile.publish_calendar): raise Http404 return handler(request, owner, task_list) return wrapper def get_instances(json, owner, model): try: ids = list(json['ids']) except KeyError: raise FormError('required format of the data POST key is a JSON \ dictionary, which contains a key "ids" which maps to a list of ids (and \ possibly other data).') return model.objects.filter( id__in=ids, owner=owner, ) @public_access def view(request, owner, task_list): return direct_to_template( request, 'todo/view.html', extra_context={ 'owner': owner, 'task_list': task_list, }, ) @public_access def xml(request, owner, task_list): from django.core.serializers import serialize return HttpResponse( serialize('xml', task_list), mimetype='text/xml' ) def vtask(task): res = ['BEGIN:VTODO'] res += ['DUE:' + task.due.strftime('%Y%m%dT%H%M00')] if task.done: res += ['STATUS:COMPLETED'] else: res += ['STATUS:NEEDS-ACTION'] res += ['SUMMARY:' + task.name] res += ['END:VTODO'] return res @public_access def icalendar(request, owner, task_list): vcalendar = [ 'BEGIN:VCALENDAR', 'VERSION:2.0', 'PRODID:-//Caira Company//Task List 1.0//EN', ] for task in task_list: vcalendar += vtask(task) vcalendar += ['END:VCALENDAR'] return HttpResponse( '\n'.join(vcalendar), mimetype='text/calendar', ) @login_required def index(request): task_list = Task.objects.filter( user=request.user, ).order_by('done', 'due') categories = Category.objects.distinct().order_by('name') return direct_to_template( request, 'todo/index.html', extra_context={ 'categories': categories, 'task_list': task_list, }, ) @login_required def details(request, id): task = Task.objects.filter(user=request.user.id, id=id) return direct_to_template( request, 'todo/details.html', extra_context={ 'task': task, } ) def _get_task(request, id): return get_object_or_404(Task, id=id, user=request.user) def _get_or_insert_category(request, json): if not json['category']: return None category = Category.objects.filter(name=json['category']) if category: return category[0].id else: form_data = { 'name': json['category'], 'user': request.user.id, } form = CategoryForm(form_data) if form.is_valid(): return form.save().id raise FormError(form.errors) @login_required @ajax def new_task(request, json): category_id = _get_or_insert_category(request, json) json.update({'user': request.user.id, 'category': category_id}) form = TaskForm(json) if form.is_valid(): record = form.save() return {'id': record.id} raise FormError(form.errors) @login_required @ajax def edit_task(request, json): task = _get_task(request, json['id']) old_category = task.category count = Task.objects.filter(category=old_category).count() category_id = _get_or_insert_category(request, json) json.update({'user': request.user.id, 'category': category_id}) form = TaskForm(json, instance=task) if form.is_valid(): record = form.save() if count <= 1 and old_category: old_category.delete() else: raise FormError(form.errors) @login_required @ajax def delete_task(request, json): _get_task(request, json['id']).delete() @login_required @ajax def done_task(request, json): task = _get_task(request, json['id']) task.done = not task.done task.save() mywebtodo-20080329/apps/todo/__init__.py0000644000175000000620000000000010730535740017210 0ustar trevorstaffmywebtodo-20080329/apps/todo/feeds.py0000644000175000000620000000207110730535740016551 0ustar trevorstafffrom django.contrib.auth.models import User from django.contrib.syndication.feeds import Feed from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse from apps.todo.models import Task from apps.accounts.models import Profile class DueSoonest(Feed): title = 'Tasks due the soonest' description = 'Updates as tasks are checked off.' link = '/todo/' def get_object(self, bits): if len(bits) != 1: raise ObjectDoesNotExist try: username = bits[0] user = User.objects.filter(username=username)[0] profile = Profile.objects.filter(user__username=username)[0] if not profile.publish_calendar: raise ObjectDoesNotExist return user except IndexError: raise ObjectDoesNotExist def items(self, obj): return Task.objects.filter( user=obj.id, done=False, ).order_by('due')[:5] def item_link(self, item): return '/todo/view/' + item.user.username mywebtodo-20080329/apps/__init__.py0000644000175000000620000000000010730535740016243 0ustar trevorstaffmywebtodo-20080329/__init__.py0000644000175000000620000000000010730535741015301 0ustar trevorstaffmywebtodo-20080329/manage.py0000755000175000000620000000030210730535741015002 0ustar trevorstaff#!/usr/bin/python import os os.environ['DJANGO_DEVEL'] = '1' if __name__ == "__main__": from django.core.management import execute_manager import settings execute_manager(settings) mywebtodo-20080329/settings.py0000644000175000000620000000360711014727754015425 0ustar trevorstaff# encoding: utf-8 import os DJANGO_DEVEL = os.environ.get('DJANGO_DEVEL', '') == '1' DEBUG = DJANGO_DEVEL TEMPLATE_DEBUG = DEBUG ADMINS = (('Trevor Caira', 'trevor@caira.com'),) MANAGERS = ADMINS if DJANGO_DEVEL: PROJECT_ROOT = os.path.sep.join(__file__.split(os.path.sep)[:-1]) MEDIA_SERVER = '/static/' DATABASE_ENGINE = 'sqlite3' DATABASE_NAME = PROJECT_ROOT + 'localhost.db' SECRET_KEY = 'stn02oanQuLGi7ToWc3N3Icm/lr2kpJ8Vg80pRmg/9SgOLbwO6Y' else: import secret PROJECT_ROOT = '/var/www/my' MEDIA_SERVER = 'http://static.caira.com/' DATABASE_ENGINE = 'postgresql_psycopg2' DATABASE_NAME = 'my' DATABASE_USER = secret.USER DATABASE_PASSWORD = secret.PASSWORD SECRET_KEY = secret.KEY DATABASE_HOST = 'localhost' DATABASE_PORT = '5432' TIME_ZONE = 'America/New_York' LANGUAGE_CODE = 'en-us' USE_I18N = True LANGUAGES = ( ('en', u'English'), ('zh-tw', u'繁體中文'), ) MEDIA_ROOT = '' MEDIA_URL = MEDIA_SERVER ADMIN_MEDIA_PREFIX = MEDIA_SERVER + 'media/' TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.load_template_source', 'django.template.loaders.app_directories.load_template_source', # 'django.template.loaders.eggs.load_template_source', ) #CACHE_BACKEND = 'locmem:///' MIDDLEWARE_CLASSES = ( 'django.middleware.gzip.GZipMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.middleware.doc.XViewMiddleware', 'django.middleware.http.ConditionalGetMiddleware', ) ROOT_URLCONF = 'urls' TEMPLATE_DIRS = ( PROJECT_ROOT + '/templates', ) INSTALLED_APPS = ( 'apps.todo', 'apps.accounts', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.admin', ) mywebtodo-20080329/htdocs/0000755000175000000620000000000010773562175014476 5ustar trevorstaffmywebtodo-20080329/htdocs/css/0000755000175000000620000000000010773562064015263 5ustar trevorstaffmywebtodo-20080329/htdocs/css/todo.css0000644000175000000620000000415310730651521016733 0ustar trevorstaff@import url('common.css'); body.todo { background: #fffaf0; } .todo h1 { margin-bottom: .5em; } .todo input { border-color: #191970; color: #191970; background: #f8f8ff; } .todo .autocomplete { background:#FFFFFF none repeat scroll 0%; border: black solid 0; border-left-width: 1px; border-right-width: 1px; border-bottom-width: 1px; } .todo .autocomplete ul { list-style-type: none; } .todo #title { margin-left: auto; margin-right: auto; margin-bottom: 2em; border-width: 0 1px 1px 1px; border-style: solid; border-color: #5F9EA0; padding: 1em; background: #e7f3ff; } .todo .links { font-family: sans-serif; margin-bottom: .25em; width: 50%; float: left; } .todo form.change-language { width: 50%; float: right; text-align: right; } .todo .navbar { overflow: hidden; } .todo .small { width: 41em; } .todo .big { width: 49em; } .todo #container { margin-top: 1.5em; margin: auto; } .todo #list { border: 1px solid #191970; clear: both; float: left; margin: auto; margin-bottom: 1em; } .todo #head { font-weight: bold; background: #ffe4c4; padding-top: .25em; padding-bottom: .25em; padding-left: .5em; } .todo #content { padding-top: .25em; padding-left: .5em; padding-bottom: .5em; background: #ffffe0; } .todo #list .task { float: left; clear: both; padding: .25em 0; } .todo #list .done-field { float: left; width: 4em; } .todo #list .category-field { float: left; width: 13em; } .todo #list .category-field select { width: 14em; } .todo #list .name { float: left; width: 15em; font-weight: bold; font-size: 11pt; } .todo #list .name input { font-weight: bold; width: 17em; } .todo #list .due { float: left; width: 12em; } .todo #list .due input { width: 12em; } .todo #list .buttons { float: left; width: 4em; } .todo #list .errors { font-weight: bold; color: red; padding: .25em 0; } .todo #new { clear: both; } .todo #new input { margin-top: 1em; } .todo address { text-align: center; margin-top: 1.5em; font-size: 90%; } .todo .done { text-decoration: line-through; } .todo .empty { color: gray; } mywebtodo-20080329/htdocs/css/common.css0000644000175000000620000000017410730535740017261 0ustar trevorstaff* { margin: 0; padding: 0; } h1 { text-align: center; } input { border: 1px solid #ccc; vertical-align: middle; } mywebtodo-20080329/htdocs/css/accounts.css0000644000175000000620000000170310730535740017607 0ustar trevorstaff@import url('common.css'); body.accounts { background: #eee; } .accounts .errors td { font-weight: bold; color: red; } .accounts .label-input { padding: 4px 0; float: left; width: 100%; } .accounts .label-input label { font-weight: bold; float: left; width: 9em; padding-right: 0.5em; vertical-align: middle; text-align: right; font-size: 1em; color: #333; } .accounts .label-input input { float: left; width: 14em; } .accounts .label-input #id_username, .label-input #id_password { width:14em; } .accounts .submit-row { padding: 1em 0 0 9.4em; text-align: right; } .accounts h1 { font-size: 150%; padding: .25em; background: #417690; color: #ffc; } .accounts #container { background: white; border: 1px solid #ccc; width: 28em; min-width: 300px; margin-left: auto; margin-right: auto; margin-top: 100px; } .accounts .content { margin: 1em 0; padding: 0 2em; } .accounts .errors { margin: 1em; } mywebtodo-20080329/htdocs/img/0000755000175000000620000000000010773562064015247 5ustar trevorstaffmywebtodo-20080329/htdocs/img/checkbox.gif0000644000175000000620000000075710730535740017527 0ustar trevorstaffGIF89aA=3pnf Tx)aPNqi@6rQH R쪥]T/$eF Ãǁ;mywebtodo-20080329/htdocs/media0000777000175000000620000000000011014727567031504 2/usr/local/lib/python2.5/site-packages/django/contrib/admin/mediaustar trevorstaffmywebtodo-20080329/htdocs/js/0000755000175000000620000000000011014731351015071 5ustar trevorstaffmywebtodo-20080329/htdocs/js/formatDate.js0000644000175000000620000003021110730535741017523 0ustar trevorstaff// formatDate : // a PHP date like function, for formatting date strings // authored by Svend Tofte // the code is in the public domain // // see http://www.svendtofte.com/code/date_format/ // and http://www.php.net/date // // thanks to // - Daniel Berlin , // major overhaul and improvements // - Matt Bannon, // correcting some stupid bugs in my days-in-the-months list! // // input : format string // time : epoch time (seconds, and optional) // // if time is not passed, formatting is based on // the current "this" date object's set time. // // supported switches are // a, A, B, c, d, D, F, g, G, h, H, i, I (uppercase i), j, l (lowecase L), // L, m, M, n, N, O, P, r, s, S, t, U, w, W, y, Y, z, Z // // unsupported (as compared to date in PHP 5.1.3) // T, e, o Date.prototype.formatDate = function (input,time) { var daysLong = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; var daysShort = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; var monthsShort = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; var monthsLong = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; var switches = { // switches object a : function () { // Lowercase Ante meridiem and Post meridiem return date.getHours() > 11? "pm" : "am"; }, A : function () { // Uppercase Ante meridiem and Post meridiem return (this.a().toUpperCase ()); }, B : function (){ // Swatch internet time. code simply grabbed from ppk, // since I was feeling lazy: // http://www.xs4all.nl/~ppk/js/beat.html var off = (date.getTimezoneOffset() + 60)*60; var theSeconds = (date.getHours() * 3600) + (date.getMinutes() * 60) + date.getSeconds() + off; var beat = Math.floor(theSeconds/86.4); if (beat > 1000) beat -= 1000; if (beat < 0) beat += 1000; if ((String(beat)).length == 1) beat = "00"+beat; if ((String(beat)).length == 2) beat = "0"+beat; return beat; }, c : function () { // ISO 8601 date (e.g.: "2004-02-12T15:19:21+00:00"), as per // http://www.cl.cam.ac.uk/~mgk25/iso-time.html return (this.Y() + "-" + this.m() + "-" + this.d() + "T" + this.h() + ":" + this.i() + ":" + this.s() + this.P()); }, d : function () { // Day of the month, 2 digits with leading zeros var j = String(this.j()); return (j.length == 1 ? "0"+j : j); }, D : function () { // A textual representation of a day, three letters return daysShort[date.getDay()]; }, F : function () { // A full textual representation of a month return monthsLong[date.getMonth()]; }, g : function () { // 12-hour format of an hour without leading zeros return date.getHours() > 12? date.getHours()-12 : date.getHours(); }, G : function () { // 24-hour format of an hour without leading zeros return date.getHours(); }, h : function () { // 12-hour format of an hour with leading zeros var g = String(this.g()); return (g.length == 1 ? "0"+g : g); }, H : function () { // 24-hour format of an hour with leading zeros var G = String(this.G()); return (G.length == 1 ? "0"+G : G); }, i : function () { // Minutes with leading zeros var min = String (date.getMinutes ()); return (min.length == 1 ? "0" + min : min); }, I : function () { // Whether or not the date is in daylight saving time (DST) // note that this has no bearing in actual DST mechanics, // and is just a pure guess. buyer beware. var noDST = new Date ("January 1 " + this.Y() + " 00:00:00"); return (noDST.getTimezoneOffset () == date.getTimezoneOffset () ? 0 : 1); }, j : function () { // Day of the month without leading zeros return date.getDate(); }, l : function () { // A full textual representation of the day of the week return daysLong[date.getDay()]; }, L : function () { // leap year or not. 1 if leap year, 0 if not. // the logic should match iso's 8601 standard. // http://www.uic.edu/depts/accc/software/isodates/leapyear.html var Y = this.Y(); if ( (Y % 4 == 0 && Y % 100 != 0) || (Y % 4 == 0 && Y % 100 == 0 && Y % 400 == 0) ) { return 1; } else { return 0; } }, m : function () { // Numeric representation of a month, with leading zeros var n = String(this.n()); return (n.length == 1 ? "0"+n : n); }, M : function () { // A short textual representation of a month, three letters return monthsShort[date.getMonth()]; }, n : function () { // Numeric representation of a month, without leading zeros return date.getMonth()+1; }, N : function () { // ISO-8601 numeric representation of the day of the week var w = this.w(); return (w == 0 ? 7 : w); }, O : function () { // Difference to Greenwich time (GMT) in hours var os = Math.abs(date.getTimezoneOffset()); var h = String(Math.floor(os/60)); var m = String(os%60); h.length == 1? h = "0"+h:1; m.length == 1? m = "0"+m:1; return date.getTimezoneOffset() < 0 ? "+"+h+m : "-"+h+m; }, P : function () { // Difference to GMT, with colon between hours and minutes var O = this.O(); return (O.substr(0, 3) + ":" + O.substr(3, 2)); }, r : function () { // RFC 822 formatted date var r; // result // Thu , 21 Dec 2000 r = this.D() + ", " + this.d() + " " + this.M() + " " + this.Y() + // 16 : 01 : 07 0200 " " + this.H() + ":" + this.i() + ":" + this.s() + " " + this.O(); return r; }, s : function () { // Seconds, with leading zeros var sec = String (date.getSeconds ()); return (sec.length == 1 ? "0" + sec : sec); }, S : function () { // English ordinal suffix for the day of the month, 2 characters switch (date.getDate ()) { case 1: return ("st"); case 2: return ("nd"); case 3: return ("rd"); case 21: return ("st"); case 22: return ("nd"); case 23: return ("rd"); case 31: return ("st"); default: return ("th"); } }, t : function () { // thanks to Matt Bannon for some much needed code-fixes here! var daysinmonths = [null,31,28,31,30,31,30,31,31,30,31,30,31]; if (this.L()==1 && this.n()==2) return 29; // ~leap day return daysinmonths[this.n()]; }, U : function () { // Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) return Math.round(date.getTime()/1000); }, w : function () { // Numeric representation of the day of the week return date.getDay(); }, W : function () { // Weeknumber, as per ISO specification: // http://www.cl.cam.ac.uk/~mgk25/iso-time.html var DoW = this.N (); var DoY = this.z (); // If the day is 3 days before New Year's Eve and is Thursday or earlier, // it's week 1 of next year. var daysToNY = 364 + this.L () - DoY; if (daysToNY <= 2 && DoW <= (3 - daysToNY)) { return 1; } // If the day is within 3 days after New Year's Eve and is Friday or later, // it belongs to the old year. if (DoY <= 2 && DoW >= 5) { return new Date (this.Y () - 1, 11, 31).formatDate ("W"); } var nyDoW = new Date (this.Y (), 0, 1).getDay (); nyDoW = nyDoW != 0 ? nyDoW - 1 : 6; if (nyDoW <= 3) { // First day of the year is a Thursday or earlier return (1 + Math.floor ((DoY + nyDoW) / 7)); } else { // First day of the year is a Friday or later return (1 + Math.floor ((DoY - (7 - nyDoW)) / 7)); } }, y : function () { // A two-digit representation of a year var y = String(this.Y()); return y.substring(y.length-2,y.length); }, Y : function () { // A full numeric representation of a year, 4 digits // we first check, if getFullYear is supported. if it // is, we just use that. ppks code is nice, but wont // work with dates outside 1900-2038, or something like that if (date.getFullYear) { var newDate = new Date("January 1 2001 00:00:00 +0000"); var x = newDate .getFullYear(); if (x == 2001) { // i trust the method now return date.getFullYear(); } } // else, do this: // codes thanks to ppk: // http://www.xs4all.nl/~ppk/js/introdate.html var x = date.getYear(); var y = x % 100; y += (y < 38) ? 2000 : 1900; return y; }, z : function () { // The day of the year, zero indexed! 0 through 366 var t = new Date("January 1 " + this.Y() + " 00:00:00"); var diff = date.getTime() - t.getTime(); return Math.floor(diff/1000/60/60/24); }, Z : function () { // Timezone offset in seconds return (date.getTimezoneOffset () * -60); } } function getSwitch(str) { if (switches[str] != undefined) { return switches[str](); } else { return str; } } var date; if (time) { var date = new Date (time); } else { var date = this; } var formatString = input.split(""); var i = 0; while (i < formatString.length) { if (formatString[i] == "\\") { // this is our way of allowing users to escape stuff formatString.splice(i,1); } else { formatString[i] = getSwitch(formatString[i]); } i++; } return formatString.join(""); } // Some (not all) predefined format strings from PHP 5.1.1, which // offer standard date representations. // See: http://www.php.net/manual/en/ref.datetime.php#datetime.constants // // Atom "2005-08-15T15:52:01+00:00" Date.DATE_ATOM = "Y-m-d\\TH:i:sP"; // ISO-8601 "2005-08-15T15:52:01+0000" Date.DATE_ISO8601 = "Y-m-d\\TH:i:sO"; // RFC 2822 "Mon, 15 Aug 2005 15:52:01 +0000" Date.DATE_RFC2822 = "D, d M Y H:i:s O"; // W3C "2005-08-15T15:52:01+00:00" Date.DATE_W3C = "Y-m-d\\TH:i:sP"; mywebtodo-20080329/htdocs/js/todo.js0000644000175000000620000002324111014731303016373 0ustar trevorstaffvar Todo = function() { this._editing = {}; this._last_new_id = 0; this._get_task_attributes = function(row) { return { row: row, checkbox: row.childElements()[0].childElements()[0], category: row.childElements()[1], name: row.childElements()[2], due: row.childElements()[3], button: row.childElements()[4].childElements()[0], x: row.childElements()[4].childElements()[1], }; }; this._get_elements = function(id) { return this._get_task_attributes($('task-' + id)); }; this._set_strikethrough = function(elements, enabled) { [ elements.category, elements.due, elements.name, ].invoke(enabled? 'addClassName': 'removeClassName', 'done'); }; this._reset_strikethrough = function(id) { if (this._editing[id]) { return; } var elements = this._get_elements(id); this._set_strikethrough(elements, elements.checkbox.checked); }; this._event_id = function(el) { return el.parentNode.parentNode.id.replace('task-', ''); }; this._get_error_row = function(id) { this._remove_error_row(id); var error_row = '' + '
' + '
 
' + '
 
' + '
 
' + '
 
' + '
'; new Insertion.After(id, error_row); return 'errors-' + id; }; this._handle_form_errors = function(id, errors) { var errors = errors[0]; var error_row_id = this._get_error_row(id); var elements = this._get_elements(id); var error_row_elements = this._get_elements(error_row_id); for (k in errors) { error_row_elements[k].innerHTML = errors[k]; } elements.button.value = gettext('save'); elements.button.disabled = ""; }; this._remove_error_row = function(id) { error_row = $('errors-' + id); if (error_row) { error_row.parentNode.removeChild(error_row); } }; this._get_selected = function(el) { option = el.options[el.selectedIndex]; return isNaN(parseInt(option.value))? {value: null, innerHTML: null}: option; }; this._stop_editing = function(id) { var elements = this._get_elements(id); delete this._editing[id]; if (elements.category.firstChild.value) { elements.category.innerHTML = elements.category.firstChild.value; } else { elements.category.innerHTML = gettext('uncategorized'); elements.category.addClassName('empty'); } elements.name.innerHTML = elements.name.firstChild.value; elements.due.innerHTML = elements.due.firstChild.value; elements.button.value = gettext('edit'); elements.button.disabled = ''; this._reset_strikethrough(id); }; this._save_new = function(id, fields) { var _todo = this; new Ajax.Request(urls['task-new'], { postBody: Object.toJSON(fields), onSuccess: function(o) { response = o.responseText.evalJSON(true); _todo._get_elements(id).row.id = 'task-' + response.id; _todo._stop_editing(response.id); _todo._remove_error_row(id); }, onFailure: function(o) { response = o.responseText.evalJSON(true); _todo._handle_form_errors(id, response); } }); }; this._save_edits = function(id, fields) { var _todo = this; new Ajax.Request(urls['task-edit'], { postBody: Object.toJSON({ id: id, category: fields.category, name: fields.name, due: fields.due, }), onSuccess: function(o) { _todo._stop_editing(id); _todo._remove_error_row(id); }, onFailure: function(o) { response = o.responseText.evalJSON(true); _todo._handle_form_errors(id, response); }, }); }; this._unsaved = function(id) { return id.indexOf('new') == 0; } this._changed = function(id) { var elements = this._get_elements(id); var old_value = this._editing[id]; var category = elements.category.firstChild.value; var name = elements.name.firstChild.value; var due = elements.due.firstChild.value; return old_value && ( old_value.name != name || old_value.due != due || old_value.category != category ); }; this._save = function(id) { var elements = this._get_elements(id); var fields = { category: elements.category.firstChild.value, name: elements.name.firstChild.value, due: elements.due.firstChild.value, done: elements.checkbox.checked == true, }; if (!this._unsaved(id) && !this._changed(id)) { this._stop_editing(id); return; } elements.button.value = gettext('saving...'); elements.button.disabled = 'disabled'; if (this._unsaved(id)) { this._save_new(id, fields); } else { this._save_edits(id, fields); } }; this._on_input_keypress = function(_todo) { return function(kp) { if (kp.keyCode == 13) { _todo._save(_todo._event_id(this)); } } }; this._edit = function(id) { var elements = this._get_elements(id); var category = elements.category.innerHTML == gettext('uncategorized')? '': elements.category.innerHTML; this._editing[id] = { category: category, name: elements.name.innerHTML, due: elements.due.innerHTML, }; elements.category.innerHTML = ""; elements.name.innerHTML = ""; elements.due.innerHTML = ""; elements.button.value = gettext('save'); this._set_strikethrough(elements, false); }; this._new_task = function() { var checkbox = document.createElement('input'); checkbox.type = 'checkbox'; var done_field = document.createElement('div'); done_field.addClassName('done-field'); done_field.appendChild(checkbox); var category_field = document.createElement('div'); category_field.addClassName('category-field'); var name = document.createElement('div'); name.addClassName('name'); var due = document.createElement('div'); due.addClassName('due'); now = new Date().formatDate('Y-m-d H:i'); due.appendChild(document.createTextNode(now)); var edit = document.createElement('input'); edit.type = 'button'; edit.value = gettext('edit'); var x = document.createElement('input'); x.type = 'button'; x.value = 'X'; var buttons = document.createElement('div'); buttons.addClassName('buttons'); buttons.appendChild(edit); buttons.appendChild(document.createTextNode(' ')); buttons.appendChild(x); var id = 'new' + this._last_new_id++; var new_row = document.createElement('div'); new_row.id = 'task-' + id; new_row.addClassName('task'); new_row.appendChild(done_field); new_row.appendChild(category_field); new_row.appendChild(name); new_row.appendChild(due); new_row.appendChild(buttons); this.bind_events(this._get_task_attributes(new_row)); Element.insert('new', {before: new_row}); this._edit(id); }; this._edit_field = function(field) { return function(el) { var id = el.parentNode.id.replace('task-', ''); if (!this._editing[id]) { this._edit(id); this._get_elements(id)[field].childElements()[0].focus(); } }; }; this._remove_task = function(id) { var elements = this._get_elements(id); elements.row.parentNode.removeChild(elements.row); this._remove_error_row(id); }; this.toggle_done = function(el) { var id = this._event_id(el); var elements = this._get_elements(id); if (this._unsaved(id)) { return; } this._reset_strikethrough(id); new Ajax.Request(urls['task-done'], { postBody: Object.toJSON({id: id}), }); }; this.edit_category = this._edit_field('category'); this.edit_name = this._edit_field('name'); this.edit_due = this._edit_field('due'); this.toggle_editing = function(el) { var id = this._event_id(el); if (this._editing[id]) { this._save(id); } else { this._edit(id); } }; /* * If you just added it and didn't change anything, just remove it. * Otherwise, confirm you want to delete it. * If it's unsaved, just remove it. * Otherwise, tell the server it needs to go and remove it. */ this.delete_task = function(el) { var id = this._event_id(el); var elements = this._get_elements(id); var unsaved = this._unsaved(id); var changed = this._changed(id); if (unsaved && !changed) { this._remove_task(id); return; } if (!confirm (gettext('Delete this task?'))) { return; } /* TODO: handle error */ elements.row.parentNode.removeChild(elements.row); this._remove_error_row(id); if (!this._unsaved(id)) { new Ajax.Request(urls['task-delete'], { postBody: Object.toJSON({id: id}), }); } }; this.bind_events = function(elements) { var _todo = this; [ ['checkbox', 'click', 'toggle_done'], ['category', 'dblclick', 'edit_category'], ['name', 'dblclick', 'edit_name'], ['due', 'dblclick', 'edit_due'], ['button', 'click', 'toggle_editing'], ['x', 'click', 'delete_task'], ].each(function(evt) { Event.observe(elements[evt[0]], evt[1], function() { _todo[evt[2]](this); }); }); }; } todo = new Todo(); $$('#list .task').each(function(el) { todo.bind_events(todo._get_task_attributes(el)); }); Event.observe('new-task', 'click', function() {todo._new_task();}); mywebtodo-20080329/htdocs/js/prototype.js0000644000175000000620000036235010731230170017503 0ustar trevorstaff/* Prototype JavaScript framework, version 1.6.0 * (c) 2005-2007 Sam Stephenson * * Prototype is freely distributable under the terms of an MIT-style license. * For details, see the Prototype web site: http://www.prototypejs.org/ * *--------------------------------------------------------------------------*/ var Prototype = { Version: '1.6.0', Browser: { IE: !!(window.attachEvent && !window.opera), Opera: !!window.opera, WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1, Gecko: navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1, MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/) }, BrowserFeatures: { XPath: !!document.evaluate, ElementExtensions: !!window.HTMLElement, SpecificElementExtensions: document.createElement('div').__proto__ && document.createElement('div').__proto__ !== document.createElement('form').__proto__ }, ScriptFragment: ']*>([\\S\\s]*?)<\/script>', JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/, emptyFunction: function() { }, K: function(x) { return x } }; if (Prototype.Browser.MobileSafari) Prototype.BrowserFeatures.SpecificElementExtensions = false; if (Prototype.Browser.WebKit) Prototype.BrowserFeatures.XPath = false; /* Based on Alex Arnell's inheritance implementation. */ var Class = { create: function() { var parent = null, properties = $A(arguments); if (Object.isFunction(properties[0])) parent = properties.shift(); function klass() { this.initialize.apply(this, arguments); } Object.extend(klass, Class.Methods); klass.superclass = parent; klass.subclasses = []; if (parent) { var subclass = function() { }; subclass.prototype = parent.prototype; klass.prototype = new subclass; parent.subclasses.push(klass); } for (var i = 0; i < properties.length; i++) klass.addMethods(properties[i]); if (!klass.prototype.initialize) klass.prototype.initialize = Prototype.emptyFunction; klass.prototype.constructor = klass; return klass; } }; Class.Methods = { addMethods: function(source) { var ancestor = this.superclass && this.superclass.prototype; var properties = Object.keys(source); if (!Object.keys({ toString: true }).length) properties.push("toString", "valueOf"); for (var i = 0, length = properties.length; i < length; i++) { var property = properties[i], value = source[property]; if (ancestor && Object.isFunction(value) && value.argumentNames().first() == "$super") { var method = value, value = Object.extend((function(m) { return function() { return ancestor[m].apply(this, arguments) }; })(property).wrap(method), { valueOf: function() { return method }, toString: function() { return method.toString() } }); } this.prototype[property] = value; } return this; } }; var Abstract = { }; Object.extend = function(destination, source) { for (var property in source) destination[property] = source[property]; return destination; }; Object.extend(Object, { inspect: function(object) { try { if (object === undefined) return 'undefined'; if (object === null) return 'null'; return object.inspect ? object.inspect() : object.toString(); } catch (e) { if (e instanceof RangeError) return '...'; throw e; } }, toJSON: function(object) { var type = typeof object; switch (type) { case 'undefined': case 'function': case 'unknown': return; case 'boolean': return object.toString(); } if (object === null) return 'null'; if (object.toJSON) return object.toJSON(); if (Object.isElement(object)) return; var results = []; for (var property in object) { var value = Object.toJSON(object[property]); if (value !== undefined) results.push(property.toJSON() + ': ' + value); } return '{' + results.join(', ') + '}'; }, toQueryString: function(object) { return $H(object).toQueryString(); }, toHTML: function(object) { return object && object.toHTML ? object.toHTML() : String.interpret(object); }, keys: function(object) { var keys = []; for (var property in object) keys.push(property); return keys; }, values: function(object) { var values = []; for (var property in object) values.push(object[property]); return values; }, clone: function(object) { return Object.extend({ }, object); }, isElement: function(object) { return object && object.nodeType == 1; }, isArray: function(object) { return object && object.constructor === Array; }, isHash: function(object) { return object instanceof Hash; }, isFunction: function(object) { return typeof object == "function"; }, isString: function(object) { return typeof object == "string"; }, isNumber: function(object) { return typeof object == "number"; }, isUndefined: function(object) { return typeof object == "undefined"; } }); Object.extend(Function.prototype, { argumentNames: function() { var names = this.toString().match(/^[\s\(]*function[^(]*\((.*?)\)/)[1].split(",").invoke("strip"); return names.length == 1 && !names[0] ? [] : names; }, bind: function() { if (arguments.length < 2 && arguments[0] === undefined) return this; var __method = this, args = $A(arguments), object = args.shift(); return function() { return __method.apply(object, args.concat($A(arguments))); } }, bindAsEventListener: function() { var __method = this, args = $A(arguments), object = args.shift(); return function(event) { return __method.apply(object, [event || window.event].concat(args)); } }, curry: function() { if (!arguments.length) return this; var __method = this, args = $A(arguments); return function() { return __method.apply(this, args.concat($A(arguments))); } }, delay: function() { var __method = this, args = $A(arguments), timeout = args.shift() * 1000; return window.setTimeout(function() { return __method.apply(__method, args); }, timeout); }, wrap: function(wrapper) { var __method = this; return function() { return wrapper.apply(this, [__method.bind(this)].concat($A(arguments))); } }, methodize: function() { if (this._methodized) return this._methodized; var __method = this; return this._methodized = function() { return __method.apply(null, [this].concat($A(arguments))); }; } }); Function.prototype.defer = Function.prototype.delay.curry(0.01); Date.prototype.toJSON = function() { return '"' + this.getUTCFullYear() + '-' + (this.getUTCMonth() + 1).toPaddedString(2) + '-' + this.getUTCDate().toPaddedString(2) + 'T' + this.getUTCHours().toPaddedString(2) + ':' + this.getUTCMinutes().toPaddedString(2) + ':' + this.getUTCSeconds().toPaddedString(2) + 'Z"'; }; var Try = { these: function() { var returnValue; for (var i = 0, length = arguments.length; i < length; i++) { var lambda = arguments[i]; try { returnValue = lambda(); break; } catch (e) { } } return returnValue; } }; RegExp.prototype.match = RegExp.prototype.test; RegExp.escape = function(str) { return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1'); }; /*--------------------------------------------------------------------------*/ var PeriodicalExecuter = Class.create({ initialize: function(callback, frequency) { this.callback = callback; this.frequency = frequency; this.currentlyExecuting = false; this.registerCallback(); }, registerCallback: function() { this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000); }, execute: function() { this.callback(this); }, stop: function() { if (!this.timer) return; clearInterval(this.timer); this.timer = null; }, onTimerEvent: function() { if (!this.currentlyExecuting) { try { this.currentlyExecuting = true; this.execute(); } finally { this.currentlyExecuting = false; } } } }); Object.extend(String, { interpret: function(value) { return value == null ? '' : String(value); }, specialChar: { '\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '\\': '\\\\' } }); Object.extend(String.prototype, { gsub: function(pattern, replacement) { var result = '', source = this, match; replacement = arguments.callee.prepareReplacement(replacement); while (source.length > 0) { if (match = source.match(pattern)) { result += source.slice(0, match.index); result += String.interpret(replacement(match)); source = source.slice(match.index + match[0].length); } else { result += source, source = ''; } } return result; }, sub: function(pattern, replacement, count) { replacement = this.gsub.prepareReplacement(replacement); count = count === undefined ? 1 : count; return this.gsub(pattern, function(match) { if (--count < 0) return match[0]; return replacement(match); }); }, scan: function(pattern, iterator) { this.gsub(pattern, iterator); return String(this); }, truncate: function(length, truncation) { length = length || 30; truncation = truncation === undefined ? '...' : truncation; return this.length > length ? this.slice(0, length - truncation.length) + truncation : String(this); }, strip: function() { return this.replace(/^\s+/, '').replace(/\s+$/, ''); }, stripTags: function() { return this.replace(/<\/?[^>]+>/gi, ''); }, stripScripts: function() { return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), ''); }, extractScripts: function() { var matchAll = new RegExp(Prototype.ScriptFragment, 'img'); var matchOne = new RegExp(Prototype.ScriptFragment, 'im'); return (this.match(matchAll) || []).map(function(scriptTag) { return (scriptTag.match(matchOne) || ['', ''])[1]; }); }, evalScripts: function() { return this.extractScripts().map(function(script) { return eval(script) }); }, escapeHTML: function() { var self = arguments.callee; self.text.data = this; return self.div.innerHTML; }, unescapeHTML: function() { var div = new Element('div'); div.innerHTML = this.stripTags(); return div.childNodes[0] ? (div.childNodes.length > 1 ? $A(div.childNodes).inject('', function(memo, node) { return memo+node.nodeValue }) : div.childNodes[0].nodeValue) : ''; }, toQueryParams: function(separator) { var match = this.strip().match(/([^?#]*)(#.*)?$/); if (!match) return { }; return match[1].split(separator || '&').inject({ }, function(hash, pair) { if ((pair = pair.split('='))[0]) { var key = decodeURIComponent(pair.shift()); var value = pair.length > 1 ? pair.join('=') : pair[0]; if (value != undefined) value = decodeURIComponent(value); if (key in hash) { if (!Object.isArray(hash[key])) hash[key] = [hash[key]]; hash[key].push(value); } else hash[key] = value; } return hash; }); }, toArray: function() { return this.split(''); }, succ: function() { return this.slice(0, this.length - 1) + String.fromCharCode(this.charCodeAt(this.length - 1) + 1); }, times: function(count) { return count < 1 ? '' : new Array(count + 1).join(this); }, camelize: function() { var parts = this.split('-'), len = parts.length; if (len == 1) return parts[0]; var camelized = this.charAt(0) == '-' ? parts[0].charAt(0).toUpperCase() + parts[0].substring(1) : parts[0]; for (var i = 1; i < len; i++) camelized += parts[i].charAt(0).toUpperCase() + parts[i].substring(1); return camelized; }, capitalize: function() { return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase(); }, underscore: function() { return this.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'#{1}_#{2}').gsub(/([a-z\d])([A-Z])/,'#{1}_#{2}').gsub(/-/,'_').toLowerCase(); }, dasherize: function() { return this.gsub(/_/,'-'); }, inspect: function(useDoubleQuotes) { var escapedString = this.gsub(/[\x00-\x1f\\]/, function(match) { var character = String.specialChar[match[0]]; return character ? character : '\\u00' + match[0].charCodeAt().toPaddedString(2, 16); }); if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"'; return "'" + escapedString.replace(/'/g, '\\\'') + "'"; }, toJSON: function() { return this.inspect(true); }, unfilterJSON: function(filter) { return this.sub(filter || Prototype.JSONFilter, '#{1}'); }, isJSON: function() { var str = this.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, ''); return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str); }, evalJSON: function(sanitize) { var json = this.unfilterJSON(); try { if (!sanitize || json.isJSON()) return eval('(' + json + ')'); } catch (e) { } throw new SyntaxError('Badly formed JSON string: ' + this.inspect()); }, include: function(pattern) { return this.indexOf(pattern) > -1; }, startsWith: function(pattern) { return this.indexOf(pattern) === 0; }, endsWith: function(pattern) { var d = this.length - pattern.length; return d >= 0 && this.lastIndexOf(pattern) === d; }, empty: function() { return this == ''; }, blank: function() { return /^\s*$/.test(this); }, interpolate: function(object, pattern) { return new Template(this, pattern).evaluate(object); } }); if (Prototype.Browser.WebKit || Prototype.Browser.IE) Object.extend(String.prototype, { escapeHTML: function() { return this.replace(/&/g,'&').replace(//g,'>'); }, unescapeHTML: function() { return this.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>'); } }); String.prototype.gsub.prepareReplacement = function(replacement) { if (Object.isFunction(replacement)) return replacement; var template = new Template(replacement); return function(match) { return template.evaluate(match) }; }; String.prototype.parseQuery = String.prototype.toQueryParams; Object.extend(String.prototype.escapeHTML, { div: document.createElement('div'), text: document.createTextNode('') }); with (String.prototype.escapeHTML) div.appendChild(text); var Template = Class.create({ initialize: function(template, pattern) { this.template = template.toString(); this.pattern = pattern || Template.Pattern; }, evaluate: function(object) { if (Object.isFunction(object.toTemplateReplacements)) object = object.toTemplateReplacements(); return this.template.gsub(this.pattern, function(match) { if (object == null) return ''; var before = match[1] || ''; if (before == '\\') return match[2]; var ctx = object, expr = match[3]; var pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/, match = pattern.exec(expr); if (match == null) return before; while (match != null) { var comp = match[1].startsWith('[') ? match[2].gsub('\\\\]', ']') : match[1]; ctx = ctx[comp]; if (null == ctx || '' == match[3]) break; expr = expr.substring('[' == match[3] ? match[1].length : match[0].length); match = pattern.exec(expr); } return before + String.interpret(ctx); }.bind(this)); } }); Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/; var $break = { }; var Enumerable = { each: function(iterator, context) { var index = 0; iterator = iterator.bind(context); try { this._each(function(value) { iterator(value, index++); }); } catch (e) { if (e != $break) throw e; } return this; }, eachSlice: function(number, iterator, context) { iterator = iterator ? iterator.bind(context) : Prototype.K; var index = -number, slices = [], array = this.toArray(); while ((index += number) < array.length) slices.push(array.slice(index, index+number)); return slices.collect(iterator, context); }, all: function(iterator, context) { iterator = iterator ? iterator.bind(context) : Prototype.K; var result = true; this.each(function(value, index) { result = result && !!iterator(value, index); if (!result) throw $break; }); return result; }, any: function(iterator, context) { iterator = iterator ? iterator.bind(context) : Prototype.K; var result = false; this.each(function(value, index) { if (result = !!iterator(value, index)) throw $break; }); return result; }, collect: function(iterator, context) { iterator = iterator ? iterator.bind(context) : Prototype.K; var results = []; this.each(function(value, index) { results.push(iterator(value, index)); }); return results; }, detect: function(iterator, context) { iterator = iterator.bind(context); var result; this.each(function(value, index) { if (iterator(value, index)) { result = value; throw $break; } }); return result; }, findAll: function(iterator, context) { iterator = iterator.bind(context); var results = []; this.each(function(value, index) { if (iterator(value, index)) results.push(value); }); return results; }, grep: function(filter, iterator, context) { iterator = iterator ? iterator.bind(context) : Prototype.K; var results = []; if (Object.isString(filter)) filter = new RegExp(filter); this.each(function(value, index) { if (filter.match(value)) results.push(iterator(value, index)); }); return results; }, include: function(object) { if (Object.isFunction(this.indexOf)) if (this.indexOf(object) != -1) return true; var found = false; this.each(function(value) { if (value == object) { found = true; throw $break; } }); return found; }, inGroupsOf: function(number, fillWith) { fillWith = fillWith === undefined ? null : fillWith; return this.eachSlice(number, function(slice) { while(slice.length < number) slice.push(fillWith); return slice; }); }, inject: function(memo, iterator, context) { iterator = iterator.bind(context); this.each(function(value, index) { memo = iterator(memo, value, index); }); return memo; }, invoke: function(method) { var args = $A(arguments).slice(1); return this.map(function(value) { return value[method].apply(value, args); }); }, max: function(iterator, context) { iterator = iterator ? iterator.bind(context) : Prototype.K; var result; this.each(function(value, index) { value = iterator(value, index); if (result == undefined || value >= result) result = value; }); return result; }, min: function(iterator, context) { iterator = iterator ? iterator.bind(context) : Prototype.K; var result; this.each(function(value, index) { value = iterator(value, index); if (result == undefined || value < result) result = value; }); return result; }, partition: function(iterator, context) { iterator = iterator ? iterator.bind(context) : Prototype.K; var trues = [], falses = []; this.each(function(value, index) { (iterator(value, index) ? trues : falses).push(value); }); return [trues, falses]; }, pluck: function(property) { var results = []; this.each(function(value) { results.push(value[property]); }); return results; }, reject: function(iterator, context) { iterator = iterator.bind(context); var results = []; this.each(function(value, index) { if (!iterator(value, index)) results.push(value); }); return results; }, sortBy: function(iterator, context) { iterator = iterator.bind(context); return this.map(function(value, index) { return {value: value, criteria: iterator(value, index)}; }).sort(function(left, right) { var a = left.criteria, b = right.criteria; return a < b ? -1 : a > b ? 1 : 0; }).pluck('value'); }, toArray: function() { return this.map(); }, zip: function() { var iterator = Prototype.K, args = $A(arguments); if (Object.isFunction(args.last())) iterator = args.pop(); var collections = [this].concat(args).map($A); return this.map(function(value, index) { return iterator(collections.pluck(index)); }); }, size: function() { return this.toArray().length; }, inspect: function() { return '#'; } }; Object.extend(Enumerable, { map: Enumerable.collect, find: Enumerable.detect, select: Enumerable.findAll, filter: Enumerable.findAll, member: Enumerable.include, entries: Enumerable.toArray, every: Enumerable.all, some: Enumerable.any }); function $A(iterable) { if (!iterable) return []; if (iterable.toArray) return iterable.toArray(); var length = iterable.length, results = new Array(length); while (length--) results[length] = iterable[length]; return results; } if (Prototype.Browser.WebKit) { function $A(iterable) { if (!iterable) return []; if (!(Object.isFunction(iterable) && iterable == '[object NodeList]') && iterable.toArray) return iterable.toArray(); var length = iterable.length, results = new Array(length); while (length--) results[length] = iterable[length]; return results; } } Array.from = $A; Object.extend(Array.prototype, Enumerable); if (!Array.prototype._reverse) Array.prototype._reverse = Array.prototype.reverse; Object.extend(Array.prototype, { _each: function(iterator) { for (var i = 0, length = this.length; i < length; i++) iterator(this[i]); }, clear: function() { this.length = 0; return this; }, first: function() { return this[0]; }, last: function() { return this[this.length - 1]; }, compact: function() { return this.select(function(value) { return value != null; }); }, flatten: function() { return this.inject([], function(array, value) { return array.concat(Object.isArray(value) ? value.flatten() : [value]); }); }, without: function() { var values = $A(arguments); return this.select(function(value) { return !values.include(value); }); }, reverse: function(inline) { return (inline !== false ? this : this.toArray())._reverse(); }, reduce: function() { return this.length > 1 ? this : this[0]; }, uniq: function(sorted) { return this.inject([], function(array, value, index) { if (0 == index || (sorted ? array.last() != value : !array.include(value))) array.push(value); return array; }); }, intersect: function(array) { return this.uniq().findAll(function(item) { return array.detect(function(value) { return item === value }); }); }, clone: function() { return [].concat(this); }, size: function() { return this.length; }, inspect: function() { return '[' + this.map(Object.inspect).join(', ') + ']'; }, toJSON: function() { var results = []; this.each(function(object) { var value = Object.toJSON(object); if (value !== undefined) results.push(value); }); return '[' + results.join(', ') + ']'; } }); // use native browser JS 1.6 implementation if available if (Object.isFunction(Array.prototype.forEach)) Array.prototype._each = Array.prototype.forEach; if (!Array.prototype.indexOf) Array.prototype.indexOf = function(item, i) { i || (i = 0); var length = this.length; if (i < 0) i = length + i; for (; i < length; i++) if (this[i] === item) return i; return -1; }; if (!Array.prototype.lastIndexOf) Array.prototype.lastIndexOf = function(item, i) { i = isNaN(i) ? this.length : (i < 0 ? this.length + i : i) + 1; var n = this.slice(0, i).reverse().indexOf(item); return (n < 0) ? n : i - n - 1; }; Array.prototype.toArray = Array.prototype.clone; function $w(string) { if (!Object.isString(string)) return []; string = string.strip(); return string ? string.split(/\s+/) : []; } if (Prototype.Browser.Opera){ Array.prototype.concat = function() { var array = []; for (var i = 0, length = this.length; i < length; i++) array.push(this[i]); for (var i = 0, length = arguments.length; i < length; i++) { if (Object.isArray(arguments[i])) { for (var j = 0, arrayLength = arguments[i].length; j < arrayLength; j++) array.push(arguments[i][j]); } else { array.push(arguments[i]); } } return array; }; } Object.extend(Number.prototype, { toColorPart: function() { return this.toPaddedString(2, 16); }, succ: function() { return this + 1; }, times: function(iterator) { $R(0, this, true).each(iterator); return this; }, toPaddedString: function(length, radix) { var string = this.toString(radix || 10); return '0'.times(length - string.length) + string; }, toJSON: function() { return isFinite(this) ? this.toString() : 'null'; } }); $w('abs round ceil floor').each(function(method){ Number.prototype[method] = Math[method].methodize(); }); function $H(object) { return new Hash(object); }; var Hash = Class.create(Enumerable, (function() { if (function() { var i = 0, Test = function(value) { this.key = value }; Test.prototype.key = 'foo'; for (var property in new Test('bar')) i++; return i > 1; }()) { function each(iterator) { var cache = []; for (var key in this._object) { var value = this._object[key]; if (cache.include(key)) continue; cache.push(key); var pair = [key, value]; pair.key = key; pair.value = value; iterator(pair); } } } else { function each(iterator) { for (var key in this._object) { var value = this._object[key], pair = [key, value]; pair.key = key; pair.value = value; iterator(pair); } } } function toQueryPair(key, value) { if (Object.isUndefined(value)) return key; return key + '=' + encodeURIComponent(String.interpret(value)); } return { initialize: function(object) { this._object = Object.isHash(object) ? object.toObject() : Object.clone(object); }, _each: each, set: function(key, value) { return this._object[key] = value; }, get: function(key) { return this._object[key]; }, unset: function(key) { var value = this._object[key]; delete this._object[key]; return value; }, toObject: function() { return Object.clone(this._object); }, keys: function() { return this.pluck('key'); }, values: function() { return this.pluck('value'); }, index: function(value) { var match = this.detect(function(pair) { return pair.value === value; }); return match && match.key; }, merge: function(object) { return this.clone().update(object); }, update: function(object) { return new Hash(object).inject(this, function(result, pair) { result.set(pair.key, pair.value); return result; }); }, toQueryString: function() { return this.map(function(pair) { var key = encodeURIComponent(pair.key), values = pair.value; if (values && typeof values == 'object') { if (Object.isArray(values)) return values.map(toQueryPair.curry(key)).join('&'); } return toQueryPair(key, values); }).join('&'); }, inspect: function() { return '#'; }, toJSON: function() { return Object.toJSON(this.toObject()); }, clone: function() { return new Hash(this); } } })()); Hash.prototype.toTemplateReplacements = Hash.prototype.toObject; Hash.from = $H; var ObjectRange = Class.create(Enumerable, { initialize: function(start, end, exclusive) { this.start = start; this.end = end; this.exclusive = exclusive; }, _each: function(iterator) { var value = this.start; while (this.include(value)) { iterator(value); value = value.succ(); } }, include: function(value) { if (value < this.start) return false; if (this.exclusive) return value < this.end; return value <= this.end; } }); var $R = function(start, end, exclusive) { return new ObjectRange(start, end, exclusive); }; var Ajax = { getTransport: function() { return Try.these( function() {return new XMLHttpRequest()}, function() {return new ActiveXObject('Msxml2.XMLHTTP')}, function() {return new ActiveXObject('Microsoft.XMLHTTP')} ) || false; }, activeRequestCount: 0 }; Ajax.Responders = { responders: [], _each: function(iterator) { this.responders._each(iterator); }, register: function(responder) { if (!this.include(responder)) this.responders.push(responder); }, unregister: function(responder) { this.responders = this.responders.without(responder); }, dispatch: function(callback, request, transport, json) { this.each(function(responder) { if (Object.isFunction(responder[callback])) { try { responder[callback].apply(responder, [request, transport, json]); } catch (e) { } } }); } }; Object.extend(Ajax.Responders, Enumerable); Ajax.Responders.register({ onCreate: function() { Ajax.activeRequestCount++ }, onComplete: function() { Ajax.activeRequestCount-- } }); Ajax.Base = Class.create({ initialize: function(options) { this.options = { method: 'post', asynchronous: true, contentType: 'application/x-www-form-urlencoded', encoding: 'UTF-8', parameters: '', evalJSON: true, evalJS: true }; Object.extend(this.options, options || { }); this.options.method = this.options.method.toLowerCase(); if (Object.isString(this.options.parameters)) this.options.parameters = this.options.parameters.toQueryParams(); } }); Ajax.Request = Class.create(Ajax.Base, { _complete: false, initialize: function($super, url, options) { $super(options); this.transport = Ajax.getTransport(); this.request(url); }, request: function(url) { this.url = url; this.method = this.options.method; var params = Object.clone(this.options.parameters); if (!['get', 'post'].include(this.method)) { // simulate other verbs over post params['_method'] = this.method; this.method = 'post'; } this.parameters = params; if (params = Object.toQueryString(params)) { // when GET, append parameters to URL if (this.method == 'get') this.url += (this.url.include('?') ? '&' : '?') + params; else if (/Konqueror|Safari|KHTML/.test(navigator.userAgent)) params += '&_='; } try { var response = new Ajax.Response(this); if (this.options.onCreate) this.options.onCreate(response); Ajax.Responders.dispatch('onCreate', this, response); this.transport.open(this.method.toUpperCase(), this.url, this.options.asynchronous); if (this.options.asynchronous) this.respondToReadyState.bind(this).defer(1); this.transport.onreadystatechange = this.onStateChange.bind(this); this.setRequestHeaders(); this.body = this.method == 'post' ? (this.options.postBody || params) : null; this.transport.send(this.body); /* Force Firefox to handle ready state 4 for synchronous requests */ if (!this.options.asynchronous && this.transport.overrideMimeType) this.onStateChange(); } catch (e) { this.dispatchException(e); } }, onStateChange: function() { var readyState = this.transport.readyState; if (readyState > 1 && !((readyState == 4) && this._complete)) this.respondToReadyState(this.transport.readyState); }, setRequestHeaders: function() { var headers = { 'X-Requested-With': 'XMLHttpRequest', 'X-Prototype-Version': Prototype.Version, 'Accept': 'text/javascript, text/html, application/xml, text/xml, */*' }; if (this.method == 'post') { headers['Content-type'] = this.options.contentType + (this.options.encoding ? '; charset=' + this.options.encoding : ''); /* Force "Connection: close" for older Mozilla browsers to work * around a bug where XMLHttpRequest sends an incorrect * Content-length header. See Mozilla Bugzilla #246651. */ if (this.transport.overrideMimeType && (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005) headers['Connection'] = 'close'; } // user-defined headers if (typeof this.options.requestHeaders == 'object') { var extras = this.options.requestHeaders; if (Object.isFunction(extras.push)) for (var i = 0, length = extras.length; i < length; i += 2) headers[extras[i]] = extras[i+1]; else $H(extras).each(function(pair) { headers[pair.key] = pair.value }); } for (var name in headers) this.transport.setRequestHeader(name, headers[name]); }, success: function() { var status = this.getStatus(); return !status || (status >= 200 && status < 300); }, getStatus: function() { try { return this.transport.status || 0; } catch (e) { return 0 } }, respondToReadyState: function(readyState) { var state = Ajax.Request.Events[readyState], response = new Ajax.Response(this); if (state == 'Complete') { try { this._complete = true; (this.options['on' + response.status] || this.options['on' + (this.success() ? 'Success' : 'Failure')] || Prototype.emptyFunction)(response, response.headerJSON); } catch (e) { this.dispatchException(e); } var contentType = response.getHeader('Content-type'); if (this.options.evalJS == 'force' || (this.options.evalJS && contentType && contentType.match(/^\s*(text|application)\/(x-)?(java|ecma)script(;.*)?\s*$/i))) this.evalResponse(); } try { (this.options['on' + state] || Prototype.emptyFunction)(response, response.headerJSON); Ajax.Responders.dispatch('on' + state, this, response, response.headerJSON); } catch (e) { this.dispatchException(e); } if (state == 'Complete') { // avoid memory leak in MSIE: clean up this.transport.onreadystatechange = Prototype.emptyFunction; } }, getHeader: function(name) { try { return this.transport.getResponseHeader(name); } catch (e) { return null } }, evalResponse: function() { try { return eval((this.transport.responseText || '').unfilterJSON()); } catch (e) { this.dispatchException(e); } }, dispatchException: function(exception) { (this.options.onException || Prototype.emptyFunction)(this, exception); Ajax.Responders.dispatch('onException', this, exception); } }); Ajax.Request.Events = ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete']; Ajax.Response = Class.create({ initialize: function(request){ this.request = request; var transport = this.transport = request.transport, readyState = this.readyState = transport.readyState; if((readyState > 2 && !Prototype.Browser.IE) || readyState == 4) { this.status = this.getStatus(); this.statusText = this.getStatusText(); this.responseText = String.interpret(transport.responseText); this.headerJSON = this._getHeaderJSON(); } if(readyState == 4) { var xml = transport.responseXML; this.responseXML = xml === undefined ? null : xml; this.responseJSON = this._getResponseJSON(); } }, status: 0, statusText: '', getStatus: Ajax.Request.prototype.getStatus, getStatusText: function() { try { return this.transport.statusText || ''; } catch (e) { return '' } }, getHeader: Ajax.Request.prototype.getHeader, getAllHeaders: function() { try { return this.getAllResponseHeaders(); } catch (e) { return null } }, getResponseHeader: function(name) { return this.transport.getResponseHeader(name); }, getAllResponseHeaders: function() { return this.transport.getAllResponseHeaders(); }, _getHeaderJSON: function() { var json = this.getHeader('X-JSON'); if (!json) return null; json = decodeURIComponent(escape(json)); try { return json.evalJSON(this.request.options.sanitizeJSON); } catch (e) { this.request.dispatchException(e); } }, _getResponseJSON: function() { var options = this.request.options; if (!options.evalJSON || (options.evalJSON != 'force' && !(this.getHeader('Content-type') || '').include('application/json'))) return null; try { return this.transport.responseText.evalJSON(options.sanitizeJSON); } catch (e) { this.request.dispatchException(e); } } }); Ajax.Updater = Class.create(Ajax.Request, { initialize: function($super, container, url, options) { this.container = { success: (container.success || container), failure: (container.failure || (container.success ? null : container)) }; options = options || { }; var onComplete = options.onComplete; options.onComplete = (function(response, param) { this.updateContent(response.responseText); if (Object.isFunction(onComplete)) onComplete(response, param); }).bind(this); $super(url, options); }, updateContent: function(responseText) { var receiver = this.container[this.success() ? 'success' : 'failure'], options = this.options; if (!options.evalScripts) responseText = responseText.stripScripts(); if (receiver = $(receiver)) { if (options.insertion) { if (Object.isString(options.insertion)) { var insertion = { }; insertion[options.insertion] = responseText; receiver.insert(insertion); } else options.insertion(receiver, responseText); } else receiver.update(responseText); } if (this.success()) { if (this.onComplete) this.onComplete.bind(this).defer(); } } }); Ajax.PeriodicalUpdater = Class.create(Ajax.Base, { initialize: function($super, container, url, options) { $super(options); this.onComplete = this.options.onComplete; this.frequency = (this.options.frequency || 2); this.decay = (this.options.decay || 1); this.updater = { }; this.container = container; this.url = url; this.start(); }, start: function() { this.options.onComplete = this.updateComplete.bind(this); this.onTimerEvent(); }, stop: function() { this.updater.options.onComplete = undefined; clearTimeout(this.timer); (this.onComplete || Prototype.emptyFunction).apply(this, arguments); }, updateComplete: function(response) { if (this.options.decay) { this.decay = (response.responseText == this.lastText ? this.decay * this.options.decay : 1); this.lastText = response.responseText; } this.timer = this.onTimerEvent.bind(this).delay(this.decay * this.frequency); }, onTimerEvent: function() { this.updater = new Ajax.Updater(this.container, this.url, this.options); } }); function $(element) { if (arguments.length > 1) { for (var i = 0, elements = [], length = arguments.length; i < length; i++) elements.push($(arguments[i])); return elements; } if (Object.isString(element)) element = document.getElementById(element); return Element.extend(element); } if (Prototype.BrowserFeatures.XPath) { document._getElementsByXPath = function(expression, parentElement) { var results = []; var query = document.evaluate(expression, $(parentElement) || document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); for (var i = 0, length = query.snapshotLength; i < length; i++) results.push(Element.extend(query.snapshotItem(i))); return results; }; } /*--------------------------------------------------------------------------*/ if (!window.Node) var Node = { }; if (!Node.ELEMENT_NODE) { // DOM level 2 ECMAScript Language Binding Object.extend(Node, { ELEMENT_NODE: 1, ATTRIBUTE_NODE: 2, TEXT_NODE: 3, CDATA_SECTION_NODE: 4, ENTITY_REFERENCE_NODE: 5, ENTITY_NODE: 6, PROCESSING_INSTRUCTION_NODE: 7, COMMENT_NODE: 8, DOCUMENT_NODE: 9, DOCUMENT_TYPE_NODE: 10, DOCUMENT_FRAGMENT_NODE: 11, NOTATION_NODE: 12 }); } (function() { var element = this.Element; this.Element = function(tagName, attributes) { attributes = attributes || { }; tagName = tagName.toLowerCase(); var cache = Element.cache; if (Prototype.Browser.IE && attributes.name) { tagName = '<' + tagName + ' name="' + attributes.name + '">'; delete attributes.name; return Element.writeAttribute(document.createElement(tagName), attributes); } if (!cache[tagName]) cache[tagName] = Element.extend(document.createElement(tagName)); return Element.writeAttribute(cache[tagName].cloneNode(false), attributes); }; Object.extend(this.Element, element || { }); }).call(window); Element.cache = { }; Element.Methods = { visible: function(element) { return $(element).style.display != 'none'; }, toggle: function(element) { element = $(element); Element[Element.visible(element) ? 'hide' : 'show'](element); return element; }, hide: function(element) { $(element).style.display = 'none'; return element; }, show: function(element) { $(element).style.display = ''; return element; }, remove: function(element) { element = $(element); element.parentNode.removeChild(element); return element; }, update: function(element, content) { element = $(element); if (content && content.toElement) content = content.toElement(); if (Object.isElement(content)) return element.update().insert(content); content = Object.toHTML(content); element.innerHTML = content.stripScripts(); content.evalScripts.bind(content).defer(); return element; }, replace: function(element, content) { element = $(element); if (content && content.toElement) content = content.toElement(); else if (!Object.isElement(content)) { content = Object.toHTML(content); var range = element.ownerDocument.createRange(); range.selectNode(element); content.evalScripts.bind(content).defer(); content = range.createContextualFragment(content.stripScripts()); } element.parentNode.replaceChild(content, element); return element; }, insert: function(element, insertions) { element = $(element); if (Object.isString(insertions) || Object.isNumber(insertions) || Object.isElement(insertions) || (insertions && (insertions.toElement || insertions.toHTML))) insertions = {bottom:insertions}; var content, t, range; for (position in insertions) { content = insertions[position]; position = position.toLowerCase(); t = Element._insertionTranslations[position]; if (content && content.toElement) content = content.toElement(); if (Object.isElement(content)) { t.insert(element, content); continue; } content = Object.toHTML(content); range = element.ownerDocument.createRange(); t.initializeRange(element, range); t.insert(element, range.createContextualFragment(content.stripScripts())); content.evalScripts.bind(content).defer(); } return element; }, wrap: function(element, wrapper, attributes) { element = $(element); if (Object.isElement(wrapper)) $(wrapper).writeAttribute(attributes || { }); else if (Object.isString(wrapper)) wrapper = new Element(wrapper, attributes); else wrapper = new Element('div', wrapper); if (element.parentNode) element.parentNode.replaceChild(wrapper, element); wrapper.appendChild(element); return wrapper; }, inspect: function(element) { element = $(element); var result = '<' + element.tagName.toLowerCase(); $H({'id': 'id', 'className': 'class'}).each(function(pair) { var property = pair.first(), attribute = pair.last(); var value = (element[property] || '').toString(); if (value) result += ' ' + attribute + '=' + value.inspect(true); }); return result + '>'; }, recursivelyCollect: function(element, property) { element = $(element); var elements = []; while (element = element[property]) if (element.nodeType == 1) elements.push(Element.extend(element)); return elements; }, ancestors: function(element) { return $(element).recursivelyCollect('parentNode'); }, descendants: function(element) { return $A($(element).getElementsByTagName('*')).each(Element.extend); }, firstDescendant: function(element) { element = $(element).firstChild; while (element && element.nodeType != 1) element = element.nextSibling; return $(element); }, immediateDescendants: function(element) { if (!(element = $(element).firstChild)) return []; while (element && element.nodeType != 1) element = element.nextSibling; if (element) return [element].concat($(element).nextSiblings()); return []; }, previousSiblings: function(element) { return $(element).recursivelyCollect('previousSibling'); }, nextSiblings: function(element) { return $(element).recursivelyCollect('nextSibling'); }, siblings: function(element) { element = $(element); return element.previousSiblings().reverse().concat(element.nextSiblings()); }, match: function(element, selector) { if (Object.isString(selector)) selector = new Selector(selector); return selector.match($(element)); }, up: function(element, expression, index) { element = $(element); if (arguments.length == 1) return $(element.parentNode); var ancestors = element.ancestors(); return expression ? Selector.findElement(ancestors, expression, index) : ancestors[index || 0]; }, down: function(element, expression, index) { element = $(element); if (arguments.length == 1) return element.firstDescendant(); var descendants = element.descendants(); return expression ? Selector.findElement(descendants, expression, index) : descendants[index || 0]; }, previous: function(element, expression, index) { element = $(element); if (arguments.length == 1) return $(Selector.handlers.previousElementSibling(element)); var previousSiblings = element.previousSiblings(); return expression ? Selector.findElement(previousSiblings, expression, index) : previousSiblings[index || 0]; }, next: function(element, expression, index) { element = $(element); if (arguments.length == 1) return $(Selector.handlers.nextElementSibling(element)); var nextSiblings = element.nextSiblings(); return expression ? Selector.findElement(nextSiblings, expression, index) : nextSiblings[index || 0]; }, select: function() { var args = $A(arguments), element = $(args.shift()); return Selector.findChildElements(element, args); }, adjacent: function() { var args = $A(arguments), element = $(args.shift()); return Selector.findChildElements(element.parentNode, args).without(element); }, identify: function(element) { element = $(element); var id = element.readAttribute('id'), self = arguments.callee; if (id) return id; do { id = 'anonymous_element_' + self.counter++ } while ($(id)); element.writeAttribute('id', id); return id; }, readAttribute: function(element, name) { element = $(element); if (Prototype.Browser.IE) { var t = Element._attributeTranslations.read; if (t.values[name]) return t.values[name](element, name); if (t.names[name]) name = t.names[name]; if (name.include(':')) { return (!element.attributes || !element.attributes[name]) ? null : element.attributes[name].value; } } return element.getAttribute(name); }, writeAttribute: function(element, name, value) { element = $(element); var attributes = { }, t = Element._attributeTranslations.write; if (typeof name == 'object') attributes = name; else attributes[name] = value === undefined ? true : value; for (var attr in attributes) { var name = t.names[attr] || attr, value = attributes[attr]; if (t.values[attr]) name = t.values[attr](element, value); if (value === false || value === null) element.removeAttribute(name); else if (value === true) element.setAttribute(name, name); else element.setAttribute(name, value); } return element; }, getHeight: function(element) { return $(element).getDimensions().height; }, getWidth: function(element) { return $(element).getDimensions().width; }, classNames: function(element) { return new Element.ClassNames(element); }, hasClassName: function(element, className) { if (!(element = $(element))) return; var elementClassName = element.className; return (elementClassName.length > 0 && (elementClassName == className || new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName))); }, addClassName: function(element, className) { if (!(element = $(element))) return; if (!element.hasClassName(className)) element.className += (element.className ? ' ' : '') + className; return element; }, removeClassName: function(element, className) { if (!(element = $(element))) return; element.className = element.className.replace( new RegExp("(^|\\s+)" + className + "(\\s+|$)"), ' ').strip(); return element; }, toggleClassName: function(element, className) { if (!(element = $(element))) return; return element[element.hasClassName(className) ? 'removeClassName' : 'addClassName'](className); }, // removes whitespace-only text node children cleanWhitespace: function(element) { element = $(element); var node = element.firstChild; while (node) { var nextNode = node.nextSibling; if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) element.removeChild(node); node = nextNode; } return element; }, empty: function(element) { return $(element).innerHTML.blank(); }, descendantOf: function(element, ancestor) { element = $(element), ancestor = $(ancestor); if (element.compareDocumentPosition) return (element.compareDocumentPosition(ancestor) & 8) === 8; if (element.sourceIndex && !Prototype.Browser.Opera) { var e = element.sourceIndex, a = ancestor.sourceIndex, nextAncestor = ancestor.nextSibling; if (!nextAncestor) { do { ancestor = ancestor.parentNode; } while (!(nextAncestor = ancestor.nextSibling) && ancestor.parentNode); } if (nextAncestor) return (e > a && e < nextAncestor.sourceIndex); } while (element = element.parentNode) if (element == ancestor) return true; return false; }, scrollTo: function(element) { element = $(element); var pos = element.cumulativeOffset(); window.scrollTo(pos[0], pos[1]); return element; }, getStyle: function(element, style) { element = $(element); style = style == 'float' ? 'cssFloat' : style.camelize(); var value = element.style[style]; if (!value) { var css = document.defaultView.getComputedStyle(element, null); value = css ? css[style] : null; } if (style == 'opacity') return value ? parseFloat(value) : 1.0; return value == 'auto' ? null : value; }, getOpacity: function(element) { return $(element).getStyle('opacity'); }, setStyle: function(element, styles) { element = $(element); var elementStyle = element.style, match; if (Object.isString(styles)) { element.style.cssText += ';' + styles; return styles.include('opacity') ? element.setOpacity(styles.match(/opacity:\s*(\d?\.?\d*)/)[1]) : element; } for (var property in styles) if (property == 'opacity') element.setOpacity(styles[property]); else elementStyle[(property == 'float' || property == 'cssFloat') ? (elementStyle.styleFloat === undefined ? 'cssFloat' : 'styleFloat') : property] = styles[property]; return element; }, setOpacity: function(element, value) { element = $(element); element.style.opacity = (value == 1 || value === '') ? '' : (value < 0.00001) ? 0 : value; return element; }, getDimensions: function(element) { element = $(element); var display = $(element).getStyle('display'); if (display != 'none' && display != null) // Safari bug return {width: element.offsetWidth, height: element.offsetHeight}; // All *Width and *Height properties give 0 on elements with display none, // so enable the element temporarily var els = element.style; var originalVisibility = els.visibility; var originalPosition = els.position; var originalDisplay = els.display; els.visibility = 'hidden'; els.position = 'absolute'; els.display = 'block'; var originalWidth = element.clientWidth; var originalHeight = element.clientHeight; els.display = originalDisplay; els.position = originalPosition; els.visibility = originalVisibility; return {width: originalWidth, height: originalHeight}; }, makePositioned: function(element) { element = $(element); var pos = Element.getStyle(element, 'position'); if (pos == 'static' || !pos) { element._madePositioned = true; element.style.position = 'relative'; // Opera returns the offset relative to the positioning context, when an // element is position relative but top and left have not been defined if (window.opera) { element.style.top = 0; element.style.left = 0; } } return element; }, undoPositioned: function(element) { element = $(element); if (element._madePositioned) { element._madePositioned = undefined; element.style.position = element.style.top = element.style.left = element.style.bottom = element.style.right = ''; } return element; }, makeClipping: function(element) { element = $(element); if (element._overflow) return element; element._overflow = Element.getStyle(element, 'overflow') || 'auto'; if (element._overflow !== 'hidden') element.style.overflow = 'hidden'; return element; }, undoClipping: function(element) { element = $(element); if (!element._overflow) return element; element.style.overflow = element._overflow == 'auto' ? '' : element._overflow; element._overflow = null; return element; }, cumulativeOffset: function(element) { var valueT = 0, valueL = 0; do { valueT += element.offsetTop || 0; valueL += element.offsetLeft || 0; element = element.offsetParent; } while (element); return Element._returnOffset(valueL, valueT); }, positionedOffset: function(element) { var valueT = 0, valueL = 0; do { valueT += element.offsetTop || 0; valueL += element.offsetLeft || 0; element = element.offsetParent; if (element) { if (element.tagName == 'BODY') break; var p = Element.getStyle(element, 'position'); if (p == 'relative' || p == 'absolute') break; } } while (element); return Element._returnOffset(valueL, valueT); }, absolutize: function(element) { element = $(element); if (element.getStyle('position') == 'absolute') return; // Position.prepare(); // To be done manually by Scripty when it needs it. var offsets = element.positionedOffset(); var top = offsets[1]; var left = offsets[0]; var width = element.clientWidth; var height = element.clientHeight; element._originalLeft = left - parseFloat(element.style.left || 0); element._originalTop = top - parseFloat(element.style.top || 0); element._originalWidth = element.style.width; element._originalHeight = element.style.height; element.style.position = 'absolute'; element.style.top = top + 'px'; element.style.left = left + 'px'; element.style.width = width + 'px'; element.style.height = height + 'px'; return element; }, relativize: function(element) { element = $(element); if (element.getStyle('position') == 'relative') return; // Position.prepare(); // To be done manually by Scripty when it needs it. element.style.position = 'relative'; var top = parseFloat(element.style.top || 0) - (element._originalTop || 0); var left = parseFloat(element.style.left || 0) - (element._originalLeft || 0); element.style.top = top + 'px'; element.style.left = left + 'px'; element.style.height = element._originalHeight; element.style.width = element._originalWidth; return element; }, cumulativeScrollOffset: function(element) { var valueT = 0, valueL = 0; do { valueT += element.scrollTop || 0; valueL += element.scrollLeft || 0; element = element.parentNode; } while (element); return Element._returnOffset(valueL, valueT); }, getOffsetParent: function(element) { if (element.offsetParent) return $(element.offsetParent); if (element == document.body) return $(element); while ((element = element.parentNode) && element != document.body) if (Element.getStyle(element, 'position') != 'static') return $(element); return $(document.body); }, viewportOffset: function(forElement) { var valueT = 0, valueL = 0; var element = forElement; do { valueT += element.offsetTop || 0; valueL += element.offsetLeft || 0; // Safari fix if (element.offsetParent == document.body && Element.getStyle(element, 'position') == 'absolute') break; } while (element = element.offsetParent); element = forElement; do { if (!Prototype.Browser.Opera || element.tagName == 'BODY') { valueT -= element.scrollTop || 0; valueL -= element.scrollLeft || 0; } } while (element = element.parentNode); return Element._returnOffset(valueL, valueT); }, clonePosition: function(element, source) { var options = Object.extend({ setLeft: true, setTop: true, setWidth: true, setHeight: true, offsetTop: 0, offsetLeft: 0 }, arguments[2] || { }); // find page position of source source = $(source); var p = source.viewportOffset(); // find coordinate system to use element = $(element); var delta = [0, 0]; var parent = null; // delta [0,0] will do fine with position: fixed elements, // position:absolute needs offsetParent deltas if (Element.getStyle(element, 'position') == 'absolute') { parent = element.getOffsetParent(); delta = parent.viewportOffset(); } // correct by body offsets (fixes Safari) if (parent == document.body) { delta[0] -= document.body.offsetLeft; delta[1] -= document.body.offsetTop; } // set position if (options.setLeft) element.style.left = (p[0] - delta[0] + options.offsetLeft) + 'px'; if (options.setTop) element.style.top = (p[1] - delta[1] + options.offsetTop) + 'px'; if (options.setWidth) element.style.width = source.offsetWidth + 'px'; if (options.setHeight) element.style.height = source.offsetHeight + 'px'; return element; } }; Element.Methods.identify.counter = 1; Object.extend(Element.Methods, { getElementsBySelector: Element.Methods.select, childElements: Element.Methods.immediateDescendants }); Element._attributeTranslations = { write: { names: { className: 'class', htmlFor: 'for' }, values: { } } }; if (!document.createRange || Prototype.Browser.Opera) { Element.Methods.insert = function(element, insertions) { element = $(element); if (Object.isString(insertions) || Object.isNumber(insertions) || Object.isElement(insertions) || (insertions && (insertions.toElement || insertions.toHTML))) insertions = { bottom: insertions }; var t = Element._insertionTranslations, content, position, pos, tagName; for (position in insertions) { content = insertions[position]; position = position.toLowerCase(); pos = t[position]; if (content && content.toElement) content = content.toElement(); if (Object.isElement(content)) { pos.insert(element, content); continue; } content = Object.toHTML(content); tagName = ((position == 'before' || position == 'after') ? element.parentNode : element).tagName.toUpperCase(); if (t.tags[tagName]) { var fragments = Element._getContentFromAnonymousElement(tagName, content.stripScripts()); if (position == 'top' || position == 'after') fragments.reverse(); fragments.each(pos.insert.curry(element)); } else element.insertAdjacentHTML(pos.adjacency, content.stripScripts()); content.evalScripts.bind(content).defer(); } return element; }; } if (Prototype.Browser.Opera) { Element.Methods._getStyle = Element.Methods.getStyle; Element.Methods.getStyle = function(element, style) { switch(style) { case 'left': case 'top': case 'right': case 'bottom': if (Element._getStyle(element, 'position') == 'static') return null; default: return Element._getStyle(element, style); } }; Element.Methods._readAttribute = Element.Methods.readAttribute; Element.Methods.readAttribute = function(element, attribute) { if (attribute == 'title') return element.title; return Element._readAttribute(element, attribute); }; } else if (Prototype.Browser.IE) { $w('positionedOffset getOffsetParent viewportOffset').each(function(method) { Element.Methods[method] = Element.Methods[method].wrap( function(proceed, element) { element = $(element); var position = element.getStyle('position'); if (position != 'static') return proceed(element); element.setStyle({ position: 'relative' }); var value = proceed(element); element.setStyle({ position: position }); return value; } ); }); Element.Methods.getStyle = function(element, style) { element = $(element); style = (style == 'float' || style == 'cssFloat') ? 'styleFloat' : style.camelize(); var value = element.style[style]; if (!value && element.currentStyle) value = element.currentStyle[style]; if (style == 'opacity') { if (value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/)) if (value[1]) return parseFloat(value[1]) / 100; return 1.0; } if (value == 'auto') { if ((style == 'width' || style == 'height') && (element.getStyle('display') != 'none')) return element['offset' + style.capitalize()] + 'px'; return null; } return value; }; Element.Methods.setOpacity = function(element, value) { function stripAlpha(filter){ return filter.replace(/alpha\([^\)]*\)/gi,''); } element = $(element); var currentStyle = element.currentStyle; if ((currentStyle && !currentStyle.hasLayout) || (!currentStyle && element.style.zoom == 'normal')) element.style.zoom = 1; var filter = element.getStyle('filter'), style = element.style; if (value == 1 || value === '') { (filter = stripAlpha(filter)) ? style.filter = filter : style.removeAttribute('filter'); return element; } else if (value < 0.00001) value = 0; style.filter = stripAlpha(filter) + 'alpha(opacity=' + (value * 100) + ')'; return element; }; Element._attributeTranslations = { read: { names: { 'class': 'className', 'for': 'htmlFor' }, values: { _getAttr: function(element, attribute) { return element.getAttribute(attribute, 2); }, _getAttrNode: function(element, attribute) { var node = element.getAttributeNode(attribute); return node ? node.value : ""; }, _getEv: function(element, attribute) { var attribute = element.getAttribute(attribute); return attribute ? attribute.toString().slice(23, -2) : null; }, _flag: function(element, attribute) { return $(element).hasAttribute(attribute) ? attribute : null; }, style: function(element) { return element.style.cssText.toLowerCase(); }, title: function(element) { return element.title; } } } }; Element._attributeTranslations.write = { names: Object.clone(Element._attributeTranslations.read.names), values: { checked: function(element, value) { element.checked = !!value; }, style: function(element, value) { element.style.cssText = value ? value : ''; } } }; Element._attributeTranslations.has = {}; $w('colSpan rowSpan vAlign dateTime accessKey tabIndex ' + 'encType maxLength readOnly longDesc').each(function(attr) { Element._attributeTranslations.write.names[attr.toLowerCase()] = attr; Element._attributeTranslations.has[attr.toLowerCase()] = attr; }); (function(v) { Object.extend(v, { href: v._getAttr, src: v._getAttr, type: v._getAttr, action: v._getAttrNode, disabled: v._flag, checked: v._flag, readonly: v._flag, multiple: v._flag, onload: v._getEv, onunload: v._getEv, onclick: v._getEv, ondblclick: v._getEv, onmousedown: v._getEv, onmouseup: v._getEv, onmouseover: v._getEv, onmousemove: v._getEv, onmouseout: v._getEv, onfocus: v._getEv, onblur: v._getEv, onkeypress: v._getEv, onkeydown: v._getEv, onkeyup: v._getEv, onsubmit: v._getEv, onreset: v._getEv, onselect: v._getEv, onchange: v._getEv }); })(Element._attributeTranslations.read.values); } else if (Prototype.Browser.Gecko && /rv:1\.8\.0/.test(navigator.userAgent)) { Element.Methods.setOpacity = function(element, value) { element = $(element); element.style.opacity = (value == 1) ? 0.999999 : (value === '') ? '' : (value < 0.00001) ? 0 : value; return element; }; } else if (Prototype.Browser.WebKit) { Element.Methods.setOpacity = function(element, value) { element = $(element); element.style.opacity = (value == 1 || value === '') ? '' : (value < 0.00001) ? 0 : value; if (value == 1) if(element.tagName == 'IMG' && element.width) { element.width++; element.width--; } else try { var n = document.createTextNode(' '); element.appendChild(n); element.removeChild(n); } catch (e) { } return element; }; // Safari returns margins on body which is incorrect if the child is absolutely // positioned. For performance reasons, redefine Position.cumulativeOffset for // KHTML/WebKit only. Element.Methods.cumulativeOffset = function(element) { var valueT = 0, valueL = 0; do { valueT += element.offsetTop || 0; valueL += element.offsetLeft || 0; if (element.offsetParent == document.body) if (Element.getStyle(element, 'position') == 'absolute') break; element = element.offsetParent; } while (element); return Element._returnOffset(valueL, valueT); }; } if (Prototype.Browser.IE || Prototype.Browser.Opera) { // IE and Opera are missing .innerHTML support for TABLE-related and SELECT elements Element.Methods.update = function(element, content) { element = $(element); if (content && content.toElement) content = content.toElement(); if (Object.isElement(content)) return element.update().insert(content); content = Object.toHTML(content); var tagName = element.tagName.toUpperCase(); if (tagName in Element._insertionTranslations.tags) { $A(element.childNodes).each(function(node) { element.removeChild(node) }); Element._getContentFromAnonymousElement(tagName, content.stripScripts()) .each(function(node) { element.appendChild(node) }); } else element.innerHTML = content.stripScripts(); content.evalScripts.bind(content).defer(); return element; }; } if (document.createElement('div').outerHTML) { Element.Methods.replace = function(element, content) { element = $(element); if (content && content.toElement) content = content.toElement(); if (Object.isElement(content)) { element.parentNode.replaceChild(content, element); return element; } content = Object.toHTML(content); var parent = element.parentNode, tagName = parent.tagName.toUpperCase(); if (Element._insertionTranslations.tags[tagName]) { var nextSibling = element.next(); var fragments = Element._getContentFromAnonymousElement(tagName, content.stripScripts()); parent.removeChild(element); if (nextSibling) fragments.each(function(node) { parent.insertBefore(node, nextSibling) }); else fragments.each(function(node) { parent.appendChild(node) }); } else element.outerHTML = content.stripScripts(); content.evalScripts.bind(content).defer(); return element; }; } Element._returnOffset = function(l, t) { var result = [l, t]; result.left = l; result.top = t; return result; }; Element._getContentFromAnonymousElement = function(tagName, html) { var div = new Element('div'), t = Element._insertionTranslations.tags[tagName]; div.innerHTML = t[0] + html + t[1]; t[2].times(function() { div = div.firstChild }); return $A(div.childNodes); }; Element._insertionTranslations = { before: { adjacency: 'beforeBegin', insert: function(element, node) { element.parentNode.insertBefore(node, element); }, initializeRange: function(element, range) { range.setStartBefore(element); } }, top: { adjacency: 'afterBegin', insert: function(element, node) { element.insertBefore(node, element.firstChild); }, initializeRange: function(element, range) { range.selectNodeContents(element); range.collapse(true); } }, bottom: { adjacency: 'beforeEnd', insert: function(element, node) { element.appendChild(node); } }, after: { adjacency: 'afterEnd', insert: function(element, node) { element.parentNode.insertBefore(node, element.nextSibling); }, initializeRange: function(element, range) { range.setStartAfter(element); } }, tags: { TABLE: ['', '
', 1], TBODY: ['', '
', 2], TR: ['', '
', 3], TD: ['
', '
', 4], SELECT: ['', 1] } }; (function() { this.bottom.initializeRange = this.top.initializeRange; Object.extend(this.tags, { THEAD: this.tags.TBODY, TFOOT: this.tags.TBODY, TH: this.tags.TD }); }).call(Element._insertionTranslations); Element.Methods.Simulated = { hasAttribute: function(element, attribute) { attribute = Element._attributeTranslations.has[attribute] || attribute; var node = $(element).getAttributeNode(attribute); return node && node.specified; } }; Element.Methods.ByTag = { }; Object.extend(Element, Element.Methods); if (!Prototype.BrowserFeatures.ElementExtensions && document.createElement('div').__proto__) { window.HTMLElement = { }; window.HTMLElement.prototype = document.createElement('div').__proto__; Prototype.BrowserFeatures.ElementExtensions = true; } Element.extend = (function() { if (Prototype.BrowserFeatures.SpecificElementExtensions) return Prototype.K; var Methods = { }, ByTag = Element.Methods.ByTag; var extend = Object.extend(function(element) { if (!element || element._extendedByPrototype || element.nodeType != 1 || element == window) return element; var methods = Object.clone(Methods), tagName = element.tagName, property, value; // extend methods for specific tags if (ByTag[tagName]) Object.extend(methods, ByTag[tagName]); for (property in methods) { value = methods[property]; if (Object.isFunction(value) && !(property in element)) element[property] = value.methodize(); } element._extendedByPrototype = Prototype.emptyFunction; return element; }, { refresh: function() { // extend methods for all tags (Safari doesn't need this) if (!Prototype.BrowserFeatures.ElementExtensions) { Object.extend(Methods, Element.Methods); Object.extend(Methods, Element.Methods.Simulated); } } }); extend.refresh(); return extend; })(); Element.hasAttribute = function(element, attribute) { if (element.hasAttribute) return element.hasAttribute(attribute); return Element.Methods.Simulated.hasAttribute(element, attribute); }; Element.addMethods = function(methods) { var F = Prototype.BrowserFeatures, T = Element.Methods.ByTag; if (!methods) { Object.extend(Form, Form.Methods); Object.extend(Form.Element, Form.Element.Methods); Object.extend(Element.Methods.ByTag, { "FORM": Object.clone(Form.Methods), "INPUT": Object.clone(Form.Element.Methods), "SELECT": Object.clone(Form.Element.Methods), "TEXTAREA": Object.clone(Form.Element.Methods) }); } if (arguments.length == 2) { var tagName = methods; methods = arguments[1]; } if (!tagName) Object.extend(Element.Methods, methods || { }); else { if (Object.isArray(tagName)) tagName.each(extend); else extend(tagName); } function extend(tagName) { tagName = tagName.toUpperCase(); if (!Element.Methods.ByTag[tagName]) Element.Methods.ByTag[tagName] = { }; Object.extend(Element.Methods.ByTag[tagName], methods); } function copy(methods, destination, onlyIfAbsent) { onlyIfAbsent = onlyIfAbsent || false; for (var property in methods) { var value = methods[property]; if (!Object.isFunction(value)) continue; if (!onlyIfAbsent || !(property in destination)) destination[property] = value.methodize(); } } function findDOMClass(tagName) { var klass; var trans = { "OPTGROUP": "OptGroup", "TEXTAREA": "TextArea", "P": "Paragraph", "FIELDSET": "FieldSet", "UL": "UList", "OL": "OList", "DL": "DList", "DIR": "Directory", "H1": "Heading", "H2": "Heading", "H3": "Heading", "H4": "Heading", "H5": "Heading", "H6": "Heading", "Q": "Quote", "INS": "Mod", "DEL": "Mod", "A": "Anchor", "IMG": "Image", "CAPTION": "TableCaption", "COL": "TableCol", "COLGROUP": "TableCol", "THEAD": "TableSection", "TFOOT": "TableSection", "TBODY": "TableSection", "TR": "TableRow", "TH": "TableCell", "TD": "TableCell", "FRAMESET": "FrameSet", "IFRAME": "IFrame" }; if (trans[tagName]) klass = 'HTML' + trans[tagName] + 'Element'; if (window[klass]) return window[klass]; klass = 'HTML' + tagName + 'Element'; if (window[klass]) return window[klass]; klass = 'HTML' + tagName.capitalize() + 'Element'; if (window[klass]) return window[klass]; window[klass] = { }; window[klass].prototype = document.createElement(tagName).__proto__; return window[klass]; } if (F.ElementExtensions) { copy(Element.Methods, HTMLElement.prototype); copy(Element.Methods.Simulated, HTMLElement.prototype, true); } if (F.SpecificElementExtensions) { for (var tag in Element.Methods.ByTag) { var klass = findDOMClass(tag); if (Object.isUndefined(klass)) continue; copy(T[tag], klass.prototype); } } Object.extend(Element, Element.Methods); delete Element.ByTag; if (Element.extend.refresh) Element.extend.refresh(); Element.cache = { }; }; document.viewport = { getDimensions: function() { var dimensions = { }; $w('width height').each(function(d) { var D = d.capitalize(); dimensions[d] = self['inner' + D] || (document.documentElement['client' + D] || document.body['client' + D]); }); return dimensions; }, getWidth: function() { return this.getDimensions().width; }, getHeight: function() { return this.getDimensions().height; }, getScrollOffsets: function() { return Element._returnOffset( window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft, window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop); } }; /* Portions of the Selector class are derived from Jack Slocum’s DomQuery, * part of YUI-Ext version 0.40, distributed under the terms of an MIT-style * license. Please see http://www.yui-ext.com/ for more information. */ var Selector = Class.create({ initialize: function(expression) { this.expression = expression.strip(); this.compileMatcher(); }, compileMatcher: function() { // Selectors with namespaced attributes can't use the XPath version if (Prototype.BrowserFeatures.XPath && !(/(\[[\w-]*?:|:checked)/).test(this.expression)) return this.compileXPathMatcher(); var e = this.expression, ps = Selector.patterns, h = Selector.handlers, c = Selector.criteria, le, p, m; if (Selector._cache[e]) { this.matcher = Selector._cache[e]; return; } this.matcher = ["this.matcher = function(root) {", "var r = root, h = Selector.handlers, c = false, n;"]; while (e && le != e && (/\S/).test(e)) { le = e; for (var i in ps) { p = ps[i]; if (m = e.match(p)) { this.matcher.push(Object.isFunction(c[i]) ? c[i](m) : new Template(c[i]).evaluate(m)); e = e.replace(m[0], ''); break; } } } this.matcher.push("return h.unique(n);\n}"); eval(this.matcher.join('\n')); Selector._cache[this.expression] = this.matcher; }, compileXPathMatcher: function() { var e = this.expression, ps = Selector.patterns, x = Selector.xpath, le, m; if (Selector._cache[e]) { this.xpath = Selector._cache[e]; return; } this.matcher = ['.//*']; while (e && le != e && (/\S/).test(e)) { le = e; for (var i in ps) { if (m = e.match(ps[i])) { this.matcher.push(Object.isFunction(x[i]) ? x[i](m) : new Template(x[i]).evaluate(m)); e = e.replace(m[0], ''); break; } } } this.xpath = this.matcher.join(''); Selector._cache[this.expression] = this.xpath; }, findElements: function(root) { root = root || document; if (this.xpath) return document._getElementsByXPath(this.xpath, root); return this.matcher(root); }, match: function(element) { this.tokens = []; var e = this.expression, ps = Selector.patterns, as = Selector.assertions; var le, p, m; while (e && le !== e && (/\S/).test(e)) { le = e; for (var i in ps) { p = ps[i]; if (m = e.match(p)) { // use the Selector.assertions methods unless the selector // is too complex. if (as[i]) { this.tokens.push([i, Object.clone(m)]); e = e.replace(m[0], ''); } else { // reluctantly do a document-wide search // and look for a match in the array return this.findElements(document).include(element); } } } } var match = true, name, matches; for (var i = 0, token; token = this.tokens[i]; i++) { name = token[0], matches = token[1]; if (!Selector.assertions[name](element, matches)) { match = false; break; } } return match; }, toString: function() { return this.expression; }, inspect: function() { return "#"; } }); Object.extend(Selector, { _cache: { }, xpath: { descendant: "//*", child: "/*", adjacent: "/following-sibling::*[1]", laterSibling: '/following-sibling::*', tagName: function(m) { if (m[1] == '*') return ''; return "[local-name()='" + m[1].toLowerCase() + "' or local-name()='" + m[1].toUpperCase() + "']"; }, className: "[contains(concat(' ', @class, ' '), ' #{1} ')]", id: "[@id='#{1}']", attrPresence: "[@#{1}]", attr: function(m) { m[3] = m[5] || m[6]; return new Template(Selector.xpath.operators[m[2]]).evaluate(m); }, pseudo: function(m) { var h = Selector.xpath.pseudos[m[1]]; if (!h) return ''; if (Object.isFunction(h)) return h(m); return new Template(Selector.xpath.pseudos[m[1]]).evaluate(m); }, operators: { '=': "[@#{1}='#{3}']", '!=': "[@#{1}!='#{3}']", '^=': "[starts-with(@#{1}, '#{3}')]", '$=': "[substring(@#{1}, (string-length(@#{1}) - string-length('#{3}') + 1))='#{3}']", '*=': "[contains(@#{1}, '#{3}')]", '~=': "[contains(concat(' ', @#{1}, ' '), ' #{3} ')]", '|=': "[contains(concat('-', @#{1}, '-'), '-#{3}-')]" }, pseudos: { 'first-child': '[not(preceding-sibling::*)]', 'last-child': '[not(following-sibling::*)]', 'only-child': '[not(preceding-sibling::* or following-sibling::*)]', 'empty': "[count(*) = 0 and (count(text()) = 0 or translate(text(), ' \t\r\n', '') = '')]", 'checked': "[@checked]", 'disabled': "[@disabled]", 'enabled': "[not(@disabled)]", 'not': function(m) { var e = m[6], p = Selector.patterns, x = Selector.xpath, le, m, v; var exclusion = []; while (e && le != e && (/\S/).test(e)) { le = e; for (var i in p) { if (m = e.match(p[i])) { v = Object.isFunction(x[i]) ? x[i](m) : new Template(x[i]).evaluate(m); exclusion.push("(" + v.substring(1, v.length - 1) + ")"); e = e.replace(m[0], ''); break; } } } return "[not(" + exclusion.join(" and ") + ")]"; }, 'nth-child': function(m) { return Selector.xpath.pseudos.nth("(count(./preceding-sibling::*) + 1) ", m); }, 'nth-last-child': function(m) { return Selector.xpath.pseudos.nth("(count(./following-sibling::*) + 1) ", m); }, 'nth-of-type': function(m) { return Selector.xpath.pseudos.nth("position() ", m); }, 'nth-last-of-type': function(m) { return Selector.xpath.pseudos.nth("(last() + 1 - position()) ", m); }, 'first-of-type': function(m) { m[6] = "1"; return Selector.xpath.pseudos['nth-of-type'](m); }, 'last-of-type': function(m) { m[6] = "1"; return Selector.xpath.pseudos['nth-last-of-type'](m); }, 'only-of-type': function(m) { var p = Selector.xpath.pseudos; return p['first-of-type'](m) + p['last-of-type'](m); }, nth: function(fragment, m) { var mm, formula = m[6], predicate; if (formula == 'even') formula = '2n+0'; if (formula == 'odd') formula = '2n+1'; if (mm = formula.match(/^(\d+)$/)) // digit only return '[' + fragment + "= " + mm[1] + ']'; if (mm = formula.match(/^(-?\d*)?n(([+-])(\d+))?/)) { // an+b if (mm[1] == "-") mm[1] = -1; var a = mm[1] ? Number(mm[1]) : 1; var b = mm[2] ? Number(mm[2]) : 0; predicate = "[((#{fragment} - #{b}) mod #{a} = 0) and " + "((#{fragment} - #{b}) div #{a} >= 0)]"; return new Template(predicate).evaluate({ fragment: fragment, a: a, b: b }); } } } }, criteria: { tagName: 'n = h.tagName(n, r, "#{1}", c); c = false;', className: 'n = h.className(n, r, "#{1}", c); c = false;', id: 'n = h.id(n, r, "#{1}", c); c = false;', attrPresence: 'n = h.attrPresence(n, r, "#{1}"); c = false;', attr: function(m) { m[3] = (m[5] || m[6]); return new Template('n = h.attr(n, r, "#{1}", "#{3}", "#{2}"); c = false;').evaluate(m); }, pseudo: function(m) { if (m[6]) m[6] = m[6].replace(/"/g, '\\"'); return new Template('n = h.pseudo(n, "#{1}", "#{6}", r, c); c = false;').evaluate(m); }, descendant: 'c = "descendant";', child: 'c = "child";', adjacent: 'c = "adjacent";', laterSibling: 'c = "laterSibling";' }, patterns: { // combinators must be listed first // (and descendant needs to be last combinator) laterSibling: /^\s*~\s*/, child: /^\s*>\s*/, adjacent: /^\s*\+\s*/, descendant: /^\s/, // selectors follow tagName: /^\s*(\*|[\w\-]+)(\b|$)?/, id: /^#([\w\-\*]+)(\b|$)/, className: /^\.([\w\-\*]+)(\b|$)/, pseudo: /^:((first|last|nth|nth-last|only)(-child|-of-type)|empty|checked|(en|dis)abled|not)(\((.*?)\))?(\b|$|(?=\s)|(?=:))/, attrPresence: /^\[([\w]+)\]/, attr: /\[((?:[\w-]*:)?[\w-]+)\s*(?:([!^$*~|]?=)\s*((['"])([^\4]*?)\4|([^'"][^\]]*?)))?\]/ }, // for Selector.match and Element#match assertions: { tagName: function(element, matches) { return matches[1].toUpperCase() == element.tagName.toUpperCase(); }, className: function(element, matches) { return Element.hasClassName(element, matches[1]); }, id: function(element, matches) { return element.id === matches[1]; }, attrPresence: function(element, matches) { return Element.hasAttribute(element, matches[1]); }, attr: function(element, matches) { var nodeValue = Element.readAttribute(element, matches[1]); return Selector.operators[matches[2]](nodeValue, matches[3]); } }, handlers: { // UTILITY FUNCTIONS // joins two collections concat: function(a, b) { for (var i = 0, node; node = b[i]; i++) a.push(node); return a; }, // marks an array of nodes for counting mark: function(nodes) { for (var i = 0, node; node = nodes[i]; i++) node._counted = true; return nodes; }, unmark: function(nodes) { for (var i = 0, node; node = nodes[i]; i++) node._counted = undefined; return nodes; }, // mark each child node with its position (for nth calls) // "ofType" flag indicates whether we're indexing for nth-of-type // rather than nth-child index: function(parentNode, reverse, ofType) { parentNode._counted = true; if (reverse) { for (var nodes = parentNode.childNodes, i = nodes.length - 1, j = 1; i >= 0; i--) { var node = nodes[i]; if (node.nodeType == 1 && (!ofType || node._counted)) node.nodeIndex = j++; } } else { for (var i = 0, j = 1, nodes = parentNode.childNodes; node = nodes[i]; i++) if (node.nodeType == 1 && (!ofType || node._counted)) node.nodeIndex = j++; } }, // filters out duplicates and extends all nodes unique: function(nodes) { if (nodes.length == 0) return nodes; var results = [], n; for (var i = 0, l = nodes.length; i < l; i++) if (!(n = nodes[i])._counted) { n._counted = true; results.push(Element.extend(n)); } return Selector.handlers.unmark(results); }, // COMBINATOR FUNCTIONS descendant: function(nodes) { var h = Selector.handlers; for (var i = 0, results = [], node; node = nodes[i]; i++) h.concat(results, node.getElementsByTagName('*')); return results; }, child: function(nodes) { var h = Selector.handlers; for (var i = 0, results = [], node; node = nodes[i]; i++) { for (var j = 0, children = [], child; child = node.childNodes[j]; j++) if (child.nodeType == 1 && child.tagName != '!') results.push(child); } return results; }, adjacent: function(nodes) { for (var i = 0, results = [], node; node = nodes[i]; i++) { var next = this.nextElementSibling(node); if (next) results.push(next); } return results; }, laterSibling: function(nodes) { var h = Selector.handlers; for (var i = 0, results = [], node; node = nodes[i]; i++) h.concat(results, Element.nextSiblings(node)); return results; }, nextElementSibling: function(node) { while (node = node.nextSibling) if (node.nodeType == 1) return node; return null; }, previousElementSibling: function(node) { while (node = node.previousSibling) if (node.nodeType == 1) return node; return null; }, // TOKEN FUNCTIONS tagName: function(nodes, root, tagName, combinator) { tagName = tagName.toUpperCase(); var results = [], h = Selector.handlers; if (nodes) { if (combinator) { // fastlane for ordinary descendant combinators if (combinator == "descendant") { for (var i = 0, node; node = nodes[i]; i++) h.concat(results, node.getElementsByTagName(tagName)); return results; } else nodes = this[combinator](nodes); if (tagName == "*") return nodes; } for (var i = 0, node; node = nodes[i]; i++) if (node.tagName.toUpperCase() == tagName) results.push(node); return results; } else return root.getElementsByTagName(tagName); }, id: function(nodes, root, id, combinator) { var targetNode = $(id), h = Selector.handlers; if (!targetNode) return []; if (!nodes && root == document) return [targetNode]; if (nodes) { if (combinator) { if (combinator == 'child') { for (var i = 0, node; node = nodes[i]; i++) if (targetNode.parentNode == node) return [targetNode]; } else if (combinator == 'descendant') { for (var i = 0, node; node = nodes[i]; i++) if (Element.descendantOf(targetNode, node)) return [targetNode]; } else if (combinator == 'adjacent') { for (var i = 0, node; node = nodes[i]; i++) if (Selector.handlers.previousElementSibling(targetNode) == node) return [targetNode]; } else nodes = h[combinator](nodes); } for (var i = 0, node; node = nodes[i]; i++) if (node == targetNode) return [targetNode]; return []; } return (targetNode && Element.descendantOf(targetNode, root)) ? [targetNode] : []; }, className: function(nodes, root, className, combinator) { if (nodes && combinator) nodes = this[combinator](nodes); return Selector.handlers.byClassName(nodes, root, className); }, byClassName: function(nodes, root, className) { if (!nodes) nodes = Selector.handlers.descendant([root]); var needle = ' ' + className + ' '; for (var i = 0, results = [], node, nodeClassName; node = nodes[i]; i++) { nodeClassName = node.className; if (nodeClassName.length == 0) continue; if (nodeClassName == className || (' ' + nodeClassName + ' ').include(needle)) results.push(node); } return results; }, attrPresence: function(nodes, root, attr) { if (!nodes) nodes = root.getElementsByTagName("*"); var results = []; for (var i = 0, node; node = nodes[i]; i++) if (Element.hasAttribute(node, attr)) results.push(node); return results; }, attr: function(nodes, root, attr, value, operator) { if (!nodes) nodes = root.getElementsByTagName("*"); var handler = Selector.operators[operator], results = []; for (var i = 0, node; node = nodes[i]; i++) { var nodeValue = Element.readAttribute(node, attr); if (nodeValue === null) continue; if (handler(nodeValue, value)) results.push(node); } return results; }, pseudo: function(nodes, name, value, root, combinator) { if (nodes && combinator) nodes = this[combinator](nodes); if (!nodes) nodes = root.getElementsByTagName("*"); return Selector.pseudos[name](nodes, value, root); } }, pseudos: { 'first-child': function(nodes, value, root) { for (var i = 0, results = [], node; node = nodes[i]; i++) { if (Selector.handlers.previousElementSibling(node)) continue; results.push(node); } return results; }, 'last-child': function(nodes, value, root) { for (var i = 0, results = [], node; node = nodes[i]; i++) { if (Selector.handlers.nextElementSibling(node)) continue; results.push(node); } return results; }, 'only-child': function(nodes, value, root) { var h = Selector.handlers; for (var i = 0, results = [], node; node = nodes[i]; i++) if (!h.previousElementSibling(node) && !h.nextElementSibling(node)) results.push(node); return results; }, 'nth-child': function(nodes, formula, root) { return Selector.pseudos.nth(nodes, formula, root); }, 'nth-last-child': function(nodes, formula, root) { return Selector.pseudos.nth(nodes, formula, root, true); }, 'nth-of-type': function(nodes, formula, root) { return Selector.pseudos.nth(nodes, formula, root, false, true); }, 'nth-last-of-type': function(nodes, formula, root) { return Selector.pseudos.nth(nodes, formula, root, true, true); }, 'first-of-type': function(nodes, formula, root) { return Selector.pseudos.nth(nodes, "1", root, false, true); }, 'last-of-type': function(nodes, formula, root) { return Selector.pseudos.nth(nodes, "1", root, true, true); }, 'only-of-type': function(nodes, formula, root) { var p = Selector.pseudos; return p['last-of-type'](p['first-of-type'](nodes, formula, root), formula, root); }, // handles the an+b logic getIndices: function(a, b, total) { if (a == 0) return b > 0 ? [b] : []; return $R(1, total).inject([], function(memo, i) { if (0 == (i - b) % a && (i - b) / a >= 0) memo.push(i); return memo; }); }, // handles nth(-last)-child, nth(-last)-of-type, and (first|last)-of-type nth: function(nodes, formula, root, reverse, ofType) { if (nodes.length == 0) return []; if (formula == 'even') formula = '2n+0'; if (formula == 'odd') formula = '2n+1'; var h = Selector.handlers, results = [], indexed = [], m; h.mark(nodes); for (var i = 0, node; node = nodes[i]; i++) { if (!node.parentNode._counted) { h.index(node.parentNode, reverse, ofType); indexed.push(node.parentNode); } } if (formula.match(/^\d+$/)) { // just a number formula = Number(formula); for (var i = 0, node; node = nodes[i]; i++) if (node.nodeIndex == formula) results.push(node); } else if (m = formula.match(/^(-?\d*)?n(([+-])(\d+))?/)) { // an+b if (m[1] == "-") m[1] = -1; var a = m[1] ? Number(m[1]) : 1; var b = m[2] ? Number(m[2]) : 0; var indices = Selector.pseudos.getIndices(a, b, nodes.length); for (var i = 0, node, l = indices.length; node = nodes[i]; i++) { for (var j = 0; j < l; j++) if (node.nodeIndex == indices[j]) results.push(node); } } h.unmark(nodes); h.unmark(indexed); return results; }, 'empty': function(nodes, value, root) { for (var i = 0, results = [], node; node = nodes[i]; i++) { // IE treats comments as element nodes if (node.tagName == '!' || (node.firstChild && !node.innerHTML.match(/^\s*$/))) continue; results.push(node); } return results; }, 'not': function(nodes, selector, root) { var h = Selector.handlers, selectorType, m; var exclusions = new Selector(selector).findElements(root); h.mark(exclusions); for (var i = 0, results = [], node; node = nodes[i]; i++) if (!node._counted) results.push(node); h.unmark(exclusions); return results; }, 'enabled': function(nodes, value, root) { for (var i = 0, results = [], node; node = nodes[i]; i++) if (!node.disabled) results.push(node); return results; }, 'disabled': function(nodes, value, root) { for (var i = 0, results = [], node; node = nodes[i]; i++) if (node.disabled) results.push(node); return results; }, 'checked': function(nodes, value, root) { for (var i = 0, results = [], node; node = nodes[i]; i++) if (node.checked) results.push(node); return results; } }, operators: { '=': function(nv, v) { return nv == v; }, '!=': function(nv, v) { return nv != v; }, '^=': function(nv, v) { return nv.startsWith(v); }, '$=': function(nv, v) { return nv.endsWith(v); }, '*=': function(nv, v) { return nv.include(v); }, '~=': function(nv, v) { return (' ' + nv + ' ').include(' ' + v + ' '); }, '|=': function(nv, v) { return ('-' + nv.toUpperCase() + '-').include('-' + v.toUpperCase() + '-'); } }, matchElements: function(elements, expression) { var matches = new Selector(expression).findElements(), h = Selector.handlers; h.mark(matches); for (var i = 0, results = [], element; element = elements[i]; i++) if (element._counted) results.push(element); h.unmark(matches); return results; }, findElement: function(elements, expression, index) { if (Object.isNumber(expression)) { index = expression; expression = false; } return Selector.matchElements(elements, expression || '*')[index || 0]; }, findChildElements: function(element, expressions) { var exprs = expressions.join(','), expressions = []; exprs.scan(/(([\w#:.~>+()\s-]+|\*|\[.*?\])+)\s*(,|$)/, function(m) { expressions.push(m[1].strip()); }); var results = [], h = Selector.handlers; for (var i = 0, l = expressions.length, selector; i < l; i++) { selector = new Selector(expressions[i].strip()); h.concat(results, selector.findElements(element)); } return (l > 1) ? h.unique(results) : results; } }); function $$() { return Selector.findChildElements(document, $A(arguments)); } var Form = { reset: function(form) { $(form).reset(); return form; }, serializeElements: function(elements, options) { if (typeof options != 'object') options = { hash: !!options }; else if (options.hash === undefined) options.hash = true; var key, value, submitted = false, submit = options.submit; var data = elements.inject({ }, function(result, element) { if (!element.disabled && element.name) { key = element.name; value = $(element).getValue(); if (value != null && (element.type != 'submit' || (!submitted && submit !== false && (!submit || key == submit) && (submitted = true)))) { if (key in result) { // a key is already present; construct an array of values if (!Object.isArray(result[key])) result[key] = [result[key]]; result[key].push(value); } else result[key] = value; } } return result; }); return options.hash ? data : Object.toQueryString(data); } }; Form.Methods = { serialize: function(form, options) { return Form.serializeElements(Form.getElements(form), options); }, getElements: function(form) { return $A($(form).getElementsByTagName('*')).inject([], function(elements, child) { if (Form.Element.Serializers[child.tagName.toLowerCase()]) elements.push(Element.extend(child)); return elements; } ); }, getInputs: function(form, typeName, name) { form = $(form); var inputs = form.getElementsByTagName('input'); if (!typeName && !name) return $A(inputs).map(Element.extend); for (var i = 0, matchingInputs = [], length = inputs.length; i < length; i++) { var input = inputs[i]; if ((typeName && input.type != typeName) || (name && input.name != name)) continue; matchingInputs.push(Element.extend(input)); } return matchingInputs; }, disable: function(form) { form = $(form); Form.getElements(form).invoke('disable'); return form; }, enable: function(form) { form = $(form); Form.getElements(form).invoke('enable'); return form; }, findFirstElement: function(form) { var elements = $(form).getElements().findAll(function(element) { return 'hidden' != element.type && !element.disabled; }); var firstByIndex = elements.findAll(function(element) { return element.hasAttribute('tabIndex') && element.tabIndex >= 0; }).sortBy(function(element) { return element.tabIndex }).first(); return firstByIndex ? firstByIndex : elements.find(function(element) { return ['input', 'select', 'textarea'].include(element.tagName.toLowerCase()); }); }, focusFirstElement: function(form) { form = $(form); form.findFirstElement().activate(); return form; }, request: function(form, options) { form = $(form), options = Object.clone(options || { }); var params = options.parameters, action = form.readAttribute('action') || ''; if (action.blank()) action = window.location.href; options.parameters = form.serialize(true); if (params) { if (Object.isString(params)) params = params.toQueryParams(); Object.extend(options.parameters, params); } if (form.hasAttribute('method') && !options.method) options.method = form.method; return new Ajax.Request(action, options); } }; /*--------------------------------------------------------------------------*/ Form.Element = { focus: function(element) { $(element).focus(); return element; }, select: function(element) { $(element).select(); return element; } }; Form.Element.Methods = { serialize: function(element) { element = $(element); if (!element.disabled && element.name) { var value = element.getValue(); if (value != undefined) { var pair = { }; pair[element.name] = value; return Object.toQueryString(pair); } } return ''; }, getValue: function(element) { element = $(element); var method = element.tagName.toLowerCase(); return Form.Element.Serializers[method](element); }, setValue: function(element, value) { element = $(element); var method = element.tagName.toLowerCase(); Form.Element.Serializers[method](element, value); return element; }, clear: function(element) { $(element).value = ''; return element; }, present: function(element) { return $(element).value != ''; }, activate: function(element) { element = $(element); try { element.focus(); if (element.select && (element.tagName.toLowerCase() != 'input' || !['button', 'reset', 'submit'].include(element.type))) element.select(); } catch (e) { } return element; }, disable: function(element) { element = $(element); element.blur(); element.disabled = true; return element; }, enable: function(element) { element = $(element); element.disabled = false; return element; } }; /*--------------------------------------------------------------------------*/ var Field = Form.Element; var $F = Form.Element.Methods.getValue; /*--------------------------------------------------------------------------*/ Form.Element.Serializers = { input: function(element, value) { switch (element.type.toLowerCase()) { case 'checkbox': case 'radio': return Form.Element.Serializers.inputSelector(element, value); default: return Form.Element.Serializers.textarea(element, value); } }, inputSelector: function(element, value) { if (value === undefined) return element.checked ? element.value : null; else element.checked = !!value; }, textarea: function(element, value) { if (value === undefined) return element.value; else element.value = value; }, select: function(element, index) { if (index === undefined) return this[element.type == 'select-one' ? 'selectOne' : 'selectMany'](element); else { var opt, value, single = !Object.isArray(index); for (var i = 0, length = element.length; i < length; i++) { opt = element.options[i]; value = this.optionValue(opt); if (single) { if (value == index) { opt.selected = true; return; } } else opt.selected = index.include(value); } } }, selectOne: function(element) { var index = element.selectedIndex; return index >= 0 ? this.optionValue(element.options[index]) : null; }, selectMany: function(element) { var values, length = element.length; if (!length) return null; for (var i = 0, values = []; i < length; i++) { var opt = element.options[i]; if (opt.selected) values.push(this.optionValue(opt)); } return values; }, optionValue: function(opt) { // extend element because hasAttribute may not be native return Element.extend(opt).hasAttribute('value') ? opt.value : opt.text; } }; /*--------------------------------------------------------------------------*/ Abstract.TimedObserver = Class.create(PeriodicalExecuter, { initialize: function($super, element, frequency, callback) { $super(callback, frequency); this.element = $(element); this.lastValue = this.getValue(); }, execute: function() { var value = this.getValue(); if (Object.isString(this.lastValue) && Object.isString(value) ? this.lastValue != value : String(this.lastValue) != String(value)) { this.callback(this.element, value); this.lastValue = value; } } }); Form.Element.Observer = Class.create(Abstract.TimedObserver, { getValue: function() { return Form.Element.getValue(this.element); } }); Form.Observer = Class.create(Abstract.TimedObserver, { getValue: function() { return Form.serialize(this.element); } }); /*--------------------------------------------------------------------------*/ Abstract.EventObserver = Class.create({ initialize: function(element, callback) { this.element = $(element); this.callback = callback; this.lastValue = this.getValue(); if (this.element.tagName.toLowerCase() == 'form') this.registerFormCallbacks(); else this.registerCallback(this.element); }, onElementEvent: function() { var value = this.getValue(); if (this.lastValue != value) { this.callback(this.element, value); this.lastValue = value; } }, registerFormCallbacks: function() { Form.getElements(this.element).each(this.registerCallback, this); }, registerCallback: function(element) { if (element.type) { switch (element.type.toLowerCase()) { case 'checkbox': case 'radio': Event.observe(element, 'click', this.onElementEvent.bind(this)); break; default: Event.observe(element, 'change', this.onElementEvent.bind(this)); break; } } } }); Form.Element.EventObserver = Class.create(Abstract.EventObserver, { getValue: function() { return Form.Element.getValue(this.element); } }); Form.EventObserver = Class.create(Abstract.EventObserver, { getValue: function() { return Form.serialize(this.element); } }); if (!window.Event) var Event = { }; Object.extend(Event, { KEY_BACKSPACE: 8, KEY_TAB: 9, KEY_RETURN: 13, KEY_ESC: 27, KEY_LEFT: 37, KEY_UP: 38, KEY_RIGHT: 39, KEY_DOWN: 40, KEY_DELETE: 46, KEY_HOME: 36, KEY_END: 35, KEY_PAGEUP: 33, KEY_PAGEDOWN: 34, KEY_INSERT: 45, cache: { }, relatedTarget: function(event) { var element; switch(event.type) { case 'mouseover': element = event.fromElement; break; case 'mouseout': element = event.toElement; break; default: return null; } return Element.extend(element); } }); Event.Methods = (function() { var isButton; if (Prototype.Browser.IE) { var buttonMap = { 0: 1, 1: 4, 2: 2 }; isButton = function(event, code) { return event.button == buttonMap[code]; }; } else if (Prototype.Browser.WebKit) { isButton = function(event, code) { switch (code) { case 0: return event.which == 1 && !event.metaKey; case 1: return event.which == 1 && event.metaKey; default: return false; } }; } else { isButton = function(event, code) { return event.which ? (event.which === code + 1) : (event.button === code); }; } return { isLeftClick: function(event) { return isButton(event, 0) }, isMiddleClick: function(event) { return isButton(event, 1) }, isRightClick: function(event) { return isButton(event, 2) }, element: function(event) { var node = Event.extend(event).target; return Element.extend(node.nodeType == Node.TEXT_NODE ? node.parentNode : node); }, findElement: function(event, expression) { var element = Event.element(event); return element.match(expression) ? element : element.up(expression); }, pointer: function(event) { return { x: event.pageX || (event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft)), y: event.pageY || (event.clientY + (document.documentElement.scrollTop || document.body.scrollTop)) }; }, pointerX: function(event) { return Event.pointer(event).x }, pointerY: function(event) { return Event.pointer(event).y }, stop: function(event) { Event.extend(event); event.preventDefault(); event.stopPropagation(); event.stopped = true; } }; })(); Event.extend = (function() { var methods = Object.keys(Event.Methods).inject({ }, function(m, name) { m[name] = Event.Methods[name].methodize(); return m; }); if (Prototype.Browser.IE) { Object.extend(methods, { stopPropagation: function() { this.cancelBubble = true }, preventDefault: function() { this.returnValue = false }, inspect: function() { return "[object Event]" } }); return function(event) { if (!event) return false; if (event._extendedByPrototype) return event; event._extendedByPrototype = Prototype.emptyFunction; var pointer = Event.pointer(event); Object.extend(event, { target: event.srcElement, relatedTarget: Event.relatedTarget(event), pageX: pointer.x, pageY: pointer.y }); return Object.extend(event, methods); }; } else { Event.prototype = Event.prototype || document.createEvent("HTMLEvents").__proto__; Object.extend(Event.prototype, methods); return Prototype.K; } })(); Object.extend(Event, (function() { var cache = Event.cache; function getEventID(element) { if (element._eventID) return element._eventID; arguments.callee.id = arguments.callee.id || 1; return element._eventID = ++arguments.callee.id; } function getDOMEventName(eventName) { if (eventName && eventName.include(':')) return "dataavailable"; return eventName; } function getCacheForID(id) { return cache[id] = cache[id] || { }; } function getWrappersForEventName(id, eventName) { var c = getCacheForID(id); return c[eventName] = c[eventName] || []; } function createWrapper(element, eventName, handler) { var id = getEventID(element); var c = getWrappersForEventName(id, eventName); if (c.pluck("handler").include(handler)) return false; var wrapper = function(event) { if (!Event || !Event.extend || (event.eventName && event.eventName != eventName)) return false; Event.extend(event); handler.call(element, event) }; wrapper.handler = handler; c.push(wrapper); return wrapper; } function findWrapper(id, eventName, handler) { var c = getWrappersForEventName(id, eventName); return c.find(function(wrapper) { return wrapper.handler == handler }); } function destroyWrapper(id, eventName, handler) { var c = getCacheForID(id); if (!c[eventName]) return false; c[eventName] = c[eventName].without(findWrapper(id, eventName, handler)); } function destroyCache() { for (var id in cache) for (var eventName in cache[id]) cache[id][eventName] = null; } if (window.attachEvent) { window.attachEvent("onunload", destroyCache); } return { observe: function(element, eventName, handler) { element = $(element); var name = getDOMEventName(eventName); var wrapper = createWrapper(element, eventName, handler); if (!wrapper) return element; if (element.addEventListener) { element.addEventListener(name, wrapper, false); } else { element.attachEvent("on" + name, wrapper); } return element; }, stopObserving: function(element, eventName, handler) { element = $(element); var id = getEventID(element), name = getDOMEventName(eventName); if (!handler && eventName) { getWrappersForEventName(id, eventName).each(function(wrapper) { element.stopObserving(eventName, wrapper.handler); }); return element; } else if (!eventName) { Object.keys(getCacheForID(id)).each(function(eventName) { element.stopObserving(eventName); }); return element; } var wrapper = findWrapper(id, eventName, handler); if (!wrapper) return element; if (element.removeEventListener) { element.removeEventListener(name, wrapper, false); } else { element.detachEvent("on" + name, wrapper); } destroyWrapper(id, eventName, handler); return element; }, fire: function(element, eventName, memo) { element = $(element); if (element == document && document.createEvent && !element.dispatchEvent) element = document.documentElement; if (document.createEvent) { var event = document.createEvent("HTMLEvents"); event.initEvent("dataavailable", true, true); } else { var event = document.createEventObject(); event.eventType = "ondataavailable"; } event.eventName = eventName; event.memo = memo || { }; if (document.createEvent) { element.dispatchEvent(event); } else { element.fireEvent(event.eventType, event); } return event; } }; })()); Object.extend(Event, Event.Methods); Element.addMethods({ fire: Event.fire, observe: Event.observe, stopObserving: Event.stopObserving }); Object.extend(document, { fire: Element.Methods.fire.methodize(), observe: Element.Methods.observe.methodize(), stopObserving: Element.Methods.stopObserving.methodize() }); (function() { /* Support for the DOMContentLoaded event is based on work by Dan Webb, Matthias Miller, Dean Edwards and John Resig. */ var timer, fired = false; function fireContentLoadedEvent() { if (fired) return; if (timer) window.clearInterval(timer); document.fire("dom:loaded"); fired = true; } if (document.addEventListener) { if (Prototype.Browser.WebKit) { timer = window.setInterval(function() { if (/loaded|complete/.test(document.readyState)) fireContentLoadedEvent(); }, 0); Event.observe(window, "load", fireContentLoadedEvent); } else { document.addEventListener("DOMContentLoaded", fireContentLoadedEvent, false); } } else { document.write("