<?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>Vesica Blog &#187; jquery</title>
	<atom:link href="/blog/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>https://vesica.ws/blog</link>
	<description>- Taking museum and art collections to the cloud</description>
	<lastBuildDate>Wed, 05 Jun 2013 16:08:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Simplifying JQuery Dialogs</title>
		<link>https://vesica.ws/blog/2013/03/simplifying-jquery-dialogs/</link>
		<comments>https://vesica.ws/blog/2013/03/simplifying-jquery-dialogs/#comments</comments>
		<pubDate>Sat, 23 Mar 2013 00:08:32 +0000</pubDate>
		<dc:creator>Asif N</dc:creator>
				<category><![CDATA[Tech Talk]]></category>
		<category><![CDATA[art collection software]]></category>
		<category><![CDATA[dialogs]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery ui]]></category>
		<category><![CDATA[museum software]]></category>
		<category><![CDATA[vesica]]></category>
		<category><![CDATA[web apps]]></category>

		<guid isPermaLink="false">https://vesica.ws/blog/?p=549</guid>
		<description><![CDATA[Working on a web application that uses multiple JQuery dialogs? You&#8217;re probably sick of rendering dialog boxes with JQuery&#8217;s .dialog() function and all of its parameters. So here&#8217;s a tiny little function that you can include in your AJAX application at the top level via a &#60;script&#62;&#60;/script&#62; tag, and then simply call each time you [...]]]></description>
			<content:encoded><![CDATA[<p>Working on a web application that uses multiple JQuery dialogs?</p>
<p>You&#8217;re probably sick of rendering dialog boxes with JQuery&#8217;s .dialog() function and all of its parameters.</p>
<p>So here&#8217;s a tiny little function that you can include in your AJAX application at the top level via a &lt;script&gt;&lt;/script&gt; tag, and then simply call each time you need to render a dialog. So you can effectively accomplish what you need to do in one line instead of 10.</p>
<p>The function below requires multiple parameters:</p>
<ol>
<li>target_class &#8211; This is the name of the class you want the dialog rendered in. It doesn&#8217;t have to exist in the DOM, the function will create it.</li>
<li>title &#8211; The title of your dialog</li>
<li>width &#8211; The width of the dialog</li>
<li>height &#8211; the height of the dialog</li>
<li>load_file &#8211; An external file or view that you want to load inside your dialog</li>
<li>buttons &#8211; A JavaScript array containing all the buttons your dialog needs. This array should contain a button id and button text, and can be formatted as:<br />
buttons[0]['id'] = &#8216;save&#8217; ;<br />
buttons[0]['id'] = &#8216;Save this Content&#8217; ;<br />
buttons[1]['id'] = &#8216;default_cancel&#8217; ;<br />
buttons[2]['id'] = &#8216;button3&#8242; ;<br />
buttons[2]['text'] = &#8216;A 3rd Button&#8217; ;&nbsp;
</li>
</ol>
<p>As shown above, you can add as many buttons as you want using an array.  The function also created a default cancel button that will close and destroy the dialog if you pass the id &#8216;default_cancel&#8217; to it.</p>
<p>Note that once you have the dialog rendered, you can use more JavaScript driven by the ID of each button to decide what happens when that ID gets clicked. This should ideally go in a JS file tied to the view or page you load into the load_file parameter of the function.</p>
<p>There are several ways to to tweak and improve the function depending on what you are rendering your dialogs for,  so please feel free to make any changes and / or share your thoughts. If you have any questions, please don&#8217;t hesitate to ask.</p><pre class="crayon-plain-tag">/**
* Function to shorten the amount of JavaScript required to create multiple JQuery UI Dialogs
* Courtesy of Vesica
* This code is provided free of any and all warranties. Please use it at your own risk.
*/

function loadDialog(target_class,title,width,height,load_file,buttons) {
	var loading = $('&lt;img src="' + siteurl + 'images/ajax-loader.gif" alt="loading" class="loading"&gt;');

	// Prepare the buttons parameter

    var theButtons = {};
	$.each(buttons, function(key, value) {
		if (buttons[key]['id'] == 'default_cancel') {
			var btname = 'Cancel';
			theButtons[btname] = {};
			theButtons[btname]['text'] = 'Cancel';
			theButtons[btname]['click'] = function(){ $(this).dialog("close") };
		} else {
			var btname = buttons[key]['text'];
			theButtons[btname] = {};
			theButtons[btname]['id'] = buttons[key]['id'];
			theButtons[btname]['text'] = buttons[key]['text'];
		}
	});
	$('.' + target_class).dialog('option', 'title', title);
    $('.' + target_class).load(load_file);
    $('&lt;div title="' + title + '" class="' + target_class + '" id="' + Math.random()*1000001 + '"&gt;&lt;/div&gt;').dialog({
		modal: true,
		open: function ()
		{
			$(this).append(loading.clone());
			$(this).load(load_file);
		},
		width: width,
		height: height,
		buttons: theButtons,
		close: function() {
			$('.' + target_class).empty();
   	        $('.' + target_class).remove();
        }
    });

}</pre><p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://vesica.ws/blog/2013/03/simplifying-jquery-dialogs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tech Talk: URL Hashing and JQuery UI Tabs</title>
		<link>https://vesica.ws/blog/2013/01/tech-talk-url-hashing-and-jquery-tabs/</link>
		<comments>https://vesica.ws/blog/2013/01/tech-talk-url-hashing-and-jquery-tabs/#comments</comments>
		<pubDate>Mon, 21 Jan 2013 22:44:30 +0000</pubDate>
		<dc:creator>Asif N</dc:creator>
				<category><![CDATA[Tech Talk]]></category>
		<category><![CDATA[art collection software]]></category>
		<category><![CDATA[hashes]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery ui tabs]]></category>
		<category><![CDATA[museum software]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[web applications]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">https://vesica.ws/blog/?p=535</guid>
		<description><![CDATA[Whilst Vesica uses JQuery, what&#8217;s discussed in this article is not used in Vesica, but in a similar application we helped build at the  NHS (National Health Service) which borrows from the Vesica interface. The application in question is a single page application, so virtually everything is done via AJAX. The URL receives different parameters via [...]]]></description>
			<content:encoded><![CDATA[<p>Whilst Vesica uses JQuery, what&#8217;s discussed in this article is not used in Vesica, but in a similar application we helped build at the  NHS (National Health Service) which borrows from the Vesica interface.</p>
<p>The application in question is a single page application, so virtually everything is done via AJAX. The URL receives different parameters via a URL hash, which updates different sections of the page DOM or accesses different parts of the interface, including JQuery UI tabs. These single page, multiple hash URLs can be called via a bookmark URL, or will trigger on a url change in the browser. What&#8217;s important to note here is that in an application like this, when you submit data, all you really need to do is change the URL &#8211; your hashing managing JavaScript should do the rest for you (in terms of routing your data to the server side, not actual processing). I&#8217;ll also show you some JavaScript to deal with JQuery UI tabs after your page loads as working with hashing will disable the default URL behaviour that allows you to call tabs via the URL.</p>
<p><strong>Requirements</strong></p>
<p>If it&#8217;s not self-explanatory, you need the following to accomplish this:</p>
<ul>
<li>JQuery - http://jquery.com/download/</li>
<li>JQuery UI - http://jqueryui.com/</li>
<li>JQuery Hashchange plugin from Ben Alman - http://github.com/cowboy/jquery-hashchange/raw/v1.3/jquery.ba-hashchange.js and http://benalman.com/projects/jquery-hashchange-plugin/</li>
</ul>
<div>Please load the JavaScript libraries in your page (preferably in the header) in the order listed.</div>
<p><strong>How it works</strong></p>
<p>Here is what we need to cover:</p>
<ol>
<li>Someone either loads a URL in their browser which is part of your single page application (this could be via a bookmarked URL or by simply typing or pasting in the address bar), in which case you simply need to pick up the URL, process, and update the page.</li>
<li>Someone performs an action that will change the URL of your application &#8211; which should either update a database or update the page, or whatever it is supposed to do in your application.</li>
</ol>
<div>The JQuery Haschange plugin will only help you accomplish number 2. Number 1 is simple JavaScript / JQuery.</div>
<div></div>
<div>So how does your application know that the URL in the browser has changed after the #? With the following code.</div>
<p></p><pre class="crayon-plain-tag">// The following line will monitor hash changes on the page this JS gets loaded into
$(window).hashchange( function(){
// If the URL has changed, any code here gets executed. For instance, you could alert something:
alert('The URL has has changed.');
});</pre><p>So if your existing URL looked like http://example.com/#Page1 and you changed it to http://example.com/#Page2 with an &lt;a href&gt; or a &lt;button&gt;, would see the alert box above. Note that if you wanted to to alert something anyway, you would simply put that code outside the $(window).hashchange() function.</p>
<p>This is the easy bit &#8211; now for how you would pick up different parts of your URL, splice them up and send them to your scripts as needed to process, and then perhaps load a JQuery UI tab on your page.</p>
<p><strong>Assumptions</strong></p>
<p>Let&#8217;s clarify what we have in our example.</p>
<p>We are trying to load a different type of product based on a type parameter, followed by an ID, followed by a bunch of parameters that style the image and options that get displayed for the product.</p>
<p>So, if you were using PHP and building your URL query string, it might look a bit like:</p>
<p>http://example.com/product.php?type=bottle&#038;id=3426&#038;colour=green</p>
<p>If you wanted to load a particular JQuery tab on this page that had the id &#8216;dimensions&#8217;, your URL would become:</p>
<p>http://example.com/product.php?type=bottle&#038;id=3426&#038;colour=green/#dimensions</p>
<p>When the page loaded, JQuery UI would know you want to load the dimensions tab and it would simply make it active.</p>
<p>But using the $(window).hashchange() function above will break this default JQuery UI functionality.</p>
<p>So, our goal, given our single page application, is to be able to reload a certain part of our page based on a URL that looks like the following:</p>
<p>http://example.com/index.php#product/type=bottle&#038;id=3426&#038;colour=green/dimensions</p>
<p>The way to read the above your URL is: Give me the product page with bottle No. 3426 in the colour green and display the dimensions tab on the product page. You could change any of the values above to process different data &#8211; so you could have product, category or generic types of pages, hundreds of different products and hundreds of different colours.</p>
<p>Sounds simple enough. This would be accomplished with the following code, and please note, as mentioned above, that to trigger this change for bookmarked URLs or those pasted in the browser you can enter this code outside the $(window).hashchange() function in a &lt;script type=&#8221;text/JavaScript&#8221;&gt;&lt;/script&gt; tag directly in index.php (where index.php is the file that runs your single page application) or create a another JavaScript file and include it in your index.php file via the &lt;script&gt; tag. To trigger it with a button click or &lt;a href&gt; change, please wrap it inside the $(window).hash function as shown below. Technically, you can wrap all this code in a function and call that on $(window).hashchange() being executed.</p><pre class="crayon-plain-tag">// The following line will monitor hash changes on the page this JS gets loaded into
$(window).hashchange( function(){

    // If the URL has changed, get the value of the URL and split up the different parts
    var postHashUrl = location.hash.substr(1); // this will return product/type=bottle&amp;id=3426&amp;colour=green/dimensions
    var urlParams = urlIdentifier.split('/'); // this will return an array having split up the postHashUrl at the '/', much like the php explode() function would
    var paramType = urlParams[0]; // this will return 'product'
    var paramDetails = urlParams[1]; // this will return 'type=bottle&amp;id=3426&amp;colour=green'
    var tabToDisplay = urlParams[2]; // this will return 'dimensions'

});</pre><p>The above code now gives you access to to all the different parts of the URL hash, and will do so every time it changes. All you need to do now is use the $.ajax() function in JQuery to process this data, get the results back, and set the active tab as shown below:</p><pre class="crayon-plain-tag">// The following line will monitor hash changes on the page this JS gets loaded into
$(window).hashchange( function(){
    // If the URL has changed, get the value of the URL and split up the different parts
    var postHashUrl = location.hash.substr(1); // this will return product/type=bottle&amp;id=3426&amp;colour=green/dimensions
    var urlParams = urlIdentifier.split('/'); // this will return an array having split up the postHashUrl at the '/', much like the php explode() function would
    var paramType = urlParams[0]; // this will return 'product'
    var paramDetails = urlParams[1]; // this will return 'type=bottle&amp;id=3426&amp;colour=green'
    var tabToDisplay = urlParams[2]; // this will return 'dimensions'

    // Post the data to your server side processing script
    $.ajax({
        type : 'POST',
        url : 'my/processing/file.php', // or.aspx or whatever language you are using
        data : "type=" + paramType + "&amp;details=" + paramDetails,
        cache : false,
        success : function(results) {
            // perhaps you want to load these results into a div with id 'myResults'
            $('#myResults').html(results);

            // Finally, if the div that contains your tabs has the id 'tabs'
            $('#tabs').tabs('select', tabToDisplay ); // this will set the active tab to dimensions
            }
    });
});</pre><p>That&#8217;s it, that code should pick up any changes to the URL and process them according to the code above.</p>
<p>As this is JQuery, remember to wrap all of the above code in $(function(){ {); as shown below. I&#8217;ve also added the code above outside the hashchange function so you can see how to setup the default page handler as well as trigger it off when the page URL changes.</p><pre class="crayon-plain-tag">$(function() {

    // Default processing to process any data when the page loads with a hashed URL
    var postHashUrl = location.hash.substr(1); // this will return product/type=bottle&amp;id=3426&amp;colour=green/dimensions
    var urlParams = urlIdentifier.split('/'); // this will return an array having split up the postHashUrl at the '/', much like the php explode() function would
    var paramType = urlParams[0]; // this will return 'product'
    var paramDetails = urlParams[1]; // this will return 'type=bottle&amp;id=3426&amp;colour=green'
    var tabToDisplay = urlParams[2]; // this will return 'dimensions'

    // Post the data to your server side processing script
    $.ajax({
        type : 'POST',
        url : 'my/processing/file.php', // or.aspx or whatever language you are using
        data : "type=" + paramType + "&amp;details=" + paramDetails,
        cache : false,
        success : function(results) {
            // perhaps you want to load these results into a div with id 'myResults'
            $('#myResults').html(results);

            // Finally, if the div that contains your tabs has the id 'tabs'
            $('#tabs').tabs('select', tabToDisplay ); // this will set the active tab to dimensions
            }
    });

        // The following line will monitor hash changes on the page this JS gets loaded into
        $(window).hashchange( function(){
        // If the URL has changed, get the value of the URL and split up the different parts
        var postHashUrl = location.hash.substr(1); // this will return product/type=bottle&amp;id=3426&amp;colour=green/dimensions
        var urlParams = urlIdentifier.split('/'); // this will return an array having split up the postHashUrl at the '/', much like the php explode() function would
        var paramType = urlParams[0]; // this will return 'product'
        var paramDetails = urlParams[1]; // this will return 'type=bottle&amp;id=3426&amp;colour=green'
        var tabToDisplay = urlParams[2]; // this will return 'dimensions'

        // Post the data to your server side processing script
        $.ajax({
            type : 'POST',
            url : 'my/processing/file.php', // or.aspx or whatever language you are using
            data : "type=" + paramType + "&amp;details=" + paramDetails,
            cache : false,
            success : function(results) {
                // perhaps you want to load these results into a div with id 'myResults'
                $('#myResults').html(results);

                // Finally, if the div that contains your tabs has the id 'tabs'
                $('#tabs').tabs('select', tabToDisplay ); // this will set the active tab to dimensions
                }
        });
});
});</pre><p>I&#8217;ve stated before that you can (and probably should) write a function to do the above so you don&#8217;t have to reproduce your code twice &#8211; but this should give you an idea of how to handle hash changes and process them.</p>
]]></content:encoded>
			<wfw:commentRss>https://vesica.ws/blog/2013/01/tech-talk-url-hashing-and-jquery-tabs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing Vesica Tech Talk</title>
		<link>https://vesica.ws/blog/2013/01/introducing-vesica-tech-talk/</link>
		<comments>https://vesica.ws/blog/2013/01/introducing-vesica-tech-talk/#comments</comments>
		<pubDate>Fri, 18 Jan 2013 22:25:42 +0000</pubDate>
		<dc:creator>Asif N</dc:creator>
				<category><![CDATA[Tech Talk]]></category>
		<category><![CDATA[art collection software]]></category>
		<category><![CDATA[art collector software]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[museum technology]]></category>
		<category><![CDATA[tech talk]]></category>
		<category><![CDATA[vesica]]></category>

		<guid isPermaLink="false">https://vesica.ws/blog/?p=532</guid>
		<description><![CDATA[After a quiet holiday blogging season, we have a bit of a twist and some regular updates planned for the Vesica blog, including a new section called Tech Talk. Tech Talk will be discussing some web based technical implementations that we at Vesica have used in the application and in exteral projects (our team gets [...]]]></description>
			<content:encoded><![CDATA[<p>After a quiet holiday blogging season, we have a bit of a twist and some regular updates planned for the Vesica blog, including a new section called Tech Talk.</p>
<p>Tech Talk will be discussing some web based technical implementations that we at Vesica have used in the application and in exteral projects (our team gets to work on several external projects that are modeled after or integrate with Vesica in a variety of industries) &#8211; small snippets of code or technical advice that could save you (or your technical team) hours or days if you&#8217;re building something similar.</p>
<p>In addition, we&#8217;ll be rolling out some videos (not in the Tech Talk but the Using Vesica and Upcoming Features Sections) to demo some of the existing functionality, new functionality (that was released over Christmas and has just recently made it to the features page &#8211; https://vesica.ws/features/timeline/), and upcoming functionality like the Research and Bibliography tab.</p>
<p>The first Tech Talk article (coming this Monday) will discuss some JQuery implementations adapted from Vesica for use by one of the applications for the National Health Service (NHS) in the UK, the interface for which was inspired by Vesica (and we helped design and build it).</p>
]]></content:encoded>
			<wfw:commentRss>https://vesica.ws/blog/2013/01/introducing-vesica-tech-talk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
