<?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/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>jQuery Archives - rweber.net</title>
	<atom:link href="https://www.rweber.net/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.rweber.net/tag/jquery/</link>
	<description>trying to be a mile wide AND a mile deep</description>
	<lastBuildDate>Sun, 09 Dec 2018 13:51:20 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
<site xmlns="com-wordpress:feed-additions:1">37896774</site>	<item>
		<title>Helpful Links for JavaScript</title>
		<link>https://www.rweber.net/javascript/helpful-links-javascript/</link>
					<comments>https://www.rweber.net/javascript/helpful-links-javascript/#respond</comments>
		
		<dc:creator><![CDATA[Rebecca]]></dc:creator>
		<pubDate>Mon, 22 May 2017 12:00:25 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[dev resources]]></category>
		<category><![CDATA[jQuery]]></category>
		<guid isPermaLink="false">http://www.rweber.net/?p=40074</guid>

					<description><![CDATA[<div><img width="300" height="200" src="https://www.rweber.net/wp-content/uploads/2017/05/books-2253569_640-300x200.jpg" class="attachment-medium size-medium wp-post-image" alt="Library photo by jenikmichal on Pixabay" style="float:left; margin-right:16px; margin-bottom:16px;" decoding="async" fetchpriority="high" srcset="https://www.rweber.net/wp-content/uploads/2017/05/books-2253569_640-300x200.jpg 300w, https://www.rweber.net/wp-content/uploads/2017/05/books-2253569_640-150x100.jpg 150w, https://www.rweber.net/wp-content/uploads/2017/05/books-2253569_640.jpg 640w" sizes="(max-width: 300px) 100vw, 300px" /></div>
<p>A small but also heavily curated collection of useful links for JavaScript.</p>
<p>The post <a href="https://www.rweber.net/javascript/helpful-links-javascript/">Helpful Links for JavaScript</a> appeared first on <a href="https://www.rweber.net">rweber.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div><img width="300" height="200" src="https://www.rweber.net/wp-content/uploads/2017/05/books-2253569_640-300x200.jpg" class="attachment-medium size-medium wp-post-image" alt="Library photo by jenikmichal on Pixabay" style="float:left; margin-right:16px; margin-bottom:16px;" decoding="async" srcset="https://www.rweber.net/wp-content/uploads/2017/05/books-2253569_640-300x200.jpg 300w, https://www.rweber.net/wp-content/uploads/2017/05/books-2253569_640-150x100.jpg 150w, https://www.rweber.net/wp-content/uploads/2017/05/books-2253569_640.jpg 640w" sizes="(max-width: 300px) 100vw, 300px" /></div><p>Time to publish my small but also heavily curated collection of useful links for JavaScript.</p>
<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript">MDN JavaScript</a> &#8211; this is the best thing going for JS language reference. I wish we could backfill a decade of useful programmer comments like in the PHP manual, and you should search it with Google rather than its internal search function (just add MDN to your search term), but it is quite clear and includes browser support data.</p>
<p><a href="http://api.jquery.com/">jQuery Documentation</a> &#8211; if you use jQuery, this is the place to see not only syntax and examples for its commands but whether they are current, present but deprecated, or absent from your version of jQuery.</p>
<p><a href="https://developer.mozilla.org/en-US/docs/Web/Reference/API">MDN Web APIs</a> &#8211; if your JavaScript is doing anything deep, you&#8217;ll find need for these. I would highlight <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model">DOM</a> (especially <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window">Window</a>) and <a href="https://developer.mozilla.org/en-US/docs/Web/API/Storage">Storage</a> (as in localStorage and sessionStorage) in particular. Same caveat as before, though: MDN is far easier to search via Google.</p>
<p><a href="http://esprima.org/demo/validate.html">Esprima Syntax Validator</a> &#8211; a useful syntax checker! It won&#8217;t give you twenty spacing errors and then quit; it only worries about things that actually affect the validity of your code. This is the only JS syntax checker that has successfully improved my code, by finding missing or stray braces and similar.</p>
<p><a href="https://developers.google.com/closure/compiler/">Google Closure Compiler</a> &#8211; this will concatenate and minify your JavaScript, which you can enter by directly pasting it in or by link.</p>
<p><a href="http://codepen.io/">CodePen</a> and <a href="https://jsfiddle.net/">JSfiddle</a> &#8211; these are both easy ways to share small programs and allow people to edit them.</p>
<p><a href="https://www.lynda.com/">Lynda.com</a> &#8211; There are a lot of JS classes on Lynda.com, of variable type and quality, so I&#8217;ll just highlight a few. If you&#8217;ve programmed before, even if long ago and far away (and mostly in C++, which was my condition), Joe Chellman&#8217;s <a href="http://www.lynda.com/JavaScript-tutorials/Introducing-JavaScript-Language/123563-2.html">Introducing the JavaScript Language</a> will be helpful. It&#8217;s a syntax course that highlights some potential gotchas where JS differs from other common languages. Joe also has project-based &#8220;for designers&#8221; courses in <a href="http://www.lynda.com/JavaScript-tutorials/JavaScript-Web-Designers/144203-2.html">JavaScript</a> and <a href="http://www.lynda.com/jQuery-tutorials/jQuery-Web-Designers/144204-2.html">jQuery</a>. Of course none of these courses is comprehensive, but I like Joe as an instructor because a) he warns you when there&#8217;s more complexity than he&#8217;s covering or when the value he&#8217;s using is design-specific or arbitrary, and b) his project courses have exercises. They are quick but they force you to immediately use what you just learned, which immensely improves the takeaway.</p>
<hr>
<p>You can consider this the JavaScript follow-up to my posts about learning <a href="/web-development/css/learning-html-css-online/">HTML, CSS</a>, and <a href="/web-development/php/learning-php-online/">PHP</a> online. After doing the Lynda classes mentioned and other tutorials there and elsewhere that are less recommendable, I learned &#8220;episodically&#8221; &#8211; my initial use for JS was for small, self-contained programs that did one or two things, and I built up from there. It suited my learning style nicely but didn&#8217;t lend itself to a list of helpful tutorial links for others.</p>
<hr>
<p><small>Library photo by <a href="https://pixabay.com/en/books-library-alphabet-reading-2253569/">jenikmichal on Pixabay</a>.</small></p>
<p>The post <a href="https://www.rweber.net/javascript/helpful-links-javascript/">Helpful Links for JavaScript</a> appeared first on <a href="https://www.rweber.net">rweber.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.rweber.net/javascript/helpful-links-javascript/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">40074</post-id>	</item>
		<item>
		<title>Working with GA&#8217;s Enhanced Ecommerce (using GTM)</title>
		<link>https://www.rweber.net/analytics/ga-enhanced-ecommerce-using-gtm/</link>
					<comments>https://www.rweber.net/analytics/ga-enhanced-ecommerce-using-gtm/#respond</comments>
		
		<dc:creator><![CDATA[Rebecca]]></dc:creator>
		<pubDate>Mon, 12 Dec 2016 13:00:25 +0000</pubDate>
				<category><![CDATA[Analytics]]></category>
		<category><![CDATA[Google Analytics]]></category>
		<category><![CDATA[Google Tag Manager]]></category>
		<category><![CDATA[jQuery]]></category>
		<guid isPermaLink="false">http://www.rweber.net/?p=39995</guid>

					<description><![CDATA[<div><img width="300" height="225" src="https://www.rweber.net/wp-content/uploads/2016/12/beach-east-frisia-300x225.jpg" class="attachment-medium size-medium wp-post-image" alt="beach sand in east frisia, by grafik_design on pixabay" style="float:left; margin-right:16px; margin-bottom:16px;" decoding="async" srcset="https://www.rweber.net/wp-content/uploads/2016/12/beach-east-frisia-300x225.jpg 300w, https://www.rweber.net/wp-content/uploads/2016/12/beach-east-frisia-768x575.jpg 768w, https://www.rweber.net/wp-content/uploads/2016/12/beach-east-frisia.jpg 1024w, https://www.rweber.net/wp-content/uploads/2016/12/beach-east-frisia-150x112.jpg 150w" sizes="(max-width: 300px) 100vw, 300px" /></div>
<p>An example of sending product impressions gradually, so your analytics data reflects actual visibility on the page.</p>
<p>The post <a href="https://www.rweber.net/analytics/ga-enhanced-ecommerce-using-gtm/">Working with GA&#8217;s Enhanced Ecommerce (using GTM)</a> appeared first on <a href="https://www.rweber.net">rweber.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div><img width="300" height="225" src="https://www.rweber.net/wp-content/uploads/2016/12/beach-east-frisia-300x225.jpg" class="attachment-medium size-medium wp-post-image" alt="beach sand in east frisia, by grafik_design on pixabay" style="float:left; margin-right:16px; margin-bottom:16px;" decoding="async" loading="lazy" srcset="https://www.rweber.net/wp-content/uploads/2016/12/beach-east-frisia-300x225.jpg 300w, https://www.rweber.net/wp-content/uploads/2016/12/beach-east-frisia-768x575.jpg 768w, https://www.rweber.net/wp-content/uploads/2016/12/beach-east-frisia.jpg 1024w, https://www.rweber.net/wp-content/uploads/2016/12/beach-east-frisia-150x112.jpg 150w" sizes="auto, (max-width: 300px) 100vw, 300px" /></div><p>Google Analytics has a suite of Enhanced Ecommerce tools that let you see which products are getting viewed and clicked on in pages that aggregate them, such as category pages. It can include position so you can see how much of a boost it is to be first in line. There&#8217;s some work involved in setting this up, though, and I thought I&#8217;d record it for my own and others&#8217; reference.</p>
<p>The simplest way to do this is to push all of the products as one big group impression, which is how the <a href="https://developers.google.com/tag-manager/enhanced-ecommerce">Enhanced Ecommerce documentation</a> tells you to do it. We wanted to be more subtle, though, and use impressions to learn whether people were interacting with the page; i.e., to send impressions only when the products had actually been in view.</p>
<p>Let&#8217;s suppose three carousels of products for which we want to track impressions and clicks. I&#8217;ll assume a very simple carousel markup, where the items inside the carousel div are links that have <a href="https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_data_attributes">data attributes</a> with all the product information. Throughout this I&#8217;ll be simplifying so that the core ideas aren&#8217;t muddied by syntax.</p>
<p><iframe src="//pastebin.com/embed_iframe/XSdquy1z" style="border:none;width:100%;height:375px;">View embedded code on the blog</iframe></p>
<p>I&#8217;m going to walk through the JavaScript top down. First, the document.ready call; inside it we keep track of which carousel panels have been visible on the visitor&#8217;s screen, and push product impression information for the visible products when a carousel is first scrolled into view or is clicked through on to a previously-unviewed panel. We also push product click information when a product is clicked on.</p>
<p>Each of our three carousels in this example has three panels. If the number of panels per carousel changes depending on the size of the viewer&#8217;s screen, you&#8217;ll want to put in some window size checks and adjust accordingly.</p>
<p><iframe src="//pastebin.com/embed_iframe/6FGQe6bk" style="border:none;width:100%;height:400px;"></iframe></p>
<p>What are those things being sent to the pushProductClick and pushProductImpressions functions? They are objects or arrays of objects, where the object properties are information about the product, which list it is in, and where in the list it occurs. I&#8217;ve used the namespacing syntax for a <a href="https://learn.jquery.com/plugins/basic-plugin-creation/">jQuery plugin</a> here (I&#8217;ll also point you to a short and sweet Stack Overflow about <a href="http://stackoverflow.com/questions/2398007/in-jquery-what-is-the-difference-between-myfunction-and-fn-myfunction">the difference between $.myFunction and $.fn.myFunction</a>).</p>
<p><iframe src="//pastebin.com/embed_iframe/1UJkL4U6" style="border:none;width:100%;height:400px;"></iframe></p>
<p>Finally, we have the push functions themselves, which take the product object or array and execute the appropriate dataLayer.push command. The product click push is more complex than the product impression push; one gotcha I ran into is that the productObj object must be enclosed in square brackets, despite being only a single thing. The eventCallback is typically a window.location, but if you set that, a visitor who tries to open a link in a new tab will also get it in the current tab. Making that a simple return statement and not preventing default in the click handler (above) allows the data to be sent to GA while also allowing the visitor to interact with the link in the way they choose.</p>
<p><iframe src="//pastebin.com/embed_iframe/WTB6JpBd" style="border:none;width:100%;height:400px;"></iframe></p>
<p>The Google Tag Manager side of the setup is pretty standard. It matches the setup in the <a href="https://developers.google.com/tag-manager/enhanced-ecommerce">Enhanced Ecommerce documentation</a> except for one detail: the trigger for the product impressions is not the event gtm.dom but the event productImpressions, mirroring the product click setup. You have to dig down a bit to get the data layer turned on, and <a href="https://www.simoahava.com/analytics/custom-event-listeners-gtm/">you can&#8217;t test it in preview mode</a>, unfortunately, but the GTM side is simple enough that it&#8217;s not too worrisome once you&#8217;ve console.debugged your way to confidence that your product objects and arrays are correct.</p>
<hr>
<p><small>Photo of beach sand on Baltrum Island, Germany by <a href="https://pixabay.com/en/beach-sand-wadden-sea-north-sea-988645/">grafik_design on Pixabay</a>.</small></p>
<p>The post <a href="https://www.rweber.net/analytics/ga-enhanced-ecommerce-using-gtm/">Working with GA&#8217;s Enhanced Ecommerce (using GTM)</a> appeared first on <a href="https://www.rweber.net">rweber.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.rweber.net/analytics/ga-enhanced-ecommerce-using-gtm/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">39995</post-id>	</item>
		<item>
		<title>jQuery’s .closest() versus Element.closest()</title>
		<link>https://www.rweber.net/javascript/jquerys-closest-versus-element-closest/</link>
					<comments>https://www.rweber.net/javascript/jquerys-closest-versus-element-closest/#respond</comments>
		
		<dc:creator><![CDATA[Rebecca]]></dc:creator>
		<pubDate>Mon, 22 Aug 2016 12:00:09 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<guid isPermaLink="false">http://www.rweber.net/?p=39961</guid>

					<description><![CDATA[<div><img width="300" height="165" src="https://www.rweber.net/wp-content/uploads/2016/08/Spot_the_difference-300x165.png" class="attachment-medium size-medium wp-post-image" alt="Spot the Difference from Wikimedia Commons" style="float:left; margin-right:16px; margin-bottom:16px;" decoding="async" loading="lazy" srcset="https://www.rweber.net/wp-content/uploads/2016/08/Spot_the_difference-300x165.png 300w, https://www.rweber.net/wp-content/uploads/2016/08/Spot_the_difference-150x83.png 150w, https://www.rweber.net/wp-content/uploads/2016/08/Spot_the_difference.png 700w" sizes="auto, (max-width: 300px) 100vw, 300px" /></div>
<p>Two implementations: same goal, different details - and hence different logic for your if statements.</p>
<p>The post <a href="https://www.rweber.net/javascript/jquerys-closest-versus-element-closest/">jQuery’s .closest() versus Element.closest()</a> appeared first on <a href="https://www.rweber.net">rweber.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div><img width="300" height="165" src="https://www.rweber.net/wp-content/uploads/2016/08/Spot_the_difference-300x165.png" class="attachment-medium size-medium wp-post-image" alt="Spot the Difference from Wikimedia Commons" style="float:left; margin-right:16px; margin-bottom:16px;" decoding="async" loading="lazy" srcset="https://www.rweber.net/wp-content/uploads/2016/08/Spot_the_difference-300x165.png 300w, https://www.rweber.net/wp-content/uploads/2016/08/Spot_the_difference-150x83.png 150w, https://www.rweber.net/wp-content/uploads/2016/08/Spot_the_difference.png 700w" sizes="auto, (max-width: 300px) 100vw, 300px" /></div><p>I recently discovered there&#8217;s a major difference between <code>.closest()</code> in jQuery and vanilla JavaScript. It came up because <code>Element.closest()</code>, a fairly recent addition to JavaScript, is not supported in any version of IE or Edge (it was added to Firefox, Chrome, and Safari over the course of the first nine months of 2015). I was using <code>.closest()</code> to detect whether a click while a popup was open was within the popup or not, in order to close the popup when the visitor clicked outside of it. My efforts to fix the functionality on IE/Edge broke it everywhere, and in the process of fixing that I learned more about <code>.closest()</code> than I would have anticipated there was to learn.</p>
<p>In both cases, the idea is that <code>(element A).closest(element B)</code> tells you whether element B is an ancestor of element A (this is also considered true if they are the same element). Therefore <code>(click target).closest(popup)</code> tells you whether the click fell within the popup regardless of whether it also fell inside an element contained in the popup.</p>
<p>The first problem I ran into in switching to jQuery&#8217;s <code>.closest()</code> function is that it can only be run on jQuery objects. That is, <code>event.target.closest()</code> will try for the vanilla JavaScript version only; you need <code>jQuery(event.target).closest()</code> to trigger the jQuery version. Depending on what else you&#8217;re trying to accomplish you may have to untangle jQuery/non-jQuery conflicts.</p>
<p>The second problem is that these two versions of the same function do not have the same return values. At all. If element B is not an ancestor of element A, <code>Element.closest()</code> will return <code>null</code>; jQuery&#8217;s <code>.closest()</code> will return an empty object. My original code had checks like <code>if ( !(click target).closest(popup) )</code>, which fall apart upon switching to jQuery &#8211; no matter what, that if condition will evaluate to false, because even empty objects are truthy values in JavaScript.</p>
<p>Instead, I needed <code>if ( $(click target).closest(popup).length === 0 )</code> to achieve the same logical outcomes. Once I made those changes everything worked again, and this time in IE/Edge as well as the rest.</p>
<p>Official sources: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/closest">Mozilla Developer Network on Element.closest()</a>, and <a href="http://api.jquery.com/closest/">jQuery API reference on $().closest()</a>. Note on the latter page that while there is deprecation, it is only for the version of closest with two parameters.</p>
<hr>
<p><small>At top: &#8220;Spot the Difference&#8221; image from <a href="https://commons.wikimedia.org/wiki/File:Spot_the_difference.png">Wikimedia Commons</a>.</small></p>
<p>The post <a href="https://www.rweber.net/javascript/jquerys-closest-versus-element-closest/">jQuery’s .closest() versus Element.closest()</a> appeared first on <a href="https://www.rweber.net">rweber.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.rweber.net/javascript/jquerys-closest-versus-element-closest/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">39961</post-id>	</item>
		<item>
		<title>Parallax without Plugins</title>
		<link>https://www.rweber.net/css/parallax-without-plugins/</link>
					<comments>https://www.rweber.net/css/parallax-without-plugins/#respond</comments>
		
		<dc:creator><![CDATA[Rebecca]]></dc:creator>
		<pubDate>Mon, 16 Nov 2015 14:00:31 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[portfolio]]></category>
		<guid isPermaLink="false">http://www.rweber.net/?p=39226</guid>

					<description><![CDATA[<div><img width="300" height="151" src="https://www.rweber.net/wp-content/uploads/2015/11/race-801940_1280-300x151.jpg" class="attachment-medium size-medium wp-post-image" alt="photo of runners waiting to race down their lanes" style="float:left; margin-right:16px; margin-bottom:16px;" decoding="async" loading="lazy" srcset="https://www.rweber.net/wp-content/uploads/2015/11/race-801940_1280-300x151.jpg 300w, https://www.rweber.net/wp-content/uploads/2015/11/race-801940_1280.jpg 1024w" sizes="auto, (max-width: 300px) 100vw, 300px" /></div>
<p>We've done some simple parallax on a couple of websites recently, using jQuery but no additional JavaScript libraries. It takes some hand-tweaking - and you have to know your items in advance - but is also much lighter weight than a plugin. Here's how.</p>
<p>The post <a href="https://www.rweber.net/css/parallax-without-plugins/">Parallax without Plugins</a> appeared first on <a href="https://www.rweber.net">rweber.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div><img width="300" height="151" src="https://www.rweber.net/wp-content/uploads/2015/11/race-801940_1280-300x151.jpg" class="attachment-medium size-medium wp-post-image" alt="photo of runners waiting to race down their lanes" style="float:left; margin-right:16px; margin-bottom:16px;" decoding="async" loading="lazy" srcset="https://www.rweber.net/wp-content/uploads/2015/11/race-801940_1280-300x151.jpg 300w, https://www.rweber.net/wp-content/uploads/2015/11/race-801940_1280.jpg 1024w" sizes="auto, (max-width: 300px) 100vw, 300px" /></div><p>We&#8217;ve done some simple parallax on a couple of websites recently, using jQuery but no additional JavaScript libraries. It takes some hand-tweaking &#8211; and you have to know your items in advance &#8211; but is also much lighter weight than a plugin.</p>
<p>The simplest version is elements scrolling independently of the page and each other, for decorative effect &#8211; so where they are when isn&#8217;t so crucial. Each needs to be fixed position and you&#8217;ll likely want some horizontal placement in the form of margins or left/right values.</p>
<p>In the JavaScript we&#8217;ll manipulate the CSS top value according to the amount we&#8217;ve scrolled the page.</p>
<p><iframe src="http://pastebin.com/embed_iframe.php?i=usqDCxNi" style="border:none;width:100%;height:250px;"></iframe></p>
<p>Bind a function to the scroll event, then within that function calculate how far the page has been scrolled and use it to compute a new top value for each parallaxed element. In this case, starting 800px from the top, the element will scroll one quarter as fast as the page itself. The initial value for top in the CSS should also be 800px, or the element will jump when the page is first scrolled (if you are starting with very large &#8211; i.e. always offscreen &#8211; top values they probably don&#8217;t need to match, but there&#8217;s also no reason not to match them).</p>
<p>By changing the initial value and the multiplier to how much the page has been scrolled, you can get a variety of rates and entry points. Careful of your opacity &#8211; with abstract images, one showing through another can be lovely, but with representative images it may just be weird and distracting.</p>
<h2>Multiple Items with Coordination</h2>
<p>Since using that version of parallax I was called on to create a more complicated version. In this, we&#8217;re scrolling many items separately from the page, but certain subsets of them have to align at points along the way. This made tweaking just starting point and rate of scroll completely impractical &#8211; it would have taken forever. It also made screen height an important consideration.</p>
<p>Algebra to the rescue: All of the parallax in this post is linear; that is, the calculation of the CSS top value from the amount the page has been scrolled is the equation of a line. We can make our choice of linear equation more deliberate with two points on the line and the following equation:<br />
<img decoding="async" src="https://s0.wp.com/latex.php?latex=+y+-+y_1+%3D+%5Cfrac%7By_2+-+y_1%7D%7Bx_2+-+x_1%7D+%28x+-+x_1%29+&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" alt=" y - y_1 = &#92;frac{y_2 - y_1}{x_2 - x_1} (x - x_1) " class="latex" /><br />
In this case, x is the amount of scroll and y is the top value. What are the two points? I used the point where the element should touch the bottom of the screen and the point when all of a batch of elements should be in their proper relative positions. You can get some complicated arithmetic, but fortunately JavaScript knows how to do that. I ended up with a helper function:</p>
<p><iframe src="http://pastebin.com/embed_iframe.php?i=wbUxmf1y" style="border:none;width:100%;height:262px;"></iframe></p>
<p>Since I had a good number of elements calling this function I expected calculating screen height once and then passing it as a function input was more efficient than calling that jQuery function repeatedly. The function above takes the inputs x<sub>1</sub>, y<sub>1</sub>, x<sub>2</sub>, y<sub>2</sub>, x, and returns y.</p>
<p>There&#8217;s more algebra to determine what the appropriate ending top value should be, dependent of course on number and desired alignment of items. I wanted three rows of items, equally spaced, with margins of 48px above, between, and below. I also wanted them to align that way when the page had been scrolled 1.25 times the screen height &#8211; they were &#8220;page two&#8221; but I needed the breathing room of that extra quarter-screen for the parallax effect.</p>
<p><iframe src="http://pastebin.com/embed_iframe.php?i=fBfvu7e5" style="border:none;width:100%;height:330px;"></iframe></p>
<p>Why not 3/4 screen height on that third item? Because that gave it far too long to get to its final position, and as a result it took forever to disappear off the top of the screen &#8211; long enough to overlap with &#8220;page three,&#8221; the items lined up when we&#8217;d scrolled 2.5 times the screen height. With 7/8 screen height it still lingers, but gets out of the way in time.</p>
<p>The post <a href="https://www.rweber.net/css/parallax-without-plugins/">Parallax without Plugins</a> appeared first on <a href="https://www.rweber.net">rweber.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.rweber.net/css/parallax-without-plugins/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">39226</post-id>	</item>
		<item>
		<title>Folders named &#8216;icons,&#8217; click handlers, and a new repo</title>
		<link>https://www.rweber.net/developer-toolbox/folders-named-icons-click-handlers-new-repo/</link>
					<comments>https://www.rweber.net/developer-toolbox/folders-named-icons-click-handlers-new-repo/#respond</comments>
		
		<dc:creator><![CDATA[Rebecca]]></dc:creator>
		<pubDate>Mon, 12 Oct 2015 16:00:46 +0000</pubDate>
				<category><![CDATA[Developer Toolbox]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[jQuery]]></category>
		<guid isPermaLink="false">http://www.rweber.net/?p=39163</guid>

					<description><![CDATA[<div><img width="275" height="300" src="https://www.rweber.net/wp-content/uploads/2015/10/lottery-146318_1280-275x300.png" class="attachment-medium size-medium wp-post-image" alt="illustration of lottery number balls in a globe" style="float:left; margin-right:16px; margin-bottom:16px;" decoding="async" loading="lazy" srcset="https://www.rweber.net/wp-content/uploads/2015/10/lottery-146318_1280-275x300.png 275w, https://www.rweber.net/wp-content/uploads/2015/10/lottery-146318_1280-768x837.png 768w, https://www.rweber.net/wp-content/uploads/2015/10/lottery-146318_1280.png 940w, https://www.rweber.net/wp-content/uploads/2015/10/lottery-146318_1280-138x150.png 138w" sizes="auto, (max-width: 275px) 100vw, 275px" /></div>
<p>Two things I&#8217;ve learned recently: Don&#8217;t use &#8220;icons&#8221; as a folder name in a website directory if you&#8217;re on Apache. Everything inside will 404. Apparently Apache aliases any directory named icons to its own icons directory by default with no .htaccess override allowed. This falls into the &#8220;but why did it work on my computer?&#8221; [&#8230;]</p>
<p>The post <a href="https://www.rweber.net/developer-toolbox/folders-named-icons-click-handlers-new-repo/">Folders named &#8216;icons,&#8217; click handlers, and a new repo</a> appeared first on <a href="https://www.rweber.net">rweber.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div><img width="275" height="300" src="https://www.rweber.net/wp-content/uploads/2015/10/lottery-146318_1280-275x300.png" class="attachment-medium size-medium wp-post-image" alt="illustration of lottery number balls in a globe" style="float:left; margin-right:16px; margin-bottom:16px;" decoding="async" loading="lazy" srcset="https://www.rweber.net/wp-content/uploads/2015/10/lottery-146318_1280-275x300.png 275w, https://www.rweber.net/wp-content/uploads/2015/10/lottery-146318_1280-768x837.png 768w, https://www.rweber.net/wp-content/uploads/2015/10/lottery-146318_1280.png 940w, https://www.rweber.net/wp-content/uploads/2015/10/lottery-146318_1280-138x150.png 138w" sizes="auto, (max-width: 275px) 100vw, 275px" /></div><p>Two things I&#8217;ve learned recently:</p>
<ol>
<li>Don&#8217;t use &#8220;icons&#8221; as a folder name in a website directory if you&#8217;re on Apache. Everything inside will 404. Apparently <a href="http://www.electrictoolbox.com/apache-icons-directory/">Apache aliases <em>any</em> directory named icons to its own icons directory by default</a> with no .htaccess override allowed. This falls into the &#8220;but why did it work on my computer?&#8221; category, since I didn&#8217;t change any defaults when I installed MAMP.</li>
<li>If you&#8217;re dynamically adding elements to a webpage and you want JavaScript (with jQuery) to react to clicks on them, you can&#8217;t use <code>$('.desired-class').click(function(e) { &hellip; });</code> &#8211; <a href="http://stackoverflow.com/questions/20754002/click-jquery-is-not-working/20754342#20754342">that will only bind clicks to elements that already exist when the JavaScript is loaded</a>. Instead, you need to bind a click handler to the entire page: <code>$(document).on('click', '.desired-class', function(e) { &hellip; });</code></li>
</ol>
<p>In other news, I added a new repo to Github over the weekend: a <a href="https://github.com/ReveWeber/doorprize">door prize program</a>. We designed it for the Boston Small Business Expo as a way to entice people to give us their email addresses. It requires name and email, allows organization and phone number, and has a function to draw three winners and also export all entrants as a CSV file. If you want to use it and have questions around adapting it, let me know!</p>
<p><small>Lottery number globe from <a href="https://pixabay.com/en/lottery-lotto-sphere-luck-win-146318/">Pixabay</a>.</small></p>
<p>The post <a href="https://www.rweber.net/developer-toolbox/folders-named-icons-click-handlers-new-repo/">Folders named &#8216;icons,&#8217; click handlers, and a new repo</a> appeared first on <a href="https://www.rweber.net">rweber.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.rweber.net/developer-toolbox/folders-named-icons-click-handlers-new-repo/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">39163</post-id>	</item>
		<item>
		<title>Tweaking the simple auto-playing slideshow</title>
		<link>https://www.rweber.net/javascript/tweaking-simple-auto-playing-slideshow/</link>
					<comments>https://www.rweber.net/javascript/tweaking-simple-auto-playing-slideshow/#respond</comments>
		
		<dc:creator><![CDATA[Rebecca]]></dc:creator>
		<pubDate>Mon, 10 Aug 2015 12:00:55 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[portfolio]]></category>
		<guid isPermaLink="false">http://www.rweber.net/?p=38469</guid>

					<description><![CDATA[<div><img width="300" height="206" src="https://www.rweber.net/wp-content/uploads/2015/07/Projecteur_de_diapositives_Prestinox_début_des_années_1960-300x206.jpg" class="attachment-medium size-medium wp-post-image" alt="image of slide projector" style="float:left; margin-right:16px; margin-bottom:16px;" decoding="async" loading="lazy" srcset="https://www.rweber.net/wp-content/uploads/2015/07/Projecteur_de_diapositives_Prestinox_début_des_années_1960-300x206.jpg 300w, https://www.rweber.net/wp-content/uploads/2015/07/Projecteur_de_diapositives_Prestinox_début_des_années_1960.jpg 752w" sizes="auto, (max-width: 300px) 100vw, 300px" /></div>
<p>Two variations on CSS-Tricks' Simple Auto-Playing Slideshow (jQuery): one to load slideshow content via AJAX, and one to turn each slideshow item into a question-answer pair.</p>
<p>The post <a href="https://www.rweber.net/javascript/tweaking-simple-auto-playing-slideshow/">Tweaking the simple auto-playing slideshow</a> appeared first on <a href="https://www.rweber.net">rweber.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div><img width="300" height="206" src="https://www.rweber.net/wp-content/uploads/2015/07/Projecteur_de_diapositives_Prestinox_début_des_années_1960-300x206.jpg" class="attachment-medium size-medium wp-post-image" alt="image of slide projector" style="float:left; margin-right:16px; margin-bottom:16px;" decoding="async" loading="lazy" srcset="https://www.rweber.net/wp-content/uploads/2015/07/Projecteur_de_diapositives_Prestinox_début_des_années_1960-300x206.jpg 300w, https://www.rweber.net/wp-content/uploads/2015/07/Projecteur_de_diapositives_Prestinox_début_des_années_1960.jpg 752w" sizes="auto, (max-width: 300px) 100vw, 300px" /></div><p>Ever since I found it probably close to a year ago, I&#8217;ve been a big fan of the <a href="https://css-tricks.com/snippets/jquery/simple-auto-playing-slideshow/">simple auto-playing slideshow on CSS-Tricks</a> (though perhaps surprisingly I have yet to apply it to a Media Library Assistant-generated WordPress gallery). I&#8217;ve tweaked it multiple times to serve different purposes, and thought I&#8217;d share two.</p>
<p>The first tweak is more of a wrapper than a modification. It has two features: it loads the slideshow content via AJAX, and it has a small change to the CSS to smooth the beginning of the slideshow.</p>
<p>I wanted to load the slideshow dynamically so I could turn it off entirely on mobile, without a Very Helpful Browser loading the images in case they were used later, slowing down the site. The page itself had the slideshow as a banner header, and it was collapsed at small sizes, so I used its height as the test in the JavaScript. There was a #slideshow div which had a background image set in CSS (via a class JavaScript removed) in case someone&#8217;s JavaScript was disabled, and the slideshow images were in a separate file as naked HTML (though the file was .php for no particular reason) to be pulled in with jQuery.load(). </p>
<p>As for the CSS, I found that trying to hide all but one image via CSS and have the JavaScript take over from there gave me a herky-jerky first transition. Instead, I hid everything in the CSS and used JavaScript to show the first image just as soon as the images were loaded up.</p>
<p>AJAXified slideshow JavaScript:</p>
<p><iframe src="http://pastebin.com/embed_iframe.php?i=RtXdEw1d" style="border:none;width:100%;height:175px;"></iframe></p>
<p>This and the JavaScript below need to be wrapped in a $(document).ready(function () { &#8230; }); to operate most smoothly.</p>
<p>CSS:</p>
<p><iframe src="http://pastebin.com/embed_iframe.php?i=PGNHEvtc" style="border:none;width:100%;height:250px;"></iframe></p>
<hr>
<p>The second tweak makes it a double slideshow: question and answer. In situ it uses WordPress text widgets, the title for the question and the content for its answer, but you can do it with any paired elements. The code below assumes a div with both class and id slideshow-wrapper, holding divs with class slideshow-item, each holding a pair of divs: .question and .answer. There are two different timeframes. The loop moves from pair to pair, and within it the question appears first, then the answer, they stay put for a while for reading, and then both fade away.</p>
<p>The other change to this one is that there&#8217;s a lone single animation outside the setInterval loop. Your choices without this separate bit are to have both the question and the answer in view immediately upon loading the page, or to wait with blank space for the entire first interval.</p>
<p>Q&#038;A slideshow JavaScript:</p>
<p><iframe src="http://pastebin.com/embed_iframe.php?i=UKTKj68q" style="border:none;width:100%;height:250px;"></iframe></p>
<p>CSS:</p>
<p><iframe src="http://pastebin.com/embed_iframe.php?i=HYYnqgmb" style="border:none;width:100%;height:250px;"></iframe></p>
<p><small><a href="https://commons.wikimedia.org/wiki/File:Projecteur_de_diapositives_Prestinox_d%C3%A9but_des_ann%C3%A9es_1960.jpg">Slide projector image by Jean-Jacques Milan via Wikimedia Commons</a></small></p>
<p>The post <a href="https://www.rweber.net/javascript/tweaking-simple-auto-playing-slideshow/">Tweaking the simple auto-playing slideshow</a> appeared first on <a href="https://www.rweber.net">rweber.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.rweber.net/javascript/tweaking-simple-auto-playing-slideshow/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">38469</post-id>	</item>
		<item>
		<title>Gilding the Gallery 3: Ajaxifying the filterable gallery</title>
		<link>https://www.rweber.net/javascript/gilding-the-gallery-3-ajaxifying-the-filterable-gallery/</link>
					<comments>https://www.rweber.net/javascript/gilding-the-gallery-3-ajaxifying-the-filterable-gallery/#respond</comments>
		
		<dc:creator><![CDATA[Rebecca]]></dc:creator>
		<pubDate>Mon, 20 Apr 2015 12:00:21 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP and MySQL]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[Fancy Fifteen]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[portfolio]]></category>
		<category><![CDATA[WordPress gallery]]></category>
		<guid isPermaLink="false">http://www.rweber.net/?p=38038</guid>

					<description><![CDATA[<div><img width="300" height="243" src="https://www.rweber.net/wp-content/uploads/2015/04/galleryscreenshot2-300x243.png" class="attachment-medium size-medium wp-post-image" alt="" style="float:left; margin-right:16px; margin-bottom:16px;" decoding="async" loading="lazy" srcset="https://www.rweber.net/wp-content/uploads/2015/04/galleryscreenshot2-300x243.png 300w, https://www.rweber.net/wp-content/uploads/2015/04/galleryscreenshot2.png 749w" sizes="auto, (max-width: 300px) 100vw, 300px" /></div>
<p>Last time we set up the PHP (slash HTML, slash CSS) to dynamically generate Media Library Assistant gallery shortcodes and an album menu. Everything works without any JavaScript. Today we're going to add JavaScript, with jQuery, to do three things.</p>
<ol>
<li>Hide the album menu under a button, a la a mobile menu.</li>
<li>Use AJAX to reload only the portion of the page containing the gallery.</li>
<li>Push each new URL into the browser history, so that the back button works and individual albums can be bookmarked.</li>
</ol>
<p>The post <a href="https://www.rweber.net/javascript/gilding-the-gallery-3-ajaxifying-the-filterable-gallery/">Gilding the Gallery 3: Ajaxifying the filterable gallery</a> appeared first on <a href="https://www.rweber.net">rweber.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div><img width="300" height="243" src="https://www.rweber.net/wp-content/uploads/2015/04/galleryscreenshot2-300x243.png" class="attachment-medium size-medium wp-post-image" alt="" style="float:left; margin-right:16px; margin-bottom:16px;" decoding="async" loading="lazy" srcset="https://www.rweber.net/wp-content/uploads/2015/04/galleryscreenshot2-300x243.png 300w, https://www.rweber.net/wp-content/uploads/2015/04/galleryscreenshot2.png 749w" sizes="auto, (max-width: 300px) 100vw, 300px" /></div><p><a href="https://www.rweber.net/web-development/php/gilding-the-gallery-2-mla-front-end-filtration">Last time</a> we set up the PHP (slash HTML, slash CSS) to dynamically generate Media Library Assistant gallery shortcodes and an album menu. Everything works without any JavaScript. Today we&#8217;re going to add JavaScript, with jQuery, to do three things.</p>
<ol>
<li>Hide the album menu under a button, a la a mobile menu. This will prevent the problem of a menu that&#8217;s so large the gallery is four pages down.</li>
<li>Use AJAX to reload only the portion of the page containing the gallery. This will make for a smoother experience.</li>
<li>Push each new URL into the browser history, so that the back button works and individual albums can be bookmarked. It&#8217;s always a source of an annoyed &#8220;really?&#8221; when I try to go back to a page I bookmarked and find that the address leads to only the most general version of the page, not where I actually was.</li>
</ol>
<p><b>Edit:</b> Since I have made so many additions to Twenty Fifteen, I thought it would be useful to assemble them into a single child theme. You can see the <a href="https://github.com/ReveWeber/fancyfifteen">Fancy Fifteen code on GitHub</a>, or look at <a href="https://www.rweber.net/tag/fancyfifteen/">all posts here tagged fancyfifteen</a>.</p>
<p><center><a href="https://www.rweber.net/wp-content/uploads/2015/04/galleryscreenshot.png"><img loading="lazy" decoding="async" src="https://www.rweber.net/wp-content/uploads/2015/04/galleryscreenshot-300x243.png" alt="screenshot of finished gallery" width="300" height="243" class="alignnone size-medium wp-image-38269" srcset="https://www.rweber.net/wp-content/uploads/2015/04/galleryscreenshot-300x243.png 300w, https://www.rweber.net/wp-content/uploads/2015/04/galleryscreenshot.png 749w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a> <a href="https://www.rweber.net/wp-content/uploads/2015/04/galleryscreenshot2.png"><img loading="lazy" decoding="async" src="https://www.rweber.net/wp-content/uploads/2015/04/galleryscreenshot2-300x243.png" alt="screenshot of finished gallery" width="300" height="243" class="alignnone size-medium wp-image-38271" srcset="https://www.rweber.net/wp-content/uploads/2015/04/galleryscreenshot2-300x243.png 300w, https://www.rweber.net/wp-content/uploads/2015/04/galleryscreenshot2.png 749w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a></center></p>
<p>Here&#8217;s a pair of screenshots. You can&#8217;t tell in this because I didn&#8217;t make a ton of categories, but the menu will also drop over the photos. Again, at least for the time being, you can see and interact with this <a href="http://rweber.net/test_site/wordpress/gallery/">on my testing site</a>.</p>
<p>All three steps are actually handled in one short jQuery-reliant JavaScript file.</p>
<p>Call it gallery-menu.js, put the following into it, and save it in your child theme folder:</p>
<p><script src="https://pastebin.com/embed_js.php?i=Ed76FGUa"></script></p>
<p>Line 2 is sort of pre-Step-1. It&#8217;s for graceful degradation &#8211; it adds a class so we can style the menu and gallery separately depending on whether JavaScript is enabled or not.<br />
Lines 3-6 control Step 1. They hide the menu to begin with and activate the button to show and hide it.</p>
<p>The rest is Steps 2 and 3. If you click a link within the menu, JS swoops in and stops the browser from following it (line 9). Then we construct the relevant piece of the desired URL from the link, using the data-slug attribute we added into the PHP last time, and furthermore tack on the specific div that holds the images (lines 10-11). Line 12 does the AJAX, Line 13 re-hides the menu as it would be were the page reloaded, and Line 14 pushes the new URL into the browser history.</p>
<p>And this is why hearts fly out of my eyes sometimes when I work with jQuery.</p>
<p><b>Edit 3 May:</b> To get my lightbox plugin to apply to this gallery I had use JS to add a rel attribute to each link. The AJAX &#8211; or maybe simply do_shortcode &#8211; seemed to prevent the automatic application of the lightbox to the image links (which wasn&#8217;t the case with the <a href="https://www.rweber.net/web-development/css/gilding-the-gallery-mla-flickity/">Flickity slideshow</a>). What you need will depend on what plugin you use, of course, but for WP Lightbox 2 I had to add <code>$( '#current-album a' ).attr( 'rel', 'lightbox[album]' );</code> at line 7 and as a post-AJAX function to the .load call (see my <a href="https://www.rweber.net/web-development/javascript/things-ive-relearned-recently/">notes on .load syntax</a>).</p>
<h2>Are we there yet?</h2>
<p>Of course not. We have bonus steps to this part of the program as well.</p>
<p>Tack this onto the end of your functions.php file:</p>
<p><script src="https://pastebin.com/embed_js.php?i=wiDHVLXc"></script></p>
<p>Insert this CSS just before the media queries in style.css:</p>
<p><iframe src="https://pastebin.com/embed_iframe.php?i=3zCz2PzY" style="height:305px;border:none;width:100%"></iframe></p>
<p>And finally, insert this CSS inside the max-width: 43.75em media query (not the portrait one):</p>
<p><script src="https://pastebin.com/embed_js.php?i=50PtnmKC"></script></p>
<p>The styling could be way better, so play with it till you lose your mind.</p>
<p>The post <a href="https://www.rweber.net/javascript/gilding-the-gallery-3-ajaxifying-the-filterable-gallery/">Gilding the Gallery 3: Ajaxifying the filterable gallery</a> appeared first on <a href="https://www.rweber.net">rweber.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.rweber.net/javascript/gilding-the-gallery-3-ajaxifying-the-filterable-gallery/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">38038</post-id>	</item>
		<item>
		<title>Things I&#8217;ve (re)learned recently</title>
		<link>https://www.rweber.net/developer-toolbox/things-ive-relearned-recently/</link>
					<comments>https://www.rweber.net/developer-toolbox/things-ive-relearned-recently/#respond</comments>
		
		<dc:creator><![CDATA[Rebecca]]></dc:creator>
		<pubDate>Mon, 06 Apr 2015 12:00:47 +0000</pubDate>
				<category><![CDATA[Developer Toolbox]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">http://www.rweber.net/?p=38030</guid>

					<description><![CDATA[<div><img width="300" height="225" src="https://www.rweber.net/wp-content/uploads/2015/04/John_Steuart_Curry_-_Ajax_-_Smithsonian-300x225.jpg" class="attachment-medium size-medium wp-post-image" alt="painting by John Steuart Curry titled Ajax" style="float:left; margin-right:16px; margin-bottom:16px;" decoding="async" loading="lazy" srcset="https://www.rweber.net/wp-content/uploads/2015/04/John_Steuart_Curry_-_Ajax_-_Smithsonian-300x225.jpg 300w, https://www.rweber.net/wp-content/uploads/2015/04/John_Steuart_Curry_-_Ajax_-_Smithsonian-768x575.jpg 768w, https://www.rweber.net/wp-content/uploads/2015/04/John_Steuart_Curry_-_Ajax_-_Smithsonian.jpg 1024w, https://www.rweber.net/wp-content/uploads/2015/04/John_Steuart_Curry_-_Ajax_-_Smithsonian-150x112.jpg 150w" sizes="auto, (max-width: 300px) 100vw, 300px" /></div>
<p>Miscellaneous little things that came up while I was working on the Flickety/MLA filterable gallery. The plurality are about jQuery's AJAX command $.load().</p>
<p>The post <a href="https://www.rweber.net/developer-toolbox/things-ive-relearned-recently/">Things I&#8217;ve (re)learned recently</a> appeared first on <a href="https://www.rweber.net">rweber.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div><img width="300" height="225" src="https://www.rweber.net/wp-content/uploads/2015/04/John_Steuart_Curry_-_Ajax_-_Smithsonian-300x225.jpg" class="attachment-medium size-medium wp-post-image" alt="painting by John Steuart Curry titled Ajax" style="float:left; margin-right:16px; margin-bottom:16px;" decoding="async" loading="lazy" srcset="https://www.rweber.net/wp-content/uploads/2015/04/John_Steuart_Curry_-_Ajax_-_Smithsonian-300x225.jpg 300w, https://www.rweber.net/wp-content/uploads/2015/04/John_Steuart_Curry_-_Ajax_-_Smithsonian-768x575.jpg 768w, https://www.rweber.net/wp-content/uploads/2015/04/John_Steuart_Curry_-_Ajax_-_Smithsonian.jpg 1024w, https://www.rweber.net/wp-content/uploads/2015/04/John_Steuart_Curry_-_Ajax_-_Smithsonian-150x112.jpg 150w" sizes="auto, (max-width: 300px) 100vw, 300px" /></div><p>Working on the filterable gallery I mentioned in the <a href="https://www.rweber.net/web-development/css/gilding-the-gallery-mla-flickity/">Flickity/MLA carousel post</a>, there were a lot of little things I had to look up or work out by trial and error, some of which were ultimately quite simple but took a while to figure out. I want to lay them out for future reference, my own and potentially that of readers of the (forthcoming) post(s) about the gallery itself.</p>
<ul>
<li>If something that&#8217;s supposed to be clickable only works on part of its area, such as a div where only the bottom half is clickable, check for overhang. You can&#8217;t click through another div even if it&#8217;s empty.</li>
<li>String concatenation: . for PHP, + for JavaScript.</li>
<li>$.load puts the second thing into the first thing: $( &#8216;#wrapper&#8217; ).load( &#8216;source-page.php #contents&#8217; ), not $( &#8216;#contents&#8217; ).load( &#8216;source-page.php #contents&#8217; ). The latter will result in two divs with the id &#8216;contents&#8217;. This of course means you have to build your page with a wrapper div.</li>
<li>$.load seems to require that the function to run after loading completes be an anonymous one. Putting in a named function doesn&#8217;t necessarily work (I found sometimes it did and sometimes it didn&#8217;t). That is, not $.load( &#8216;source.php&#8217;, setup() ); but instead $.load( &#8216;source.php&#8217;, function() { setup(); });</li>
<li>If all you want is to add or change a query string (that is, &#8216;?attr=value&#8217;) on the current URL, $.load() needs only the query string itself. If you give it the page slug also, WordPress will show you the correct page, but the slug will be doubled in the URL. The same goes for window.history.pushState();</li>
<li>Using WordPress&#8217;s get_terms to access a taxonomy nets you an array of objects. The PHP syntax to access pieces of an array is completely different than the syntax used to access pieces of an object. Remember that and things will work better.</li>
<li>You can add whatever information you want to an anchor element by adding a data attribute; syntax is <code>&lt;a href="..." data-slug="..."></code>, where &#8220;slug&#8221; would be whatever the kind of data is in your application.</li>
</ul>
<p><small>John Steuart Curry&#8217;s painting <em>Ajax</em> via <a href="https://en.wikipedia.org/wiki/John_Steuart_Curry#/media/File:John_Steuart_Curry_-_Ajax_-_Smithsonian.jpg">Wikimedia Commons</a>.</small></p>
<p>The post <a href="https://www.rweber.net/developer-toolbox/things-ive-relearned-recently/">Things I&#8217;ve (re)learned recently</a> appeared first on <a href="https://www.rweber.net">rweber.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.rweber.net/developer-toolbox/things-ive-relearned-recently/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">38030</post-id>	</item>
		<item>
		<title>Gilding the Gallery: MLA + Flickity</title>
		<link>https://www.rweber.net/javascript/gilding-the-gallery-mla-flickity/</link>
					<comments>https://www.rweber.net/javascript/gilding-the-gallery-mla-flickity/#respond</comments>
		
		<dc:creator><![CDATA[Rebecca]]></dc:creator>
		<pubDate>Mon, 23 Mar 2015 12:00:24 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP and MySQL]]></category>
		<category><![CDATA[Fancy Fifteen]]></category>
		<category><![CDATA[Flickity]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[portfolio]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress gallery]]></category>
		<guid isPermaLink="false">http://www.rweber.net/?p=37349</guid>

					<description><![CDATA[<p>Applying the JavaScript carousel program Flickity to a WordPress gallery, or more properly a Media Library Assistant gallery, for responsiveness and easy updating.</p>
<p>The post <a href="https://www.rweber.net/javascript/gilding-the-gallery-mla-flickity/">Gilding the Gallery: MLA + Flickity</a> appeared first on <a href="https://www.rweber.net">rweber.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I&#8217;ve done a lot of looking at gallery/slider/carousel plugins for WordPress, and haven&#8217;t been terribly enthusiastic about the selection. Very few interface directly with the WP Media Library, for instance, or allow easy categorization/photo album structure, and the responsiveness situation isn&#8217;t inspiring. Time to roll my own.</p>
<p><b>Edit:</b> Since I have made so many additions to Twenty Fifteen, I thought it would be useful to assemble them into a single child theme. You can see the <a href="https://github.com/ReveWeber/fancyfifteen">Fancy Fifteen code on GitHub</a>, or look at <a href="https://www.rweber.net/tag/fancyfifteen/">all posts here tagged fancyfifteen</a>.</p>
<p><a href="https://www.rweber.net/wp-content/uploads/2015/03/gallery-screenshot.png"><img loading="lazy" decoding="async" src="https://www.rweber.net/wp-content/uploads/2015/03/gallery-screenshot.png" alt="screenshot of carousel built with flickity.js and the WordPress plugin Media Library Assistant" width="792" height="468" class="aligncenter size-full wp-image-37466" srcset="https://www.rweber.net/wp-content/uploads/2015/03/gallery-screenshot.png 792w, https://www.rweber.net/wp-content/uploads/2015/03/gallery-screenshot-300x177.png 300w" sizes="auto, (max-width: 792px) 100vw, 792px" /></a></p>
<p>The goal here: a front page carousel that could be easily updated, with just half a dozen or so selections from the most recent images added to the site. The pictures would be human-chosen. The carousel needed to be responsive and easy to navigate (for everyone; i.e., accessible), and ideally the whole shebang could coordinate with a filterable photo gallery to be created for the same site.</p>
<p>Enter <a href="https://wordpress.org/plugins/media-library-assistant/">Media Library Assistant</a>. There are two functions of MLA that are important for this use: the addition of taxonomies to media library items directly, and the expansion of WordPress&#8217;s gallery shortcode into mla-gallery, with dynamic selection of media items by taxonomy, user-defined templates (as in direct control of the gallery&#8217;s HTML structure), and many other settings.</p>
<p>I figured I could apply a nice jQuery carousel to an MLA gallery of the correct form, and after looking around, <a href="http://flickity.metafizzy.co/">Flickity</a> seemed like the best candidate (with the implicit recommendation of <a href="https://css-tricks.com/creating-responsive-touch-friendly-carousels-with-flickity/">CSS-Tricks</a>). It is responsive, accessible, well-adapted to mouse/trackpad, keyboard, and touch, and styleable from the theme&#8217;s CSS file. After one significant (but easily remedied) hiccup we were in business!</p>
<p>Here&#8217;s how to set it up. There are some places where I made arbitrary decisions (such as downloading flickity.css but using a CDN for the .js file), but it should be easy to figure out how to make different ones.</p>
<p>For specificity, we&#8217;ll make a child theme to add this functionality to Twenty Fifteen. For now you can see this on my <a href="http://rweber.net/test_site/wordpress/carousel-page/">WordPress test site</a> but there is no guarantee that will continue to be true indefinitely.</p>
<p>style.css:<br />
<script src="https://pastebin.com/embed_js.php?i=DJhJRCEi"></script></p>
<p>Many themes set max-width: 100% on images for responsiveness purposes; it keeps them from exploding out of their housings when the browser gets smaller. However, you have to override it here or the images you can&#8217;t originally see may collapse to width 0. That was the hiccup I referred to &#8211; why is there blank white space when I click through the carousel?!? The last section highlights the gallery if you tab to it so you know you&#8217;ve tabbed to it; it&#8217;s straight off the Flickity website. I set a height of 200px; you can let it be determined by the images by removing that line of CSS and the line setGallerySize: false in carousel.js, below.</p>
<p>carousel.js:<br />
<script src="https://pastebin.com/embed_js.php?i=DzbT6BGc"></script></p>
<p>functions.php:<br />
<script src="https://pastebin.com/embed_js.php?i=PPeeD1LA"></script></p>
<p>Just put flickity.css, carousel.js, functions.php, and style.css (for your child theme) all into a folder called twenty-fifteen-flickity, zip it up, and upload it.</p>
<p>In Settings -> Media Library Assistant -> MLA Gallery (the middle tab), scroll to the bottom and create a template called carousel. Fill in the following boxes:<br />
Open: <code>&lt;div id='carousel-gallery' class='carousel-no-js'></code><br />
Item: <code>&lt;div class='carousel-item'><br />
	[+link+]<br />
&lt;/div></code><br />
Close: <code>&lt;/div></code></p>
<p>In Media -> Assistant, tag all images for the slideshow with &#8220;featured&#8221; (or something else, and then change &#8220;featured&#8221; in the shortcode below).<br />
Where you want the carousel, place the shortcode<br />
<code>[mla_gallery attachment_tag=featured mla_style="none" mla_markup="carousel" size=medium link=full]</code></p>
<p>Some notes:<br />
&#8211; Most everything is adjustable from the CSS file, the MLA shortcode options, or the Flickity options.<br />
&#8211; You&#8217;ll have to add appropriate styling for responsiveness, but no differently from usual.<br />
&#8211; For graceful degradation the images start with the class carousel-no-js and carousel.js replaces that with carousel-js-on; I haven&#8217;t styled .carousel-no-js at all and wouldn&#8217;t count this as finished without doing so, but how to style it is a matter of taste.<br />
&#8211; I threw a lightbox plugin onto the test site as well (Responsive Lightbox by dfactory) and it works without a squawk.</p>
<p>The post <a href="https://www.rweber.net/javascript/gilding-the-gallery-mla-flickity/">Gilding the Gallery: MLA + Flickity</a> appeared first on <a href="https://www.rweber.net">rweber.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.rweber.net/javascript/gilding-the-gallery-mla-flickity/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">37349</post-id>	</item>
	</channel>
</rss>
