<?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>Nicolas Kuttler &#187; JavaScript</title>
	<atom:link href="http://www.nicolaskuttler.de/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nicolaskuttler.de</link>
	<description>IT Dienstleistungen, Saarbrücken</description>
	<lastBuildDate>Sat, 12 Jun 2010 21:42:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Shortcodes, CSS und JS nur wenn nötig einbinden</title>
		<link>http://www.nicolaskuttler.de/2009/10/24/shortcodes-css-und-js-nur-wenn-notig-einbinden/</link>
		<comments>http://www.nicolaskuttler.de/2009/10/24/shortcodes-css-und-js-nur-wenn-notig-einbinden/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 10:05:48 +0000</pubDate>
		<dc:creator>nicolas</dc:creator>
				<category><![CDATA[Content Management]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.nicolaskuttler.de/?p=379</guid>
		<description><![CDATA[Vor kurzem wollte ich eine neue Funktionalität für mein Blog haben, und ich wollte dafür ein neues plugin hinzufügen. Also habe ich verschiedene getestet und bin auf etwas überraschendes gestoßen: zumindest eines der plugins, die ich mir angeschaut habe, wollte seine CSS-Datei und jquery auf jeder Seite meines Blogs laden. Nach einigen weiteren Tests wurde [...]]]></description>
			<content:encoded><![CDATA[<p>Vor kurzem wollte ich eine neue Funktionalität für mein Blog haben, und ich wollte dafür ein neues plugin hinzufügen. Also habe ich verschiedene getestet und bin auf etwas überraschendes gestoßen: zumindest eines der plugins, die ich mir angeschaut habe, wollte seine CSS-Datei <strong>und</strong> jquery auf jeder Seite meines Blogs laden. Nach einigen weiteren Tests wurde mir dann klar dass dieses Verhalten weit verbreitet ist.<span id="more-379"></span></p>
<p>Und das ist nicht gut so. Jquery ist durchaus klein, CSS Stile normalerweise auch. Aber das ist kein Grund sie jedem Besucher beim Aufruf irgend einer beliebigen Seite aufzuzwingen. Ein paar weitere Nachforschungen haben keine einfache Lösung ergeben, also habe ich meine eigene geschrieben.</p>
<p>Normalerweise bindet ein plugin seine Dateien über die <tt>wp_print_styles</tt> oder <tt>wp_print_scripts</tt> Aktionen ein:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'wp_print_styles'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'deinplugin_css_einbinden'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> deinplugin_css_einbinden<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$csslink</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Nimm statt dessen etwas wie folgendes:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'wp_print_styles'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'deinplugin_css_einbinden'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> deinplugin_css_einbinden<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Prüfen ob der shortcode im Inhalt der Seite vorkommt</span>
    <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$post</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">strstr</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_content</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'[deinshortcode]'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$csslink</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Das ist schon alles. Bitte fügt eure CSS- und JavaScript-Dateien nicht jeder Seite meines Blogs hinzu.</p>
<p><strong>Update</strong>: Dieser <a href="http://beerpla.net/2010/01/13/wordpress-plugin-development-how-to-include-css-and-javascript-conditionally-and-only-when-needed-by-the-posts/">exzellente Artikel</a> stellt eine verbesserte Lösung dieses Problems dar.</p>
<p><strong>Update 2</strong>: <a href="http://scribu.net/wordpress/optimal-script-loading.html">Die bisher beste Lösung um JavaScript zu laden</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nicolaskuttler.de/2009/10/24/shortcodes-css-und-js-nur-wenn-notig-einbinden/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML Formulare und onclick/onfocus Ereignisse</title>
		<link>http://www.nicolaskuttler.de/2009/08/26/html-formulare-und-onclickonfocus-ereignisse/</link>
		<comments>http://www.nicolaskuttler.de/2009/08/26/html-formulare-und-onclickonfocus-ereignisse/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 10:07:52 +0000</pubDate>
		<dc:creator>nicolas</dc:creator>
				<category><![CDATA[Technik]]></category>
		<category><![CDATA[Formular]]></category>
		<category><![CDATA[Formulare]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[onclick]]></category>
		<category><![CDATA[onfocus]]></category>

		<guid isPermaLink="false">http://www.nicolaskuttler.de/?p=3</guid>
		<description><![CDATA[Wenn man HTML Formulare auf eine Seite stellt kann es hilfreich sein, Eingabefelder in Voraus auszufüllen. Man kann seinen Besuchern so einen Hinweis darauf geben, welche Daten sie eingeben sollen. Dies sieht zum Beispiel hilfreich aus: &#60;form&#62; &#60;input onclick=&#34;this.value=''&#34; type=&#34;text&#34; value=&#34;Ihre E-Mail&#34; /&#62; &#60;/form&#62; Wenn der Benutzer das Feld anklickt sollte der Hinweis entfernt werden. [...]]]></description>
			<content:encoded><![CDATA[<p>Wenn man HTML Formulare auf eine Seite stellt kann es hilfreich sein, Eingabefelder in Voraus auszufüllen. Man kann seinen Besuchern so einen Hinweis darauf geben, welche Daten sie eingeben sollen.<span id="more-411"></span> Dies sieht zum Beispiel hilfreich aus:</p>
<form>
<input type="text" value="Ihre E-Mail" /></form>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span>&gt;</span>    
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;this.value=''&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Ihre E-Mail&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div>

<p>Wenn der Benutzer das Feld anklickt sollte der Hinweis entfernt werden. Dies kann mit mit dem <strong>onclick</strong> JavaScript Ereignis geschehen:</p>
<form>
<input onclick="this.value=''" type="text" value="Ihre E-Mail" /></form>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">onfocus</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;this.value=''&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Ihre E-Mail&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div>

<p>Unsere Besucher können die Eingabefelder aber auch anders erreichen. Die <tt>Tab</tt> Taste kann beispielsweise benutzt werden, um zwischen den Feldern zu navigieren. Daher ist das <strong>onfocus</strong> Ereignis besser für unsere Zwecke geeignet:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">onfocus</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;this.value=''&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Ihre E-Mail&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div>

<form>
<input onfocus="this.value=''" type="text" value="Ihre E-Mail" />
</form>
<p>Die scheint gut zu funktionieren. Es gibt aber immer noch ein Problem wenn der Besucher seine E-Mail Adresse eingibt, und dann etwas anderes auf unserer Seite liest. Klickt er das Feld dann noch einmal an verschwindet seine Vorherige Eingabe. Um dies zu verhindern überprüfen wir, ob sich der Inhalt des Textfelds geändert hat:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Ihre E-Mail&quot;</span> <span style="color: #000066;">onfocus</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;if (this.value == 'Ihre E-Mail')  {this.value=''}&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div>

<p>Hier das Beispiel:</p>
<form>
<input type="text" value="Ihre E-Mail" onfocus="if (this.value == 'Ihre E-Mail')  {this.value=''}" />
</form>
<a name="wptoc_0_0_0"></a><h2>Den Ausgangstext wiederherstellen wenn nichts eingegeben wurde</h2>
<p>Wunderbar, so weit funktioniert alles. Was passiert aber, wenn unser Besucher das Feld anklickt und dann nichts eingibt? Das Feld bleibt einfach leer. Wenn das Formular keine weiteren Beschreibungen hat kann der Benutzer vergessen haben, welche Informationen in das Feld sollen. Wir umgehen diesen Fall indem wir den ursprünglichen Wert wiederherstellen, wenn das Feld verlassen wird und nichts eingegeben wurde:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Ihre E-Mail&quot;</span> <span style="color: #000066;">onblur</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;if(this.value == '') { this.       value='Ihre E-Mail'}&quot;</span> <span style="color: #000066;">onfocus</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;if (this.value == 'Ihre E-Mail') {this.value=''}&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div>

<form>
<input type="text" value="Ihre E-Mail" onblur="if(this.value == '') { this.       value='Ihre E-Mail'}" onfocus="if (this.value == 'Ihre E-Mail') {this.value=''}" />
</form>
<a name="wptoc_0_0_1"></a><h2>Text beim anklicken auswählen</h2>
<p>Bei einigen Eingabefelder kann etwas anderes nützlich sein, beispielsweise den Text auszuwählen. Wenn wir dies tun kann der Besucher den Feldinhalt entweder löschen oder bearbeiten:</p>
<form>
<input onfocus="this.select()" type="text" value="Vorherige Suche" />
</form>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">onfocus</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;this.select()&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Vorherige Suche&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div>

<a name="wptoc_0_0_2"></a><h2>Dynamische Farben</h2>
<p>Dies ist ein etwas komplizierteres Thema. Nehmen wir an wir wollen den Hinweistext in einer anderen Farbe haben als die Eingabe des Benutzers. Hier ist ein Weg um dies zu erreichen:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;color: #f00&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Ihre E-Mail&quot;</span> <span style="color: #000066;">onblur</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;if(this.value  == '') { this.style.color='#f00'; this.value='Ihre E-Mail'}&quot;</span> <span style="color: #000066;">onfocus</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;if (this.value  == 'Ihre E-Mail') {this.style.color='#0f0'; this.value=''}&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div>

<form>
<input style="color: #f00" type="text" value="Ihre E-Mail" onblur="if(this.value  == '') { this.style.color='#f00'; this.value='Ihre E-Mail'}" onfocus="if (this.value  == 'Ihre E-Mail') {this.style.color='#0f0'; this.value=''}" />
</form>
<p>Hier muss man im Auge behalten, dass beim erneuten Laden der Seite Probleme auftreten können. Manche Browser werden vorher vom Benutzer eingegeben Werte automatisch wiederherstellen. Dann haben wir diese Werte jedoch in der falschen Farbe.<br />
Möchte man dies verhindern kann man zu <strong>onload</strong> oder ähnlichen JavaScript Ereignissen greifen.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nicolaskuttler.de/2009/08/26/html-formulare-und-onclickonfocus-ereignisse/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
