[Ktutorial-commits] SF.net SVN: ktutorial:[72] trunk
Status: Alpha
Brought to you by:
danxuliu
|
From: <dan...@us...> - 2010-01-31 16:15:59
|
Revision: 72
http://ktutorial.svn.sourceforge.net/ktutorial/?rev=72&view=rev
Author: danxuliu
Date: 2010-01-31 16:15:52 +0000 (Sun, 31 Jan 2010)
Log Message:
-----------
Add web sources to SVN (except apidocs and doc).
Added Paths:
-----------
trunk/web-src/
trunk/web-src/cybertron.sh
trunk/web-src/data/
trunk/web-src/data/files/
trunk/web-src/data/files/cortado.jar
trunk/web-src/data/files/ktutorial-l10n.ogg
trunk/web-src/data/files/ktutorial-l10n.png
trunk/web-src/data/files/ktutorial-limpiar.ogg
trunk/web-src/data/files/ktutorial-limpiar.png
trunk/web-src/data/files/ktutorial-mover.ogg
trunk/web-src/data/files/ktutorial-mover.png
trunk/web-src/data/images/
trunk/web-src/data/images/icon-atom.png
trunk/web-src/data/images/icon-atom.svg
trunk/web-src/data/images/icon-rss.png
trunk/web-src/data/images/play.png
trunk/web-src/data/images/screenshots/
trunk/web-src/data/images/valid-a.png
trunk/web-src/data/images/valid-aa.png
trunk/web-src/data/images/valid-aaa.png
trunk/web-src/data/images/valid-atom.png
trunk/web-src/data/images/valid-css.png
trunk/web-src/data/images/valid-rss.png
trunk/web-src/data/images/valid-xhtml11.png
trunk/web-src/data/script/
trunk/web-src/data/script/foldableList.js
trunk/web-src/data/script/galleryGenerator.js
trunk/web-src/data/script/ogg.js
trunk/web-src/data/script/roundedCorners.js
trunk/web-src/data/script/videoEmbedder.js
trunk/web-src/data/style/
trunk/web-src/data/style/style.css
trunk/web-src/news-toAtom.xsl
trunk/web-src/news-toHTML.xsl
trunk/web-src/newsList.xml
trunk/web-src/newsList.xsd
trunk/web-src/pages/
trunk/web-src/pages/about.xml
trunk/web-src/pages/aboutWeb.xml
trunk/web-src/pages/development.xml
trunk/web-src/pages/documentation.xml
trunk/web-src/pages/download.xml
trunk/web-src/pages/faq.xml
trunk/web-src/pages/index.xml
trunk/web-src/pages/news.xml
trunk/web-src/pages/page.xsd
trunk/web-src/pages/screenshots.xml
trunk/web-src/pages/screenshotsGallery.xml
trunk/web-src/screenshotsList.dtd
trunk/web-src/screenshotsList.xml
trunk/web-src/transformers/
trunk/web-src/transformers/footer.xsl
trunk/web-src/transformers/head.xsl
trunk/web-src/transformers/header.xsl
trunk/web-src/transformers/menu.xml
trunk/web-src/transformers/menu.xsl
trunk/web-src/transformers/optimusPrime.xsl
trunk/web-src/updateNewsInPage.xsl
trunk/web-src/updateScreenshotsInPage.xsl
Added: trunk/web-src/cybertron.sh
===================================================================
--- trunk/web-src/cybertron.sh (rev 0)
+++ trunk/web-src/cybertron.sh 2010-01-31 16:15:52 UTC (rev 72)
@@ -0,0 +1,236 @@
+#!/bin/bash
+#
+# This script creates the website from the XML documents and data dirs.
+# It can be invoked with -e, -o and -u options.
+# -e is the output XHTML files encoding to be used. Default is utf-8.
+# -o is the output directory to be used. Default is "../build/"
+# -u is the base URL where the website will be.
+#
+# It needs xsltproc, xmllint (with support for XML Schema) and, if other
+# encoding than utf-8 is used, recode.
+#
+# Cybertron name was used as an easter egg for Transformers animation series,
+# as Cybertron was the planet where all the Transformers lived... This script
+# prepares everything needed by the XSL "Transformers" and creates and
+# environment to be executed... so that's why it's called cybertron :)
+#
+# TODO
+# -create XHTML files only when they were changed since the last execution.
+# -change this script into a Makefile?
+
+
+# Validates all the XML files under pages directory using XML Schema.
+# The XML Schema is located at pages/page.xsd
+function validateXmlPages() {
+ returnValue=0;
+
+ for i in `find pages -iname "*.xml"`
+ do
+ xmllint --noout --schema pages/page.xsd $i;
+ let "returnValue = $returnValue || $?";
+ done
+
+ return $returnValue;
+}
+
+# Validates the XML newsList.xml file using XML Schema.
+# The XML Schema is located at newsList.xsd
+function validateNews() {
+ xmllint --noout --schema newsList.xsd newsList.xml;
+ return $?;
+}
+
+# Validates the XML screenshotsList.xml file using DTD.
+# The DTD is located at screenshotsList.dtd
+function validateScreenshotsList() {
+ xmllint --noout --valid screenshotsList.xml \
+ && echo "screenshotsList.xml validates";
+ return $?;
+}
+
+# Validates all the XML files which have a DTD oir XML Schema.
+# Those files are pages files, news file and screenshotsList file.
+function validate() {
+ validation=0;
+
+ validateXmlPages;
+ let "validation = $validation || $?";
+
+ validateNews;
+ let "validation = $validation || $?";
+
+ validateScreenshotsList;
+ let "validation = $validation || $?";
+
+ return $validation;
+}
+
+# Prepares the XML pages that need to be updated before transforming them to
+# XHTML.
+# The pages that needs update are index.xml, news.xml and screenshotsGallery.xml
+# The first two have their news list updated, and the last its screenshots list.
+function preparePages() {
+ xsltproc -o $newsHtmlTmpFile news-toHTML.xsl newsList.xml;
+
+ # Prepares index.xml
+ xsltproc --stringparam newsHtmlFile $newsHtmlTmpFile -o pages/index.xml \
+ updateNewsInPage.xsl pages/index.xml
+ xmllint --format -o pages/index.xml pages/index.xml;
+
+ # Prepares news.xml
+ xsltproc --stringparam newsHtmlFile $newsHtmlTmpFile \
+ --stringparam numberOfNews -1 -o pages/news.xml \
+ updateNewsInPage.xsl pages/news.xml
+ xmllint --format -o pages/news.xml pages/news.xml;
+
+ # Prepares screenshotsGallery.xml
+ xsltproc --stringparam screenshotsHtmlFile screenshotsList.xml \
+ -o pages/screenshotsGallery.xml updateScreenshotsInPage.xsl \
+ pages/screenshotsGallery.xml
+ xmllint --format -o pages/screenshotsGallery.xml \
+ pages/screenshotsGallery.xml;
+}
+
+# Transforms all the XML documents under pages directory.
+# It creates all the XHTML pages using optimusPrime XSLT.
+# The pages are copied to the output dir (using subdirectories if they
+# existed under pages directory) and also reformatted (because xsltproc
+# sometimes doesn't create well formatted documents).
+# Before creating the XHTML pages, the output directory is created (if it
+# existed already, it is removed first). If it isn't valid, it returns 1.
+function createPages() {
+ if [ -e $outputDir ]; then
+ rm -fr $outputDir;
+ fi
+
+ mkdir -p $outputDir;
+ if [ $? -ne 0 ]; then
+ return 1;
+ fi
+
+ cd pages;
+
+ for i in `find . -iname "*.xml"`
+ do
+ # Gets the extension of the file
+ fileExtension=`expr match "$i" '.*\(\.[^\.]*\)'`;
+ # Removes the extension of the file from the file name
+ fileName=${i%"$fileExtension"}
+ # Removes leading "./" from the file name
+ fileName=${fileName:2};
+
+ xsltproc -o ../$outputDir/$fileName.html ../transformers/optimusPrime.xsl $fileName.xml;
+
+ xmllint --format -o ../$outputDir/$fileName.html ../$outputDir/$fileName.html;
+
+ if [ $encoding != "utf-8" ]; then
+ recode utf-8..$encoding ../$outputDir/$fileName.html;
+ sed -e "s/utf-8/$encoding/g" ../$outputDir/$fileName.html > ../$outputDir/$fileName.html.tmp;
+ mv ../$outputDir/$fileName.html.tmp ../$outputDir/$fileName.html
+ fi
+ done
+
+ cd ..;
+
+ return 0;
+}
+
+# Creates the news feed from newsList.xml
+# The feed is copied to "feed/atom/news.xml" under output dir.
+function createFeeds() {
+ xsltproc --stringparam baseURL $baseURL -o $outputDir/feed/atom/news.xml news-toAtom.xsl newsList.xml;
+}
+
+# Copies the data dirs to the output dir.
+function copyDataDirs() {
+ cp -r data/* $outputDir;
+}
+
+# Copies the source dir to the output dir.
+function copySrcDir() {
+ cp -r . $outputDir/src;
+ rm -fr $outputDir/src/data/apidocs;
+ rm -fr $outputDir/src/data/doc;
+ rm -fr $outputDir/src/data/files;
+}
+
+# Removes all the .svn folders in the output directory.
+function removeSvnFolders() {
+ find $outputDir -name ".svn" -print0 | xargs -0 rm -rf;
+}
+
+# Packs the source dir and copies it to the files subdirectory of output dir.
+function packSrcDir() {
+ # Tar removes leading "../" from filenames. It must be disabled with
+ # --absolute-names to ensure the name is transformed as expected.
+ tar --absolute-names --transform="s,$outputDir/src,src," -czf $outputDir/files/webSrc.tar.gz $outputDir/src;
+}
+
+
+encoding="utf-8";
+outputDir=../build/;
+baseURL="http://csl2-ktutorial.forja.rediris.es/";
+
+while getopts e:o:u: o
+do
+ case "$o" in
+ e) encoding="$OPTARG";;
+ o) outputDir="$OPTARG";;
+ u) baseURL="$OPTARG";;
+ [?]) echo "Usage: $0 [-e encoding] [-o outputDir] [-u baseURL]";
+ echo " Default encoding: utf-8";
+ echo " Default output directory: ../build/";
+ echo " Default baseURL: http://csl2-ktutorial.forja.rediris.es/";
+ exit 1;;
+ esac
+done
+shift $(($OPTIND -1))
+
+# Ensures baseURL ends with a "/"
+if [ ${baseURL:`expr ${#baseURL} - 1`} != "/" ]; then
+ baseURL=$baseURL"/";
+fi
+
+export XMLLINT_INDENT=" ";
+
+newsHtmlTmpFile=news-html.xml;
+
+
+echo "Validating XML files..."
+validate;
+if [ $? -ne 0 ]; then
+ echo "Validation failed. Aborting...";
+ exit;
+fi
+
+echo "Preparing pages...";
+preparePages;
+
+echo "Creating XHTML pages...";
+createPages;
+if [ $? -ne 0 ]; then
+ echo "Output directory $outputDir isn't valid. Aborting..."
+ exit;
+fi
+
+echo "Creating feeds...";
+createFeeds;
+
+echo "Copying data dirs...";
+copyDataDirs;
+
+if [ $outputDir != .. ]; then
+ echo "Copying source dir...";
+ copySrcDir;
+fi;
+
+echo "Removing SVN folders...";
+removeSvnFolders;
+
+echo "Packing source dir...";
+packSrcDir;
+
+echo "Cleaning up...";
+rm -f $newsHtmlTmpFile;
+
+echo "Done!";
Property changes on: trunk/web-src/cybertron.sh
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:eol-style
+ native
Added: trunk/web-src/data/files/cortado.jar
===================================================================
(Binary files differ)
Property changes on: trunk/web-src/data/files/cortado.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/web-src/data/files/ktutorial-l10n.ogg
===================================================================
(Binary files differ)
Property changes on: trunk/web-src/data/files/ktutorial-l10n.ogg
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/web-src/data/files/ktutorial-l10n.png
===================================================================
(Binary files differ)
Property changes on: trunk/web-src/data/files/ktutorial-l10n.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: trunk/web-src/data/files/ktutorial-limpiar.ogg
===================================================================
(Binary files differ)
Property changes on: trunk/web-src/data/files/ktutorial-limpiar.ogg
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/web-src/data/files/ktutorial-limpiar.png
===================================================================
(Binary files differ)
Property changes on: trunk/web-src/data/files/ktutorial-limpiar.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: trunk/web-src/data/files/ktutorial-mover.ogg
===================================================================
(Binary files differ)
Property changes on: trunk/web-src/data/files/ktutorial-mover.ogg
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/web-src/data/files/ktutorial-mover.png
===================================================================
(Binary files differ)
Property changes on: trunk/web-src/data/files/ktutorial-mover.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: trunk/web-src/data/images/icon-atom.png
===================================================================
(Binary files differ)
Property changes on: trunk/web-src/data/images/icon-atom.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: trunk/web-src/data/images/icon-atom.svg
===================================================================
--- trunk/web-src/data/images/icon-atom.svg (rev 0)
+++ trunk/web-src/data/images/icon-atom.svg 2010-01-31 16:15:52 UTC (rev 72)
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="128px" height="128px" id="RSSicon" viewBox="0 0 256 256">
+<defs>
+<linearGradient x1="0.085" y1="0.085" x2="0.915" y2="0.915" id="RSSg">
+<stop offset="0.0" stop-color="#E3702D"/><stop offset="0.1071" stop-color="#EA7D31"/>
+<stop offset="0.3503" stop-color="#F69537"/><stop offset="0.5" stop-color="#FB9E3A"/>
+<stop offset="0.7016" stop-color="#EA7C31"/><stop offset="0.8866" stop-color="#DE642B"/>
+<stop offset="1.0" stop-color="#D95B29"/>
+</linearGradient>
+</defs>
+<rect width="256" height="256" rx="55" ry="55" x="0" y="0" fill="#CC5D15"/>
+<rect width="246" height="246" rx="50" ry="50" x="5" y="5" fill="#F49C52"/>
+<rect width="236" height="236" rx="47" ry="47" x="10" y="10" fill="url(#RSSg)"/>
+<circle cx="68" cy="189" r="24" fill="#FFF"/>
+<path d="M160 213h-34a82 82 0 0 0 -82 -82v-34a116 116 0 0 1 116 116z" fill="#FFF"/>
+<path d="M184 213A140 140 0 0 0 44 73 V 38a175 175 0 0 1 175 175z" fill="#FFF"/>
+</svg>
Added: trunk/web-src/data/images/icon-rss.png
===================================================================
(Binary files differ)
Property changes on: trunk/web-src/data/images/icon-rss.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: trunk/web-src/data/images/play.png
===================================================================
(Binary files differ)
Property changes on: trunk/web-src/data/images/play.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: trunk/web-src/data/images/valid-a.png
===================================================================
(Binary files differ)
Property changes on: trunk/web-src/data/images/valid-a.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: trunk/web-src/data/images/valid-aa.png
===================================================================
(Binary files differ)
Property changes on: trunk/web-src/data/images/valid-aa.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: trunk/web-src/data/images/valid-aaa.png
===================================================================
(Binary files differ)
Property changes on: trunk/web-src/data/images/valid-aaa.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: trunk/web-src/data/images/valid-atom.png
===================================================================
(Binary files differ)
Property changes on: trunk/web-src/data/images/valid-atom.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: trunk/web-src/data/images/valid-css.png
===================================================================
(Binary files differ)
Property changes on: trunk/web-src/data/images/valid-css.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: trunk/web-src/data/images/valid-rss.png
===================================================================
(Binary files differ)
Property changes on: trunk/web-src/data/images/valid-rss.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: trunk/web-src/data/images/valid-xhtml11.png
===================================================================
(Binary files differ)
Property changes on: trunk/web-src/data/images/valid-xhtml11.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: trunk/web-src/data/script/foldableList.js
===================================================================
--- trunk/web-src/data/script/foldableList.js (rev 0)
+++ trunk/web-src/data/script/foldableList.js 2010-01-31 16:15:52 UTC (rev 72)
@@ -0,0 +1,404 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Daniel Calviño Sánchez *
+ * ka...@us... *
+ * *
+ * This library is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This library is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this library; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+/******************************************************************************
+ * *
+ * DESCRIPTION OF THIS SCRIPT *
+ * *
+ *****************************************************************************/
+
+/*
+
+DESCRIPTION
+-----------
+Adds special links to compound lists so sublists can be folded and unfolded.
+
+Each sublist (a list in a list item) of the list with class "foldableList" are
+made foldable. Every sublist is unfolded at the beginning.
+
+When the "fold" link (represented by a "-") in an unfolded list is clicked, all
+the sublists are removed from the item list and the "fold" link changes to
+"unfold".
+When the "unfold" link (represented by a "+") in a folded list is clicked, all
+the sublists are added again to the item list and the "unfold" link changes to
+"fold".
+
+No style is applied to the generated elements. The only new elements added are
+the fold/unfold links, which belong to "foldLink" class, so they can be styled
+with CSS.
+
+Elements are added and removed instead of only shown or hidden using CSS, so it
+works even when no stylesheets are used.
+
+
+HOW DOES IT WORK?
+-----------------
+All the root lists with "foldableList" class are selected and made foldable.
+Root list referes to class with "foldableList" class which aren't child (direct
+or deep) of another list with "foldableList" class.
+
+When a list is made foldable, all its list item are checked to know if they can
+be made foldable. A list item can be made foldable if it contains at least one
+list (ordered or unordered). All the list items that can be made foldable are
+made foldable recursively. In each foldable list item a link is inserted before
+the first child. This link will fold or unfold the list, depending on the state.
+
+When a list item is folded, the list item is copied to an array of folded lists.
+It's cloned, and all the child lists are removed from the clone. The original
+list item is then substituted in the document by its clone. The link to fold in
+the clone is also changed to unfold to reflect the new state.
+
+When a list item is unfolded, the previously saved original list item is put
+again in the document replacing the folded clone.
+
+
+LIST THAT CAN BE MADE FOLDABLE EXAMPLE
+--------------------------------------
+The XML below shows an example of a list that can be made foldable. It's simply
+a two levels list.
+
+<ul class="foldableList">
+ <li>Item 1
+ <ul>
+ <li>Item 1.1</li>
+ <li>Item 1.2</li>
+ </ul>
+ </li>
+ <li>Item 2</li>
+ <li>Item 3
+ <ul>
+ <li>Item 3.1</li>
+ <li>Item 3.2
+ <ul>
+ <li>Item 3.2.1</li>
+ </ul>
+ </li>
+ </ul>
+ </li>
+</ul>
+
+The shown foldable list will be:
+* -Item 1
+ * Item 1.1
+ * Item 1.2
+* Item 2
+* -Item 3
+ * Item 3.1
+ * -Item 3.2
+ * Item 3.2.1
+
+
+TESTED WITH:
+------------
+-Mozilla Firefox 1.0.2 (should work with all the Gecko based browsers)
+-Konqueror 3.4 (should work with all the KHTML based browsers)
+
+
+*/
+
+/******************************************************************************
+ * *
+ * PROTOYPES *
+ * *
+ *****************************************************************************/
+
+/**
+ * Adds an item to the array in the first empty position and returns the
+ * position.
+ * If no empty position was found the item is appended.
+ *
+ * @param item The item to be added.
+ * @return The position where the item was added.
+ */
+Array.prototype.add = function(item) {
+ var i;
+ for (i=0; i<this.length; i++) {
+ if (this[i] == null) {
+ this[i] = item;
+ return i;
+ }
+ }
+
+ this.push(item);
+
+ return i;
+}
+
+
+/******************************************************************************
+ * *
+ * FOLDABLE LISTS FUNCTIONS *
+ * *
+ *****************************************************************************/
+
+/**
+ * A list containing all the folded lists.
+ */
+var foldedLists;
+
+/**
+ * Makes all the lists (ordered or unordered) with class "foldableList"
+ * foldables.
+ * A foldable list has a special link in each sublist so they can be hidden or
+ * shown. Every sublist of a foldable list is foldable, no matter how deep it
+ * is. Child lists can also have class "foldableList", but it's superfluous.
+ */
+function makeListsFoldable() {
+ if (!scriptCanBeHandled()) {
+ return;
+ }
+
+ foldedLists = [];
+
+ var selectedLists = getListsToMakeFoldable();
+
+ var i;
+ for (i=0; i<selectedLists.length; i++) {
+ makeListFoldable(selectedLists[i]);
+ }
+}
+
+/**
+ * Checks if the browser implementes all the needed ECMAScript bindings for the
+ * script.
+ * This script uses DOM Level 2 Core and DOM Level 2 Events module.
+ *
+ * @return True if the browser conforms to the needed modules, false otherwise.
+ */
+function scriptCanBeHandled() {
+ if (!(document.implementation.hasFeature("Core", "2.0") &&
+ document.implementation.hasFeature("Events", "2.0"))) {
+ return false;
+ }
+
+ return true;
+}
+
+/**
+ * Makes the specified list foldable.
+ * All the child nodes are checked and, if they can be foldable, are made
+ * foldable recursively.
+ *
+ * @param list The list to be made foldable.
+ */
+function makeListFoldable(list) {
+ var childNodes = list.childNodes;
+
+ var i;
+ for (i=0; i<childNodes.length; i++) {
+ if (childNodes[i].nodeType == Node.ELEMENT_NODE &&
+ childNodes[i].tagName.toLowerCase() == "li") {
+
+ makeListElementFoldable(childNodes[i]);
+ }
+ }
+}
+
+/**
+ * Checks if a list item should be made foldable and, if it should, makes it.
+ * A list item should be made foldable if it contains any list (ordered or
+ * unordered). When made foldable, a link is added in the list item before any
+ * other child. This link will fold or unfold the list depending on the state.
+ * An event listener is added to the link so it can handle click events.
+ *
+ * @param listItem The list item to be made foldable.
+ */
+function makeListElementFoldable(listItem) {
+ var childNodes = listItem.childNodes;
+
+ var makeFoldable = false;
+
+ var i;
+ for (i=0; i<childNodes.length; i++) {
+ if (childNodes[i].nodeType == Node.ELEMENT_NODE &&
+ (childNodes[i].tagName.toLowerCase() == "ul" ||
+ childNodes[i].tagName.toLowerCase() == "ol")) {
+ makeFoldable = true;
+
+ makeListFoldable(childNodes[i]);
+ }
+ }
+
+ if (makeFoldable) {
+ var foldLink = document.createElement("a");
+ foldLink.setAttribute("class", "foldLink");
+ foldLink.setAttribute("href", "#fold");
+ foldLink.setAttribute("title", "Fold this menu");
+ foldLink.appendChild(document.createTextNode("-"));
+
+ foldLink.addEventListener("click", foldMenuHandler, false);
+
+ listItem.insertBefore(foldLink, listItem.firstChild);
+ }
+}
+
+/**
+ * Hanlder for click event in the fold link in an unfolded list.
+ * The list item is saved, and replaced by a copy of that list item with child
+ * list elements removed. The list item is saved in the first free position in
+ * the foldedLists array. This position is added to the href so it can be later
+ * (when unfolding) retrieved.
+ * The unfold link in the cloned (and folded) list is edited so it reflects its
+ * new function (unfold instead of fold).
+ */
+function foldMenuHandler(event) {
+ var listItem = event.currentTarget.parentNode;
+
+ var position = foldedLists.add(listItem);
+
+ var listItemClone = listItem.cloneNode(true);
+ var childNodes = listItemClone.childNodes;
+
+ var i;
+ for (i=0; i<childNodes.length; i++) {
+ if (childNodes[i].nodeType == Node.ELEMENT_NODE &&
+ (childNodes[i].tagName.toLowerCase() == "ul" ||
+ childNodes[i].tagName.toLowerCase() == "ol")) {
+ listItemClone.removeChild(childNodes[i]);
+ }
+ }
+
+ listItem.parentNode.replaceChild(listItemClone, listItem);
+ var foldLink = listItemClone.firstChild;
+
+ foldLink.setAttribute("href", "#unfold" + position);
+ foldLink.setAttribute("title", "Unfold this menu");
+
+ foldLink.replaceChild(document.createTextNode("+"), foldLink.firstChild);
+
+ foldLink.removeEventListener("click", foldMenuHandler, false);
+ foldLink.addEventListener("click", unfoldMenuHandler, false);
+}
+
+/**
+ * Hanlder for click event in the unfold link in a folded list.
+ * The unfolded list item is get from the saved list items using the id in the
+ * href element of the link. The current list item is replaced by the saved (and
+ * unfolded) list item.
+ */
+function unfoldMenuHandler(event) {
+ var foldLink = event.currentTarget;
+ var listItem = foldLink.parentNode;
+
+ //"#unfold" length is 7
+ var position = foldLink.getAttribute("href").substring(7);
+
+ listItem.parentNode.replaceChild(foldedLists[position], listItem);
+ foldedLists[position] = null;
+}
+
+
+
+/******************************************************************************
+ * *
+ * GET ELEMENTS *
+ * *
+ *****************************************************************************/
+
+/**
+ * Returns an array with all the list to make foldable.
+ * All the root list elements of "foldableList" class are selected. Lists can be
+ * unordered or ordered.
+ * If two lists, A and B, have "foldableList" class, and B is child (direct or
+ * deep) of A, only A is returned.
+ *
+ * Any element other element of "foldableList" class is ignored.
+ *
+ * @return All the lists to make foldable.
+ */
+function getListsToMakeFoldable() {
+ var selectedElementsByClass = getRootElementsByClass(
+ document.documentElement,
+ "foldableList");
+ var selectedElements = [];
+
+ var i;
+ for (i=0; i<selectedElementsByClass.length; i++) {
+ if (selectedElementsByClass[i].tagName.toLowerCase() == "ul" ||
+ selectedElementsByClass[i].tagName.toLowerCase() == "ol") {
+ selectedElements.push(selectedElementsByClass[i]);
+ }
+ }
+
+ return selectedElements;
+}
+
+/**
+ * Returns all the root child elements of "element" with the specified class
+ * name (or the element itself if it's from the specified class).
+ * All the root children are returned, not only direct root children.
+ *
+ * The term root child refers to an element which is from the specified class
+ * and hasn't an ancestor also from that class. That is, if two elements, A and
+ * B, have the specified class, and B is child (direct or deep) of A, only A is
+ * returned.
+ *
+ * @param element The element to get the elements from.
+ * @param className The class name of the elements to get.
+ * @return An array with all the root elements of the specified class.
+ */
+function getRootElementsByClass(element, className) {
+ var selectedElements = [];
+
+ var added = false;
+ var elementClasses = element.className.split(" ");
+ var i;
+ for (i=0; !added && i<elementClasses.length; i++) {
+ if (elementClasses[i] == className) {
+ selectedElements.push(element);
+ added = true;
+ }
+ }
+
+ if (added) {
+ return selectedElements;
+ }
+
+ var directChildElements = [];
+ getDirectChildElements(element, directChildElements);
+
+ for (i=0; i<directChildElements.length; i++) {
+ selectedElements = selectedElements.concat(getRootElementsByClass(
+ directChildElements[i],
+ className));
+ }
+
+ return selectedElements;
+}
+
+/**
+ * Appends all the child elements of "element" in the array "elementsList".
+ * Children are added only if they're true elements, not if they're only nodes.
+ *
+ * Only direct children are appended.
+ *
+ * @param element The element to add its children.
+ * @param elementsList The list to append the elements to.
+ */
+function getDirectChildElements(element, elementsList) {
+ var childNodes = element.childNodes;
+
+ var i;
+ for (i=0; i<childNodes.length; i++) {
+ if (childNodes[i].nodeType == Node.ELEMENT_NODE) {
+ elementsList.push(childNodes[i]);
+ }
+ }
+}
Added: trunk/web-src/data/script/galleryGenerator.js
===================================================================
--- trunk/web-src/data/script/galleryGenerator.js (rev 0)
+++ trunk/web-src/data/script/galleryGenerator.js 2010-01-31 16:15:52 UTC (rev 72)
@@ -0,0 +1,656 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Daniel Calviño Sánchez *
+ * ka...@us... *
+ * *
+ * This library is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This library is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this library; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+/******************************************************************************
+ * *
+ * DESCRIPTION OF THIS SCRIPT *
+ * *
+ *****************************************************************************/
+
+/*
+
+DESCRIPTION
+-----------
+Generates a screenshot gallery from a list of screenshots with a specific
+structure.
+
+When an item of the list is clicked, it shows an individual screenshot with the
+screenshot title, a screenshots counter and a navigation bar to go to the
+previous and next screenshots, if any. The individual screenshots, when clicked
+on them, show the full size screenshots. Individual screenshots also resize
+themselves to fit in the window each time it is resized.
+
+No style is applied to the generated elements. However, they have specific ids,
+so they can be styled with CSS. See the section "Generated screenshot structure"
+for further information on the generated elements and theirs ids.
+
+
+HOW DOES IT WORK?
+-----------------
+The screenshots list is read and stored in a variable. It's modified so each
+thumbnail now is linked to the generated enlarged screenshot instead of the
+full size screenshot.
+Both enlarged screenshots and the screenshots list are child of the same
+element: when the list is shown, the individual screenshot is removed; when an
+individual screenshot is shown, the list (or another screenshot) is removed.
+
+The needed information for each individual screenshot is got from the
+screenshots list. Screenshots are identified by the number they have in the
+screenshots list. Each screenshot can be shown individually appending "#number"
+to the url of the page. If there's no "#number", the whole list is shown.
+
+Resize event of the window is handled so, if there's any individual screenshot
+being shown, it'll be resized every time the window is resized, so it can fit
+in the available space.
+
+Default handlers for click events aren't prevented to be executed, so the
+location of the page is updated to the specified new link.
+
+
+SCREENSHOTS LIST STRUCTURE
+--------------------------
+The XML below shows the structure the screenshots list must conform with to be
+used with this script. Only one list item is shown, the others should follow the
+same structure.
+
+<ul id="screenshotsList">
+ <li>
+ <p>Screenshot title</p>
+ <a href="path/screenshotName.extension" title="Click for full size">
+ <img src="path/screenshotName-widthOfThumbnail.extension"
+ alt="(Screenshot title) screenshot thumbnail"/>
+ </a>
+ </li>
+ ...
+</ul>
+
+
+GENERATED SCREENSHOT STRUCTURE
+------------------------------
+The code below is an example of the XML elements created for every screenshot
+shown. The things that change depending on each screenshot are the title of
+the screenshot, the counter of screenshots, the pathname to the screenshot and
+the links to the next and previous screenshots.
+
+<div id="screenshot">
+ <p id="screenshotTitle">The title of the screenshot</p>
+ <p>2/3</p>
+ <p id="screenshotImageWrapper">
+ <a id="screenshotImageLink" href="images/aScreenshot.jpg"
+ title="Click for full size">
+ <img width="(a number that depends on window size)" id="screenshotImage"
+ src="images/aScreenshot.jpg"
+ alt="Current screenshot: images/aScreenshot.jpg"/>
+ </a>
+ </p>
+ <div id="navigationBar">
+ <p id="nextWrapper">
+ <a href="path/page.html#0" title="Next screenshot">< Previous</a>
+ </p>
+ <p id="upWrapper">
+ <a href="path/page.html" title="Screenshots list">Up</a>
+ </p>
+ <p id="nextWrapper">
+ <a href="path/page.html#2" title="Next screenshot">Next ></a>
+ </p>
+ </div>
+</div>
+
+
+LIMITATIONS:
+------------
+If a screenshot or the screenshot list are currently loaded, changing the url
+in the address bar from page.html#number to page.html#otherNumber (for example)
+won't do anything. Once the url is changed, the page must be refreshed.
+
+
+TESTED WITH:
+------------
+-Mozilla Firefox 1.0.2 (should work with all the Gecko based browsers)
+-Konqueror 3.4 (should work with all the KHTML based browsers)
+
+
+*/
+
+
+/******************************************************************************
+ * *
+ * GALLERY GENERATOR fUNCTIONS *
+ * *
+ *****************************************************************************/
+
+/**
+ * The URL of the page with the list of screenshots.
+ */
+var screenshotsURL;
+
+/**
+ * The element to append screenshots and the screenshots list to.
+ */
+var screenshotsParent;
+
+/**
+ * The next sibling to the screenshots and the screenshots list.
+ */
+var screenshotsNextSibling;
+
+/**
+ * The list containing all the screenshots.
+ */
+var screenshotsList;
+
+/**
+ * The current screenshots being shown, if any.
+ */
+var currentScreenshot;
+
+/**
+ * The number of the current screenshots being shown, if any.
+ */
+var currentScreenshotNumber;
+
+/**
+ * The item in the screenshots list of the current screenshot being shown, if
+ * any.
+ */
+var currentScreenshotListItem;
+
+/**
+ * Generates the screenshots gallery, and shows it or a concrete screenshot
+ * depending on the URL.
+ * It modifies the default list to make links point to the enlarged screenshot
+ * instead of the full size screenshot.
+ * If the URL has the form "path/page.html#number", it shows the screenshot with
+ * that number (or first or last screenshot, if the number is out of range).
+ * Otherwise, it shows the screenshots list.
+ */
+function generateGallery() {
+ if (!scriptCanBeHandled()) {
+ return;
+ }
+
+ screenshotsList = document.getElementById("screenshotsList");
+
+ if (document.URL.indexOf('#') < 0) {
+ screenshotsURL = document.URL;
+ } else {
+ screenshotsURL = document.URL.substring(0, document.URL.indexOf('#'));
+ }
+
+ //Prepares the screenshots list
+ var linksList = screenshotsList.getElementsByTagName("a");
+ var i;
+ for (i=0; i<linksList.length; i++) {
+ linksList[i].setAttribute("href", screenshotsURL + "#" + i);
+ linksList[i].setAttribute("title", "Click to enlarge");
+ linksList[i].addEventListener("click", showScreenshotHandler, false);
+ }
+
+ //No screenshot is currently being shown
+ currentScreenshot = null;
+ currentScreenshotNumber = -1;
+ currentScreenshotListItem = null;
+
+ if (screenshotsList.getElementsByTagName("li")[0]) {
+ screenshotsNextSibling = screenshotsList.nextSibling;
+ screenshotsParent = screenshotsList.parentNode;
+
+ var screenshotNumber = getScreenshotNumberFromURL(document.URL);
+
+ if (screenshotNumber != -1) {
+ setNewScreenshot(screenshotNumber);
+ } else {
+ showScreenshotsList();
+ }
+
+ onresize = updateScreenshotSize;
+ }
+}
+
+/**
+ * Checks if the browser implementes all the needed ECMAScript bindings for the
+ * script.
+ * This script uses DOM Level 2 Core, DOM Level 2 HTML module and DOM Level 2
+ * Events module and DOM Level 2 CSS2 module.
+ *
+ * However, CSS2 module isn't truly checked. Instead, the needed objects
+ * availability is checked, as browsers like Konqueror which can handle all the
+ * needed objects doesn't fully support the binding.
+ *
+ * @return True if the browser conforms to the needed modules, false otherwise.
+ */
+function scriptCanBeHandled() {
+ if (!(document.implementation.hasFeature("Core", "2.0") &&
+ document.implementation.hasFeature("Events", "2.0") &&
+ document.implementation.hasFeature("HTML", "2.0") &&
+ checkCSS2())) {
+ return false;
+ }
+
+ return true;
+}
+
+/**
+ * Checks if the browser can handle all the needed DOM Level 2 CSS2 module
+ * objects.
+ * hasFeature() isn't used because some browsers as Konqueror can handle all the
+ * needed objects but doesn't fully support the module.
+ *
+ * @return True if the browser can handle all the needed objects, false
+ * otherwise.
+ */
+function checkCSS2() {
+ if (!(document.defaultView && document.defaultView.getComputedStyle)) {
+ return false;
+ }
+
+ return true;
+}
+
+/**
+ * Shows the screenshosts list.
+ * If an enlarged screenshot is being shown, it's removed and the list shown
+ * instead.
+ */
+function showScreenshotsList() {
+ if (currentScreenshot !=null) {
+ screenshotsParent.removeChild(currentScreenshot);
+
+ currentScreenshot = null;
+ currentScreenshotNumber = -1;
+ currentScreenshotListItem = null;
+ }
+
+ screenshotsParent.appendChild(screenshotsList);
+}
+
+/**
+ * Shows the screenshot clicked.
+ * Gets the number of screenshot from the link clicked and sets that screenshot.
+ */
+function showScreenshotHandler(event) {
+ var screenshotNumber = getScreenshotNumberFromURL(event.currentTarget.href);
+
+ if (screenshotNumber != -1) {
+ setNewScreenshot(screenshotNumber);
+ }
+}
+
+/**
+ * Returns the screenshot number from a URL in the form "path/page.html#number".
+ * If there's no number specified in the url, or it's not a valid number, it
+ * returns -1.
+ *
+ * @param url The url to get the screenshot number from.
+ * @return The screenshot number from the URL.
+ */
+function getScreenshotNumberFromURL(url) {
+ var screenshotNumber = -1;
+
+ if (url.indexOf('#') >= 0) {
+ screenshotNumber = parseInt(
+ url.substr(url.indexOf('#') + 1));
+
+ if (isNaN(screenshotNumber)) {
+ screenshotNumber = -1;
+ }
+ }
+
+ return screenshotNumber;
+}
+
+/**
+ * Shows a new screenshot.
+ * The screenshot is specified by its number, indexed in 0.
+ * The already loaded screenshot or screenshot list is removed to show the new
+ * screenshot.
+ *
+ * @param screenshotNumber The number of the screenshot to show.
+ */
+function setNewScreenshot(screenshotNumber) {
+ if (currentScreenshot) {
+ screenshotsParent.removeChild(currentScreenshot);
+ } else {
+ screenshotsParent.removeChild(screenshotsList);
+ }
+
+ screenshotsParent.insertBefore(
+ createScreenshot(screenshotNumber),
+ screenshotsNextSibling);
+ updateScreenshotSize();
+}
+
+/**
+ * Returns a div element containing the screenshot title, the screenshots
+ * counter, the screenshot image and the navigation bar.
+ * Screenshot number is indexed in 0. If the specified screenshot number is
+ * smaller or larger than 0 or the number of screenshots available, it's set to
+ * 0 or the number of the last screenshot.
+ *
+ * currentScreenshot, currentScreenshotNumber and currentScreenshotListItem
+ * are set to the needed values.
+ */
+function createScreenshot(screenshotNumber) {
+ var listItemElements = screenshotsList.getElementsByTagName("li");
+
+ if (screenshotNumber < 0) {
+ screenshotNumber = 0;
+ } else if (screenshotNumber >= listItemElements.length) {
+ screenshotNumber = listItemElements.length - 1;
+ }
+
+ var listItemElement = listItemElements[screenshotNumber];
+
+ var divElement = document.createElement("div");
+ divElement.setAttribute("id", "screenshot");
+
+ currentScreenshot = divElement;
+ currentScreenshotNumber = screenshotNumber;
+ currentScreenshotListItem = listItemElement;
+
+ //Screenshot title
+ var pElement = listItemElement.getElementsByTagName("p")[0].cloneNode(true);
+ pElement.setAttribute("id", "screenshotTitle");
+ divElement.appendChild(pElement);
+
+ divElement.appendChild(createScreenshotCounter());
+
+ var thumbnailImageElement = listItemElement.getElementsByTagName("img")[0];
+ divElement.appendChild(createImageLink(thumbnailImageElement));
+
+ divElement.appendChild(createNavigationBar(listItemElement));
+
+ return divElement;
+}
+
+/**
+ * Returns a paragraph with the current number of the screenshot (indexed in 1)
+ * and the total number of screenshots.
+ *
+ * @return The paragraph with the numbers.
+ */
+function createScreenshotCounter() {
+ var screenshotCountText = (currentScreenshotNumber + 1) + "/" +
+ screenshotsList.getElementsByTagName("li").length;
+
+ var screenshotCountElement = document.createElement("p");
+ screenshotCountElement.appendChild(
+ document.createTextNode(screenshotCountText));
+
+ return screenshotCountElement;
+}
+
+/**
+ * Returns a link to the full image containing also this image.
+ * The link uses the id "currentScreenshotImageLink" and the image uses the id
+ * "currentScreenshotImage".
+ * The link is wrapped in a paragraph.
+ *
+ * @param thumbnailImageElement The image in the screenshot thumbnail.
+ * @return The link element containing the image, wrapped in a paragraph.
+ */
+function createImageLink(thumbnailImageElement) {
+ var imageLinkWrapperElement = document.createElement("p");
+ imageLinkWrapperElement.setAttribute("id", "screenshotImageWrapper");
+
+ var imageLinkElement = document.createElement("a");
+ imageLinkElement.setAttribute("id", "screenshotImageLink");
+
+ var thumbnailImageSrc = thumbnailImageElement.getAttribute("src");
+ var imageName = thumbnailImageSrc.substring(0,
+ thumbnailImageSrc.lastIndexOf("-"));
+ var imageExtension = thumbnailImageSrc.substr(
+ thumbnailImageSrc.lastIndexOf("."));
+ var imageSrc = imageName + imageExtension;
+ imageLinkElement.setAttribute("href", imageSrc);
+ imageLinkElement.setAttribute("title", "Click for full size");
+
+ var imageElement = document.createElement("img");
+ imageElement.setAttribute("id", "screenshotImage");
+ imageElement.setAttribute("src", imageSrc);
+ imageElement.setAttribute("alt", "Current screenshot: " + imageSrc);
+ imageLinkElement.appendChild(imageElement);
+
+ imageLinkWrapperElement.appendChild(imageLinkElement);
+
+ return imageLinkWrapperElement;
+}
+
+/**
+ * Returns the navigation bar.
+ * The navigation bar includes links to the previous and next elements, and to
+ * the list of screenshots.
+ * If the screenshot is the first, previous link isn't added. If the screenshot
+ * is the last, next link isn't added.
+ *
+ * @param listItemElement The list item element in the screenshots list for the
+ * current screenshot.
+ * @return The navigation bar.
+ */
+function createNavigationBar(listItemElement) {
+ var divElement = document.createElement("div");
+ divElement.setAttribute("id", "navigationBar");
+
+ var previousElement = createNavigationBarPrevious(listItemElement);
+ if (previousElement) {
+ divElement.appendChild(previousElement);
+ }
+
+ divElement.appendChild(createNavigationBarUp());
+
+ var nextElement = createNavigationBarNext(listItemElement);
+ if (nextElement) {
+ divElement.appendChild(nextElement);
+ }
+
+ return divElement;
+}
+
+/**
+ * Returns the "Previous" link for the navigation bar.
+ * If the list item is the first in the list, a null element is returned.
+ * The link handles clicks showing the previous screenshot in the list.
+ * The link is wrapped in a paragraph.
+ *
+ * @param listItemElement The list item element in the screenshots list for the
+ * current screenshot.
+ * @return The "Previous" link for the navigation bar, wrapped in a paragraph.
+ */
+function createNavigationBarPrevious(listItemElement) {
+ var previousLinkWrapperElement;
+
+ var hasPrevious = (getPreviousSiblingElement(listItemElement) != null);
+
+ if (hasPrevious) {
+ previousLinkWrapperElement = document.createElement("p");
+ previousLinkWrapperElement.setAttribute("id", "previousWrapper");
+
+ var previousLinkElement = document.createElement("a");
+ previousLinkElement.appendChild(document.createTextNode("< Previous"));
+ previousLinkElement.setAttribute("href", screenshotsURL + "#" +
+ (currentScreenshotNumber - 1));
+ previousLinkElement.setAttribute("title", "Previous screenshot");
+ previousLinkElement.addEventListener("click", previousScreenshotHandler,
+ false);
+
+ previousLinkWrapperElement.appendChild(previousLinkElement);
+ }
+
+ return previousLinkWrapperElement;
+}
+
+/**
+ * Returns the "Up" link for the navigation bar.
+ * The link handles clicks showing the list of screenshots.
+ * The link is wrapped in a paragraph.
+ *
+ * @return The "Up" link for the navigation bar, wrapped in a paragraph.
+ */
+function createNavigationBarUp() {
+ var upLinkWrapperElement = document.createElement("p");
+ upLinkWrapperElement.setAttribute("id", "upWrapper");
+
+ var upLinkElementHref = screenshotsURL;
+ var upLinkElement = document.createElement("a");
+ upLinkElement.appendChild(document.createTextNode("Up"));
+ upLinkElement.setAttribute("href", upLinkElementHref);
+ upLinkElement.setAttribute("title", "Screenshots list");
+ upLinkElement.addEventListener("click", upScreenshotHandler, false);
+
+ upLinkWrapperElement.appendChild(upLinkElement);
+
+ return upLinkWrapperElement;
+}
+
+/**
+ * Returns the "Next" link for the navigation bar.
+ * If the list item is the last in the list, a null element is returned.
+ * The link handles clicks showing the next screenshot in the list.
+ * The link is wrapped in a paragraph.
+ *
+ * @param listItemElement The list item element in the screenshots list for the
+ * current screenshot.
+ * @return The "Next" link for the navigation bar, wrapped in a paragraph.
+ */
+function createNavigationBarNext(listItemElement) {
+ var nextLinkWrapperElement;
+
+ var hasNext = (getNextSiblingElement(listItemElement) != null);
+
+ if (hasNext) {
+ nextLinkWrapperElement = document.createElement("p");
+ nextLinkWrapperElement.setAttribute("id", "nextWrapper");
+
+ var nextLinkElement = document.createElement("a");
+ nextLinkElement.appendChild(document.createTextNode("Next >"));
+ nextLinkElement.setAttribute("href", screenshotsURL + "#" +
+ (currentScreenshotNumber + 1));
+ nextLinkElement.setAttribute("title", "Next screenshot");
+ nextLinkElement.addEventListener("click", nextScreenshotHandler, false);
+
+ nextLinkWrapperElement.appendChild(nextLinkElement);
+ }
+
+ return nextLinkWrapperElement;
+}
+
+/**
+ * Handles clicks on "Previous" link.
+ * Sets the screenshot to the previous screenshot of the current one.
+ */
+function previousScreenshotHandler(event) {
+ setNewScreenshot(currentScreenshotNumber - 1);
+}
+
+/**
+ * Handles clicks on "Up" link.
+ * Shows the list of screenshots.
+ */
+function upScreenshotHandler(event) {
+ showScreenshotsList();
+}
+
+/**
+ * Handles clicks on "Next" link.
+ * Sets the screenshot to the next screenshot of the current one.
+ */
+function nextScreenshotHandler(event) {
+ setNewScreenshot(currentScreenshotNumber + 1);
+}
+
+/**
+ * Gets the previous sibling with "element" type of the specified element.
+ * This function is needed because browsers tend to add dummy text nodes between
+ * element nodes.
+ *
+ * @param element The element to get its previous sibling.
+ * @return The previous sibling of element type, or null if there is none.
+ */
+function getPreviousSiblingElement(element) {
+ var previousElement = null;
+ var previousSibling = element.previousSibling;
+ while (!previousElement && previousSibling) {
+ if (previousSibling.nodeType == Node.ELEMENT_NODE) {
+ previousElement = previousSibling;
+ }
+ previousSibling = previousSibling.previousSibling;
+ }
+
+ return previousElement;
+}
+
+/**
+ * Gets the next sibling with "element" type of the specified element.
+ * This function is needed because browsers tend to add dummy text nodes between
+ * element nodes.
+ *
+ * @param element The element to get its next sibling.
+ * @return The next sibling of element type, or null if there is none.
+ */
+function getNextSiblingElement(element) {
+ var nextElement = null;
+ var nextSibling = element.nextSibling;
+ while (!nextElement && nextSibling) {
+ if (nextSibling.nodeType == Node.ELEMENT_NODE) {
+ nextElement = nextSibling;
+ }
+ nextSibling = nextSibling.nextSibling;
+ }
+
+ return nextElement;
+}
+
+/**
+ * Updates the size of the screenshot shown to fit it in the window.
+ * The screenshot is set to a width equal to its parent width minus the double
+ * of its left and right padding.
+ * Once set the width, the browser resizes the height automatically.
+ *
+ * If no screenshot is being currently shown, it does nothing.
+ */
+function updateScreenshotSize() {
+ if (!currentScreenshot) {
+ return;
+ }
+
+ var parentWidth = getPixelsNumber(
+ document.defaultView.getComputedStyle(
+ currentScreenshot.parentNode, null)["width"]);
+ var parentLeftPadding = getPixelsNumber(
+ document.defaultView.getComputedStyle(
+ currentScreenshot.parentNode, null)["paddingLeft"]);
+ var parentRightPadding = getPixelsNumber(
+ document.defaultView.getComputedStyle(
+ currentScreenshot.parentNode, null)["paddingRight"]);
+
+ var currentScreenshotImage = document.getElementById("screenshotImage");
+ var imageWidth = parentWidth - parentLeftPadding * 2 - parentRightPadding * 2;
+ currentScreenshotImage.setAttribute("width", imageWidth);
+}
+
+/**
+ * Returns the number of pixels from a string in the form "3px", for example.
+ *
+ * @param pixelsString The string to get the number of pixels.
+ * @return The number of pixels.
+ */
+function getPixelsNumber(pixelsString) {
+ return pixelsString.replace("px", "");
+}
\ No newline at end of file
Added: trunk/web-src/data/script/ogg.js
===================================================================
--- trunk/web-src/data/script/ogg.js (rev 0)
+++ trunk/web-src/data/script/ogg.js 2010-01-31 16:15:52 UTC (rev 72)
@@ -0,0 +1,756 @@
+// Copyright (c) Fluendo
+// Copyright (c) Tim Starling
+
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+// This is a global configuration object which can embed multiple video instances
+var wgOggPlayer = {
+ 'detectionDone': false,
+ 'msie': false,
+ 'safari' : false,
+ 'opera' : false,
+ 'mozilla': false,
+
+ // List of players in order of preference
+ // Downpreffed VLC because it crashes my browser all the damn time -- TS
+ 'players': ['cortado', 'quicktime-mozilla', 'quicktime-activex', 'vlc-mozilla', 'vlc-activex', 'totem', 'kmplayer', 'kaffeine', 'mplayerplug-in', 'oggPlugin', 'videoElement'],
+
+ // Client support table
+ 'clientSupports': { 'thumbnail' : true },
+
+ // MIME type to be used to invoke a given plugin with <object>
+ // May be changed by detect()
+ 'mimeTypes' : {
+ 'quicktime-mozilla': 'video/quicktime',
+ 'quicktime-activex': 'video/quicktime',
+ 'vlc-mozilla': 'application/x-vlc-plugin',
+ 'oggPlugin': 'application/ogg',
+ 'totem': 'application/ogg',
+ 'kmplayer': 'application/ogg',
+ 'kaffeine': 'application/ogg',
+ 'mplayerplug-in': 'application/ogg'
+ },
+
+ 'savedThumbs': {},
+ 'qtTimers' : {},
+ // Text for new messages, to support cached HTML invocation
+ 'defaultMsg' : {
+ 'ogg-player-totem': 'Totem',
+ 'ogg-player-kmplayer': 'KMPlayer',
+ 'ogg-player-kaffeine': 'Kaffeine',
+ 'ogg-player-mplayerplug-in': 'mplayerplug-in'
+ },
+
+ // Configuration from MW
+ 'msg': {},
+ 'cortadoUrl' : '',
+ 'extPathUrl' : '',
+ 'showPlayerSelect': true,
+ 'controlsHeightGuess': 20,
+
+ /**
+ * Main entry point: initialise a video player
+ * Player will be created as a child of the given ID
+ * There may be multiple players in a document.
+ * Parameters are: id, videoUrl, width, height, length, linkUrl, isVideo
+ */
+ 'init': function ( player, params ) {
+ elt = document.getElementById( params.id );
+
+ // Save still image HTML
+ if ( !(params.id in this.savedThumbs) ) {
+ var thumb = document.createDocumentFragment();
+ for ( i = 0; i < elt.childNodes.length; i++ ) {
+ thumb.appendChild( elt.childNodes.item( i ).cloneNode( true ) );
+ }
+ this.savedThumbs[params.id] = thumb;
+ }
+
+ this.detect();
+
+ if ( !player ) {
+ // See if there is a cookie specifying a preferred player
+ var cookieVal = this.getCookie( 'ogg_player' );
+ if ( cookieVal && cookieVal != 'thumbnail' ) {
+ player = cookieVal;
+ }
+ }
+
+ if ( !this.clientSupports[player] ) {
+ player = false;
+ }
+
+ if ( !player ) {
+ for ( var i = 0; i < this.players.length; i++ ) {
+ if ( this.clientSupports[this.players[i]] ) {
+ player = this.players[i];
+ break;
+ }
+ }
+ }
+
+ elt.innerHTML = '';
+ switch ( player ) {
+ case 'videoElement':
+ this.embedVideoElement( elt, params );
+ break;
+ case 'oggPlugin':
+ case 'kaffeine':
+ case 'totem':
+ case 'kmplayer':
+ case 'mplayerplug-in':
+ this.embedOggPlugin( elt, params, player );
+ break;
+ case 'vlc-mozilla':
+ this.embedVlcPlugin( elt, params );
+ break;
+ case 'vlc-activex':
+ this.embedVlcActiveX( elt, params );
+ break;
+ case 'cortado':
+ this.embedCortado( elt, params );
+ break;
+ case 'quicktime-mozilla':
+ case 'quicktime-activex':
+ this.embedQuicktimePlugin( elt, params, player );
+ break;
+ case 'thumbnail':
+ default:
+ if ( params.id in this.savedThumbs ) {
+ elt.appendChild( this.savedThumbs[params.id].cloneNode( true ) );
+ } else {
+ elt.appendChild( document.createTextNode( 'Missing saved thumbnail for ' + params.id ) );
+ }
+ if ( player != 'thumbnail' ) {
+ var div = document.createElement( 'div' );
+ div.className = 'ogg-player-options';
+ div.style.cssText = 'width: ' + ( params.width - 10 ) + 'px;';
+ div.innerHTML = this.msg['ogg-no-player'];
+ elt.appendChild( div );
+ player = 'none';
+ }
+ }
+ if ( player != 'thumbnail' ) {
+ var optionsBox = this.makeOptionsBox( player, params );
+ var optionsLink = this.makeOptionsLink( params.id );
+ var div = document.createElement( 'div' );
+ div.appendChild( optionsBox );
+ div.appendChild( optionsLink );
+ elt.appendChild( div );
+ }
+ },
+
+ 'debug': function( s ) {
+ //alert(s);
+ },
+
+ // Detect client capabilities
+ 'detect': function() {
+ if (this.detectionDone) {
+ return;
+ }
+ this.detectionDone = true;
+
+ // First some browser detection
+ this.msie = ( navigator.appName == "Microsoft Internet Explorer" )...
[truncated message content] |