<?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; jQuery</title>
	<atom:link href="http://query7.com/category/jquery/feed" rel="self" type="application/rss+xml" />
	<link>http://query7.com</link>
	<description>PHP, Javascript, Python and Web Development</description>
	<lastBuildDate>Sat, 25 Jun 2011 21:29:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</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 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');</pre><p>&#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>Dual form processing</title>
		<link>http://query7.com/dual-form-processing</link>
		<comments>http://query7.com/dual-form-processing#comments</comments>
		<pubDate>Tue, 14 Apr 2009 14:18:39 +0000</pubDate>
		<dc:creator>Kishore Nallan</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.webdevelopmentbits.com/?p=477</guid>
		<description><![CDATA[<p>Recently, a client of mine wanted a single web form, residing on the localhost to submit the form contents to a database in the localhost, and as well as to a web server simultaneously. Although this sounds like an unnecessary duplication of data, my client wanted some of the form data to be stored on the localhost for the intranet applications to use. Achieving this functionality <em>would have</em> been a piece of cake, if we were not handicapped by the unavailability of cross-domain AJAX. For those of us familiar with AJAX, we know that we cannot send an AJAX request to a remote server due to security reasons &#8211; atleast not in a reliable, hack-less way.</p>
<p>So, instead of looking for a pure AJAX solution, I decided to implement this functionality by using a combination of AJAX (for the localhost) and a traditional PHP POST request (for the web server). The trick here is to execute the AJAX call before the form is submitted &#8211; by catching the form submission event using JavaScript. Once the AJAX call is successful, we allow the default form submission to take place. In case there is an error with our AJAX call, we should&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Recently, a client of mine wanted a single web form, residing on the localhost to submit the form contents to a database in the localhost, and as well as to a web server simultaneously. Although this sounds like an unnecessary duplication of data, my client wanted some of the form data to be stored on the localhost for the intranet applications to use. Achieving this functionality <em>would have</em> been a piece of cake, if we were not handicapped by the unavailability of cross-domain AJAX. For those of us familiar with AJAX, we know that we cannot send an AJAX request to a remote server due to security reasons &#8211; atleast not in a reliable, hack-less way.</p>
<p>So, instead of looking for a pure AJAX solution, I decided to implement this functionality by using a combination of AJAX (for the localhost) and a traditional PHP POST request (for the web server). The trick here is to execute the AJAX call before the form is submitted &#8211; by catching the form submission event using JavaScript. Once the AJAX call is successful, we allow the default form submission to take place. In case there is an error with our AJAX call, we should stop the propogation of the traditional form submission too.</p>
<p>Ok, so let&#8217;s start off with a simple example &#8211; a no-frills form with a few fields.</p>
<pre>

&lt;form method="post" id="webform" action="http://www.example.com/path/to/PHPscript.php"&gt;

&lt;label for="firstname"&gt;first name:&lt;/label&gt;
&lt;input type="text" name="firstname" id="firstname" value="" /&gt;

&lt;label for="lastname"&gt;last name:&lt;/label&gt;
&lt;input type="text" name="lastname" id="lastname" value="" /&gt;

&lt;label for="email" id="l_email"&gt;email address:&lt;/label&gt;
&lt;input type="text" name="email" id="email" value="" /&gt;

&lt;input type="submit" name="Submit" id="submit_butt" value="Submit" /&gt;
&lt;input type="reset" /&gt;

&lt;/form&gt;
</pre>
<p>When the above form is submitted as it is, the form contents will be sent to the PHP script in the webserver. As I mentioned earlier, what we need to do now is &#8220;catch&#8221; this form submission event and insert our AJAX call before that. Let&#8217;s see how we can do that now. We will be using jQuery for our JavaScript needs.</p>
<pre>

$(document).ready(function(){
$("#webform").submit( function()
{
var success = -1;

$.post("localScript.php",
{
firstname: $("#firstname").val(),
lastname: $("#lastname").val(),
email: $("#email").val()
},

function(response){

if(response.status == "0")
success = false;
else
success = true;

}, "json");

var d = new Date();
var t = d.getSeconds();

while(success==-1)
{
var d = new Date();
if(d.getSeconds() - t &gt; 4)
{
success = false;
break;
}
}

return success;
});
});
</pre>
<p>We set-up an event handler using jQuery, which fires whenever the form is submitted. We then make an AJAX call to the localhost to submit the form contents. We have a callback function which checks the status of the AJAX call. In case, any error occurs on the localhost, an error code can be returned (in our case, the status value will be 0) and we have to stop the form submission by returning &#8220;false&#8221; from the event handler function. This will stop the default action of the submit button, i.e. it will prevent the HTTP form submission.</p>
<p>This is achieved using a hack. Since the script will not wait for the callback function to return, the next statement, i.e. the &#8220;return&#8221; statement will be executed immediately after the $.post() call is made to the server. However, we cannot return from the function without knowing whether the operation on the backend succeeded or not. Since, JavaScript does not natively have any sleep()-like function, we have to force our script to get into a blocked state using a while() loop. We then manually terminate the while loop if we did not hear back from the server within a &#8220;few&#8221; seconds. In our example we have defined the timeout to be 4 seconds. In case we don&#8217;t hear from the server within this time, we will terminate the form submission by returning a &#8220;false&#8221;. This elaborate hack is required to ensure that we do not proceed to the next stage without knowing what happened to the data we submitted to the localhost.</p>
<p>If everything goes well in the localhost, the contents of the form will be processed and stored in the localhost database by the PHP script we have called using AJAX. The submit event handler will then return &#8220;true&#8221;. This would in turn cause the form to be submitted to the PHP script on the remote server, as defined in the action attribute of the &lt;form&gt; tag. Once the form is submitted, the browser requests, and loads this PHP script. The PHP scripts recieves the form contents as POST variables and saves them (by perhaps, storing them in a database).</p>
<p>We are not done yet, though. We still have to send the user back to a page on the localhost once the PHP script has finished processing and storing the form contents. We do that by:</p>
<pre>
</pre>
<pre>$redirect_url = "http://localhost/path/to/some/page";
header( 'Location: ' . $redirect_url );
exit;</pre>
<p>It is important that the header() is called <em>before</em> any actual output is sent to the browser. For example, you should not have any echo statement, or raw HTML output before calling the header().</p>
<p>That&#8217;s about it! Now we are really done! In most cases, you will notice that this entire process is so slick that your user would hardly notice the redirection from the page on the webserver to the page on the localhost! I have put together a barebones HTML page containing the code fragments above, which you can download for your reference and use from <a href="http://labs.sourcebits.com/wdb/dual_form_processing_demo.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/dual-form-processing/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>No IE6 support on new W3C website?</title>
		<link>http://query7.com/no-ie6-support-on-new-w3c-website</link>
		<comments>http://query7.com/no-ie6-support-on-new-w3c-website#comments</comments>
		<pubDate>Fri, 27 Mar 2009 14:00:59 +0000</pubDate>
		<dc:creator>Dilip Shukla</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[IE6]]></category>
		<category><![CDATA[W3]]></category>
		<category><![CDATA[Web Standards]]></category>

		<guid isPermaLink="false">http://www.webdevelopmentbits.com/?p=445</guid>
		<description><![CDATA[<p><a title="World Wide Web Consortium" href="http://www.w3.org" target="_blank">W3.org</a> is overhauling its website in order to make it more user-friendly and quiet people who used to wonder (including me) why the administrator body of web have such dull, flat, unorganized and old fashioned website?</p>
<p>The new website looks more attractive and organized. 10 minutes tour of new website <a title="10 Minutes Tour of http://beta.w3.org/" href="http://dotsub.com/view/41e149bd-8b98-4103-a9f8-c96787497211" target="_blank">can be found here</a>. In contrast with the previous version, this new website uses rich content presentation, including JavaScript.</p>
<p>The website uses <a title="Download jQuery 1.3.2 from Google Code" href="http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.3.2.min.js" target="_blank">jQuery 1.3.2</a>, a very known and popular JavaScript library, instead of pure JavaScript. This is very good news and a big leap towards streamlining the use of JavaScript frameworks, specially in case of jQuery. In addition of core jQuery framework, <a title="Beta World Wide Web Consortium" href="http://beta.w3.org" target="_blank">beta.w3.org</a> also uses jQuery plugins (e.g.: <a title="jQuery Cycle Plugin" href="http://malsup.com/jquery/cycle/" target="_blank">http://malsup.com/jquery/cycle/</a>), to enhance the user experience.</p>
<p>The biggest news of the day is w3.org beta website doesn&#8217;t render correctly in IE6. It&#8217;s supposed to be a strong argument for web developers in order to inspire and take initiative towards to stop exclusive coding to render their websites correctly in IE6.</p>
<p style="text-align: center;"><img class="size-full wp-image-451 aligncenter" src="http://query7.com/wp-content/uploads/ie6.jpg" alt="" width="500" height="428" /></p>
]]></description>
			<content:encoded><![CDATA[<p><a title="World Wide Web Consortium" href="http://www.w3.org" target="_blank">W3.org</a> is overhauling its website in order to make it more user-friendly and quiet people who used to wonder (including me) why the administrator body of web have such dull, flat, unorganized and old fashioned website?</p>
<p>The new website looks more attractive and organized. 10 minutes tour of new website <a title="10 Minutes Tour of http://beta.w3.org/" href="http://dotsub.com/view/41e149bd-8b98-4103-a9f8-c96787497211" target="_blank">can be found here</a>. In contrast with the previous version, this new website uses rich content presentation, including JavaScript.</p>
<p>The website uses <a title="Download jQuery 1.3.2 from Google Code" href="http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.3.2.min.js" target="_blank">jQuery 1.3.2</a>, a very known and popular JavaScript library, instead of pure JavaScript. This is very good news and a big leap towards streamlining the use of JavaScript frameworks, specially in case of jQuery. In addition of core jQuery framework, <a title="Beta World Wide Web Consortium" href="http://beta.w3.org" target="_blank">beta.w3.org</a> also uses jQuery plugins (e.g.: <a title="jQuery Cycle Plugin" href="http://malsup.com/jquery/cycle/" target="_blank">http://malsup.com/jquery/cycle/</a>), to enhance the user experience.</p>
<p>The biggest news of the day is w3.org beta website doesn&#8217;t render correctly in IE6. It&#8217;s supposed to be a strong argument for web developers in order to inspire and take initiative towards to stop exclusive coding to render their websites correctly in IE6.</p>
<p style="text-align: center;"><img class="size-full wp-image-451 aligncenter" src="http://query7.com/wp-content/uploads/ie6.jpg" alt="" width="500" height="428" /></p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/no-ie6-support-on-new-w3c-website/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Other jQuery Uses</title>
		<link>http://query7.com/other-jquery-uses</link>
		<comments>http://query7.com/other-jquery-uses#comments</comments>
		<pubDate>Mon, 19 Jan 2009 20:32:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://query7.com/?p=332</guid>
		<description><![CDATA[<p>We traditionally think that jQuery&#8217;s selector engine can only select elements/information off of the document that we are working on. And AJAX&#8217;s only use is to process web forms without the page needing to reload. While both of these are common uses, they are not the only uses. In this tutorial I&#8217;m going to show you a not-so-mainstream use of jQuery, but a very useful one all the same.</p>
<p>Take this standard web page. It pulls the latest news items from a database and displays them like so. That is the basic DOM of the page.</p>
<pre>&#60;head&#62;
&#60;title&#62;Latest News&#60;/title&#62;
&#60;/head&#62;

&#60;body&#62;

# More Header, sidebar code here #

&#60;p class="latest"&#62;Employees at the Karate Bank are getting the chop&#60;/p&#62;
&#60;p class="latest"&#62;NASA shares have sky-rocketed&#60;/p&#62;
&#60;p class="latest"&#62;Investors at the Sushi Bank feel they are getting a raw deal&#60;/p&#62;

# More content, footer code here #

&#60;/body&#62;

&#60;/html&#62;
&#60;/pre&#62;</pre>
<p>If we wanted to highlight all of the news items on this page we can use jQuery&#8217;s each method to iterate through them and modify their CSS.</p>
<pre>$("p.latest").each(function(){

	$(this).css({"background-color" : "yellow"});

});</pre>
<p>But what if we wanted to pull that information from another page? Due to some restrictions in the software the website is&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>We traditionally think that jQuery&#8217;s selector engine can only select elements/information off of the document that we are working on. And AJAX&#8217;s only use is to process web forms without the page needing to reload. While both of these are common uses, they are not the only uses. In this tutorial I&#8217;m going to show you a not-so-mainstream use of jQuery, but a very useful one all the same.</p>
<p>Take this standard web page. It pulls the latest news items from a database and displays them like so. That is the basic DOM of the page.</p>
<pre>&lt;head&gt;
&lt;title&gt;Latest News&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

# More Header, sidebar code here #

&lt;p class="latest"&gt;Employees at the Karate Bank are getting the chop&lt;/p&gt;
&lt;p class="latest"&gt;NASA shares have sky-rocketed&lt;/p&gt;
&lt;p class="latest"&gt;Investors at the Sushi Bank feel they are getting a raw deal&lt;/p&gt;

# More content, footer code here #

&lt;/body&gt;

&lt;/html&gt;
&lt;/pre&gt;</pre>
<p>If we wanted to highlight all of the news items on this page we can use jQuery&#8217;s each method to iterate through them and modify their CSS.</p>
<pre>$("p.latest").each(function(){

	$(this).css({"background-color" : "yellow"});

});</pre>
<p>But what if we wanted to pull that information from another page? Due to some restrictions in the software the website is using, mayby they can&#8217;t display the latest posts on every page that they want to. To get this information we would need to do 2 things. The first is to pull the latest news page itselfand the second is to parse that page and only show the latest news (not the header, sidebar etc.)</p>
<h3>Ajax</h3>
<p>First of all we want to pull the page using AJAX and save it in a variable. To do this we use jQuery&#8217;s $.get method. We specify the page and since we are not sending any data (like information from a form) we don&#8217;t need to specify anything else. We then save the contents of latestnews.html into the variable content. This is important.</p>
<pre>$.get('http://urlto.com/latestnews.html' ,function(content) {

});</pre>
<h3>Narrowing Our Search</h3>
<p>At this stage we cannot simply document.write(content) as it contains all of the header, footer, sidebar and text in there. We need to select the latest news paragraphs that we want. For this we use jQuery&#8217;s standard selector. We don&#8217;t need to use a special plugin or write our own function. The only thing we need to change is to pass an extra parameter into the selector. This parameter tells jQuery&#8217;s selector engine where it look for the pattern/rule. If it isn&#8217;t specified (it usually isn&#8217;t in standard codes) then jQuery assumes you mean the current page&#8217;s source (DOM) however by specifying this we can narrow our search. In the code below we pass the content variable (which contains the entire source of latestnews.html) into the selector. jQuery will then look for all paragraphs with a class of latest inside the content variable.</p>
<pre>$.get('http://urlto.com/latestnews.html' ,function(content) {

$("p.latest", content).each(function(){

});

});</pre>
<h3>Displaying the data</h3>
<p>Since we have matched the URLs, we can display the content as we please.<br />
If we wanted to highlight the latest news paragraphs on that page then we would:</p>
<pre>$.get('http://urlto.com/latestnews.html' ,function(content) {

$("p.latest", content).each(function(){

$(this).appendTo("#latest");

});

});</pre>
<h3>More</h3>
<p>Using the information you&#8217;ve learnt, you can apply this to other situations. For example you can parse RSS feeds and reflect live updates of the RSS feed on the website straight away. These techniques are especially useful in remotely hosted software systems where you have no control over the source code. Or if PHP coding isn&#8217;t your strong point, but you know a little bit of jQuery, you can easily modify some of your website content this way.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/other-jquery-uses/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Increase Development Speed With jQuery</title>
		<link>http://query7.com/increase-development-speed-with-jquery</link>
		<comments>http://query7.com/increase-development-speed-with-jquery#comments</comments>
		<pubDate>Wed, 24 Dec 2008 06:23:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://query7.com/?p=299</guid>
		<description><![CDATA[<p>As we all know jQuery is a very small language. Not only is the file size of the jQuery library small, but the amount of code you need to write to achieve something is also very small. Because of this it is sometimes more efficient to write and test jQuery code in the browser than in a local file. To do this we need a couple of things.</p>
<ol>
<li>The Firebug Extension for Firefox</li>
<li>Greasemonkey</li>
</ol>
<p>If the page that we are going to manipulate doesn&#8217;t already include jQuery on it, then we can include it with this small Greasemonkey script. If jQuery is already included on the page, there is no use for this script.</p>
<pre><code>// Add jQuery
    var GM_JQ = document.createElement('script');
    GM_JQ.src = 'http://jquery.com/src/jquery-latest.js';
    GM_JQ.type = 'text/javascript';
    document.getElementsByTagName('head')[0].appendChild(GM_JQ);

// Check if jQuery's loaded
    function GM_wait() {
        if(typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(GM_wait,100); }
    else { $ = unsafeWindow.jQuery; letsJQuery(); }
    }
    GM_wait();

// All your GM code must be inside this function
    function letsJQuery() {
        alert($); // check if the dollar (jquery) function works

    }
</code></pre>
<p><a href="http://joanpiedra.com/jquery/greasemonkey/">Source</a><br />
With the jQuery library on the page we can now go ahead and start entering commands. For this example we&#8217;ll take&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>As we all know jQuery is a very small language. Not only is the file size of the jQuery library small, but the amount of code you need to write to achieve something is also very small. Because of this it is sometimes more efficient to write and test jQuery code in the browser than in a local file. To do this we need a couple of things.</p>
<ol>
<li>The Firebug Extension for Firefox</li>
<li>Greasemonkey</li>
</ol>
<p>If the page that we are going to manipulate doesn&#8217;t already include jQuery on it, then we can include it with this small Greasemonkey script. If jQuery is already included on the page, there is no use for this script.</p>
<pre><code>// Add jQuery
    var GM_JQ = document.createElement('script');
    GM_JQ.src = 'http://jquery.com/src/jquery-latest.js';
    GM_JQ.type = 'text/javascript';
    document.getElementsByTagName('head')[0].appendChild(GM_JQ);

// Check if jQuery's loaded
    function GM_wait() {
        if(typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(GM_wait,100); }
    else { $ = unsafeWindow.jQuery; letsJQuery(); }
    }
    GM_wait();

// All your GM code must be inside this function
    function letsJQuery() {
        alert($); // check if the dollar (jquery) function works

    }
</code></pre>
<p><a href="http://joanpiedra.com/jquery/greasemonkey/">Source</a><br />
With the jQuery library on the page we can now go ahead and start entering commands. For this example we&#8217;ll take jQuery.com, we can enter a basic jQuery Selector and see what happens.</p>
<p>before.png (http://img228.imageshack.us/img228/1918/beforeus0.png) Download, rehost, embed this image here.</p>
<p>after.png (http://img218.imageshack.us/img218/5812/aftercd6.png) Download, rehost, embed this image here.</p>
<p>As you can see it&#8217;s very easy to manipulate pages. You can use this to manipulate scripts that your working on. For example, if you were trying to nail down a certain selector, or find a 4th parent of something, its going to be alot easier and faster to do it in the Firebug terminal than editing, saving and refreshing the page while your trying to perfect it. With jQuery&#8217;s CSS capabilities, you can also test your CSS out live, without needing to switch back and forth between your editor and firefox.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/increase-development-speed-with-jquery/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP/jQuery Todo List Part 2</title>
		<link>http://query7.com/php-jquery-todo-list-part-2</link>
		<comments>http://query7.com/php-jquery-todo-list-part-2#comments</comments>
		<pubDate>Mon, 08 Dec 2008 04:24:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://query7.com/?p=280</guid>
		<description><![CDATA[<p>This is part 2 of a 2 part series on making a Todo List with PHP and enhancing it with jQuery&#8217;s AJAX</p>
<p>In part 1 of the tutorial, we covered the PHP and MySQL side of things. In this part we will be enhancing it with jQuery&#8217;s AJAX and manipulation functionality. The to-do list will degrade fine &#8211; if the user has Javascript disabled, the application will still work. All changes occur in the <strong>index.php</strong> file.</p>
<p>There are two parts to the script. One handles the posting of new posts, while the other handles posts being deleted. We&#8217;ll start with adding new posts.</p>
<pre>//When the button with an id of submit is clicked (the submit button)
$("#submit").click(function(){

//Retrieve the contents of the textarea (the content)
var formvalue = $("#content").val();

//Build the URL that we will send
var url = 'submit=1&#38;content=' + formvalue;

//Use jQuery's ajax function to send it
 $.ajax({
   type: "POST",
   url: "process.php",
   data: url,
   success: function(){

//If successful , notify the user that it was added
   $("ul").before("&#60;p class='new'&#62;You just added: &#60;i&#62;" + formvalue + "&#60;/i&#62;&#60;/p&#62;");

   }
 });

//We return false so when the button is clicked, it doesn't follow the action
return false;

});</pre>
<p>The <em>url</em> part confuses&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>This is part 2 of a 2 part series on making a Todo List with PHP and enhancing it with jQuery&#8217;s AJAX</p>
<p>In part 1 of the tutorial, we covered the PHP and MySQL side of things. In this part we will be enhancing it with jQuery&#8217;s AJAX and manipulation functionality. The to-do list will degrade fine &#8211; if the user has Javascript disabled, the application will still work. All changes occur in the <strong>index.php</strong> file.</p>
<p>There are two parts to the script. One handles the posting of new posts, while the other handles posts being deleted. We&#8217;ll start with adding new posts.</p>
<pre>//When the button with an id of submit is clicked (the submit button)
$("#submit").click(function(){

//Retrieve the contents of the textarea (the content)
var formvalue = $("#content").val();

//Build the URL that we will send
var url = 'submit=1&amp;content=' + formvalue;

//Use jQuery's ajax function to send it
 $.ajax({
   type: "POST",
   url: "process.php",
   data: url,
   success: function(){

//If successful , notify the user that it was added
   $("ul").before("&lt;p class='new'&gt;You just added: &lt;i&gt;" + formvalue + "&lt;/i&gt;&lt;/p&gt;");

   }
 });

//We return false so when the button is clicked, it doesn't follow the action
return false;

});</pre>
<p>The <em>url</em> part confuses some people. What we are doing is sending a request to the process page, we need to include some data with that request. In process.php there was the line</p>
<pre>if($_POST['submit']){</pre>
<p>It checks to see if $_POST['submit'] isn&#8217;t null (has a value). If it is null (has no value), then it means that the form hadn&#8217;t been submitted, by sending any value, in our case <em>submit=1</em>, we are telling process.php that the button had been clicked so it should run the rest of the PHP script. The rest of the PHP script calls for the content, which we also send in the url (<em>content= &#8216; + formvalue</em>). Instead of sending anything, we only want to send the value of the form (The stuff inside the textarea &#8211; that the user wants to submit). By returning false at the end, it prevents the submit button from carrying through with its <em>action=&#8221;process.php&#8221;</em>. If it did, it means the page would refresh when the information was sent which is exactly what we don&#8217;t want.</p>
<p>The code that handles the deletion of posts is similar.</p>
<pre>//Check to see if an anchor link was clicked (The delete link)
$("a").click(function(){

//Save the link in a variable called element
var element = $(this);

//Find the id of the link that was clicked
var noteid = element.attr("id");

//Built a url to send
var info = 'id=' + noteid;

 $.ajax({
   type: "GET",
   url: "delete.php",
   data: info,
   success: function(){
   element.parent().eq(0).fadeOut("slow");
   }
 });

//We return false so the browser doesn't actually follow the link
return false;

});</pre>
<p>When we were displaying the posts in <strong>process.php</strong> we echo&#8217;d the id of the post in the anchor tag. We are then getting this id <em>element.attr(&#8220;id&#8221;)</em> and building the URL. So when the AJAX call is sent, it will be something like <em>delete.php?id=POSTID. </em>If the AJAX call is successful, then we need to hide the list item.</p>
<pre>element.parent().eq(0).fadeOut("slow");</pre>
<p>In that bit of code, we select the element (anchor tag) that was clicked. We then find it&#8217;s parents and take the first one using <em>eq(0)</em>. It&#8217;s &#8216;first&#8217; parent is the list item its in (&lt;li&gt;&lt;a href&gt;&lt;/a&gt;&lt;/li&gt;) and we fade that out slowly.</p>
<p>Demo: <a href="http://query7.com/demos/php-jquery-todolist/" target="_blank">http://query7.com/demos/php-jquery-todolist/</a></p>
<p>Download: <a href="http://query7.com/wp-content/uploads/php-jquery-todolist.zip" target="_blank">http://query7.com/wp-content/uploads/php-jquery-todolist.zip</a></p>
<p>You can read the first part of the series at <a href="http://query7.com/php-jquery-todo-list-part-1/">PHP + jQuery Todo List Part 1</a></p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/php-jquery-todo-list-part-2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP + jQuery Todo List Part 1</title>
		<link>http://query7.com/php-jquery-todo-list-part-1</link>
		<comments>http://query7.com/php-jquery-todo-list-part-1#comments</comments>
		<pubDate>Wed, 03 Dec 2008 15:54:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://query7.com/?p=270</guid>
		<description><![CDATA[<p>This is part 1 of a 2 part series on making a Todo List with PHP and enhancing it with jQuery&#8217;s AJAX</p>
<p>In this two part series I&#8217;m going to show you how to make a simple to-do list in PHP, and then enhance it using jQuery&#8217;s AJAX and manipulation capabilities. This won&#8217;t follow any proper coding principles, but will give you the skills to adapt the code to fit your own situations. A todo list isn&#8217;t that far away from a simple threaded forum.</p>
<p>It will consist of a few files.</p>
<ul>
<li>delete.php &#8211; delete the note.</li>
<li>process.php &#8211; create the note, display the notes.</li>
<li>index.html &#8211; form, javascript</li>
</ul>
<p>We will be storing the list items in a MySQL database. The query:</p>
<pre>CREATE TABLE `notes`
(
`id` INT PRIMARY KEY AUTO INCREMENT NOT NULL,
`content` VARCHAR(500) NOT NULL
)</pre>
<p><strong>index.php</strong> will only contain the form (for now). It&#8217;s a fairly basic form, it contains a textarea (where the user enters their note) and a button they hit to submit it. The information is sent to a file called process.php through the post method.</p>
<pre>&#60;form id="form" action="process.php" method="post"&#62;
&#60;textarea name="content" id="content" cols="50" rows="3"&#62;&#60;/textarea&#62;
&#60;input type="submit" id="submit" name="submit" value="Post it"</pre><p>&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>This is part 1 of a 2 part series on making a Todo List with PHP and enhancing it with jQuery&#8217;s AJAX</p>
<p>In this two part series I&#8217;m going to show you how to make a simple to-do list in PHP, and then enhance it using jQuery&#8217;s AJAX and manipulation capabilities. This won&#8217;t follow any proper coding principles, but will give you the skills to adapt the code to fit your own situations. A todo list isn&#8217;t that far away from a simple threaded forum.</p>
<p>It will consist of a few files.</p>
<ul>
<li>delete.php &#8211; delete the note.</li>
<li>process.php &#8211; create the note, display the notes.</li>
<li>index.html &#8211; form, javascript</li>
</ul>
<p>We will be storing the list items in a MySQL database. The query:</p>
<pre>CREATE TABLE `notes`
(
`id` INT PRIMARY KEY AUTO INCREMENT NOT NULL,
`content` VARCHAR(500) NOT NULL
)</pre>
<p><strong>index.php</strong> will only contain the form (for now). It&#8217;s a fairly basic form, it contains a textarea (where the user enters their note) and a button they hit to submit it. The information is sent to a file called process.php through the post method.</p>
<pre>&lt;form id="form" action="process.php" method="post"&gt;
&lt;textarea name="content" id="content" cols="50" rows="3"&gt;&lt;/textarea&gt;
&lt;input type="submit" id="submit" name="submit" value="Post it" /&gt;
&lt;/form&gt;</pre>
<p><strong>process.php</strong> then handles the information that was sent from the form. We only need to insert the content into the database because the <em>id</em> field auto_increments itself. We display the to-do list in a nice and tidy list. We also provide a link after the post to delete it.</p>
<pre>&lt;?php
//Connect to the database
$connection = mysql_connect('host (usually localhost)', 'mysql_username' , 'mysql_password');
$selection = mysql_select_db('mysql_database', $connection);

//Was the form submitted?
if($_POST['submit']){

//Map the content that was sent by the form a variable. Not necessary but it keeps things tidy.
$content = $_POST['content'];

//Insert the content into database
$ins = mysql_query("INSERT INTO `notes` (content) VALUES ('$content')");

//Redirect the user back to the index page
header("Location:index.php");
}

/*Doesn't matter if the form has been posted or not, show the latest posts*/

//Find all the notes in the database and order them in a descending order (latest post first).
$find = mysql_query("SELECT * FROM `notes` ORDER BY id DESC");

//Setup the un-ordered list
echo '&lt;ul&gt;';

//Continue looping through all of them
while($row = mysql_fetch_array($find)){

//For each one, echo a list item giving a link to the delete page with it's id.
echo '&lt;li&gt;' . $row['content'] . ' &lt;a id="' . $row['id'] . '" href="delete.php?id=' . $row['id'] . '"&gt;&lt;img src="cancel.png" alt="Delete?" /&gt;&lt;/a&gt;&lt;/li&gt;';

}

//End the un-ordered list
echo '&lt;/ul&gt;';

?&gt;</pre>
<p><strong>delete.php</strong> does nothing more than delete the post. It uses the id parameter its provided to find the post entry in the database. Once it&#8217;s found, it&#8217;s deleted.</p>
<pre>&lt;?php

//Connect to the database
$connection = mysql_connect('host (usually localhost)', 'mysql_username' , 'mysql_password');
$selection = mysql_select_db('mysql_database', $connection);

//delete.php?id=IdOfPost
if($_GET['id']){

$id = $_GET['id'];

//Delete the record of the post
$delete = mysql_query("DELETE FROM `notes` WHERE `id` = '$id'");

//Redirect the user
header("Location:index.php");

}

?&gt;</pre>
<p>All of this produces a tidy to-do system. The source, stylesheet and images will be provided in a .zip file at the end of Part 2 of this tutorial.</p>
<p>You can read the second part of the series at <a href="http://query7.com/php-jquery-todo-list-part-2/">PHP/jQuery Todo List Part 2</a></p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/php-jquery-todo-list-part-1/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery In Action</title>
		<link>http://query7.com/jquery-in-action</link>
		<comments>http://query7.com/jquery-in-action#comments</comments>
		<pubDate>Thu, 20 Nov 2008 10:30:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.query7.com/?p=129</guid>
		<description><![CDATA[<p>In an attempt to sharpen up my jQuery, i purchased the book <a href="http://www.amazon.com/gp/product/1933988355?ie=UTF8&#38;tag=query7com-20&#38;linkCode=as2&#38;camp=1789&#38;creative=9325&#38;creativeASIN=1933988355">jQuery in Action</a><img style="border:none !important; margin:0px !important;" src="http://www.assoc-amazon.com/e/ir?t=query7com-20&#38;l=as2&#38;o=1&#38;a=1933988355" border="0" alt="" width="1" height="1" /> by Bear Bibeault and Yehuda Katz. Reading through the book, i could see that the first few chapters were obviously aimed at beginners. They covered selectors (If you know CSS already your fine) and events. You can easily get this information off the jQuery doc site, nothing spectacular there. Chapter 5 covers the effects, slides and fades but goes into depth abit more on the animate function. Something (in my opinion) which is under documented on the jQuery doc site. It shows off a few different examples.</p>
<p>Chapter 7 is another excellent chapter &#8211; showing you how to write your own plugins. It goes into alot of detail, from extending the wrapper to proper naming conventions to looping through each element effected. This chapter is a must read for anyone considering writing their own jQuery plugins. Again, the authors have written 3 example plugins providing alot of reference material.</p>
]]></description>
			<content:encoded><![CDATA[<p>In an attempt to sharpen up my jQuery, i purchased the book <a href="http://www.amazon.com/gp/product/1933988355?ie=UTF8&amp;tag=query7com-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1933988355">jQuery in Action</a><img style="border:none !important; margin:0px !important;" src="http://www.assoc-amazon.com/e/ir?t=query7com-20&amp;l=as2&amp;o=1&amp;a=1933988355" border="0" alt="" width="1" height="1" /> by Bear Bibeault and Yehuda Katz. Reading through the book, i could see that the first few chapters were obviously aimed at beginners. They covered selectors (If you know CSS already your fine) and events. You can easily get this information off the jQuery doc site, nothing spectacular there. Chapter 5 covers the effects, slides and fades but goes into depth abit more on the animate function. Something (in my opinion) which is under documented on the jQuery doc site. It shows off a few different examples.</p>
<p>Chapter 7 is another excellent chapter &#8211; showing you how to write your own plugins. It goes into alot of detail, from extending the wrapper to proper naming conventions to looping through each element effected. This chapter is a must read for anyone considering writing their own jQuery plugins. Again, the authors have written 3 example plugins providing alot of reference material.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/jquery-in-action/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More jQuery Effects</title>
		<link>http://query7.com/more-jquery-effects</link>
		<comments>http://query7.com/more-jquery-effects#comments</comments>
		<pubDate>Thu, 20 Nov 2008 10:27:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.query7.com/?p=58</guid>
		<description><![CDATA[<p>With the arrival of jQuery UI 1.5 i was browsing its&#8217; wiki pages and learning all of the API. I came across the jQuery UI wiki page, its essentially more jQuery effects except these ones are alot more dynamic! You can explode, puff, slide, highlight and alot more. I was a amazed that i hadn&#8217;t seen this page or been linked to it before, its something the jQuery UI team should be proud of.</p>
<p><a href="http://docs.jquery.com/UI/Effects">Check it out</a></p>
]]></description>
			<content:encoded><![CDATA[<p>With the arrival of jQuery UI 1.5 i was browsing its&#8217; wiki pages and learning all of the API. I came across the jQuery UI wiki page, its essentially more jQuery effects except these ones are alot more dynamic! You can explode, puff, slide, highlight and alot more. I was a amazed that i hadn&#8217;t seen this page or been linked to it before, its something the jQuery UI team should be proud of.</p>
<p><a href="http://docs.jquery.com/UI/Effects">Check it out</a></p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/more-jquery-effects/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery UI</title>
		<link>http://query7.com/jquery-ui</link>
		<comments>http://query7.com/jquery-ui#comments</comments>
		<pubDate>Thu, 20 Nov 2008 10:26:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.query7.com/?p=55</guid>
		<description><![CDATA[<p>For those of you with no jQuery background what-so-ever, jQuery UI is a series of user interface (UI) enhancements made in Javascript. These range from tabs (which also support ajax loading), to dialog boxes which you can drag, drop and resize. All cross browser! Although its currently still under development the finish line is in sight for the 1.5 release. I encourage everyone to check it out, it can add some really professional effects to your website for minimal lines of code.</p>
]]></description>
			<content:encoded><![CDATA[<p>For those of you with no jQuery background what-so-ever, jQuery UI is a series of user interface (UI) enhancements made in Javascript. These range from tabs (which also support ajax loading), to dialog boxes which you can drag, drop and resize. All cross browser! Although its currently still under development the finish line is in sight for the 1.5 release. I encourage everyone to check it out, it can add some really professional effects to your website for minimal lines of code.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/jquery-ui/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

