<?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>CodeBlog.ch &#187; JavaScript</title>
	<atom:link href="http://www.codeblog.ch/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codeblog.ch</link>
	<description>Coding and more - Concrete5, Flex, JavaScript</description>
	<lastBuildDate>Mon, 05 Dec 2011 16:10:29 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Schriften im Internet &#8211; Cufón</title>
		<link>http://www.codeblog.ch/de/2009/04/schriften-im-internet-cufon/</link>
		<comments>http://www.codeblog.ch/de/2009/04/schriften-im-internet-cufon/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 08:43:55 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=264</guid>
		<description><![CDATA[Schriften im Internet Schriften unter Internetseiten ist seit langem ein beliebtes Thema. Grafiker wollen logischerweise völlige Freiheiten, der Programmierer eine solide Lösung die keine Probleme verursacht. Oft interessiert es den Leser nicht in welcher Schrift etwas dargestellt wird, solange der Inhalt lesbar ist. Bei kleinen Seiten mit wenig Inhalt spielen Schriften jedoch schnell eine grössere [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Schriften im Internet</strong></p>
<p>Schriften unter Internetseiten ist seit langem ein beliebtes Thema. Grafiker wollen logischerweise völlige Freiheiten, der Programmierer eine solide Lösung die keine Probleme verursacht. Oft interessiert es den Leser nicht in welcher Schrift etwas dargestellt wird, solange der Inhalt lesbar ist. Bei kleinen Seiten mit wenig Inhalt spielen Schriften jedoch schnell eine grössere Rolle.</p>
<p>Wie kann man sowas umsetzen:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2009/04/font.png"><img src="http://www.codeblog.ch/wp-content/uploads/2009/04/font-300x264.png" alt="font" title="font" width="300" height="264" class="alignnone size-medium wp-image-265" /></a></p>
<p><span id="more-264"></span></p>
<p><strong>Eigene Schriften im Internet</strong></p>
<p>Mit EOT, sIFR und anderen Ansätzen gibt es schon länger Lösungen. Unschöne Darstellungen wenn die Seite noch nicht gelanden ist, fehlende Unterstützung von Seiten der Browser haben jedoch die meisten Lösungen eher unbrauchbar gemacht.</p>
<p>Mit Cufón gibt&#8217;s jedoch eine neue Lösung die sehr vielversprechend aussieht!</p>
<ul>
<li>Keine Plugins erforderlich</li>
<li>Unterstützung von zahlreichen Browsern</li>
<li>Einfach einzusetzen</li>
<li>Schnell</li>
</ul>
<p>Die Schriften werden im JavaScript Format abgespeichert. Damit man allerdings ein JavaScript File verwenden kann, muss es zuerst erstellt werden. Dazu kann ein simples Webinterface verwendet werden:</p>
<p><a href="http://cufon.shoqolate.com/generate/">http://cufon.shoqolate.com/generate/</a></p>
<p>Im Hintergrund werden einige Aktionen ausgeführt. Die Linux Applikation FontForge wird verwendet um eine SVG Schrift zu erstellen. Aus der SVG Datei werden VML Pfade generiert und daraus wird ein JSON String erstellt. Klingt umständlich, ist es auch, aber glücklicherweise müssen wir uns um fast nichts kümmern!</p>
<p>Wir wählen als unsere Schrift aus und erhalten eine JavaScript Datei als Download wenn wir das Formular abschicken.</p>
<p><strong>JavaScript Schrift einbinden</strong></p>
<p>Wir benötigen als erstes das Cufon Script. <a href="http://cufon.shoqolate.com/js/cufon-yui.js">Komprimiert </a> oder auch <a href="http://github.com/sorccu/cufon/tree/master/js/cufon.js">unkomprimiert</a>.</p>
<p>Als Ausgangslage haben wir eine simple HTML Datei:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Etiam vel odio&lt;/h1&gt;
Proin tristique elit eget nisl. Donec dictum mauris a sem. Pellentesque at arcu. Mauris cursus erat at magna adipiscing commodo. Integer ornare. Sed sollicitudin, est imperdiet hendrerit bibendum, erat turpis venenatis mauris, non ullamcorper quam arcu sit amet lacus. Nullam ut eros. Vivamus luctus urna rhoncus sem. Duis vel nibh.
&lt;h2&gt;Praesent lobortis&lt;/h2&gt;
Mauris ornare tincidunt arcu. Mauris pretium. Vestibulum ac metus in erat condimentum accumsan. Aenean dignissim consectetur risus. Maecenas purus. Duis eget mauris. Duis venenatis. Fusce tortor nunc, adipiscing id, gravida vel, ullamcorper ac, metus. Pellentesque suscipit. Suspendisse mollis augue eu mauris. Nulla facilisi. 
&nbsp;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>Wir wollen nun, dass H1 und H2 in unserer neu erstellten JavaScript Schrift dargestellt werden. Dazu kopieren wir die beiden JavaScripts in dasselbe Verzeichnis und ergänzen unsere HTML Datei so, dass wir folgendes Ergebnis erhalten:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
	&lt;script src=&quot;cufon-yui.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
	&lt;script src=&quot;Remo_Laubacher_400.font.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
		Cufon.replace('h1')('h2');
	&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Etiam vel odio&lt;/h1&gt;
Proin tristique elit eget nisl. Donec dictum mauris a sem. Pellentesque at arcu. Mauris cursus erat at magna adipiscing commodo. Integer ornare. Sed sollicitudin, est imperdiet hendrerit bibendum, erat turpis venenatis mauris, non ullamcorper quam arcu sit amet lacus. Nullam ut eros. Vivamus luctus urna rhoncus sem. Duis vel nibh.
&lt;h2&gt;Praesent lobortis&lt;/h2&gt;
Mauris ornare tincidunt arcu. Mauris pretium. Vestibulum ac metus in erat condimentum accumsan. Aenean dignissim consectetur risus. Maecenas purus. Duis eget mauris. Duis venenatis. Fusce tortor nunc, adipiscing id, gravida vel, ullamcorper ac, metus. Pellentesque suscipit. Suspendisse mollis augue eu mauris. Nulla facilisi. 
&nbsp;
&lt;script type=&quot;text/javascript&quot;&gt;Cufon.now();&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>Im Kopf die beiden JavaScripts einbinden, mit Cufon.replace die HTML Tags ersetzen und am Ende, vor dem </body> Tag Cufon.now() aufrufen um ein Darstellungsprobleme von Internet-Explorer zu beheben &#8211; fertig!</p>
<p>Sämtliche Files zum <a href='http://www.codeblog.ch/wp-content/uploads/2009/04/cufon-beispiel.zip'>Download</a>. Viel Spass!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/de/2009/04/schriften-im-internet-cufon/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WYSIWYG Editor mit Flex</title>
		<link>http://www.codeblog.ch/de/2008/10/wysiwyg-editor-mit-flex/</link>
		<comments>http://www.codeblog.ch/de/2008/10/wysiwyg-editor-mit-flex/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 08:04:09 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=72</guid>
		<description><![CDATA[Adobe liefert Flex mit einem RichTextEditor aus. Dieser lässt sich sehr einfach einbinden und passt vom Layout her auch wunderbar zu den restlichen Flex Controls.  Dieser Editor hat aber leider eine ziemlich begrenzte Funktionalität. Bereits beim Einfügen eines Bildes scheitern wir! Dazu kommt, dass der generierte Code nicht HTML konform ist, ein direktes verwenden in [...]]]></description>
			<content:encoded><![CDATA[<p>Adobe liefert Flex mit einem RichTextEditor aus. Dieser lässt sich sehr einfach einbinden und passt vom Layout her auch wunderbar zu den restlichen Flex Controls. </p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2008/10/richtexteditor.png"><img class="alignnone size-medium wp-image-73" title="richtexteditor" src="http://www.codeblog.ch/wp-content/uploads/2008/10/richtexteditor.png" alt="" width="334" height="308" /></a></p>
<p>Dieser Editor hat aber leider eine ziemlich begrenzte Funktionalität. Bereits beim Einfügen eines Bildes scheitern wir! Dazu kommt, dass der generierte Code nicht HTML konform ist, ein direktes verwenden in einer HTML Ausgabe ist deswegen zum Beispiel nicht möglich.</p>
<p><span id="more-72"></span></p>
<p><strong>Alternative Lösungsmöglichkeit</strong></p>
<p>Die einzige flash-basierte Lösung die ich finden konnte, ist diese hier: <a href="http://flashtexteditor.com/flexdemo/full/">http://flashtexteditor.com/flexdemo/full</a> Sieht auf den ersten Blick nett aus, eingefügte Bilder verhalten sich aber nicht wie gewohnt und fliessen mit dem Text mit und zudem ist dieses Control inzwischen nur noch kommerziell verfügbar. </p>
<p>Wer sich mit HTML und JavaScript beschäftigt hat, wird sicherlich den einen oder anderen WYSIWYG HTML Editor gefunden haben. Um nur ein paar zu nennen:</p>
<ul>
<li><a href="http://tinymce.moxiecode.com/">http://tinymce.moxiecode.com/</a></li>
<li><a href="http://www.fckeditor.net/">http://www.fckeditor.net/</a></li>
<li><a href="http://www.wymeditor.org/">http://www.wymeditor.org/</a></li>
</ul>
<p>Wäre es nicht schön, wir könnten diese Editoren in Flex verwenden? Können wir!</p>
<p><strong>Flex mit Adobe AIR vs. Flex im Browser</strong></p>
<p>Es gibt einen Unterschied in der Art wie wir unsere Flex Anwendung starten bzw. ausführen lassen.</p>
<p>Es besteht die Möglichkeit mittels NPRuntime den Browser einzubinden, der das Flash aufgerufen hat. Details dazu findet man zum Beispiel bei Adobe: <a href="http://livedocs.adobe.com/flex/gumbo/langref/flash/external/ExternalInterface.html">http://livedocs.adobe.com/flex/gumbo/langref/flash/external/ExternalInterface.html</a></p>
<p>Auf derselben Seite findet man auch den Hinweis, dass diese Funktionalität mit Adobe AIR nicht funktioniert.</p>
<p><em>Note:</em> Adobe AIR currently does not support the ExternalInterface class.</p>
<p>In diesem Artikel wird nur eine mögliche Lösung beim Einsatz von Adobe AIR präsentiert. Der Lösungsweg über ExternalInterface dürfte aber ähnlich verlaufen.</p>
<p><a href="http://osflash.org/projects/wrapper">http://osflash.org/projects/wrapper</a></p>
<p><strong>HTML Code einbinden</strong></p>
<p>Bei einem AIR Projekt, haben wir ein zusätzliches Control zu Verfügung: mx:HTML. Dieses lässt sich wie jedes andere Control in Flex mit MXML verwenden.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">HTML</span> id=<span style="color: #ff0000;">&quot;html&quot;</span> location=<span style="color: #ff0000;">&quot;http://www.codeblog.ch&quot;</span><span style="color: #66cc66;">/&gt;</span></pre></td></tr></table></div>

<p>Wir können damit auch lokale HTML Files einbinden. Wir installieren als erstes die aktuelle TinyMCE Version. http://tinymce.moxiecode.com/download.php</p>
<p>Wir kopieren anschliessend sämtliche Files in unser Flex Projekt und erhalten diese Struktur:<br />
<a href="http://www.codeblog.ch/wp-content/uploads/2008/10/struct.png"><img src="http://www.codeblog.ch/wp-content/uploads/2008/10/struct.png" alt="" title="struct" width="156" height="166" class="alignnone size-medium wp-image-78" /></a></p>
<p>editor.html ist nicht Teil von TinyMCE und TinyMCE.mxml ist unser Flex Control &#8211; mehr dazu später.</p>
<p><strong>Der HTML Code</strong></p>
<p>Wir könnten den ganzen HTML Code für den TinyMCE Aufruf in unserem Flex Code speichern, ich hab mich jedoch entschieden den Code in einer HTML Datei abzulegen. Der Code ist fast 1:1 aus dem TinyMCE Beispiel entnommen.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&nbsp;
&lt;style type=&quot;text/css&quot;&gt;
html, body {
	margin: 0px;
}
&lt;/style&gt;
&nbsp;
&lt;!-- TinyMCE --&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;jscripts/tiny_mce/tiny_mce.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
	tinyMCE.init({
		mode : &quot;textareas&quot;,
		theme : &quot;simple&quot;
	});
&lt;/script&gt;
&lt;!-- /TinyMCE --&gt;
&nbsp;
&lt;/head&gt;
&lt;body&gt;
	&lt;textarea id=&quot;elm&quot; name=&quot;elm&quot; rows=&quot;15&quot; cols=&quot;80&quot; style=&quot;width: 100%;&quot;&gt;&lt;/textarea&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>Ich habe versucht den Code in ein neues MXML Control zu packen. Gleich zu Beginn der vollständige Code &#8211; sind ja nur ein paar Zeilen:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">HTML</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> location=<span style="color: #ff0000;">&quot;tinymce/editor.html&quot;</span> initialize=<span style="color: #ff0000;">&quot;init()&quot;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> htmlComplete:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> localHtmlCode:<span style="color: #0066CC;">String</span> = <span style="color: #000000; font-weight: bold;">null</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>: <span style="color: #0066CC;">void</span>
	<span style="color: #66cc66;">&#123;</span>
		addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, onHTMLLoadComplete<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> htmlCode <span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// in case the html file hasn't been loaded yet, delay the call..</span>
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>htmlComplete<span style="color: #66cc66;">&#41;</span>
			setHtml<span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">else</span>
			localHtmlCode = value;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> htmlCode<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">this</span>.<span style="color: #006600;">htmlLoader</span>.<span style="color: #006600;">window</span>.<span style="color: #006600;">tinyMCE</span>.<span style="color: #006600;">triggerSave</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">return</span> <span style="color: #0066CC;">this</span>.<span style="color: #006600;">htmlLoader</span>.<span style="color: #006600;">window</span>.<span style="color: #006600;">elm1</span>.<span style="color: #006600;">value</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> setHtml<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>: <span style="color: #0066CC;">void</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">this</span>.<span style="color: #006600;">htmlLoader</span>.<span style="color: #006600;">window</span>.<span style="color: #006600;">tinyMCE</span>.<span style="color: #0066CC;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'elm'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">setContent</span><span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">this</span>.<span style="color: #006600;">htmlLoader</span>.<span style="color: #006600;">window</span>.<span style="color: #006600;">document</span>.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'elm'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">value</span> = value;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onHTMLLoadComplete<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
	<span style="color: #66cc66;">&#123;</span>
		htmlComplete = <span style="color: #000000; font-weight: bold;">true</span>;
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>localHtmlCode <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>
			callLater<span style="color: #66cc66;">&#40;</span>setHtml,<span style="color: #66cc66;">&#91;</span>localHtmlCode<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:HTML<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Als Basis für unser Control dient mx:HTML. Wir fügen lediglich die Eigenschaft htmlCode hinzu, um den Inhalt von TinyMCE zu ändern und auslesen.</p>
<p>Dazu müssen wir lediglich eine Methode mit dem Zusatz &#8220;get&#8221; ausstatten und eine mit &#8220;set&#8221;.</p>
<p>Nun hatte ich jedoch das Problem, dass TinyMCE noch nicht komplett geladen war, als ich versucht habe die Eigenschaft htmlCode zu verändern. Ich hab deswegen, eine noch nicht vollständig getestete, Lösung versucht umzusetzen &#8211; durch das abfangen des Events &#8220;COMPLETE&#8221;, wird uns mitgeteilt wann das HTML Control geladen ist, wurde die Eigenschaft htmlCode von vorher gesetzt (htmlComplete == false), so wird nachdem das Control geladen ist, der Code mittels callLater gesetzt. callLater sollte eigentlich schon selber erst ausgeführt werden, wenn das Control fertig geladen ist. In meinem Fall hat dies jedoch nicht gereicht. (bin für jeden Hinweis dankbar).</p>
<p>Alles speichern und schon haben wir im Flex Builder ein neues Control in der Rubrik &#8220;Custom&#8221; zur Verfügung. Per Drag&#8217;n'Drop einfügen, Projekt starten!<br />
<a href="http://www.codeblog.ch/wp-content/uploads/2008/10/tinymce.png"><img src="http://www.codeblog.ch/wp-content/uploads/2008/10/tinymce-475x145.png" alt="" title="tinymce" width="475" height="145" class="alignnone size-medium wp-image-86" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/de/2008/10/wysiwyg-editor-mit-flex/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Web Applikation mit Adobe AIR</title>
		<link>http://www.codeblog.ch/de/2008/09/web-applikation-mit-adobe-air/</link>
		<comments>http://www.codeblog.ch/de/2008/09/web-applikation-mit-adobe-air/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 09:06:14 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=44</guid>
		<description><![CDATA[Von Adobe gibt es seit einiger Zeit eine Technologie mit dem Namen AIR. Adobe AIR erlaubt es, Appliationen welche fürs Web entwickelt wurden, besser ins lokale Betriebssystem zu integrieren. Man hat Zugriff auf eine Reihe von Funktionen welche Webapplikationen normalerweise nicht haben (Zwischenablage, Dateisystem usw.) Die Applikation kann direkt aus dem Startmenü (bei Windows) geöffnet [...]]]></description>
			<content:encoded><![CDATA[<p>Von Adobe gibt es seit einiger Zeit eine Technologie mit dem Namen <a href="http://www.adobe.com/products/air/" target="_blank">AIR</a>. Adobe AIR erlaubt es, Appliationen welche fürs Web entwickelt wurden, besser ins lokale Betriebssystem zu integrieren.</p>
<ul>
<li>Man hat Zugriff auf eine Reihe von Funktionen welche Webapplikationen normalerweise nicht haben (Zwischenablage, Dateisystem usw.)</li>
<li>Die Applikation kann direkt aus dem Startmenü (bei Windows) geöffnet werden.</li>
</ul>
<div>Adobe AIR unterstützt dabei HTML + Javascript, AJAX Appliationen. Natürlich wird aber auch die hauseigene Technologie Flash und damit auch Flex unterstützt.</div>
<div></div>
<p><span id="more-44"></span></p>
<p>Bevor wir beginnen, muss zuerst das (frei verfügbare) AIR SDK installiert werden. Dazu von dieser Seite das entsprechende ZIP herunterladen und installieren. <a href="http://www.adobe.com/products/air/tools/sdk/">http://www.adobe.com/products/air/tools/sdk/<br />
</a></p>
<p><strong>HTML Applikation mit AIR starten</strong></p>
<p>Neben dem bekannten HTML und JavaScript Code brauchen wir für Adobe AIR lediglich eine simple XML Datei.</p>
</p>
<p>Wir erstellen eine Datei mit dem Namen hellocodeblog-app.xml</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;application</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://ns.adobe.com/air/application/1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>hellocodeblog.html.hellocodeblog<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0.1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filename<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>hellocodeblog<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filename<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;initialWindow<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;content<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>hellocodeblog.html<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/content<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;visible<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/visible<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;width<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>400<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/width<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;height<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>200<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/height<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/initialWindow<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Als nächstes brauchen wir wie gewohnt ein bisschen HTML Code. Damit wir die AIR Funktionalität komplett nutzen können, binden wir die Datei AIRAliases.js ein. In diesem Beispiel werden wir sie allerdings nicht verwenden.</p>
<p>Die Datei hellocodeblog.html enthält diesen Code</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Hello CodeBlog&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;h1&gt;Hello CodeBlog!&lt;/h1&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p><strong>Applikation starten</strong><br />
Unsere Applikation starten wir nun indem wir der Datei adl.bat aus dem AIR SDK unsere XML Datei übergeben:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2008/09/hellocodeblog.png"><img src="http://www.codeblog.ch/wp-content/uploads/2008/09/hellocodeblog-475x166.png" alt="" title="hellocodeblog" width="475" height="166" class="alignnone size-medium wp-image-45" /></a></p>
<p><strong>Applikation publizieren</strong></p>
<p>Wir können unsere Applikation mit AIR gleich verpacken so dass wir ohne das SDK die Applikation starten können.</p>
<p>Applikationen müssen zertifiziert werden. Wenn man bereits ein Zertifikat hat, natürlich dieses verwenden. In unserem Fall erstellen wir uns aber ein eigenes. Dazu brauchen wir das Tool adt welches sich ebenfalls im bin Verzeichnis des AIR SDKs befindet.</p>
<pre>
adt -certificate -cn SelfSigned 1024-RSA codeBlog.pfx ein-password
</pre>
<p>Anschliessend rufen wir das Tool adt mit anderen Parametern auf um unsere Files in eine AIR Datei zu packen. Diese kann anschliessend mit einem Doppelklick installiert werden.</p>
<pre>adt -package -storetype pkcs12 -keystore codeBlog.pfx HelloCodeBlog.air hellocodeblog-app.xml hellocodeblog.html</pre>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2008/09/install.png"><img src="http://www.codeblog.ch/wp-content/uploads/2008/09/install-475x370.png" alt="" title="install" width="475" height="370" class="alignnone size-medium wp-image-48" /></a></p>
<p>Anschliessend läuft unsere Applikation ohne das Konsolen Fenster und einem SDK Tool.</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2008/09/running.png"><img src="http://www.codeblog.ch/wp-content/uploads/2008/09/running.png" alt="" title="running" width="400" height="200" class="alignnone size-medium wp-image-49" /></a></p>
<p><strong>Weitere Informationen</strong></p>
<p>Von Adobe gibt es ein gut strukturierter Büchlein in Englisch welches in Kapitel 4 die Möglichkeiten beschreibt die AIR bietet. <a href="http://onair.adobe.com/files/AIRforJSDevPocketGuide.pdf">http://onair.adobe.com/files/AIRforJSDevPocketGuide.pdf</a></p>
<p><strong>Update 18. September 2008</strong></p>
<p>Scheint so als gäbe es einige Einschränkungen bei der Integration ins Betriebssystem. Die trivial wirkende Anforderung einen Prozess zu starten erweist sich als deutlich komplexer als erwartet. Bisher scheint dies lediglich über einen zusätzlichen &#8220;Proxy&#8221; machbar zu sein. <a href="http://www.mikechambers.com/blog/2008/01/17/commandproxy-net-air-integration-proof-of-concept/">http://www.mikechambers.com/blog/2008/01/17/commandproxy-net-air-integration-proof-of-concept/</a></p>
<p>Warten wir mal ab und schauen was Adobe vielleicht nachliefert. Einfache Web Applikationen vom Desktop aus starten ist ja nett, aber wirklich konkurrenzfähig mit klassischen Applikationen ist das in dieser Form sicherlich nicht. Keine direkte Nutzung von lokalen (nativen) Bibliotheken usw&#8230;</p>
<p><strong>Update 18. September 2008 &#8211; 2</strong></p>
<p>Es scheint auch ohne Zusatzsoftware zu gehen, allerdings auch nicht wirklich elegant. Dieser Code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> request <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> air.<span style="color: #660066;">URLRequest</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;file://c:/windows/notepad.exe&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
air.<span style="color: #660066;">navigateToURL</span><span style="color: #009900;">&#40;</span>request<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>scheint zu funktionieren, jedoch abhängig vom Standard Browser. URLRequest öffnet nämlich jeweils den Browser und abhängig vom Browser erhält man dann auch noch eine Warnung (als würde man einen Link im Internet anklicken). Hat man aber zum Beispiel Google&#8217;s Chrome installiert, so wird die Datei heruntergeladen, auch nicht wirklich optimal&#8230;</p>
<p><strong>Update 8. Oktober 2008</strong></p>
<p>Unter Windows kann man diese Erweiterung nutzen: <a href="http://aperture.fluorinefx.com/">http://aperture.fluorinefx.com/</a>. Damit kann man sehr einfach Prozesse starten, Screenshots erstellen und auf gewisse Outlook Daten zugreifen. Allerdings nur für Windows!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/de/2008/09/web-applikation-mit-adobe-air/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Link Klicks zählen</title>
		<link>http://www.codeblog.ch/de/2008/04/link-klicks-zahlen/</link>
		<comments>http://www.codeblog.ch/de/2008/04/link-klicks-zahlen/#comments</comments>
		<pubDate>Wed, 23 Apr 2008 08:36:38 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=17</guid>
		<description><![CDATA[Dies ist eine ganz banale Aufgabe, aber mir ist eine Unschönheit aufgefallen bei vielen Scripts die ich gefunden haben, deswegen ein ganz kleiner Artikel zu diesem Thema. Die Aufgabe ist relativ einfach &#8211; wir wollen die Anzahl Klicks auf einem Link zählen. Dazu gibt es viele Varianten und meistens sind die auch sinnvoller als meine.. [...]]]></description>
			<content:encoded><![CDATA[<p>Dies ist eine ganz banale Aufgabe, aber mir ist eine Unschönheit aufgefallen bei vielen Scripts die ich gefunden haben, deswegen ein ganz kleiner Artikel zu diesem Thema.</p>
<p>Die Aufgabe ist relativ einfach &#8211; wir wollen die Anzahl Klicks auf einem Link zählen. Dazu gibt es viele Varianten und meistens sind die auch sinnvoller als meine..</p>
<p><span id="more-17"></span></p>
<p>Zahlreiche Scripts die ich gefunden haben, manipulieren die Adresse die aufgerufen wird:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;http://localhost/linkcounter.php?link=http://www.link.com&quot;&gt;</pre></div></div>

<p>(Der Wert von link müsste noch entsprechend &#8220;angepasst&#8221; werden so dass alle Zeichen korrekt übergeben werden &#8211; php: urlencode, asp: Server.URLEncode usw.)</p>
<p>Nun hat dies zur Folge, dass in der Statuszeile eine unschöne Adresse steht. Wie löst man dies? Per JavaScript die Statuszeile anpassen &#8211; falsch! Früher hat die ganz gut funktioniert, inzwischen ist diese Funktion aber oft deaktiviert. <a href="http://de.selfhtml.org/javascript/objekte/window.htm#status">http://de.selfhtml.org/javascript/objekte/window.htm#status</a></p>
<p><strong>Wie es besser gemacht wird</strong></p>
<p>Wir belassen den Wert in &#8220;href&#8221; so wie er ist. Jedoch erweitern wir den link um einen kleinen JavaScript aufruf</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;http://www.codeblog.ch&quot; onmousedown=&quot;clickCounter(this)&quot;&gt;super blog&lt;/a&gt;</pre></div></div>

<p>Dann noch ein kleines JavaScript in den Header einfügen:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;JavaScript&quot;</span> <span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">function</span> clickCounter<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   obj.<span style="color: #660066;">href</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://localhost/linkcounter.php?link=&quot;</span> <span style="color: #339933;">+</span> escape<span style="color: #009900;">&#40;</span>obj.<span style="color: #660066;">href</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Dadurch wird die Zieladresse dynamisch bei jedem Klick verändert &#8211; google macht dies übrigens auch so, die Idee ist also alles andere als neu..</p>
<p>Vollständigkeitshalber hier noch ein simples PHP Script das die Links zählt. Für einen praktischen Einsatz aber wohl etwas zu einfach.</p>
<p>Ich habe als DB MySQL verwendet da dies einfach und schnell einzurichten ist. Tabelle &#8220;linkcounter&#8221; mit zwei Spalten erstellen (link,hits). Wichtig ist hier, dass &#8220;link&#8221; eindeutig ist (Primary Key).</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> linkcounter <span style="color: #66cc66;">&#40;</span>link <span style="color: #993333; font-weight: bold;">VARCHAR</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> hits <span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">&#40;</span>link<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Dann im PHP Script die Zugangsdaten anpassen und fertig!</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// we must have an item &quot;link&quot; in the url</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'link'</span><span style="color: #339933;">,</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// connect to database</span>
<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'server'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'user'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'database'</span><span style="color: #339933;">,</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// build query</span>
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'INSERT INTO linkcounter (link,hits) VALUES (\'%s\',1) ON DUPLICATE KEY UPDATE hits=hits+1;'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">,</span><span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// execute query and close db connection</span>
<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">,</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// redirect</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'location: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Zum Schluss sei noch ein kleiner Trick erwähnt. Das Insert Query hat eine kleine Erweiterung &#8220;ON DUPLICATE KEY&#8221;. Dies ist eine MySQL spezifische Anweisung die für diese Anwendung sehr nützlich ist. Dadurch müssen wir kein zweites Query absetzen für den Fall dass der Link bereits in der Datenbank steht. Es gibt schliesslich zwei Operationen: Neue Links einfügen (dies soll ja automatisch geschehen) und den Hit-Counter erhöhen.</p>
<p>Dank MySQL können wir dies mit einem Query tun!<br />
<a href="http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html">http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/de/2008/04/link-klicks-zahlen/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

