<?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; Java Script</title>
	<atom:link href="http://www.antusblog.de/tag/javascript/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>Farbauswahl-Dialog mit ColorPicker</title>
		<link>http://www.antusblog.de/2009/09/27/farbauswahl-dialog-mit-colorpicker/</link>
		<comments>http://www.antusblog.de/2009/09/27/farbauswahl-dialog-mit-colorpicker/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 16:59:33 +0000</pubDate>
		<dc:creator>Antu</dc:creator>
				<category><![CDATA[Java Script]]></category>
		<category><![CDATA[ColorPicker]]></category>
		<category><![CDATA[Dialog]]></category>
		<category><![CDATA[Farbauswahl]]></category>
		<category><![CDATA[Farben]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.antusblog.de/?p=1993</guid>
		<description><![CDATA[ColorPicker ist eine jQuery-Klasse, mit der ein Farbauswahl-Dialog erstellt werden kann, der dem Benutzer die Eingabe/Auswahl von Farben erleichtert. Der Dialog ist ähnlich aufgebaut wie der vieler Bildbearbeitungsprogramme, und hat einen ähnlichen Funktionsumfang.  Die Klasse steht unter der MIT- und der GPL-Lizenz. Colorpicker in Aktion (Demo) Webseite vom Colorpicker-Skript Benutzung Zuerst werden jQuery und die [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.antusblog.de/wp-content/uploads/2009/09/jQuery.Color.Picker.png"><img class="aligncenter size-full wp-image-1994" title="jQuery ColorPicker" src="http://www.antusblog.de/wp-content/uploads/2009/09/jQuery.Color.Picker.png" alt="jQuery ColorPicker" width="500" height="200" /></a>ColorPicker ist eine jQuery-Klasse, mit der ein Farbauswahl-Dialog erstellt werden kann, der dem Benutzer die Eingabe/Auswahl von Farben erleichtert. Der Dialog ist ähnlich aufgebaut wie der vieler Bildbearbeitungsprogramme, und hat einen ähnlichen Funktionsumfang.  Die Klasse steht unter der MIT- und der GPL-Lizenz.</p>
<p style="padding-left: 30px;"><a href="/demos/9-farbauswahl-dialog-mit-colorpicker/colorpicker.xhtml">Colorpicker in Aktion (Demo)</a><br />
<a href="http://www.eyecon.ro/colorpicker/">Webseite vom Colorpicker-Skript</a></p>
<p><span id="more-1993"></span></p>
<h2>Benutzung</h2>
<p>Zuerst werden <code>jQuery</code> und die <code>colorpicker.js</code> eingebunden.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;js/jquery.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;js/colorpicker.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Anschließend können HTML-Elemente mit dem Aufruf der ColorPicker-Funktion erweitert werden. Die Funktion akzeptiert einige Parameter, die aber alle optional sind. Ruft man die Funktion ohne Parameter auf, öffnet sich der Dialog beim Anklicken des Elements.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#element'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ColorPicker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Möchte man eine Farbauswahl direkt auf der Seite anzeigen, verwendet man die <code>flat</code>-Option.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#farbauswahl'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ColorPicker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    flat<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
    color <span style="color: #339933;">:</span> <span style="color: #3366CC;">'#123456'</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>Mit der <code>color</code>-Option lässt sich außerdem eine Farbe vorgeben.</p>
<p><a href="http://www.antusblog.de/wp-content/uploads/2009/09/Input.und.Color.Picker.png"><img class="aligncenter size-full wp-image-2010" title="Input.und.Color.Picker" src="http://www.antusblog.de/wp-content/uploads/2009/09/Input.und.Color.Picker.png" alt="Input.und.Color.Picker" width="370" height="220" /></a></p>
<p>Meistens möchte man die ausgewählte Farbe aber auch noch irgendwie weiterverarbeiten, beispielsweise in ein Formularfeld eintragen. Dazu eignen sich die Optionen <code>onSubmit</code> und <code>onChange</code>, die beim Abspeichern der Farbe (onSubmit) bzw. beim Verändern der Farbe (onChange) aufgerufen 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: #3366CC;">'input'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ColorPicker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    onSubmit <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>hsb<span style="color: #339933;">,</span> hex<span style="color: #339933;">,</span> rgb<span style="color: #339933;">,</span> element<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// hsb = HSB-Farbraum als Objekt ({ 'h' : 100, 'b' : 200, 's' : 300})</span>
        <span style="color: #006600; font-style: italic;">// hex = Hexadezimale Schreibweise (#123456)</span>
        <span style="color: #006600; font-style: italic;">// rgb = RGB-Farbraum als Objekt ({ 'r' : 123, 'g' : 123, 'b' : 123})</span>
        <span style="color: #006600; font-style: italic;">// element = Das Element, an welches der ColorPicker angehangen wurde.</span>
        $<span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span> <span style="color: #339933;">+</span> hex<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></pre></div></div>

<p>Das sind die wichtigsten Optionen. Eine ausführlichere Beschreibung aller Optionen findet sich auf der Webseite von ColorPicker.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.antusblog.de/2009/09/27/farbauswahl-dialog-mit-colorpicker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>Formulare: Datei-Element umgestalten</title>
		<link>http://www.antusblog.de/2009/07/04/formulare-datei-element-umgestalten/</link>
		<comments>http://www.antusblog.de/2009/07/04/formulare-datei-element-umgestalten/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 11:23:33 +0000</pubDate>
		<dc:creator>Antu</dc:creator>
				<category><![CDATA[Java Script]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Datei]]></category>
		<category><![CDATA[Formular]]></category>
		<category><![CDATA[hochladen]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://www.antusblog.de/?p=1687</guid>
		<description><![CDATA[Das Formularelement zum Auswählen einer Datei lässt sich nicht mittels CSS umgestalten, der Browser verwendet für dieses Element immer das Standardaussehen, so wie es vom Betriebssystem vorgegeben ist. Bei der Gestaltung von Formularen ist das natürlich ärgerlich, da das Element meistens nicht zum Aussehen der anderen Formularelemente passt. Shaun Inman beschreibt in seinem Artikel Styling [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.antusblog.de/wp-content/uploads/2009/07/Dateiformular.umgestalten.png"><img class="aligncenter size-full wp-image-1691" title="Ein Dateiformular, welches nicht die Standardoberfläche des Betriebssystems verwendet." src="http://www.antusblog.de/wp-content/uploads/2009/07/Dateiformular.umgestalten.png" alt="Ein Dateiformular, welches nicht die Standardoberfläche des Betriebssystems verwendet." width="500" height="150" /></a>Das Formularelement zum Auswählen einer Datei lässt sich nicht mittels CSS umgestalten, der Browser verwendet für dieses Element immer das Standardaussehen, so wie es vom Betriebssystem vorgegeben ist. Bei der Gestaltung von Formularen ist das natürlich ärgerlich, da das Element meistens nicht zum Aussehen der anderen Formularelemente passt.</p>
<p>Shaun Inman beschreibt in seinem Artikel <a href="http://www.shauninman.com/archive/2007/09/10/styling_file_inputs_with_css_and_the_dom">Styling File Inputs with CSS and the DOM</a> eine Methode diesem Element mittels Java Script und CSS trotzdem ein anderes Aussehen zu verpassen. Wie seine Methode funktioniert, und wie man sie noch verbessern/erweitern kann, erkläre ich in diesem Artikel.</p>
<p><span id="more-1687"></span></p>
<h2>Funktionsweise seiner Methode</h2>
<p>Man erstellt ein Element, welches die Schaltfläche darstellen soll. Dieses Element kann man mit CSS gestalten, ihm beispielsweise mittels der <code>background</code>-Eigenschaft ein Hintergrundbild zuweisen. Innerhalb dieses Elements befindet sich dann das <code>input</code>-Element.</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;">label</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;durchsuchen&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: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;datei&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span></pre></div></div>

<p>Dieses wird allerdings mittels <code>opacity</code> zu 100% transparent gemacht, so dass man es nicht sieht. Wenn man auf die sichtbare Schaltfläche klickt (also die, die man beliebig mit CSS formatieren kann), klickt man in Wirklichkeit auf die Durchsuchen-Schaltfläche des Eingabeelementes.</p>
<p><a href="http://www.antusblog.de/wp-content/uploads/2009/07/Verstecktes.Eingabefeld.png"><img class="alignright size-full wp-image-1694" title="Verstecktes Eingabefeld" src="http://www.antusblog.de/wp-content/uploads/2009/07/Verstecktes.Eingabefeld.png" alt="Verstecktes Eingabefeld" width="150" height="150" /></a>Die Durchsuchen-Schaltfläche ist allerdings von Betriebssystem zu Betriebssystem verschieden groß. Wenn die Schaltfläche die man selbst gestaltet hat größer ist, könnte es passieren, das man darauf klickt und nichts passiert. Deswegen muss dafür gesorgt werden, das die echte Durchsuchen-Schaltfläche immer unter der Maus ist, wenn die Maus über der &#8220;gefälschten&#8221; Schaltfläche ist. Hier kommt dann Java Script ins Spiel, sobald die Maus über der Schaltfläche ist, wird das <code>input</code>-Element so bewegt, das die Durchsuchen-Schaltfläche unter der Maus ist.</p>
<p>Diese Methode hat allerdings einen Nachteil: Es ist zwar möglich, neben der Schaltfläche noch ein Eingabefeld hinzuzufügen, welches den Dateinamen/Pfad der ausgewählten Datei anzeigt, es ist aber nicht möglich dieses Eingabeelement zu verändern, bzw. anschließend den Wert des <code>input</code>-Elements anzupassen/zu verändern. Das geht bei Dateielementen aus Sicherheitsgründen nicht, denn sonst könnte ein böswilliger Programmierer ja ein verstecktes Dateielement erstellen, welches ohne das der Benutzer davon etwas mitbekommt Dateien von seinem Recher hochlädt.</p>
<p><strong>Vorteile:</strong></p>
<ul>
<li>Dateielemente können an das Aussehen der Webseite/der anderen Formularelemente angepasst werden.</li>
<li>Wenn der Browser des Benutzers kein Java Script unterstützt, sieht der Benutzer einfach das normale Dateielement.</li>
</ul>
<p><strong>Nachteile:</strong></p>
<ul>
<li>Etwas umständlich.</li>
<li>Der Benutzer kann den Pfad zur Datei nicht mehr direkt im Eingabefeld eingeben, er muss die Durchsuchen-Schaltfläche benutzen.</li>
</ul>
<p>Ich habe auch wieder eine Demo-Seite eingerichtet: <a href="/demos/6-durchsuchen-schaltflaeche/umgestalten.html">Demo</a>.</p>
<h2>Benutzung</h2>
<p>Zuerst wird das Skript im <code>head</code>-Bereich eingebunden, dann muss/will man noch die Schaltfläche mit CSS gestalten, außerdem muss das Dateielement sich innerhalb des umgestalteten Elementes befinden. Ein Aufruf von <code>SI.Files.stylizeAll()</code> wendet das Skript dann an.</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;">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;">title</span>&gt;</span>Dateielement umgestalten<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;">style</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span>         
            .SI-FILES-STYLIZED label.durchsuchen {
                /* Hier kann die Schaltflaeche gestaltet werden. */
                width:140px;
                height:30px;
                background: url('durchsuchen.png') 0 0 no-repeat;
                display:inline-block;
                overflow:hidden;
                cursor:pointer;
            }
&nbsp;
            .SI-FILES-STYLIZED label.durchsuchen input.datei {
                position:relative;
                height:100%;
                width:auto;
                opacity:0;
                -moz-opacity:0;
                filter:alpha(opacity=0); 
            }
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</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> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;si.files.js&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: #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> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;...&quot;</span> <span style="color: #000066;">enctype</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;multipart/form-data&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;durchsuchen&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;">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>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</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;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Hochladen&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>
                SI.Files.stylizeAll();
            <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;">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>Das Skript weist dem <code>html</code>-Element die Klasse <code>SI-FILES-STYLIZED</code> zu. Der erste CSS-Selektor des Beispiels ist für die sichtbare Schaltfläche, hier kann diese umgestaltet werden. Der zweite Selektor sorgt dafür das das <code>input</code>-Element nicht sichtbar ist. Anstatt eines <code>label</code>-Elements kann natürlich auch irgendein anderes Element verwendet werden, die Klassennamen sind auch austauschbar. </p>
<h3>Internet Explorer 7</h3>
<p>Der Internet Explorer 7 macht leider ein paar Probleme, das Fenster zum Auswählen einer Datei öffnet sich, egal wo man klickt, nachdem man mit der Maus einmal über dem input-Element war. Glücklicherweise hat jemand namens jxtps eine Lösung für dieses Problem gefunden (siehe Kommentar 29 zum Artikel von Shaun Inman). Um das Problem im IE 7 zu beheben, müssen 3 Zeilen Quelltext nach Zeile 55 der si.files.js hinzugefügt werden.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>51
52
53
54
55
56
57
58
59
60
61
62
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> e.<span style="color: #660066;">pageX</span> <span style="color: #339933;">-</span> ox<span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> y <span style="color: #339933;">=</span> e.<span style="color: #660066;">pageY</span> <span style="color: #339933;">-</span> oy<span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> w <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">file</span>.<span style="color: #660066;">offsetWidth</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> h <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">file</span>.<span style="color: #660066;">offsetHeight</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Fix for IE7+, otherwise the control can get dragged outside despite overflow: hidden;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>x <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">||</span> y <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">||</span> x <span style="color: #339933;">&gt;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">offsetWidth</span> <span style="color: #339933;">||</span> y <span style="color: #339933;">&gt;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">offsetHeight</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	x <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> y <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> h <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> w <span style="color: #339933;">=</span> <span style="color: #CC0000;">30</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">file</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">top</span>	<span style="color: #339933;">=</span> y <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>h <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span>  <span style="color: #339933;">+</span> <span style="color: #3366CC;">'px'</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">file</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">left</span>	<span style="color: #339933;">=</span> x <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>w <span style="color: #339933;">-</span> <span style="color: #CC0000;">30</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'px'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Die ausgewählte Datei anzeigen</h3>
<p>Aus Gründen der Benutzerfreundlichkeit sollte der Benutzer den Namen der ausgewählten Datei auch sehen können. Das geht ganz einfach: Man erstellt ein Element, in welches bei jeder Veränderung am <code>input</code>-Element der Wert von selbigem kopiert wird. Das kann ein Texteingabefeld sein, oder beispielsweise ein <code>span</code>-Element, ich bevorzuge letzteres, denn da der Dateiname eh nicht manuell geändert werden kann ist ein Texteingabefeld für den Benutzer ziemlich  verwirrend.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&lt;div id=&quot;d&quot;&gt;
&lt;!-- Hier wird das Text-Element mittels JS eingefuegt --&gt;
    &lt;label class=&quot;durchsuchen&quot; id=&quot;durchsuchen&quot;&gt;
        &lt;input type=&quot;file&quot; class=&quot;datei&quot; id=&quot;datei&quot; name=&quot;datei&quot;&gt;
    &lt;/label&gt;
&lt;/div&gt;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
    SI.<span style="color: #660066;">Files</span>.<span style="color: #660066;">stylizeAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>SI.<span style="color: #660066;">Files</span>.<span style="color: #660066;">able</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> anzeige <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'span'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        anzeige.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'Keine Datei ausgewählt.'</span><span style="color: #339933;">;</span>
        anzeige.<span style="color: #660066;">id</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'anzeige'</span><span style="color: #339933;">;</span>
&nbsp;
        document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'d'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">insertBefore</span><span style="color: #009900;">&#40;</span>anzeige<span style="color: #339933;">,</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'durchsuchen'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'datei'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">onchange</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> datei <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'datei'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
            document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'anzeige'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> datei<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Das Element wird per Java Script erstellt, da Benutzer ohne JavaScript sonst trotzdem neben dem Dateielement noch &#8220;Keine Datei ausgewählt&#8221; stehen hätten. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.antusblog.de/2009/07/04/formulare-datei-element-umgestalten/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Geteilte Eingabe</title>
		<link>http://www.antusblog.de/2009/06/27/geteilte-eingabe/</link>
		<comments>http://www.antusblog.de/2009/06/27/geteilte-eingabe/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 16:13:20 +0000</pubDate>
		<dc:creator>Antu</dc:creator>
				<category><![CDATA[Java Script]]></category>
		<category><![CDATA[Formular]]></category>
		<category><![CDATA[Geteilte Eingabe]]></category>
		<category><![CDATA[Produkt-Aktivierung]]></category>
		<category><![CDATA[Seriennummer]]></category>

		<guid isPermaLink="false">http://www.antusblog.de/?p=1633</guid>
		<description><![CDATA[Seriennummern und ähnliche Codes werden oft auf mehrere Teile aufgeteilt, um es dem Benutzer zu erleichtern sie abzulesen.  Bei der Eingabe ist es oft ähnlich, die Seriennummer kann in mehreren Teilen eingegeben werden, sinnvollerweise in den gleichen Teilen wie sie dem Benutzer übergeben wurde. Wenn der Benutzer das erste Feld ausgefüllt hat, wäre es praktisch, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.antusblog.de/wp-content/uploads/2009/06/Produkt.Aktivierung.Bitte.Seriennummer.eingeben.png"><img class="aligncenter size-full wp-image-1634" title="Eingabe einer Seriennummer" src="http://www.antusblog.de/wp-content/uploads/2009/06/Produkt.Aktivierung.Bitte.Seriennummer.eingeben.png" alt="Eingabe einer Seriennummer" width="500" height="160" /></a>Seriennummern und ähnliche Codes werden oft auf mehrere Teile aufgeteilt, um es dem Benutzer zu erleichtern sie abzulesen.  Bei der Eingabe ist es oft ähnlich, die Seriennummer kann in mehreren Teilen eingegeben werden, sinnvollerweise in den gleichen Teilen wie sie dem Benutzer übergeben wurde.</p>
<p>Wenn der Benutzer das erste Feld ausgefüllt hat, wäre es praktisch, wenn der Browser automatisch zum zweiten Feld weiterspringen würde. Sowas lässt sich mit Java Script leicht realisieren. Noch besser wäre es natürlich, wenn der Benutzer auch mit den Pfeiltasten zwischen den Feldern navigieren könnte, oder wenn nur bestimmte Zeichen vom Benutzer eingegeben werden können.</p>
<p>In diesem Artikel erkläre ich, wie man mittels Java Script ein solches automatisches Weiterspringen zwischen Formularfeldern programmiert. Außerdem stelle ich eine kleine Klasse vor die es zusätzlich dazu noch ermöglicht mit den Pfeiltasten durch die Felder zu navigieren und die Eingabe auf bestimmte Zeichen zu begrenzen.</p>
<p><span id="more-1633"></span></p>
<h2>Automatisches Weiterspringen</h2>
<p>Man überprüft einfach bei jedem Tastendruck, ob das aktuelle Feld bereits voll ist, ist das der Fall wird das nächste Feld (sofern vorhanden) aktiviert. Bei einem Tastendruck werden drei Ereignisse ausgelöst:</p>
<ul>
<li><strong>keydown</strong>, wenn eine Taste gedrückt wird.</li>
<li><strong>keypress</strong>, wenn ein Zeichen geschrieben wird bzw. die Aktion der Taste ausgeführt wird (z.B. neue Zeile bei der Eingabetaste).</li>
<li><strong>keyup</strong>, wenn die Taste wieder losgelassen wird.</li>
</ul>
<p>Das <code>keypress</code>-Ereignis halte ich für am besten geeignet, da es sofort auf jedes eingegebene Zeichen reagiert. Um überprüfen zu können, ob ein Feld bereits voll ist, muss erstmal bekannt sein wie viele Zeichen ein Feld aufnehmen darf, hierzu wird das <code>maxlength</code>-Attribut des <code>input</code>-Elements verwendet.</p>
<p>Die Überprüfung selbst ist einfach, man vergleicht einfach die max. Länge mit der Länge des Inhalts, ist sie gleich, wird zum nächsten Element gesprungen. Der Inhalt des Eingabefelds ist in der Eigenschaft <code>value</code> gespeichert, die Länge lässt sich über die Eigenschaft <code>length</code> von <code>value</code> ermitteln. Jedes Formular-Element hat die Methode <code>focus()</code>, mittels derer man das Element &#8220;aktivieren&#8221; kann, so dass der Eingabezeiger dorthin springt.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><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> <span style="color: #000066;">dir</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ltr&quot;</span> <span style="color: #000066;">lang</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;de-DE&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>Seriennummer-Eingabe<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 weiterspringen(aktuellesFeld, naechstesFeld) {
      if (aktuellesFeld.value.length == aktuellesFeld.getAttribute('maxlength'))
        document.getElementsByName(naechstesFeld)[0].focus();
    }
    <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;">h1</span>&gt;</span>Produkt-Aktivierung<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span>&gt;</span>Bitte geben Sie die Seriennummer des von Ihnen erworbenen Produkts an.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;formular&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;seriennummer.html&quot;</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">onkeypress</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;weiterspringen(this, 's2');&quot;</span> <span style="color: #000066;">maxlength</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;4&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;s1&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span>&gt;</span> - 
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">onkeypress</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;weiterspringen(this, 's3');&quot;</span> <span style="color: #000066;">maxlength</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;4&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;s2&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span>&gt;</span> - 
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">maxlength</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;4&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;s3&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</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>Ich habe auch diesmal wieder eine Beispielseite angelegt:</p>
<p style="padding-left:30px;"><a href="/demos/5-seriennummer/einfach.html">Zur Beispielseite</a></p>
<h2>Die Klasse</h2>
<p>Ich habe eine kleine Klasse programmiert die noch etwas mehr kann:</p>
<ul>
<li>Der Benutzer kann nur noch bestimmte Zeichen eingeben. Wenn eine Seriennummer also beispielsweise keine Zahlen enthalten kann, kann der Benutzer sie auch nicht eingeben.</li>
<li>Man kann auch mit den Pfeiltasten hin- und her navigieren, auch zwischen den Feldern.</li>
<li>Im Internet Explorer und bei Gecko-basierten Browsern (z.B. Firefox) springt der Eingabezeiger automatisch zum letzten Zeichen, wenn man ein Feld zurück springt.</li>
</ul>
<p>Um die Funktionalität zu aktivieren erstellt man einfach eine neue Instanz der Klasse, und weist ihr mittels der Methode <code>elementHinzufuegen(&lt;Element&gt;)</code> die einzelnen Felder zu.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">window.<span style="color: #000066;">onload</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> sn <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> GeteilteEingabe<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	sn.<span style="color: #660066;">elementHinzufuegen</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementsByName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'s1'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	sn.<span style="color: #660066;">elementHinzufuegen</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementsByName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'s2'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	sn.<span style="color: #660066;">elementHinzufuegen</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementsByName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'s3'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Die Variable <code>erlaubteZeichen</code> kann angepasst werden, um festzulegen, welche Zeichen der Benutzer in den Eingabefeldern der Seriennummer benutzen darf.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> erlaubteZeichen <span style="color: #339933;">=</span> <span style="color: #3366CC;">'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789'</span><span style="color: #339933;">;</span></pre></div></div>

<p>Für die Klasse habe ich natürlich auch wieder eine Beispielseite zur Demonstration erstellt.</p>
<p style="padding-left:30px;"><a href="/downloads/geteilteeingabe/geteilteeingabe.js">Zum Quelltext der Klasse</a><br />
<a href="/demos/5-seriennummer/seriennummer.html">Zur Beispielseite</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.antusblog.de/2009/06/27/geteilte-eingabe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ein einfacher Buchstaben- und Wörterzähler</title>
		<link>http://www.antusblog.de/2009/06/18/ein-einfacher-buchstaben-und-worterzahler/</link>
		<comments>http://www.antusblog.de/2009/06/18/ein-einfacher-buchstaben-und-worterzahler/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 16:47:46 +0000</pubDate>
		<dc:creator>Antu</dc:creator>
				<category><![CDATA[Java Script]]></category>
		<category><![CDATA[Buchstabe]]></category>
		<category><![CDATA[Buchstabenzähler]]></category>
		<category><![CDATA[Wort]]></category>
		<category><![CDATA[Wörterzählern]]></category>
		<category><![CDATA[Zeichen]]></category>
		<category><![CDATA[Zeichenzähler]]></category>

		<guid isPermaLink="false">http://www.antusblog.de/?p=1555</guid>
		<description><![CDATA[Ein Wörter- bzw. Buchstabenzähler kann für den Benutzer von großem Nutzen sein. Wenn ihm (z.B. aus technischen Gründen) nur eine bestimmte Anzahl von Zeichen zur Verfügung stehen, sieht er bereits bei der Eingabe, wie viele Zeichen er noch schreiben kann. Beim Verfassen längerer Texte ist ein Wörterzähler hilfreich, denn so kann der Benutzer ungefähr abschätzen [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.antusblog.de/wp-content/uploads/2009/06/Buchstabenzaehler.Woerterzaehler.Javascript.png"><img class="aligncenter size-full wp-image-1559" title="Buchstabenzaehler.Woerterzaehler.Javascript" src="http://www.antusblog.de/wp-content/uploads/2009/06/Buchstabenzaehler.Woerterzaehler.Javascript.png" alt="Buchstabenzaehler.Woerterzaehler.Javascript" width="528" height="336" /></a>Ein Wörter- bzw. Buchstabenzähler kann für den Benutzer von großem Nutzen sein. Wenn ihm (z.B. aus technischen Gründen) nur eine bestimmte Anzahl von Zeichen zur Verfügung stehen, sieht er bereits bei der Eingabe, wie viele Zeichen er noch schreiben kann. Beim Verfassen längerer Texte ist ein Wörterzähler hilfreich, denn so kann der Benutzer ungefähr abschätzen wie lang sein Text bereits ist.</p>
<ul>
<li>Beim Schreiben von Kurznachrichten (SMS) ist die maximale Anzahl von Zeichen begrenzt. Bei privaten Nachrichten in Foren, oder Kontaktformularen gibt es oft ähnliche Begrenzungen. Hier ist eine Anzeige der noch verfügbaren Zeichen sinnvoll.</li>
<li>Eine Anzeige der Wortzahl ist beispielsweise für einen Redakteur oder Blogger nützlich, denn so sieht er ob er seinen Text vielleicht etwas kürzen, oder noch etwas mehr schreiben sollte.</li>
</ul>
<p>In diesem Artikel stelle ich einen einfachen <strong>Buchstabenzähler</strong> bzw. <strong>Wörterzähler</strong> in Form einer Java Script-Klasse vor, und erkläre seine Funktionsweise.<span id="more-1555"></span></p>
<h2>Der Wörter- bzw. Buchstabenzähler</h2>
<p>Die Zählerklasse ist in der Lage die Wörter und Buchstaben in einem Eingabefeld zu zählen. Außerdem können Angaben zur maximalen Anzahl von Zeichen/Wörtern gemacht werden, zusätzlich kann eine Funktion angegeben werden, welche beim Überschreiten der maximalen Anzahl aufgerufen wird.</p>
<p style="padding-left: 30px;"><a href="http://www.antusblog.de/downloads/eingabenzaehler/EingabenZaehlen.js">Die Zählerklasse</a><br />
<a href="/demos/4-eingabenzaehler/woerterzaehler.html">Beispielseite (Texteingabe mit Wörter- und Zeichenzähler)</a></p>
<h3>Benutzung der Klasse</h3>
<p>Beim Erstellen der Klasse wird die ID des Eingabeelementes angegeben, dessen Inhalt ausgewertet werden soll. Sobald eine der Zählerfunktionen aufgerufen wird, bindet die Klasse die Funktion zum Zählen der Zeichen bzw. die zum Zählen der Wörter an die <code>onchange</code>- und <code>onkeyup</code>-Ereignisse. Bei jeder Veränderung des Textes wird neu gezählt und die Anzeige aktualisiert.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Wenn der Zähler sofort loszählen soll, kann er einfach beim onload-</span>
<span style="color: #006600; font-style: italic;">// Ereignis initialisiert werden.</span>
window.<span style="color: #000066;">onload</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: #006600; font-style: italic;">// Wörter- und Buchstabenzähler initialisieren</span>
	<span style="color: #006600; font-style: italic;">// 'text' ist die ID des Eingabefeldes</span>
	<span style="color: #003366; font-weight: bold;">var</span> eingabenzaehler <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> EingabenZaehler<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'text'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// Maximale Anzahl an Buchstaben festlegen. (450)</span>
	<span style="color: #006600; font-style: italic;">// 'bmax' ist die ID des Elements, in dem die maximale Anzahl von </span>
	<span style="color: #006600; font-style: italic;">// Buchstaben angezeigt wird. text_einfaerben ist die Funktion, </span>
	<span style="color: #006600; font-style: italic;">// die beim Überschreiten der max. Anzahl aufgerufen wird</span>
	eingabenzaehler.<span style="color: #660066;">maxBuchstaben</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">450</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'bmax'</span><span style="color: #339933;">,</span> text_einfaerben<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #006600; font-style: italic;">// Diese Funktion hat auch noch einen vierten, optionalen Parameter,</span>
	<span style="color: #006600; font-style: italic;">// der festlegt, wie lang ein Wort maximal sein darf. Ab dieser Zahl wird es</span>
	<span style="color: #006600; font-style: italic;">// als mehrere Wörter gezählt. Die Voreinstellung ist 50. Ein Wort aus 153</span>
	<span style="color: #006600; font-style: italic;">// Zeichen würde also als 3 Wörter gezählt werden.</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// Man könnte auch eine max. Anzahl Wörter festlegen.</span>
	<span style="color: #006600; font-style: italic;">// eingabenzaehler.maxWoerter(100, 'wmax', max_woerter);</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// Wörterzähler aktivieren, 'wz' ist die ID des Elements in dem</span>
	<span style="color: #006600; font-style: italic;">// die Anzahl der Wörter angezeigt wird.</span>
	eingabenzaehler.<span style="color: #660066;">woerterZaehler</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'wz'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// Buchstabenzähler aktivieren, 'bz' ist die ID des Elements in dem</span>
	<span style="color: #006600; font-style: italic;">// die Anzahl der Buchstaben angezeigt wird.</span>
	eingabenzaehler.<span style="color: #660066;">buchstabenZaehler</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'bz'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Die beim Erreichen der maximalen Zeichen/Wort-Anzahl aufgerufene Funktion muss einen Parameter annehmen, welcher angibt ob die max. Anzahl überschritten wurde. Wenn die max. Anzahl überschritten wurde, wird <code>true</code> als 1. Parameter mitgeliefert, ansonsten <code>false</code>. Die Funktion könnte beispielsweise 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> text_einfaerben<span style="color: #009900;">&#40;</span>drueber<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// Variablen initialisieren (beim ersten Aufruf)</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">geaendert</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">geaendert</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">alteFarbe</span> <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'warnung'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">color</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #006600; font-style: italic;">// max. Anzahl überschritten, färbe Text rot ein.</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>drueber <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">geaendert</span> <span style="color: #339933;">===</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">geaendert</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'warnung'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">color</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'red'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #006600; font-style: italic;">// max. Anzahl nicht oder nicht mehr überschritten, normale Farbe.</span>
	<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>drueber <span style="color: #339933;">===</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">geaendert</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'warnung'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">color</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">alteFarbe</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Funktionsweise</h3>
<p>Das Zählen der Zeichen in einem Eingabefeld gestaltet sich ziemlich einfach. Jedes Text-Eingabefeld hat die Eigenschaft <code>value</code>, in der der eingegebene Text enthalten ist. Diese Eigenschaft hat wiederum die Eigenschaft <code>length</code>, die angibt wie viele Zeichen der Text enthält.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">anzahl <span style="color: #339933;">=</span> eingabefeld.<span style="color: #660066;">value</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span></pre></div></div>

<p>Herauszufinden, aus wie vielen Wörtern ein Text besteht, ist hingegen schon schwieriger. Es genügt nicht, einfach alle Leerzeichen zu zählen, denn so würden mehrere Leerzeichen auch als mehrere Wörter gezählt werden. Außerdem gibt es noch andere Zeichen, mit denen Wörter getrennt werden können, beispielsweise Tabulatoren, Zeilenumbrüche oder Kommata. </p>
<p>Die Klasse geht zum Zählen der Wörter den gesamten Text Zeichen für Zeichen durch, und merkt sich mittels der Variable <code>imwort</code> ob der Zeiger sich gerade in einem Wort befindet, oder nicht. Immer wenn ein Zeichen kommt, welches kein Teil eines Wortes ist (Leerzeichen, Zeilenumbruch, Komma, Punkt, etc.) wird die Anzahl der Wörter um eins erhöht und die Variable <code>imwort</code> zurückgesetzt. Die <code>imwort</code>-Variable wird gleichzeitig dazu verwendet die Länge eines Wortes zu erfahren, so dass sehr lange Wörter als mehrere Wörter gezählt werden. </p>
<p>Eine Funktion, die es verhindert, das der Benutzer weiterschreibt, wenn die max. Wort/Zeichen-Anzahl erreicht ist hat die Klasse ebenfalls nicht. Solche Funktionen behindern den Benutzer nur, und können ohnehin leicht umgangen werden. Solche Funktionen verhindern, dass der Benutzer seinen Text erst einmal zu Ende schreibt, und dann guckt, was er weglassen kann, um die Begrenzung einzuhalten. </p>
<h4>Verbesserungsmöglichkeiten</h4>
<p>Bei jeder Veränderung, und jedem neuen Zeichen zählt die Klasse neu, bei längeren Texten und älteren Rechnern kann das die Ausführung ziemlich verlangsamen. Man könnte die Klasse aber einfach so umschreiben, das nur alle X Sekunden neu gezählt wird, und nicht bei jeder Veränderung.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.antusblog.de/2009/06/18/ein-einfacher-buchstaben-und-worterzahler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Absenden, Zurücksetzen und Verlassen von Formularen</title>
		<link>http://www.antusblog.de/2009/06/15/absenden-zurucksetzen-und-verlassen-von-formularen/</link>
		<comments>http://www.antusblog.de/2009/06/15/absenden-zurucksetzen-und-verlassen-von-formularen/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 20:48:58 +0000</pubDate>
		<dc:creator>Antu</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[Java Script]]></category>
		<category><![CDATA[Absenden]]></category>
		<category><![CDATA[Formular]]></category>
		<category><![CDATA[Schließen]]></category>
		<category><![CDATA[Verlassen]]></category>
		<category><![CDATA[Zurücksetzen]]></category>

		<guid isPermaLink="false">http://www.antusblog.de/?p=1510</guid>
		<description><![CDATA[Manchmal verklickt man sich, oder man überliest in Eile einen Hinweis. Da kann es schon mal passieren, das man ausversehen auf die Zurücksetzen-Schaltfläche anstatt auf die direkt daneben liegende Absenden-Schaltfläche klickt. Oder man schließt versehentlich das falsche Fenster, und alle im Formular eingegebenen Daten müssen noch einmal eingegeben werden. Gerade bei längeren Forenbeiträgen, oder Blog-Artikeln [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.antusblog.de/wp-content/uploads/2009/06/Formular.schliessen.png"><img src="http://www.antusblog.de/wp-content/uploads/2009/06/Formular.schliessen.png" alt="Abfrage vor dem Schließen eines Formulars/einer Seite" title="Abfrage vor dem Schließen eines Formulars/einer Seite" width="380" height="150" class="aligncenter size-full wp-image-1549" /></a>Manchmal verklickt man sich, oder man überliest in Eile einen Hinweis. Da kann es schon mal passieren, das man ausversehen auf die Zurücksetzen-Schaltfläche anstatt auf die direkt daneben liegende Absenden-Schaltfläche klickt. Oder man schließt versehentlich das falsche Fenster, und alle im Formular eingegebenen Daten müssen noch einmal eingegeben werden. Gerade bei längeren Forenbeiträgen, oder Blog-Artikeln ist das sehr ärgerlich. </p>
<p>Ein paar einfache Java Script-Funktionen schaffen da Abhilfe. Vor dem Absenden oder Zurücksetzen eines Formulars kann der Benutzer noch einmal gefragt werden ob er das wirklich tun will. Auch vor dem Verlassen/Schließen der Seite lässt sich eine solche Abfrage erstellen. Außerdem erkläre ich, wie man eine Schaltfläche erst nach einer bestimmten Zeit aktivieren kann.</p>
<p><span id="more-1510"></span></p>
<h2>Zurücksetzen der Formularfelder</h2>
<p>Um dem Benutzer die Möglichkeit zu geben, die Formularfelder wieder auf den Anfangswert zurückzusetzen bzw. sie wieder zu leeren genügt ein <code>input</code>-Element vom Typ <code>reset</code>.</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;reset&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Zur&amp;uuml;cksetzen&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p>Mit Java Script ist es allerdings auch möglich, beim Zurücksetzen des Formulars noch weitere Aktionen auszuführen oder das Zurücksetzen besser zu steuern. So ist es beispielsweise möglich nur bestimmte Felder zurückzusetzen oder den Benutzer zu fragen ob er die Daten wirklich zurücksetzen möchte. Dazu trägt man im <code>onreset</code>-Ereignis des <code>form</code>-Elementes die Funktion ein, die beim Zurücksetzen des Formulars ausgeführt werden 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;">form</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;...&quot;</span> <span style="color: #000066;">onreset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;return wirklichZuruecksetzen();&quot;</span>&gt;</span></pre></div></div>

<p>Es ist auch möglich die Funktion einen Wert zurückgeben zu lassen, mit dem man steuern kann ob das Formular auch wirklich zurückgesetzt wird. Gibt die aufgerufene Funktion <code>false</code> zurück wird das Formular nicht zurückgesetzt, bei <code>true</code> wird es zurückgesetzt.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> wirklichZuruecksetzen<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066;">confirm</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Alle Eingaben loeschen?'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #006600; font-style: italic;">// Anstatt dessen koennte man hier auch nur bestimmte Felder zuruecksetzen und</span>
	<span style="color: #006600; font-style: italic;">// false zurueckgeben.</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>Abfrage vor dem Absenden</h2>
<p>Um eine Abfrage vor dem Absenden zu erstellen, trägt man einfach eine Funktion beim <code>onsubmit</code>-Ereignis des <code>form</code>-Elements ein, auch hier entscheidet wieder der Rückgabewert darüber ob das Formular abgesendet wird.</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;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;...&quot;</span> <span style="color: #000066;">onsubmit</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;return confirm('Daten abschicken?');&quot;</span>&gt;</span></pre></div></div>

<p>Der Vorteil dieser Methode ist, das sie schnell und einfach programmiert ist, der Nachteil das sie nur funktioniert, wenn der Benutzer Java Script aktiviert hat bzw. sein Browser Java Script unterstützt. Bei wichtigen Formularen (beispielsweise einer Bestellung) ist es empfehlenswert, die Daten erst an eine Zwischenseite zu senden, welche noch einmal alle Eingaben auflistet und auf der noch einmal das Absenden bestätigt werden muss. </p>
<p>Im <code>onsubmit</code>-Ereignis lässt sich übrigens nicht nur eine Abfrage einbauen. Man könnte beispielsweise auch überprüfen ob alle Felder (richtig) ausgefüllt sind, und den Benutzer auf eventuelle Fehler hinweisen/auffordern diese zu korrigieren.</p>
<h2>Verlassen/Schließen des Formulars: Abfrage bzw. Funktion ausführen</h2>
<p>Man kann den Benutzer vor dem Verlassen der aktuellen Seite zu fragen ob er die Seite wirklich verlassen möchte. Dazu kann das <a href="https://developer.mozilla.org/en/DOM/window.onbeforeunload"><code>onbeforeunload</code></a>-Ereignis verwendet werden, welches heutzutage von den meisten Browsern unterstützt wird, obwohl es nicht zum Standard gehört.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* Fragt den Benutzer, ob er die Seite wirklich verlassen moechte.
 */</span>
window.<span style="color: #660066;">onbeforeunload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// Hier koennte man noch abfragen ob bereits Eingaben getaetigt wurden,</span>
	<span style="color: #006600; font-style: italic;">// wenn nicht, braucht man in den meisten Faellen wohl auch keine Nachricht</span>
	<span style="color: #006600; font-style: italic;">// anzeigen.</span>
	<span style="color: #003366; font-weight: bold;">var</span> nachricht <span style="color: #339933;">=</span> <span style="color: #3366CC;">'Sie haben das Formular noch nicht abgesendet, möchten Sie das Fenster trotzdem schließen?'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> e <span style="color: #339933;">=</span> e <span style="color: #339933;">||</span> window.<span style="color: #660066;">event</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		e.<span style="color: #660066;">returnValue</span> <span style="color: #339933;">=</span> nachricht<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">return</span> nachricht<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
window.<span style="color: #000066;">onload</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: #006600; font-style: italic;">// Keine Meldung ausgeben, wenn der Benutzer die Seite ueber die</span>
	<span style="color: #006600; font-style: italic;">// Absenden-Schaltflaeche verlaesst.</span>
	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> document.<span style="color: #660066;">forms</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		document.<span style="color: #660066;">forms</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">onsubmit</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> window.<span style="color: #660066;">onbeforeunload</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Die dem <code>onbeforeunload</code>-Ereignis zugewiesene Funktion sorgt dafür das der Benutzer beim Schließen des Fensters bzw. beim Verlassen der Seite gefragt wird ob er die Seite wirklich schließen möchte. Damit das geschieht, muss die Nachricht, die angezeigt werden soll in das <code>returnValue</code>-Element von dem Ereignis geschrieben, und als Rückgabewert zurückgegeben werden. Bleibt <code>returnValue</code> leer bzw. wird nichts zurückgegeben, erscheint auch keine Nachricht.</p>
<h2>Absenden-Schaltfläche erst nach Ablauf einer bestimmten Zeit freigeben</h2>
<p><a href="http://www.antusblog.de/wp-content/uploads/2009/06/Abschicken.erst.nach.einer.bestimmten.Zeit.png"><img src="http://www.antusblog.de/wp-content/uploads/2009/06/Abschicken.erst.nach.einer.bestimmten.Zeit.png" alt="Die Abschicken-Schaltfläche ist ausgegraut und zeigt an, dass das Formular erst in 17 Sekunden abgeschickt werden kann." title="Die Abschicken-Schaltfläche ist ausgegraut und zeigt an, dass das Formular erst in 17 Sekunden abgeschickt werden kann." width="140" height="80" class="alignright size-full wp-image-1541" /></a>Es ist möglich die Absenden-Schaltfläche erst nach Ablauf einer bestimmten Zeit zu aktivieren, so dass der Benutzer sie vorher nicht anklicken kann. Das ist beispielsweise in einem Forum sinnvoll, wo der Benutzer nur alle 60 Sekunden einen Beitrag schreiben kann. Der Browser des Benutzers stellt die Schaltfläche ausgegraut da, und zeigt auf der Schaltfläche an wie lange es noch dauert bis das Formular abgesendet werden kann. Die Zeit muss selbstverständlich auch serverseitig überprüft werden, diese Funktion ist nur dazu gedacht, es dem Benutzer einfacher zu machen, zu erkennen wann er auf die Absenden-Schaltfläche klicken kann. Durch das Deaktivieren von Java Script kann die Funktion &#8220;umgangen&#8221; werden, sie stellt also keinen Sicherheitsmechanismus dar!</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* Sorgt dafuer, das eine Schaltflaeche erst nach Ablauf einer bestimmten Zeit
 * klickbar wird, kann aber leicht &quot;umgangen&quot; werden.
 */</span>
<span style="color: #003366; font-weight: bold;">function</span> AbsendenENA<span style="color: #009900;">&#40;</span>sf<span style="color: #339933;">,</span> zeit<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> self <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> intervall <span style="color: #339933;">=</span> window.<span style="color: #660066;">setInterval</span><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> self.<span style="color: #660066;">aktualisieren</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	sf.<span style="color: #660066;">disabled</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;">var</span> sftext <span style="color: #339933;">=</span> sf.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">aktualisieren</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: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>zeit <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			sf.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> sftext <span style="color: #339933;">+</span> <span style="color: #3366CC;">'('</span> <span style="color: #339933;">+</span> zeit <span style="color: #339933;">+</span> <span style="color: #3366CC;">')'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			sf.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> sftext<span style="color: #339933;">;</span>
			sf.<span style="color: #660066;">disabled</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
			window.<span style="color: #660066;">clearInterval</span><span style="color: #009900;">&#40;</span>intervall<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		zeit<span style="color: #339933;">--;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">aktualisieren</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
window.<span style="color: #000066;">onload</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: #006600; font-style: italic;">// Absenden-Schaltflaeche erst nach einer bestimmten Zeit benutzbar machen</span>
	<span style="color: #003366; font-weight: bold;">new</span> AbsendenENA<span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'abschicken'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Im Beispiel wird eine neue Instanz des AbsendenENA-Objekts erstellt, der erste Parameter ist das Schaltflächen-Objekt (mit der ID <em>abschicken</em>), der zweite die Zeit bis zum Aktivieren, in Sekunden. Die Klasse kann theoretisch an jeder Stelle benutzt werden, im Beispiel wird sie beim <code>onload</code>-Ereignis aufgerufen.</p>
<p>Ich rate dazu, die Funktion nur an Stellen zu verwenden, an denen es dem Benutzer aus technischen (oder auch anderen) Gründen eh nicht möglich wäre das Formular vor Ablauf der Zeit abzuschicken, beispielsweise weil ein Spamschutz das Abschicken serverseitig eh nur alle X Sekunden zulässt. Man kann den Benutzer mit einer solchen Funktion nicht dazu zwingen sich irgendwelche Forenregeln, AGBs, oder sonstwas durchzulesen.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.antusblog.de/2009/06/15/absenden-zurucksetzen-und-verlassen-von-formularen/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Elemente ein- und ausblenden</title>
		<link>http://www.antusblog.de/2009/04/28/elemente-ein-und-ausblenden/</link>
		<comments>http://www.antusblog.de/2009/04/28/elemente-ein-und-ausblenden/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 18:27:15 +0000</pubDate>
		<dc:creator>Antu</dc:creator>
				<category><![CDATA[Java Script]]></category>
		<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[Bildergalerie]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Effekte]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Transparente Elemente]]></category>

		<guid isPermaLink="false">http://antusblog.de/?p=561</guid>
		<description><![CDATA[Wie man HTML-Elemente mittels CSS transparent machen kann habe ich ja bereits in diesem Artikel beschrieben. In diesem Artikel erkläre ich wie man mit JavaScript Elemente ein- und ausblenden kann. Solche Effekte eigenen sich sehr gut zum Beispiel für Bildergalerien, Fehlermeldungen oder dynamisch nachgeladene Inhalte. Per JavaScript CSS-Eigenschaften verändern Jedes erlaubte Attribut eines HTML-Elements stellt [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://antusblog.de/wp-content/uploads/2009/04/bild.png"><img src="http://antusblog.de/wp-content/uploads/2009/04/bild-150x150.png" alt="Bildergalerie" title="Bildergalerie" width="150" height="150" class="alignright size-thumbnail wp-image-960" /></a>Wie man HTML-Elemente mittels CSS transparent machen kann habe ich ja bereits in <a href="http://antusblog.de/2009/03/19/transparente-farben-und-elemente-mit-css/" target="_blank">diesem Artikel</a> beschrieben. In diesem Artikel erkläre ich wie man mit JavaScript Elemente ein- und ausblenden kann. Solche Effekte eigenen sich sehr gut zum Beispiel für Bildergalerien, Fehlermeldungen oder dynamisch nachgeladene Inhalte.<br />
<span id="more-561"></span></p>
<h2>Per JavaScript CSS-Eigenschaften verändern</h2>
<p>Jedes erlaubte Attribut eines HTML-Elements stellt auch eine DOM-Eigenschaft dieses Elements dar. Der Zugriff auf die CSS-Eigenschaften eines Elements ist also über die Eigenschaft <code>style</code> möglich. Die einzelnen CSS-Eigenschaften sind wiederum Eigenschaften von <code>style</code>.</p>
<p>Ein Beispiel:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Text im HTML-Element mit der ID beschreibung rot färben</span>
document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'beschreibung'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">color</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'red'</span><span style="color: #339933;">;</span></pre></div></div>

<p>Dabei muss man beachten das Eigenschaften die einen Bindestrich enthalten etwas anders geschrieben werden. Bei solchen Eigenschaften wird anstelle des Bindestrichs einfach der nächste Buchstabe großgeschrieben.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// text-decoration:line-through;</span>
document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'beschreibung'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">textDecoration</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'line-through'</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Deckkraft mit JavaScript ändern</h2>
<p>Um die Deckkraft eines Elements mit JavaScript zu verändern muss man einfach über die <code>style</code>-Eigenschaft den entsprechenden CSS-Eigenschaften neue Werte zuweisen. <code>MozOpacity</code> für Mozilla, <code>KhtmlOpacity</code> für Webkit, <code>filter</code> für den Internet Explorer und <code>opacity</code> für neuere Browser. Folgende Funktion tut genau das. Der erste Parameter ist die ID des HTML-Elements dessen Deckkraft geändert werden soll und der zweite Parameter ist ein Wert von 0 (komplett durchsichtig) bis 100 (voll sichtbar).</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> aendereDeckkraft<span style="color: #009900;">&#40;</span>id<span style="color: #339933;">,</span> transparenz<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> style <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span><span style="color: #339933;">;</span>
	style.<span style="color: #660066;">filter</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;alpha(opacity=&quot;</span> <span style="color: #339933;">+</span> transparenz <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;)&quot;</span><span style="color: #339933;">;</span>
	transparenz <span style="color: #339933;">/=</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">;</span>
	style.<span style="color: #660066;">opacity</span> <span style="color: #339933;">=</span> transparenz<span style="color: #339933;">;</span>
	style.<span style="color: #660066;">MozOpacity</span> <span style="color: #339933;">=</span> transparenz<span style="color: #339933;">;</span>
	style.<span style="color: #660066;">KhtmlOpacity</span> <span style="color: #339933;">=</span> transparenz<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><code>Filter</code> erwartet einen Wert von 0-100, die anderen 3 Eigenschaften erwarten einen Wert zwischen 0 und 1. Deswegen wird der Wert der Variable <code>transparenz</code> durch 100 geteilt nachdem <code>filter</code> der neue Wert zugewiesen wurde.</p>
<h2>Etwas langsamer</h2>
<p>Es sieht natürlich viel besser aus wenn sich die Deckkraft nicht schlagartig ändert sondern langsam von einem Zustand in den anderen übergeht. Dazu verringert bzw. erhöht man einfach in kurzen Zeitabständen immer wieder die Deckkraft bis der gewünschte Wert erreicht ist. Dafür eignet sich die Funktion <a href="http://de.selfhtml.org/javascript/objekte/window.htm#set_timeout" target="_blank">setTimeout</a> recht gut.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> aendereSichtbarkeit<span style="color: #009900;">&#40;</span>id<span style="color: #339933;">,</span> anfang<span style="color: #339933;">,</span> ende<span style="color: #339933;">,</span> zeit<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> schritte <span style="color: #339933;">=</span> Math.<span style="color: #660066;">abs</span><span style="color: #009900;">&#40;</span>anfang <span style="color: #339933;">-</span> ende<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>schritte <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> geschwindigkeit <span style="color: #339933;">=</span> Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>zeit <span style="color: #339933;">/</span> schritte<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;=</span> schritte<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>anfang <span style="color: #339933;">&gt;</span> ende<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> anfang <span style="color: #339933;">-</span> i<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #003366; font-weight: bold;">var</span> neu <span style="color: #339933;">=</span> anfang <span style="color: #339933;">+</span> i<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
		setTimeout<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;aendereDeckkraft('&quot;</span> <span style="color: #339933;">+</span> id <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;', &quot;</span> <span style="color: #339933;">+</span> neu <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;)&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">*</span> geschwindigkeit<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Der erste Parameter der Funktion gibt wieder die ID des HTML-Elements an, Parameter 2 und 3 den Start- und Endwert für die Deckkraft und der vierte Parameter legt fest wie lange es dauern soll die Deckkraft zu ändern (in Millisekunden).</p>
<h2>Verblassen, Sichtbar machen, Sichtbarkeit wechseln</h2>
<p>Um ein Element verblassen zu lassen kann diese Funktion verwendet werden.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> verblassen<span style="color: #009900;">&#40;</span>id<span style="color: #339933;">,</span> zeit<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> aktuell <span style="color: #339933;">=</span> aktuelleSichtbarkeit<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	aendereSichtbarkeit<span style="color: #009900;">&#40;</span>id<span style="color: #339933;">,</span> aktuell<span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> zeit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Die Funktion um ein Element wieder sichtbar zu machen ist ähnlich.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> sichtbarMachen<span style="color: #009900;">&#40;</span>id<span style="color: #339933;">,</span> zeit<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> aktuell <span style="color: #339933;">=</span> aktuelleSichtbarkeit<span style="color: #009900;">&#40;</span>id<span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	aendereSichtbarkeit<span style="color: #009900;">&#40;</span>id<span style="color: #339933;">,</span> aktuell<span style="color: #339933;">,</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> zeit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Wenn man die Deckkraft wechseln möchte (nicht voll sichtbare Elemente werden zu 100% sichtbar, sichtbare werden unsichtbar), kann man diese Funktion benutzen:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> wechseln<span style="color: #009900;">&#40;</span>id<span style="color: #339933;">,</span> zeit<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> aktuell <span style="color: #339933;">=</span> aktuelleSichtbarkeit<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>aktuell <span style="color: #339933;">==</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		aendereSichtbarkeit<span style="color: #009900;">&#40;</span>id<span style="color: #339933;">,</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> zeit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		aendereSichtbarkeit<span style="color: #009900;">&#40;</span>id<span style="color: #339933;">,</span> aktuell<span style="color: #339933;">,</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> zeit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Die aktuelle Deckkraft eines Elements herausfinden</h3>
<p>Will man herausfinden welche Deckkraft ein Element hat, kann diese Funktion benutzt werden.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> aktuelleSichtbarkeit<span style="color: #009900;">&#40;</span>id<span style="color: #339933;">,</span> vorgabe<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> vorgabe <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>vorgabe <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #CC0000;">100</span> <span style="color: #339933;">:</span> vorgabe<span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> aktuell <span style="color: #339933;">=</span> parseFloat<span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">opacity</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isNaN<span style="color: #009900;">&#40;</span>aktuell<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> aktuell <span style="color: #339933;">=</span> vorgabe <span style="color: #339933;">/</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
	aktuell <span style="color: #339933;">=</span> aktuell <span style="color: #339933;">*</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> aktuell<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Die Funktion überprüft allerdings nur die CSS-Eigenschaft opacity, wenn die Deckkraft vorher mit <code>aendereDeckkraft</code> geändert wurde funktioniert das immer, da die Funktion diese Eigenschaft verändert. Es gibt aber noch andere Möglichkeiten Elemente transparent/unsichtbar zu machen (<code>visibility</code>, oder proprietäre Eigenschaften wie <code>-moz-opacity</code>). Man sollte die Funktion also nur benutzen um die Deckkraft von Elementen abzufragen die mit den hier beschriebenen Funktionen geändert wurde. Wenn <code>opacity</code> keinen Wert hat wird, falls angegeben, der Wert des Parameters <code>vorgabe</code> zurückgegeben, ansonsten wird eine Deckkraft von 100% angenommen.</p>
<h2>Beispielseite</h2>
<p>Ich habe wieder eine Beispielseite eingerichtet auf der man die in diesem Artikel beschriebenen Effekte ausprobieren kann.</p>
<p style="padding-left:30px;">
<a href="http://antusblog.de/demos/2-elemente-ein-und-ausblenden/verblassen.html">Zur Beispielseite</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.antusblog.de/2009/04/28/elemente-ein-und-ausblenden/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Browser-Update.org &#8211; Benutzer über neue Browserversionen informieren</title>
		<link>http://www.antusblog.de/2009/04/05/browser-updateorg-benutzer-uber-neue-browserversionen-informieren/</link>
		<comments>http://www.antusblog.de/2009/04/05/browser-updateorg-benutzer-uber-neue-browserversionen-informieren/#comments</comments>
		<pubDate>Sun, 05 Apr 2009 21:05:06 +0000</pubDate>
		<dc:creator>Antu</dc:creator>
				<category><![CDATA[Webgestaltung]]></category>
		<category><![CDATA[Browser]]></category>
		<category><![CDATA[Browser-Update.org]]></category>
		<category><![CDATA[Java Script]]></category>
		<category><![CDATA[Sicherheit]]></category>
		<category><![CDATA[Sicherheitslücken]]></category>

		<guid isPermaLink="false">http://antusblog.de/?p=781</guid>
		<description><![CDATA[Viele Benutzer verwenden hoffnungslos veraltete Browser um im Internet zu surfen. Das ist sowohl für die Benutzer selbst als auch für Webdesigner von Nachteil. Neuere Browser sind komfortabler, schneller und vorallem sicherer. Denn veraltete, meist nicht mal mehr vom Hersteller unterstützte Browserversionen enthalten oft Sicherheitslücken und schützen den Benutzer nur mangelhaft vor Viren, Trojanern, Datendiebstahl [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://antusblog.de/wp-content/uploads/2009/04/hinweis.png"><img class="size-medium wp-image-783 alignright" title="Diesen Warnhinweis sehen Besucher die einen veralteten Browser benutzen." src="http://antusblog.de/wp-content/uploads/2009/04/hinweis-300x44.png" alt="Diesen Warnhinweis sehen Besucher die einen veralteten Browser benutzen." width="300" height="44" /></a>Viele Benutzer verwenden hoffnungslos veraltete Browser um im Internet zu surfen. Das ist sowohl für die Benutzer selbst als auch für Webdesigner von Nachteil. Neuere Browser sind <strong>komfortabler</strong>, <strong>schneller</strong> und vorallem <strong>sicherer</strong>. Denn veraltete, meist nicht mal mehr vom Hersteller unterstützte Browserversionen enthalten oft <strong>Sicherheitslücken</strong> und schützen den Benutzer nur mangelhaft vor <strong>Viren</strong>, <strong>Trojanern</strong>, <strong>Datendiebstahl</strong> und anderen <strong>Bedrohungen</strong>. Auch für Webdesigner ist das ein Problem, denn sie müssen Rücksicht auf solche veralteten Browser nehmen und die von ihnen erstellten Seiten extra an die Fehler dieser Browser anpassen. Viele neue Techniken können sie nicht verwenden weil ein großer Prozentsatz der Benutzer Browser benutzt die diese nicht unterstützen.</p>
<p>Doch viele Benutzer wissen gar nicht das ihr Browser veraltet ist bzw. das man den Browser überhaupt aktualisieren kann. <a href="http://browser-update.org/" target="_blank">Browser-Update.org</a> ist eine noch relativ <a href="http://browser-update.org/blog/?p=10" target="_blank">neue</a> Initiative mit dem Ziel genau das zu ändern.</p>
<p><span id="more-781"></span></p>
<h2>Browser-Update.org</h2>
<p>Die Seite bietet einen kleinen JavaScript-Quelltext an, den man in die eigene Webseite einbinden kann. Dieser überprüft die Browserversion des Benutzers, und falls er einen veralteten Browser verwendet bekommt er einen kleinen unaufdringlichen Warnhinweis zu sehen, der ihn auf die Nachteile eines veralteten Browsers und die Möglichkeit selbigen zu aktualisieren hinweist. Der Hinweis enthält einen Link auf eine Seite auf der sich eine Liste von Gründen für eine Aktualisierung sowie Hinweise und Links zu aktuellen Browsern findet.</p>
<p>Wenn der Benutzer den Hinweis ignoriert wird selbiger auch erstmal einige Zeit lang nicht mehr angezeigt, der Benutzer wird also nicht dauerhaft von dem Hinweis genervt. Es ist auch möglich einzustellen bei welchen Versionen der Besucher eine Warnung angezeigt bekommen soll, und bei welchen nicht.</p>
<h2>Fast 400 Seiten benutzen das Skript bereits</h2>
<p>Laut den <a href="http://browser-update.org/stat.html" target="_blank">Statistiken</a> von Browser-Update.org wird das Skript bereits von fast 400 Seiten verwendet und konnte bereits fast 500 Benutzer dazu überreden ihren Browser zu aktualisieren (wobei ich mich frage wie das gemessen wird).</p>
<p>Ich finde diese Initiative sinnvoll, deswegen läuft dieses Skript ab heute auch auf meinem Blog.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.antusblog.de/2009/04/05/browser-updateorg-benutzer-uber-neue-browserversionen-informieren/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

