<?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>Orange Juice Liberation Front &#187; overview</title>
	<atom:link href="http://orangejuiceliberationfront.com/tag/overview/feed/" rel="self" type="application/rss+xml" />
	<link>http://orangejuiceliberationfront.com</link>
	<description>Uli&#039;s citrussy fresh thoughts on technical stuff</description>
	<lastBuildDate>Mon, 13 May 2013 20:59:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Custom Elements on WebKit Pages</title>
		<link>http://orangejuiceliberationfront.com/custom-elements-on-webkit-pages/</link>
		<comments>http://orangejuiceliberationfront.com/custom-elements-on-webkit-pages/#comments</comments>
		<pubDate>Sat, 12 Jul 2008 11:05:43 +0000</pubDate>
		<dc:creator>uliwitness</dc:creator>
				<category><![CDATA[Macintosh]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[html editor]]></category>
		<category><![CDATA[overview]]></category>
		<category><![CDATA[placeholder]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[webkit]]></category>

		<guid isPermaLink="false">http://blog.orangejuiceliberationfront.com/?p=86</guid>
		<description><![CDATA[Recently, I wanted to create a simple HTML editor. basically, I just wanted to WYSIWYG-edit styled text, and maybe insert a few images. But, of course there was one reason I could not use one of the existing HTML editors: I needed to be able to insert special placeholder items. Little boxes, that could be &#8230;  <a href="http://orangejuiceliberationfront.com/custom-elements-on-webkit-pages/">Continue reading</a>]]></description>
				<content:encoded><![CDATA[<p>Recently, I wanted to create a simple HTML editor. basically, I just wanted to WYSIWYG-edit styled text, and maybe insert a few images. But, of course there was one reason I could not use one of the existing HTML editors:</p>
<p>I needed to be able to insert special placeholder items. Little boxes, that could be double clicked for editing, and would otherwise just be part of the text like a regular character. In the final output, these would expand to special commands in a server-side scripting language, but I didn&#8217;t want to see them in the editor of course.</p>
<p>Luckily, after a bunch of code contributions and bug reports by <a href="http://karelia.com/" target="_blank">Karelia</a>, makers of <a href="http://karelia.com/" target="_blank">SandVox</a>, and then Mail.app using WebKit for editing styled e-mails, WebKit supports in-line editing. It is quite easy, actually: You just call <tt>[myWebView setEditable: YES]</tt> and give the <a href="http://developer.apple.com/documentation/Cocoa/Reference/WebKit/Classes/WebView_Class/Reference/Reference.html#//apple_ref/doc/uid/20001903" target="_blank">WebView</a> an empty HTML document. That is all you need to have a styled edit field from which you can get HTML and to which you can assign HTML.</p>
<p>Apple&#8217;s website also documents <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/DisplayWebContent/Tasks/SaveAndLoad.html#//apple_ref/doc/uid/TP40001472" target="_blank">how to load HTML into the WebView, and how to get it back out</a>. Loading is trivial using <tt>[[myWebView mainFrame] loadHTMLString: @"&lt;html&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;"]</tt>, and of course you can insert your HTML text in between these two tags. Writing them back out is slightly more complicated: What you do is get to the <tt>DOMDocument</tt> and then the <tt>documentElement</tt> from the <tt>mainFrame</tt>, then grab the element named <tt>@"body"</tt> out of that, and then you can typecast that to a <tt>DOMHTMLElement</tt> to obtain its <tt>innerHTML</tt>, which is a string containing the HTML for your styled text. If you want the full document and not just edit HTML fragments, you can simply take the document element&#8217;s <tt>outerHTML</tt>.</p>
<p>That was all straightforward so far, once I&#8217;d grown used to WebKit&#8217;s terminology. Now, how to manage the placeholders? Well, first, you will have to create a new <a href="http://developer.apple.com/documentation/InternetWeb/Conceptual/WebKit_PluginProgTopic/Tasks/WebKitPlugins.html">WebKit plug-in</a> project from the <em>Standard Apple plug-ins</em> category. This gives you a simple <tt>NSView</tt>, which you can associate with a MIME type by editing its <em>Info.plist</em>. Set up this project, so that it is built with your application project, and make sure you have a <em>Copy Files</em> build phase that copies it into a <em>PlugIns</em> folder in your application&#8217;s bundle.</p>
<p>You should now be able to <a href="http://developer.apple.com/documentation/InternetWeb/Conceptual/WebKit_PluginProgTopic/Concepts/AboutPlugins.html#//apple_ref/doc/uid/30001248-206518" target="_blank">specify an <tt>embed</tt> tag</a> in your HTML source code with the <tt>type</tt> attribute set to your plugin&#8217;s MIME type, and WebKit will automatically load your plug-in and place it in this spot. However, you will either have to manually specify <tt>width</tt> and <tt>height</tt> attributes on the <tt>embed</tt> tag, or your plug-in will have to calculate the sizes, and use the <tt>arguments</tt> dictionary it gets passed on creation to add to them to the <tt>embed</tt> tag in code by manipulating the DOM tree through the <tt>DOMElement</tt> in <tt>WebPlugInContainingElementKey</tt> in the <tt>arguments</tt> dictionary. Since this key already refers to our <tt>embed</tt> tag, this is as simple as using the <tt>-setAttribute:value:</tt> call on this object, and using <tt>+stringWithFormat:</tt> to convert our sizes into strings.</p>
<p>What I learned from this? Once you know that there is no way to load a plug-in directly from inside your application, it is fairly straightforward to add your own objects to a WebView. Sadly, you always only know that after&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://orangejuiceliberationfront.com/custom-elements-on-webkit-pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

 Served from: orangejuiceliberationfront.com @ 2013-05-19 20:58:33 by W3 Total Cache -->