<?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>Query7 &#187; javascript</title>
	<atom:link href="http://query7.com/category/javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://query7.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Fri, 09 Apr 2010 09:36:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Codemirror &#8211; javascript syntax highlighting</title>
		<link>http://query7.com/codemirror-javascript-syntax-highlighting</link>
		<comments>http://query7.com/codemirror-javascript-syntax-highlighting#comments</comments>
		<pubDate>Wed, 22 Jul 2009 21:05:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://query7.com/?p=512</guid>
		<description><![CDATA[<p><a href="http://marijn.haverbeke.nl/codemirror/">CodeMirror</a> is an on the fly syntax highlighting engine, written in Javascript. Like CodePress (the syntax highlighter used in the latest version of wordpress for editing plugins), it can highlight many different languages (PHP, JS, HTML, CSS to name a&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://marijn.haverbeke.nl/codemirror/">CodeMirror</a> is an on the fly syntax highlighting engine, written in Javascript. Like CodePress (the syntax highlighter used in the latest version of wordpress for editing plugins), it can highlight many different languages (PHP, JS, HTML, CSS to name a few). This tutorial will show you how to implement CodeMirror on your site, there is a great article written by the author of this library <a href="http://marijn.haverbeke.nl/codemirror/story.html">here</a> on how it works under the hood.</p>
<h3>Installation</h3>
<p>Download the latest version from the CodeMirror <a href="http://marijn.haverbeke.nl/codemirror/">website</a>. As of today, it is version 0.62. After you unzip it you will see 3 directories &#8211; <em>js</em>, <em>css</em> and <em>contrib</em>. <em>contrib</em> holds parsers that other people have written such as the lua, python and PHP. <em>css</em> holds the color schemes for syntax highlighting and <em>js</em> contains the necessary scripts for CodeMirror to run.</p>
<h3>Basic Usage</h3>
<p>If we have a textarea with an id of code that we wanted to turn into a CodeMirror editor with a MirrorFrame(more on this later) then we would use the code below. Note that we need to specify where the parserfiles and stylesheets for the particular type of syntax (in this case javascript) are located.</p>
<pre>
  var textarea = document.getElementById('code');
  var editor = new MirrorFrame(CodeMirror.replace(textarea), {
    height: "350px",
    content: textarea.value,
    parserfile: ["tokenizejavascript.js", "parsejavascript.js"],
    stylesheet: "css/jscolors.css",
    path: "js/",
    autoMatchParens: true
  });
</pre>
<p>The result would be:<br />
<img src="http://query7.com/wp-content/uploads/2009/07/default1.png" alt="default1" title="default1" width="565" height="367" class="alignnone size-full wp-image-517" /></p>
<h3>MirrorFrame</h3>
<p>The MirrorFrame class extends the syntax highlighter and makes the editor feel more of a true editor &#8211; with a toolbar/buttons. You can find the source of the MirrorFrame implementation in <em>js/mirrorframe.js</em>. As an example we&#8217;ll take the &#8216;get current line number&#8217; function. It references <em>this</em> which in our case is the current editor. There are alot of functions CodeMirror makes available (<a href="http://marijn.haverbeke.nl/codemirror/manual.html#programming">list here</a>), you can write your own functions and attach them to a button in your own MirrorFrame editor.</p>
<pre>
  line: function() {
    alert("The cursor is currently at line " + this.mirror.currentLine());
    this.mirror.focus();
  },
</pre>
<h3>CodeMirror</h3>
<p>We can pass many configuration options to the CodeMirror class when we instantiate it such as whether we want line numbering and the size of tab width. An example below:</p>
<pre>
editor = CodeMirror.fromTextArea(textarea, {
content: textarea.value,
parserfile: ["parser/tokenizejavascript.js", "parser/parsejavascript.js"],
stylesheet: "css/editor_colours/jscolours.css",
path: "js/",
autoMatchParens: true,
width: '100%',
height: '100%',
textWrapping: false,
lineNumbers: true,
tabMode: 'spaces',
iframeClass: 'ifc',
indentUnit: 4
});
</pre>
<p><img src="http://query7.com/wp-content/uploads/2009/07/custom.png" alt="custom" title="custom" width="435" height="321" class="alignnone size-full wp-image-528" /></p>
<p>There are also 2 events available for the developer to use. <em>onChange</em> and <em>initCallBack</em>. initCallBack is called when the editor has loaded and is ready for the user to start entering code (remember an iframe is created, additional javascript files are loaded). onChange occurs whenever a change is made in the editor itself. If we wanted to build an on-the-fly code tester, and needed to fetch the code from the editor whenever the code in the editor changed, then we would do the following:</p>
<pre>
  var editor = CodeMirror.fromTextArea(textarea, {
    height: "350px",
    content: textarea.value,
    parserfile: ["tokenizejavascript.js", "parsejavascript.js"],
    stylesheet: "css/jscolors.css",
    path: "js/",
    autoMatchParens: true,
    onChange: function (n) { alert(editor.getCode()); },
  });
</pre>
<p><img src="http://query7.com/wp-content/uploads/2009/07/alert1.png" alt="alert1" title="alert1" width="626" height="354" class="alignnone size-full wp-image-531" /></p>
<p>This was just a quick look at CodeMirror, but hopefully you can appreciate just how powerful it is. It could be used in your website&#8217;s admin interface to alter code on the fly, or be used in <a href="http://www.appcelerator.com/">Titanium</a> or <a href="http://www.adobe.com/products/air/">AIR</a> to create a desktop IDE in HTML/Javascript.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/codemirror-javascript-syntax-highlighting/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery AJAX Tutorial Pt2</title>
		<link>http://query7.com/jquery-ajax-tutorial-pt2</link>
		<comments>http://query7.com/jquery-ajax-tutorial-pt2#comments</comments>
		<pubDate>Tue, 13 May 2008 04:35:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.query7.com/?p=50</guid>
		<description><![CDATA[<p>Heres Part 2 of the jQuery AJAX login tutorial. If you haven&#8217;t already, i suggest you read part 1 located <a href="http://www.query7.com/jquery-ajax-login-series-pt1/">here</a>.</p>
<p>We are going to start writing the PHP code to process the form. This is fairly basic stuff,&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Heres Part 2 of the jQuery AJAX login tutorial. If you haven&#8217;t already, i suggest you read part 1 located <a href="http://www.query7.com/jquery-ajax-login-series-pt1/">here</a>.</p>
<p>We are going to start writing the PHP code to process the form. This is fairly basic stuff, using <em>$_POST</em> to get the values from the form, then checking them against pre-assigned values, if they match, then echo approved, if they don&#8217;t then echo denied.</p>
<pre lang="php"><?php

if($_POST['submit']){

$username = $_POST['username'];
$password = $_POST['password'];

// Here you would put your validation, checking existing database records.

if($username == panzer &#038;&#038; $password == query7){

echo 'Logged in';

//Insert your cookie setting code here

} else {

echo 'Denied';

}

} else {

echo "Form not submitted";

}
?></pre>
<p>So at the end of this stage, you will have an HTML form set up and this PHP file. You can enter the username Panzer and the password of query7 into the form and it will return Logged in.</p>
<p>Next tutorial, the fun part, the AJAX!</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/jquery-ajax-tutorial-pt2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AJAX Series Coming Soon!</title>
		<link>http://query7.com/ajax-series-coming-soon</link>
		<comments>http://query7.com/ajax-series-coming-soon#comments</comments>
		<pubDate>Fri, 09 May 2008 03:50:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.query7.com/?p=48</guid>
		<description><![CDATA[<p>Hey guys, just thought i&#8217;d post a little interim post (as such). Im in the process of making a 4 part tutorial series on using jQuery&#8217;s AJAX. Its a &#8220;case study&#8221; where i/we will make a basic login form with&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Hey guys, just thought i&#8217;d post a little interim post (as such). Im in the process of making a 4 part tutorial series on using jQuery&#8217;s AJAX. Its a &#8220;case study&#8221; where i/we will make a basic login form with a PHP backend and then use jQuery to make the login seemless. Eg. you put your username/password in the form and click the login button the page doesn&#8217;t reload but it will tell you whether its the correct user/pass , in which case a cookie is set, or if its bad info.</p>
<p>It might take a little while to finish up so i might not be posting much over the next week (sorry) but it will be worth it in the end.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/ajax-series-coming-soon/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
