<?xml version="1.0" encoding="utf-8"?>
			
			<rss version="2.0">
			<channel>
			<title>SamSpeak - Javascript</title>
			<link>http://sam.curren.ws/index.cfm</link>
			<description>What I Gotta Say</description>
			<language>en-us</language>
			<pubDate>Thu, 09 Sep 2010 02:55:15-0700</pubDate>
			<lastBuildDate>Tue, 30 Jun 2009 09:19:00-0700</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>telegramsam@byu.edu</managingEditor>
			<webMaster>telegramsam@byu.edu</webMaster>
			
			<item>
				<title>Sam Rides 1000: Augmenting the Web</title>
				<link>http://sam.curren.ws/index.cfm/2009/6/30/Sam-Rides-1000-Augmenting-the-Web</link>
				<description>
				
				&lt;p&gt;In my previous two posts, I introduced my project and described data collection using my G1 and Google Spreadsheets. Today, I&apos;m going to show you how I used Kynetx Network Services to add my ride stats to my personal blog and to the Google homepage.&lt;/p&gt;

&lt;h2&gt;Dataset Conversion&lt;/h2&gt;

&lt;p&gt;Google Spreadsheets, where my stats are calculated, can publish data in a variety of formats. It cannot publish JSON data, so I use Yahoo&apos;s YQL to convert the data from CSV to json, with the following statement:&lt;/p&gt;
&lt;code&gt;
select * from csv where url=&apos;http://spreadsheets.google.com/pub?key=rxzHBMZyj1S-HVLy9lFEU7A&amp;single=true&amp;gid=1&amp;range=A12%3AC16&amp;output=csv&apos; and columns=&apos;period,miles,hours&apos; and period != &quot;&quot;
&lt;/code&gt;
&lt;p&gt;(See the &lt;a href=&quot;http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20csv%20where%20url%3D&apos;http%3A%2F%2Fspreadsheets.google.com%2Fpub%3Fkey%3DrxzHBMZyj1S-HVLy9lFEU7A%26single%3Dtrue%26gid%3D1%26range%3DA12%253AC16%26output%3Dcsv&apos;%20and%20columns%3D&apos;period%2Cmiles%2Chours&apos;%20and%20period%20!%3D%20%22%22&amp;format=json&amp;callback=&quot;&gt;raw JSON results&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;Building the App&lt;/h2&gt;

&lt;p&gt;I then build my Kynetx App in &lt;a href=&quot;http://appbuilder.kynetx.com&quot;&gt;AppBuilder&lt;/a&gt;, defining the following datasource in the Global block:&lt;/p&gt;

&lt;code&gt;
dataset ridestats &lt;- &quot;http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20csv%20where%20url%3D&apos;http%3A%2F%2Fspreadsheets.google.com%2Fpub%3Fkey%3DrxzHBMZyj1S-HVLy9lFEU7A%26single%3Dtrue%26gid%3D1%26range%3DA12%253AC16%26output%3Dcsv&apos;%20and%20columns%3D&apos;period%2Cmiles%2Chours&apos;%20and%20period%20!%3D%20%22%22&amp;format=json&amp;callback=&quot; cachable for 2 hours
&lt;/code&gt;

&lt;p&gt;Since I ride in the morning and the evening, I cache the dataset for 2 hours. This keeps the data fairly current, but still keeps the service fast.&lt;/p&gt;

&lt;h2&gt;Annotating My Blog&lt;/h2&gt;

&lt;p&gt;I have two rules, the first of which adds stats to my personal blog:&lt;/p&gt;
&lt;code&gt;
select using &quot;http://sam.curren.ws/&quot; setting ()

pre {
    daymiles = ridestats.pick(&quot;$..results.row[0].miles&quot;);
    weekmiles = ridestats.pick(&quot;$..results.row[1].miles&quot;);
    monthmiles = ridestats.pick(&quot;$..results.row[2].miles&quot;);
    totalmiles = ridestats.pick(&quot;$..results.row[3].miles&quot;);
milesmessage = &lt;&lt;
&lt;h2&gt;Sam is riding 1,000 miles. Progress:
#{(daymiles &gt; 0 ? daymiles + &quot; Today, &quot; : &quot;&quot;)}
#{(weekmiles &gt; 0 &amp;&amp; weekmiles != daymiles ? weekmiles + &quot; This Week, &quot; : &quot;&quot;)}
#{(monthmiles &gt; 0 ? monthmiles + &quot; This Month, &quot; : &quot;&quot;)}
#{totalmiles} Total.&lt;/h2&gt;
&gt;&gt;

}

replace_html(&quot;#logo h2&quot;, milesmessage);
&lt;/code&gt;

&lt;p&gt;I set the rule to fire on my blog&apos;s domain, and then use the pick() method to extract different totals from the json dataset declared in the Global block. I construct a message string that varies depending on the different stat values. Finally, I replace the text at the top of my blog page with the message.&lt;/p&gt;

&lt;p&gt;To run the Kynetx application on my blog, I plant Kynetx tags on my blog. This enables everyone to see the Kynetx Application with no installs or Action Cards. The html tags are available within AppBuilder, and I simply copied them into the template for my blog.&lt;/p&gt;

&lt;h2&gt;Annotating Google&apos;s Homepage&lt;/h2&gt;

&lt;p&gt;My second rule is activated by an Action Card installed on the user&apos;s computer (instructions for installing this are in my first post). My second rule is very similar to the first rule, with some minor difference in inserted HTML and appending the message to the existing site, instead of replacing anything on the page.&lt;/p&gt;

&lt;code&gt;
select using &quot;http://www.google.com/&quot; setting ()

pre {
    daymiles = ridestats.pick(&quot;$..results.row[0].miles&quot;);
    weekmiles = ridestats.pick(&quot;$..results.row[1].miles&quot;);
    monthmiles = ridestats.pick(&quot;$..results.row[2].miles&quot;);
    totalmiles = ridestats.pick(&quot;$..results.row[3].miles&quot;);
milesmessage = &lt;&lt;
&lt;h2&gt;Sam is riding 1,000 miles.&lt;/h2&gt;&lt;p&gt; Progress:
#{(daymiles &gt; 0 ? daymiles + &quot; Today, &quot; : &quot;&quot;)}
#{(weekmiles &gt; 0 &amp;&amp; weekmiles != daymiles ? weekmiles + &quot; This Week, &quot; : &quot;&quot;)}
#{(monthmiles &gt; 0 ? monthmiles + &quot; This Month, &quot; : &quot;&quot;)}
#{totalmiles} Total.&lt;/p&gt;
&gt;&gt;

}

append(&quot;#body&gt;center&quot;, milesmessage);
&lt;/code&gt;

&lt;p&gt;Activating Kynetx Rules with an Action Card also requires an update to the Dispatch block of the rule, adding this line:&lt;/p&gt;

&lt;code&gt;
domain &quot;www.google.com&quot;
&lt;/code&gt;

&lt;p&gt;I also generate the card inside AppBuilder, providing a custom image that I created using &lt;a href=&quot;http://pixlr.com&quot;&gt;Pixlr&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And there you have it. Sam rides 1000 miles, with automated stats provided by Android MyTracks, Google Spreadsheets, YQL, and Kynetx Network Services.&lt;/p&gt;

&lt;h2&gt;Shameless Plug&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;http://www.kynetx.com&quot;&gt;Kynetx&lt;/a&gt; is a cloud based automation engine, capable of doing the things I&apos;ve demonstrated and much, much more. If you&apos;d like to use Kynetx Network Services, &lt;a href=&quot;http://accounts.kynetx.com&quot;&gt;sign up for an account&lt;/a&gt;, and start using &lt;a href=&quot;http://appbuilder.kynetx.com&quot;&gt;AppBuilder&lt;/a&gt;. 
				</description>
				
				<category>Web-Applications</category>				
				
				<category>Javascript</category>				
				
				<category>Android</category>				
				
				<category>Development</category>				
				
				<category>Personal</category>				
				
				<category>Technology</category>				
				
				<pubDate>Tue, 30 Jun 2009 09:19:00-0700</pubDate>
				<guid>http://sam.curren.ws/index.cfm/2009/6/30/Sam-Rides-1000-Augmenting-the-Web</guid>
				
			</item>
			
			<item>
				<title>jEditable TinyMCE Plugin</title>
				<link>http://sam.curren.ws/index.cfm/2008/6/12/jEditable-TinyMCE-Plugin</link>
				<description>
				
				&lt;p&gt;Over the past view weeks, I&apos;ve been working with &lt;a href=&quot;http://www.appelsiini.net/&quot;&gt;Mika Tuupola&lt;/a&gt;, author of the &lt;a href=&quot;http://www.appelsiini.net/projects/jeditable&quot;&gt;jEditable&lt;/a&gt; &lt;a href=&quot;http://jquery.com/&quot;&gt;jQuery&lt;/a&gt; extension. jEditable makes edit in place forms easy, and is itself extensible, allowing the creation of custom edit types, such as a date picker.&lt;/p&gt;  &lt;p&gt;I&apos;ve been using &lt;a href=&quot;http://tinymce.moxiecode.com/&quot;&gt;TinyMCE&lt;/a&gt; as a richtext editor, and decided to create a custom edit type for jEditable that makes TinyMCE easy. Mike added a few additional customization hooks that enabled me to complete the plugin, and I&apos;ve included example code below. This example is not meant to be a full and complete explanation, so make sure you dig into the jEditable and TinyMCE documentation.&lt;/p&gt;  &lt;p&gt;A big thanks to Mike for his help. He has &lt;a href=&quot;http://www.appelsiini.net/2008/7/jeditable-and-tinymce&quot;&gt;released the updated jEditable code&lt;/a&gt; that contains some additional hooks needed by my example code below.&lt;/p&gt;
&lt;p&gt;First, I include the necessary javascript files for each library. Your specific versions or names may vary:&lt;/p&gt;
&lt;code&gt;
&lt;script src=&quot;/resource/tiny_mce/tiny_mce_src.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;/resource/jquery/jquery-1.2.3.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;/resource/jquery/jquery.jeditable.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;/code&gt;
&lt;p&gt;Then, I setup TinyMCE, and the TinyMCE jEditable plugin as well:&lt;/p&gt;
&lt;code&gt;
&lt;script type=&quot;text/javascript&quot;&gt;

$.fn.tinymce = function(options){
	return this.each(function(){ 
		tinyMCE.execCommand(&quot;mceAddControl&quot;, true, this.id);
	});
}

function initMCE(){
	tinyMCE.init({mode : &quot;none&quot;,
		theme : &quot;advanced&quot;,
		theme_advanced_toolbar_location : &quot;top&quot;,
		theme_advanced_toolbar_align : &quot;left&quot;,
		theme_advanced_statusbar_location : &quot;bottom&quot;,
		theme_advanced_buttons1 : &quot;bold,italic,underline,strikethrough,separator,bullist,numlist,undo,redo,link,unlink&quot;,
		theme_advanced_buttons2 : &quot;&quot;,
		theme_advanced_buttons3 : &quot;&quot;,
		theme_advanced_resizing : true});
}

initMCE();


$.editable.addInputType(&apos;mce&apos;, {
	element : function(settings, original) {
		var textarea = $(&apos;&lt;textarea id=&quot;&apos;+$(original).attr(&quot;id&quot;)+&apos;_mce&quot;/&gt;&apos;);
		if (settings.rows) {
			textarea.attr(&apos;rows&apos;, settings.rows);
		} else {
			textarea.height(settings.height);
		}
		if (settings.cols) {
			textarea.attr(&apos;cols&apos;, settings.cols);
		} else {
			textarea.width(settings.width);
		}
		$(this).append(textarea);
			return(textarea);
		},
	plugin : function(settings, original) {
		tinyMCE.execCommand(&quot;mceAddControl&quot;, true, $(original).attr(&quot;id&quot;)+&apos;_mce&apos;);
		},
	submit : function(settings, original) { 
		tinyMCE.triggerSave();
		tinyMCE.execCommand(&quot;mceRemoveControl&quot;, true, $(original).attr(&quot;id&quot;)+&apos;_mce&apos;);
		},
	reset : function(settings, original) {
		tinyMCE.execCommand(&quot;mceRemoveControl&quot;, true, $(original).attr(&quot;id&quot;)+&apos;_mce&apos;);
		original.reset(); 
	}
});
&lt;/script&gt;
&lt;/code&gt;
&lt;p&gt;This next block of code initializes TinyMCE, first as a regular jQuery plugin (not in place editable), and then as the jEditable enabled in place editor:

&lt;code&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(function(){
	$(&apos;#foo&apos;).tinymce();
	
	$(&quot;#bar&quot;).editable(function(value, settings){
		console.log(this, value, settings);
		return value;
	
	}, { 
		type      : &apos;mce&apos;,
		submit    : &apos;OK&apos;,
		indicator : &quot;Saving...&quot;,
		tooltip   : &apos;Click to edit...&apos;,
		width     : &apos;500px&apos;,
		height    : &apos;100px&apos;
	});
});

&lt;/script&gt;
&lt;/code&gt;
&lt;p&gt;In this example, both of the selected elements are HTML textareas. Clearly, your settings for jEditable and TinyMCE will change with your own needs, but this should get you started.&lt;/p&gt;
&lt;p&gt;Finally, a big thanks to Mike, for writing the jEditable plugin in the first place, and for being so supportive and patient in helping me write this TinyMCE plugin!&lt;/p&gt;
&lt;p&gt;Edited 24Jan09: Applied IE6 Fix as recommended by Rick in comments.&lt;/p&gt; 
				</description>
				
				<category>Web-Applications</category>				
				
				<category>Javascript</category>				
				
				<category>Development</category>				
				
				<category>ColdFusion</category>				
				
				<pubDate>Thu, 12 Jun 2008 13:25:00-0700</pubDate>
				<guid>http://sam.curren.ws/index.cfm/2008/6/12/jEditable-TinyMCE-Plugin</guid>
				
			</item>
			</channel></rss>