<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>/home/antu &#187; mootools</title>
	<atom:link href="http://www.antusblog.de/tag/mootools/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.antusblog.de</link>
	<description>Linux, Programmierung und andere Dinge die mich interessieren</description>
	<lastBuildDate>Mon, 26 Oct 2009 06:00:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Fortschrittsbalken mit CSS/JavaScript</title>
		<link>http://www.antusblog.de/2009/07/27/fortschrittsbalken-mit-cssjavascript/</link>
		<comments>http://www.antusblog.de/2009/07/27/fortschrittsbalken-mit-cssjavascript/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 20:48:28 +0000</pubDate>
		<dc:creator>Antu</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Java Script]]></category>
		<category><![CDATA[dwProgressBar]]></category>
		<category><![CDATA[Fortschrittsanzeige]]></category>
		<category><![CDATA[Fortschrittsbalken]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jQuery UI]]></category>
		<category><![CDATA[jsProgressBarHandler]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[Prototype]]></category>

		<guid isPermaLink="false">http://www.antusblog.de/?p=1798</guid>
		<description><![CDATA[Fortschrittsbalken werden vor allem bei Webanwendungen gebraucht, die mit dem Benutzer interagieren, beispielsweise beim Hochladen von Dateien oder um den Fortschritt in einem Formular anzuzeigen. Aber auch bei anderen Webanwendungen können Fortschrittsbalken sinnvoll sein, beispielsweise um den aktuellen Stand eines noch nicht fertiggestellten Projektes anzuzeigen oder den noch verfügbaren Speicherplatz, o.Ä. In dieser Anleitung erkläre [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.antusblog.de/wp-content/uploads/2009/07/jQueryUI-FSB.png"><img class="aligncenter size-full wp-image-1799" title="Fortschrittsbalken" src="http://www.antusblog.de/wp-content/uploads/2009/07/jQueryUI-FSB.png" alt="Fortschrittsbalken" width="500" height="150" /></a>Fortschrittsbalken werden vor allem bei Webanwendungen gebraucht, die mit dem Benutzer interagieren, beispielsweise beim Hochladen von Dateien oder um den Fortschritt in einem Formular anzuzeigen. Aber auch bei anderen Webanwendungen können Fortschrittsbalken sinnvoll sein, beispielsweise um den aktuellen Stand eines noch nicht fertiggestellten Projektes anzuzeigen oder den noch verfügbaren Speicherplatz, o.Ä.</p>
<p>In dieser Anleitung erkläre ich wie man einfache Fortschrittsbalken mit CSS erstellen kann, und stelle 4 JavaScript-Skripte vor mit denen sich &#8220;bewegliche&#8221; Fortschrittsbalken erstellen lassen.</p>
<p><span id="more-1798"></span></p>
<h2>Einfache Fortschrittsbalken</h2>
<p>Fortschrittsbalken mittels CSS zu erstellen ist nicht weiter schwer, man braucht im Grunde nur zwei Elemente, die übereinander gelegt werden.</p>
<h3>Ohne Bilder</h3>
<p><a href="http://www.antusblog.de/wp-content/uploads/2009/07/Einfacher.Fortschrittsbalken.ohne.Bilder.png"><img class="aligncenter size-full wp-image-1802" title="Einfacher Fortschrittsbalken ohne Bilder" src="http://www.antusblog.de/wp-content/uploads/2009/07/Einfacher.Fortschrittsbalken.ohne.Bilder.png" alt="Einfacher Fortschrittsbalken ohne Bilder" width="300" height="100" /></a>Man erstellt ein Element, gibt ihm eine Hintergrundfarbe und weist ihm eine Breite/Höhe zu. In diesem Element erstellt man nun ein zweites Element, dem man ebenfalls eine Hintergrundfarbe (möglichst eine andere, als die vom ersten Element) und die gleiche Höhe wie dem ersten Element zu. Die Breite des zweiten Elements gibt dann an, welchen Wert der Fortschrittsbalken anzeigen soll.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">style</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span>
  div.fsb {
    border:1px solid #000;
    background-color:white;
    width:200px;
    height:28px;
    padding:1px;
  }
&nbsp;
  div.fortschritt {
    background-color:#000;
    height:28px;
    width:50%; /* Fortschritt */
  }
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- [...] --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fsb&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fortschritt&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>In Aktion sieht das dann so aus: <a href="/demos/8-fortschrittsbalken/cssbalken/ohnebilder.html">Demo</a>.</p>
<h3>Mit Bildern</h3>
<p><a href="http://www.antusblog.de/wp-content/uploads/2009/07/Einfacher.Fortschrittsbalken.mit.Bildern.png"><img src="http://www.antusblog.de/wp-content/uploads/2009/07/Einfacher.Fortschrittsbalken.mit.Bildern.png" alt="Einfacher Fortschrittsbalken mit Bildern" title="Einfacher Fortschrittsbalken mit Bildern" width="350" height="125" class="aligncenter size-full wp-image-1805" /></a>Möchte man den Fortschrittsbalken etwas schöner gestalten, kann man natürlich auch Bilder verwenden, die Methode funktioniert eigentlich genau so. Der einzige Unterschied ist, das anstatt von Hintergrundfarben Bilder verwendet werden.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">div<span style="color: #6666ff;">.fsb</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'normal.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">300px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
div<span style="color: #6666ff;">.fortschritt</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'farbig.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>In Aktion sieht das dann so aus: <a href="/demos/8-fortschrittsbalken/cssbalken/mitbildern.html">Demo</a>.</p>
<h2>JavaScript-Fortschrittsbalken</h2>
<p>Mit JavaScript kann man den Fortschrittsbalken auch Leben einhauchen, bzw. den angezeigten Wert verändern. Ein einfaches JS-Skript, welches die Breite des inneren Elements ändert ist schnell geschrieben. Im folgenden stelle ich allerdings 4 Skripte/Klassen vor, die noch etwas mehr können als nur das. Das erste Skript basiert auf jQuery/jQuery UI, das zweite benötigt nur jQuery, das dritte ist für Prototype und das vierte verwendet mootools.</p>
<p>Ich habe für jedes Skript eine Demo erstellt: <a href="/demos/8-fortschrittsbalken/jsbalken/fortschrittsbalken.html">Fortschrittsbalken-Demo</a></p>
<h3>jQueryUI &#8211; ProgressBar</h3>
<p><a href="http://www.antusblog.de/wp-content/uploads/2009/07/Fortschrittsbalken.mit.jQueryUI.png"><img src="http://www.antusblog.de/wp-content/uploads/2009/07/Fortschrittsbalken.mit.jQueryUI.png" alt="Fortschrittsbalken mit jQuery UI" title="Fortschrittsbalken mit jQuery UI" width="500" height="100" class="aligncenter size-full wp-image-1811" /></a>Die JS-Bibliothek <a href="http://jqueryui.com/">jQuery UI</a> stellt diverse Werkzeuge und Benutzeroberflächen-Elemente bereit. Unter anderem bietet sie auch eine Klasse zur Erstellung von Fortschrittsbalken. Praktischerweise kann man auf der Download-Seite von jQuery UI direkt die Elemente angeben, die man benötigt, so braucht man nicht die ganze Bibliothek runterzuladen/einzubinden (wenn man nur den Fortschrittsbalken braucht), und spart so einiges an Speicherplatz/Datentransfer. Die Bibliothek basiert auf <a href="http://jquery.com/">jQuery</a>, dieses muss also auch eingebunden werden.</p>
<p>Eine Besonderheit von jQuery UI: Das Aussehen der Benutzeroberfläche (und somit des Fortschrittsbalkens) wird durch Themen festgelegt. Auf der Webseite von jQuery UI findet sich (unter Gallery) bereits eine kleine Auswahl von fertigen Themen, natürlich ist es auch möglich eigene Themen zu erstellen. Das Thema wird über eine css-Datei definiert, diese muss ebenfalls in die Seite eingebunden werden.</p>
<h4>Einbinden</h4>
<p>Benötigt werden: jQuery, jQuery UI (Progressbar), und ein jQuery UI Thema.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery-ui/css/ui-lightness/jquery-ui-1.7.2.custom.css&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery-ui/js/jquery-1.3.2.min.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery-ui/js/jquery-ui-1.7.2.custom.min.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<p>(Die Pfade müssen eventuell angepasst werden.)</p>
<h4>HTML</h4>
<p>Man erstellt einfach ein div-Element, den Rest erledigt das Skript. Dem Element kann man noch eine ID geben, das macht es leichter es anzusprechen.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fsb&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<h4>Fortschrittsbalken erstellen</h4>
<p>Um den Balken zu erstellen, selektiert man das Ziel-Element mit der <code>$()</code>-Funktion, und ruft die Methode <code>progressbar()</code> auf. Mittels dem Parameter <code>value</code> kann man den Ausgangswert des Fortschrittsbalkens angeben. Außerdem kann man, wenn man möchte, mit dem Parameter <code>change</code> auch gleich eine Funktion festlegen, welche aufgerufen wird, wenn der Wert sich ändert. Beide Parameter sind optional.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#fsb'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">progressbar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        value<span style="color: #339933;">:</span><span style="color: #CC0000;">50</span><span style="color: #339933;">,</span>
        change<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
            <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#fsb'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">progressbar</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'option'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'value'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'%'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h4>Methoden und Ereignisse</h4>
<p>Die Klasse bietet Methoden zum Abfragen und Ändern des angezeigten Werts, sowie ein Ereignis welches ausgelöst wird, wenn der Wert sich ändert.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Wert aendern</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#fsb'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">progressbar</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'option'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'value'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Wert abfragen</span>
<span style="color: #003366; font-weight: bold;">var</span> wert <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#fsb'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">progressbar</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'option'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'value'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Weitere Informationen zu der Klasse und ihren Methoden finden sich in der <a href="http://jqueryui.com/demos/progressbar/">offiziellen Dokumentation</a>.</p>
<h3>jQuery &#8211; ProgressBar</h3>
<p><a href="http://www.antusblog.de/wp-content/uploads/2009/07/Fortschrittsbalken.mit.jQueryProgressBar.png"><img src="http://www.antusblog.de/wp-content/uploads/2009/07/Fortschrittsbalken.mit.jQueryProgressBar.png" alt="Fortschrittsbalken mit jQuery Progress Bar" title="Fortschrittsbalken mit jQuery Progress Bar" width="500" height="100" class="aligncenter size-full wp-image-1821" /></a>Das Skript <a href="http://t.wits.sg/2008/06/20/jquery-progress-bar-11/">jQuery Progress Bar</a> basiert auf jQuery und bietet einige nützliche Funktionen, die die jQuery UI-Variante nicht hat. Es ist möglich verschiedene Bilder zur Anzeige des Fortschritts zu verwenden, so kann man beispielsweise für die ersten 10-20% einen roten Hintergrund, für die nächsten 10-20% dann einen orangen, dann einen gelben und zum Schluss einen grünen Hintergrund verwenden. Es lässt sich auch festlegen ob neben dem Balken auch der Fortschritt noch einmal als Prozentzahl angezeigt werden soll, und auch eine Anzeige des genauen Wertes (123/465) ist möglich. Außerdem ist die Bewegung des Fortschrittsbalkens animiert, es lässt sich sogar die Geschwindigkeit der Animation festlegen. </p>
<h4>Einbinden</h4>
<p>Benötigt werden jQuery und das Skript selbst.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery-ui/js/jquery-1.3.2.min.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery.progressbar/js/jquery.progressbar.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<h4>HTML</h4>
<p>Auch bei diesem Skript wird nur ein <code>div</code>-Element benötigt, den Rest erstellt das Skript selbst.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fsb&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<h4>Fortschrittsbalken erstellen</h4>
<p>Erstellt wird der Fortschrittsbalken mittels der Funktion <code>progressBar()</code>. Dabei gibt es einige Parameter, mittels derer das Aussehen und Verhalten des Fortschrittsbalkens beeinflusst werden können:</p>
<ul>
<li><code>steps</code> und <code>step_duration</code>: Geben an, wie viele Schritte beim Ändern des Anzeigewertes gegangen werden sollen, und wie lange ein Schritt dauert. (Standard: <code>20</code>/<code>20</code>)</li>
<li><code>max</code>: Der max. Wert, bis zu dem der Fortschrittsbalken geht. (Standard: <code>100</code>)</li>
<li><code>showText</code> und <code>textFormat</code>: Ob neben dem Balken noch der Fortschritt in Textform angezeigt werden soll, und ob dieser als Prozentzahl (<code>'percentage'</code> = 50%) oder als Anteil (<code>'fraction'</code> = 50/100) angezeigt werden soll. (Standard: <code>true</code>, <code>'percentage'</code>)</li>
<li><code>width</code> und <code>height</code>: Breite und Höhe des Fortschrittsbalkens bzw. der verwendeten Bilder.</li>
<li><code>callback</code>: Legt eine Funktion fest, welche aufgerufen wird, wenn sich der Balken bewegt. Die Funktion bekommt ein Argument mitgeliefert, welches das <code>config</code>-Feld, erweitert um die Werte <code>increment</code> (um wie viele Pixel hat sich der Balken bewegt), <code>running_value</code> (aktueller Wert) sowie <code>value</code> (Ziel-Wert).</li>
<li><code>boxImage</code>: Pfad zum Bild welches den Balken umschließt.</li>
<li><code>barImage</code>: Pfad zum inneren Bild des Balkens. Hier kann auch ein Feld übergeben werden, falls verschiedene Bilder verwendet werden sollen (siehe Beispiel).</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#fsb'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">progressBar</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">20</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
        boxImage<span style="color: #339933;">:</span> <span style="color: #3366CC;">'jquery.progressbar/images/progressbar.gif'</span><span style="color: #339933;">,</span>
        barImage<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #CC0000;">0</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'jquery.progressbar/images/progressbg_red.gif'</span><span style="color: #339933;">,</span>
            <span style="color: #CC0000;">30</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'jquery.progressbar/images/progressbg_orange.gif'</span><span style="color: #339933;">,</span>
            <span style="color: #CC0000;">50</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'jquery.progressbar/images/progressbg_yellow.gif'</span><span style="color: #339933;">,</span>
            <span style="color: #CC0000;">70</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'jquery.progressbar/images/progressbg_green.gif'</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h4>Methoden und Ereignisse</h4>
<p>Die Klasse bietet ein Ereignis (<code>callback</code>) und keine Methode. Will man den angezeigten Wert ändern, ruft man die Klasse einfach wieder wie folgt auf:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Aendere Wert auf 50%.</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#fsb'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">progressBar</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>Prototype &#8211; jsProgressBarHandler</h3>
<p><a href="http://www.antusblog.de/wp-content/uploads/2009/07/Fortschrittsbalken.mit.Prototype.jsProgressBarHandler.png"><img src="http://www.antusblog.de/wp-content/uploads/2009/07/Fortschrittsbalken.mit.Prototype.jsProgressBarHandler.png" alt="Fortschrittsbalken mit Prototype jsProgressBarHandler" title="Fortschrittsbalken mit Prototype jsProgressBarHandler" width="500" height="100" class="aligncenter size-full wp-image-1828" /></a>Die <a href="http://www.bram.us/projects/js_bramus/jsprogressbarhandler/">jsProgressBarHandler</a>-Klasse basiert auf <a href="http://www.prototypejs.org/">Prototype</a> und steht unter der <a href="http://creativecommons.org/licenses/by-sa/2.5/">Creative Commons Attribution-Share Alike 2.5</a> Lizenz. Das tolle an dieser Klasse ist: Sie kann auch automatisch Fortschrittsbalken erstellen, alle <code>span</code>-Elemente mit der CSS-Klasse <code>progressBar</code>, die einen Prozentwert enthalten, werden automatisch zu Fortschrittsbalken umgewandelt. Der herkömmliche Weg über JavaScript funktioniert natürlich auch.</p>
<h4>Einbinden der Klasse</h4>
<p>Neben der Klasse selbst, muss auch die JavaScript-Bibliothek Prototype eingebunden werden.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;js/prototype/prototype.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;js/bramus/jsProgressBarHandler.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<h4>HTML</h4>
<p>Die Klasse wandelt alle span-Elemente mit der CSS-Klasse <code>progressBar</code> automatisch in Fortschrittsbalken um.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;progressBar&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fsb&quot;</span>&gt;</span>50%<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span></pre></div></div>

<p>Möchte man den Balken selbst mittels JavaScript erstellen, benötigt man ein <code>div</code>-Element mit einer ID.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fsb&quot;</span>&gt;</span>[Lade Fortschrittsbalken]<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<h4>Fortschrittsbalken erstellen</h4>
<p>Um den Balken selbst mittels JavaScript zu erstellen, muss man nur ein Objekt der Klasse <code>JS_BRAMUS.jsProgressBar</code> erstellen.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> fsb <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> JS_BRAMUS.<span style="color: #660066;">jsProgressBar</span><span style="color: #009900;">&#40;</span>
    <span style="color: #3366CC;">'fsb'</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// ID des div-Elements</span>
    <span style="color: #CC0000;">50</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// Ausgangswert (Prozent)</span>
    <span style="color: #009900;">&#123;</span>
        showText <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
        animate <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
        barImage <span style="color: #339933;">:</span> <span style="color: #3366CC;">'jsprogressbarhandler/images/bramus/percentImage_back1.png'</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Der dritte Parameter kann zur Konfiguration verwendet werden, und ist optional. Folgende Optionen gibt es:</p>
<ul>
<li><code>animate</code>: Ob der Fortschrittsbalken animiert sein soll. (Standard: ja)</li>
<li><code>showText</code>: Ob der Wert neben dem Balken angezeigt werden soll (Standard: ja)</li>
<li><code>width</code>: Breite des Balkens. Nicht vergessen: Das Bild muss ebenfalls angepasst werden. (Standard: 120)</li>
<li><code>boxImage</code>: Das Bild um den Balken.</li>
<li><code>barImage</code>: Der Hintergrund des Balkens. Hier kann auch ein Feld mit mehreren Bildern angegeben werden, dann ändert sich der Hintergrund, wenn der Balken weiter fortschreitet.</li>
<li><code>height</code>: Die Höhe des Balkens. (Standard: 12)</li>
<li><code>onTick</code>: Funktion die bei jeder Änderung am Wert des Balkens aufgerufen wird.</li>
</ul>
<p>Die Standardwerte sind am Anfang der <code>jsProgressBarHandler.js</code> definiert. Dort findet sich auch die Variable <code>autoHook</code>, diese kann man auf <code>false</code> setzen, wenn man nicht möchte, das alle <code>span.progressBar</code>-Elemente automatisch umgewandelt werden. Die Pfade zu den Bildern bzw. die Breite/Höhe will/muss man wahrscheinlich eh ändern.</p>
<h4>Methoden und Ereignisse</h4>
<p>Die Klasse hat zwei Funktionen und ein Ereignis, welches bei jeder Änderung am Wert aufgerufen wird (<code>onTick</code>). Mit der Funktion <code>getPercentage()</code> kann der aktuelle Wert abgefragt werden, mit <code>setPercentage()</code> kann der Wert verändert werden. Letztere Funktion akzeptiert zwei Parameter, der erste gibt den neuen Wert an, der zweite gibt an ob der Balken direkt zum neuen Wert gehen soll. Wenn man den Wert ändert, während der Balken sich noch bewegt, macht er normalerweise zuerst seine Bewegung zu Ende, bevor er zum neuen Wert geht, ist der zweite Parameter true, verwirft er alle anderen Bewegungen und bewegt sich direkt zum neuen Wert.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Wert abfragen</span>
<span style="color: #003366; font-weight: bold;">var</span> aktuellerWert <span style="color: #339933;">=</span> fsb.<span style="color: #660066;">getPercentage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Wert aendern</span>
fsb.<span style="color: #660066;">setPercentage</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>mootools &#8211; dwProgressBar</h3>
<p><a href="http://www.antusblog.de/wp-content/uploads/2009/07/Fortschrittsbalken.mit.mootools.dwProgressBar.png"><img src="http://www.antusblog.de/wp-content/uploads/2009/07/Fortschrittsbalken.mit.mootools.dwProgressBar.png" alt="Fortschrittsbalken mit mootools - dwProgressBar" title="Fortschrittsbalken mit mootools - dwProgressBar" width="500" height="100" class="aligncenter size-full wp-image-1833" /></a>Die <code><a href="http://davidwalsh.name/dwprogressbar-2-stepping-events-mootools-progress-bar">dwProgressBar</a></code>-Klasse verfolgt einen etwas anderen Ansatz, als die vorigen beiden Klassen. Mit der Klasse können Fortschrittsbalken erstellt, und der angezeigte Wert geändert werden. Um die Animation kümmert sich die Klasse. Ansonsten können (müssen) die Fortschrittsbalken komplett selbst mittels CSS gestaltet werden. </p>
<h4>Einbinden der Klasse</h4>
<p>Die JavaScript-Bibliothek <a href="http://mootools.net/">mootools</a> wird vorausgesetzt. Außerdem muss natürlich die Klasse selbst eingebunden werden.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mootools-1.2.3-core-yc.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;dwprogressbar.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<h4>HTML und CSS</h4>
<p>Es wird nur ein div-Element benötigt.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fsb&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>Die Gestaltung des Fortschrittsbalkens übernimmt die Klasse nicht, das muss man selber machen. Es gibt drei Elemente, die gestaltet werden können: Der Rahmen, der Balken, und der Text (optional). Beim Erstellen des Fortschrittsbalkens kann angegeben werden, welche ID die Elemente bekommen sollen, über die ID können die Elemente dann mittels CSS gestaltet werden. </p>
<h5>Ohne Bilder</h5>
<p>Die CSS-Selektoren für einen Fortschrittsbalken ohne Bilder (aber mit Text) könnten z.B. so aussehen:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#rahmen</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#8C2229</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span>inline-<span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#balken</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#8C2229</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#text</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span>inline-<span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<h5>Mit Bildern</h5>
<p>Wenn man den Fortschrittsbalken mit Bildern gestalten möchte, kann man folgende CSS-Selektoren verwenden. Die Höhen- und Breitenangaben müssen natürlich angepasst werden.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#rahmen</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'rahmen.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">right</span> <span style="color: #993333;">center</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">300px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#balken</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'balken.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #993333;">center</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<h4>Den Fortschrittsbalken erstellen</h4>
<p>Zum Erstellen des Fortschrittsbalkens wird einfach ein neues <code>dwProgressBar</code>-Objekt erstellt.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">window.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'domready'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> fsb <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> dwProgressBar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// Das Element, in dem der Fortschrittsbalken angezeigt wird</span>
        container<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fortschrittsbalken'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #006600; font-style: italic;">// Startwert (Prozent)</span>
        startPercentage<span style="color: #339933;">:</span> <span style="color: #CC0000;">50</span><span style="color: #339933;">,</span>
        <span style="color: #006600; font-style: italic;">// Geschwindigkeit/Dauer der Animation (in Millisekunden)</span>
        speed<span style="color: #339933;">:</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">,</span>
        <span style="color: #006600; font-style: italic;">// Die ID des Rahmens</span>
        boxID<span style="color: #339933;">:</span> <span style="color: #3366CC;">'rahmen'</span><span style="color: #339933;">,</span>
        <span style="color: #006600; font-style: italic;">// Die ID des Balkens</span>
        percentageID<span style="color: #339933;">:</span> <span style="color: #3366CC;">'balken'</span><span style="color: #339933;">,</span>
        <span style="color: #006600; font-style: italic;">// Wieviel Prozent pro Schritt (dwProgressBar.step() geht</span>
        <span style="color: #006600; font-style: italic;">// immer einen Schritt weiter, in diesem Beispiel also 10%.</span>
        step<span style="color: #339933;">:</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">,</span>
        <span style="color: #006600; font-style: italic;">// Erlaube Werte jenseits 100%</span>
        allowMore<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
        <span style="color: #006600; font-style: italic;">// Prozentwert als Text anzeigen?</span>
        displayText<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
        <span style="color: #006600; font-style: italic;">// ID für das Textelement</span>
        displayID<span style="color: #339933;">:</span> <span style="color: #3366CC;">'text'</span><span style="color: #339933;">,</span>
        <span style="color: #006600; font-style: italic;">// Ereignis, welches aufgerufen wird, wenn der Balken 100%</span>
        <span style="color: #006600; font-style: italic;">// erreicht.</span>
        onComplete<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Fertig!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #006600; font-style: italic;">// Ereignis welches nach jeder abgeschlossenen Änderung am</span>
        <span style="color: #006600; font-style: italic;">// Wert aufgerufen wird. (Wenn man von 10% auf 50% geht,</span>
        <span style="color: #006600; font-style: italic;">// wird es einmal aufgerufen, nämlich wenn 50% erreicht sind.)</span>
        onChange<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Wert geändert!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Es müssen nur die Optionen <code>container</code>, <code>boxID</code> und <code>percentageID</code> angegeben werden, der Rest ist optional.</p>
<h4>Funktionen und Ereignisse</h4>
<p>Die Klasse bietet die Funktionen <code>set(neuerwert)</code> und <code>step()</code>, außerdem die Ereignisse <code>onComplete</code> und <code>onChange</code>. Die Ereignisse sind im obigen Beispielquelltext bereits erklärt.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Wert auf 100% setzen</span>
fsb.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Einen Schritt weitergehen (um options.step Prozent)</span>
fsb.<span style="color: #660066;">step</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Zum Schluss noch einmal die Demo-Seite für die JavaScript-Fortschrittsbalken: <a href="/demos/8-fortschrittsbalken/jsbalken/fortschrittsbalken.html">Fortschrittsbalken-Demo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.antusblog.de/2009/07/27/fortschrittsbalken-mit-cssjavascript/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Mehrere Dateien flexibel hochladen</title>
		<link>http://www.antusblog.de/2009/07/22/mehrere-dateien-flexibel-hochladen/</link>
		<comments>http://www.antusblog.de/2009/07/22/mehrere-dateien-flexibel-hochladen/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 16:10:06 +0000</pubDate>
		<dc:creator>Antu</dc:creator>
				<category><![CDATA[Java Script]]></category>
		<category><![CDATA[Dateien]]></category>
		<category><![CDATA[hochladen]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[Multiple File Upload Plugin]]></category>

		<guid isPermaLink="false">http://www.antusblog.de/?p=1771</guid>
		<description><![CDATA[Mit einem Dateieingabe-Element kann immer nur eine Datei ausgewählt und hochgeladen werden. Will man dem Benutzer die Möglichkeit geben mehrere Dateien auf einmal hochzuladen, kann man einfach mehrere Dateieingabe-Elemente erstellen. Das hat allerdings einen Nachteil: In den meisten Fällen sind entweder zu viele, oder zu wenige Dateielemente da. Mit etwas JavaScript kann man dieses Problem [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.antusblog.de/wp-content/uploads/2009/07/jquery_multiple_file_upload2.png"><img src="http://www.antusblog.de/wp-content/uploads/2009/07/jquery_multiple_file_upload2.png" alt="Mehrere Dateien flexibel hochladen" title="Mehrere Dateien flexibel hochladen" width="500" height="140" class="aligncenter size-full wp-image-1773" /></a>Mit einem Dateieingabe-Element kann immer nur eine Datei ausgewählt und hochgeladen werden. Will man dem Benutzer die Möglichkeit geben mehrere Dateien auf einmal hochzuladen, kann man einfach mehrere Dateieingabe-Elemente erstellen. Das hat allerdings einen Nachteil: In den meisten Fällen sind entweder zu viele, oder zu wenige Dateielemente da. Mit etwas JavaScript kann man dieses Problem lösen: Der Benutzer entscheidet selbst, wie viele Dateien er hochladen möchte.</p>
<p>Eine Lösung wäre, dass man eine Schaltfläche erstellt, mittels derer der Benutzer weitere Eingabefelder hinzufügen kann. Neben den zusätzlichen Eingabefeldern erstellt man dann einfach noch jeweils eine Schaltfläche zum Entfernen des Eingabefeldes, falls der Benutzer es sich anders überlegt.</p>
<p>Eine andere Möglichkeit wäre, das der Benutzer nur ein Eingabefeld, und eine Liste von ausgewählten Dateien hat. Nachdem eine Datei ausgewählt wurde, wird kommt die Datei in die Liste, und das Eingabefeld ist wieder leer, für die nächste Datei. Eigentlich wird das Eingabefeld dabei durch ein neues ersetzt, und das alte unsichtbar gemacht. Für den Benutzer sieht es aber so aus, als würde er die ganze Zeit dasselbe Eingabeelement benutzen.</p>
<p><span id="more-1771"></span></p>
<h2>Weitere Eingabefelder hinzufügen</h2>
<p><a href="http://www.antusblog.de/wp-content/uploads/2009/07/javascript_mfu.png"><img src="http://www.antusblog.de/wp-content/uploads/2009/07/javascript_mfu.png" alt="Mehrere Dateien flexibel hochladen - mit JavaScript." title="Mehrere Dateien flexibel hochladen - mit JavaScript." width="320" height="140" class="aligncenter size-full wp-image-1784" /></a>
<p>Mittels der JavaScript-Funktion <code><a href="http://de.selfhtml.org/javascript/objekte/document.htm#create_element">document.createElement(element)</a></code> können dynamisch neue Elemente erstellt werden, diese können dann mit Funktionen wie <code><a href="http://de.selfhtml.org/javascript/objekte/node.htm#append_child">appendChild</a></code>, <code>insertBefore</code>, o.Ä. an beliebiger Stelle eingefügt werden.</p>
<p>Um eine Schaltfläche zum Hinzufügen zusätzlicher Eingabefelder zu erstellen, braucht man zuerst ein Verweis-Element, oder irgendein anderes Element, mittels dem der Benutzer das neue Eingabefeld hinzufügt. Damit das funktioniert, weist man dem <code>onlick</code>-Attribut eine Funktion zu, die ein neues Eingabefeld erstellt und im Dokument einfügt. Diese Funktion könnte zum Beispiel so aussehen:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> hinzu<span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> neu <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    neu.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;input type=&quot;file&quot; class=&quot;datei&quot; name=&quot;datei[]&quot; /&gt;'</span><span style="color: #339933;">;</span>
    element.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>neu<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Mittels <code>parentNode</code> greift man auf den Elternknoten des Elementes zu. Im Beispiel wird das neue <code>div</code>-Element welches das Eingabeelement enthält am Ende vom <code>form</code>-Element eingefügt.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;datei&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;datei[]&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hinzu&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hinzu(this); return false;&quot;</span>&gt;</span>Datei hinzufügen<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- An dieser Stelle werden neue Eingabeelemente eingefügt, wenn auf den</span>
<span style="color: #808080; font-style: italic;">    Verweis geklickt wird. Also z.B. so: --&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;datei&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;datei[]&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- Ende --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div>

<p>Der Benutzer soll die hinzugefügten Eingabeelemente aber auch wieder entfernen können, dazu fügt man zu jedem Element noch eine Schaltfläche zum Entfernen hinzu. Dieser weist man eine JavaScript-Funktion zu, die das Elternelement (und somit auch alle Elemente darin) löscht. Der komplette Quelltext könnte (aufs nötigste reduziert) so aussehen:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;?xml <span style="color: #000066;">version</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1.0&quot;</span> ?&gt;</span>
<span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span>
<span style="color: #00bbdd;">  &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span> xmlns<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>Mehrere Dateien flexibel hochladen<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/html; charset=UTF-8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
      function hinzu(element) {
        var neu = document.createElement('div');
        neu.innerHTML = '<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;datei&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;datei[]&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> \
          <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;weg&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;loeschen(this); return false;&quot;</span>&gt;</span>entfernen<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>';
        element.parentNode.parentNode.appendChild(neu);
      }
&nbsp;
      function loeschen(element) {
        element.parentNode.parentNode.removeChild(element.parentNode);
      }
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;datei&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;datei[]&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hinzu&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hinzu(this);&quot;</span>&gt;</span>Datei hinzufügen<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>Auf der Demo-Seite sieht man das Skript auch in Aktion.</p>
<p style="padding-left:30px;"><a href="/demos/7-mehrere-dateien-flexibel-hochladen/nur_js/beispiel.html">Demo</a></p>
<h2>Eingabefeld + Liste</h2>
<p><a href="http://www.antusblog.de/wp-content/uploads/2009/07/jquery_multiple_file_upload2.png"><img src="http://www.antusblog.de/wp-content/uploads/2009/07/jquery_multiple_file_upload2.png" alt="Mehrere Dateien flexibel hochladen" title="Mehrere Dateien flexibel hochladen" width="500" height="140" class="aligncenter size-full wp-image-1773" /></a><br />
Ein einzelnes Eingabefeld, und eine Liste ausgewählter Dateien zu erstellen ist schon etwas komplizierter. Zum Glück haben sich schon andere die Arbeit gemacht. Es gibt sowohl für mootools, als auch für jQuery entsprechende Erweiterungen.</p>
<h2>Für jQuery</h2>
<p>Für jQuery gibt es das <a href="http://www.fyneworks.com/jquery/multiple-file-upload/">jQuery Multiple File Upload Plugin</a>. Es bietet zusätzlich noch die Möglichkeit die verwendbaren Dateitypen einzuschränken und eine maximale Anzahl von Dateien anzugeben.</p>
<h3>Einbinden und Benutzen</h3>
<p>Zuerst müssen jQuery und die Erweiterung im <code>head</code>-Bereich eingebunden werden. Außerdem gibt es noch drei weitere (optionale) Erweiterungen, mit denen die Multi File Upload Erweiterung zusammenarbeiten kann: <a href="http://plugins.jquery.com/project/metadata/">MetaData</a>, <a href="http://plugins.jquery.com/project/blockUI">BlockUI</a>, und <a href="http://www.malsup.com/jquery/form/">Form</a>. Ersteres ermöglicht es das Element direkt über das <code>class</code>-Attribut des <code>input</code>-Elements zu konfigurieren, mit BlockUI werden schönere Fehlermeldungen angezeigt, und Form ermöglicht das Absenden des Formulars mittels AJAX.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- jQuery wird vorausgesetzt. --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- Die Erweiterung selbst. --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery.MultiFile.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<p>Anschließend muss nur noch das <code>input</code>-Element entsprechend angepasst werden:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file&quot;</span> <span style="color: #000066;">accept</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;png|gif|jpg|xcf&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;multi&quot;</span> <span style="color: #000066;">maxlength</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;3&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;bild&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- oder --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;multi accept-png|gif|jpg|xcf max-3&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;bild&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p>Die Klasse <code>multi</code> sorgt dafür, das die Erweiterung sich dem Element annimmt. Mittels <code>maxlength</code>/<code>accept</code> lassen sich noch die max. Anzahl Dateien bzw. die akzeptierten Dateitypen festlegen.</p>
<p>Alternativ ist es auch möglich das Element mittels einer JavaScript-Funktion umzuwandeln. Dabei können außerdem noch einige weitere Parameter angegeben werden.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input.datei'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">MultiFile</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        list<span style="color: #339933;">:</span> <span style="color: #3366CC;">'#liste'</span><span style="color: #339933;">,</span>
        max<span style="color: #339933;">:</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span>
        afterFileRemove <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>e<span style="color: #339933;">,</span> v<span style="color: #339933;">,</span> m<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Datei entfernt!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        afterFileSelect <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>e<span style="color: #339933;">,</span> v<span style="color: #339933;">,</span> m<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Datei hinzugefügt!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        STRING<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> file<span style="color: #339933;">:</span> <span style="color: #3366CC;">'&lt;em title=&quot;Zum entfernen hier klicken&quot; <span style="color: #000099; font-weight: bold;">\</span>
                         onclick=&quot;$(this).parent().prev().click()&quot;&gt;$file&lt;/em&gt;'</span><span style="color: #339933;">,</span>
                  remove<span style="color: #339933;">:</span> <span style="color: #3366CC;">'&lt;img src=&quot;entfernen.png&quot; alt=&quot;X&quot; <span style="color: #000099; font-weight: bold;">\</span>
                           style=&quot;height:24px; width:24px; <span style="color: #000099; font-weight: bold;">\</span>
                           vertical-align:middle;border:0;&quot; /&gt;'</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So lässt sich beispielsweise festlegen, in welchem Element die Liste der ausgewählten Dateien angezeigt wird und welche Texte für die Fehlermeldungen verwendet werden. Außerdem können Funktionen angegeben werden die beispielsweise beim Auswählen oder Entfernen einer Datei ausgeführt werden.</p>
<p>Ausführlichere Informationen und einige weitere Beispiele finden sich auf der Webseite der Erweiterung.</p>
<p style="padding-left:30px;">Webseite: <a href="http://www.fyneworks.com/jquery/multiple-file-upload/#tab-Overview">jQuery Multiple File Upload Plugin</a><br />
<a href="/demos/7-mehrere-dateien-flexibel-hochladen/jquery_multiple_file_upload_plugin/beispiel.html">Demo</a></p>
<h2>Mit mootools</h2>
<p><a href="http://www.antusblog.de/wp-content/uploads/2009/07/mootools_upload.png"><img src="http://www.antusblog.de/wp-content/uploads/2009/07/mootools_upload-150x150.png" alt="Mehrere Dateien flexibel hochladen mit der mootools-Erweiterung." title="Mehrere Dateien flexibel hochladen mit der mootools-Erweiterung." width="150" height="150" class="alignright size-thumbnail wp-image-1793" /></a>Für <a href="http://www.mootools.org">mootools</a> gibt es ebenfalls eine <a href="http://the-stickman.com/web-development/javascript/multiple-file-uploader-mootools-version/">Erweiterung</a>.</p>
<h3>Einbinden und Benutzen</h3>
<p>Um diese Erweiterung zu benutzen, müssen zuerst <code>mootools</code> und die Erweiterung selbst eingebunden werden.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mootools-1.2.3-core-yc.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Stickman.MultiUpload.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<p>Das <code>input</code>-Element braucht keine bestimmte Klasse.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;formular&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;datei&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div>

<p>Nun muss nur noch ein <code>MultiUpload</code>-Objekt erstellt werden.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">window.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'domready'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">new</span> MultiUpload<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'formular'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">datei</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'[]'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Der erste Parameter ist das <code>input</code>-Element, die folgenden 4 Parameter sind optional:</p>
<ul>
<li>Maximale Anzahl von Dateien (Standard: 0/unlimitiert).</li>
<li>Was an den Namen des Elements angehangen wird (Standard: _{id}).</li>
<li>Pfad anzeigen? (Standard: nein).</li>
<li>Leeres Element entfernen, bevor das Formular abgeschickt wird? (Standard: ja).</li>
</ul>
<p>Die Liste der ausgewählten Dateien lässt sich mittels CSS umgestalten.</p>
<p>Auch für diese Erweiterung habe ich wieder eine Demo-Seite eingerichtet:</p>
<p style="padding-left:30px;"><a href="/demos/7-mehrere-dateien-flexibel-hochladen/mootools_multiple_file_uploader/beispiel.html">Demo</a></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.antusblog.de/2009/07/22/mehrere-dateien-flexibel-hochladen/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

