<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Css on Damian Galarza | Software Engineering &amp; AI Consulting</title><link>https://www.damiangalarza.com/tags/css/</link><description>Recent posts from Damian Galarza | Software Engineering &amp; AI Consulting</description><generator>Hugo</generator><language>en-us</language><managingEditor>Damian Galarza</managingEditor><atom:link href="https://www.damiangalarza.com/tags/css/feed.xml" rel="self" type="application/rss+xml"/><item><title>CSS3 Transition Idiom</title><link>https://www.damiangalarza.com/posts/2012-04-02-css3-transition-idiom/</link><pubDate>Mon, 02 Apr 2012 02:58:25 +0000</pubDate><author>Damian Galarza</author><guid>https://www.damiangalarza.com/posts/2012-04-02-css3-transition-idiom/</guid><content:encoded><![CDATA[<p>As more browsers are starting to support CSS3 transitions I&rsquo;ve found myself trying to take advantage of their
availability more and more. The issue often that comes with this the fact that many times, we need to support
transitions in browsers which do not support them through JavaScript. While some people question the
extra work being performed in order to get CSS transitions working, I feel that the effort isn&rsquo;t as great as it seems.  The benefits of using CSS transitions are great and I feel the effort is well worth it.</p>
<ul>
<li><strong>Smoother Experience</strong> CSS transitions offer a smoother experience when compared to JavaScript animations. Since everything is being handled natively by the browser engine, we can get much smoother transitions.</li>
<li><strong>Mobile Performance</strong> This subcategory to the first note. While CSS transitions will most always provide a smoother experience in regular browsers, mobile devices will benefit from this the most. Since mobile devices lack the power that our desktops have, taking advantage of the browser engine for transitions is a must.</li>
</ul>
<h2 id="gracefully-degrading">Gracefully Degrading</h2>
<p>In most cases front end developers will err on the side of progressive enhancement. That is, to provide users who support newer technologies an experience with these technologies and user&rsquo;s who do not support it
will be left behind, in a usable state just without the bells and whistles. I consider this following method to be graceful degradation instead. The reason behind this is that we will not be removing the transition effects
all together from the page, but rather the method that we are using to apply the transition will be different, degrading to JavaScript animations when CSS transitions are not available (More on this later).</p>
<h3 id="detecting-our-features">Detecting our features</h3>
<p>Moving forward with our graceful degradation, we must determine how to apply the transition effect for the user. This should almost never be done via browser agent detection but rather through feature detection. Instead of only serving
CSS transitions to certain versions of a browser we should instead detect whether or not the user supports our feature, in this case, CSS transitions. This can be done through JavaScript early on before trying to transition. One option is to
use the open source JavaScript library <a href="http://www.modernizr.com/">Modernizr</a>. Modernizr will detect the HTML5 and CSS3 features that the browser has and you have the option to populate your HTML tag with classes which describe support. Along with these CSS classes,
a Modernizr object is created which you can check with JavaScript to see features that are supported. Modernizr even supports the ability for you to customize the features it detects. If you plan on using a lot of feature detection, then I highly recommend using
Modernizr.</p>
<p>However, in some cases you may not need all of the features that Modernizr provides and it would be wasteful to add the bloat it provides or we simply may not be able to add Modernizr to our page. In this case we can detect features ourselves. For our transitions example we will need to detect whether or not a CSS3 property is available in the user&rsquo;s browser.  Since as of this writing the transition property is prefixed by the vendor we will need to run through and check each vendor prefix version of the transition property to see if the users&rsquo; browser supports it or not.</p>
<div class="highlight"><pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic">// Check for CSS3 Transition Support
</span></span></span><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic"></span><span style="color:#f38ba8">var</span> doc <span style="color:#89dceb;font-weight:bold">=</span> <span style="color:#89dceb">document</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f38ba8">var</span> css_transitions <span style="color:#89dceb;font-weight:bold">=</span> <span style="color:#f38ba8">function</span>() {
</span></span><span style="display:flex;"><span>    <span style="color:#f38ba8">var</span> el <span style="color:#89dceb;font-weight:bold">=</span> doc.createElement(<span style="color:#a6e3a1">&#39;div&#39;</span>);
</span></span><span style="display:flex;"><span>    <span style="color:#f38ba8">var</span> vendors <span style="color:#89dceb;font-weight:bold">=</span> [<span style="color:#a6e3a1">&#39;&#39;</span>, <span style="color:#a6e3a1">&#39;Khtml&#39;</span>, <span style="color:#a6e3a1">&#39;Ms&#39;</span>, <span style="color:#a6e3a1">&#39;Moz&#39;</span>,<span style="color:#a6e3a1">&#39; Webkit&#39;</span>,<span style="color:#a6e3a1">&#39;O&#39;</span>];
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#cba6f7">for</span> (<span style="color:#f38ba8">var</span> i <span style="color:#89dceb;font-weight:bold">=</span> <span style="color:#fab387">0</span>, len <span style="color:#89dceb;font-weight:bold">=</span> vendors.length; i <span style="color:#89dceb;font-weight:bold">&lt;</span> len; i<span style="color:#89dceb;font-weight:bold">++</span>) {
</span></span><span style="display:flex;"><span>        <span style="color:#f38ba8">var</span> prop <span style="color:#89dceb;font-weight:bold">=</span> vendors[i] <span style="color:#89dceb;font-weight:bold">+</span> <span style="color:#a6e3a1">&#39;Transition&#39;</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#cba6f7">if</span> (prop <span style="color:#cba6f7">in</span> el.style) <span style="color:#cba6f7">return</span> <span style="color:#fab387">true</span>;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#cba6f7">return</span> <span style="color:#fab387">false</span>;
</span></span><span style="display:flex;"><span>}();
</span></span></code></pre></div><p>First, we create a test element in memory to test against. Then we create an array of vendor prefixes <code>['', 'Khtml', 'Ms', 'Moz', 'Webkit', 'O']</code>. Note that our first entry is a blank string. This is so that when browsers have fully implemented the transition spec and vendor prefixes are no longer used, we detect the feature correctly. Now we loop through the array. For each iteration we create a property to test which is a combination of the vendor prefix and our base property, in this case Transition. So for example. we will test <code>MozTransition</code>.
We test to see if the property exists as part of the test elements style property. If this comes back true, then our browser supports CSS transitions. In the case of our example we execute our function immediately and store the result in a variable called <code>css_transitions</code>.</p>
<h3 id="putting-our-css_transitions-variable-to-use">Putting our css_transitions variable to use</h3>
<p>Now that we&rsquo;ve determined whether or not the user&rsquo;s browser supports CSS transitions we need to go put it to work. In this case, let&rsquo;s transition the opacity of an element:</p>
<div class="highlight"><pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>&lt;<span style="color:#cba6f7">style</span> <span style="color:#89b4fa">type</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;text/css&#34;</span>&gt;
</span></span><span style="display:flex;"><span>    .<span style="color:#f9e2af">transition-me</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#cba6f7">-o-</span><span style="color:#f38ba8">transition(opacity</span> <span style="color:#f38ba8">0.25s</span> <span style="color:#f38ba8">linear</span> <span style="color:#f38ba8">0s)</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#cba6f7">-moz-</span><span style="color:#f38ba8">transition(opacity</span> <span style="color:#f38ba8">0.25s</span> <span style="color:#f38ba8">linear</span> <span style="color:#f38ba8">0s)</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#cba6f7">-webkit-</span><span style="color:#f38ba8">transition(opacity</span> <span style="color:#f38ba8">0.25s</span> <span style="color:#f38ba8">linear</span> <span style="color:#f38ba8">0s)</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#cba6f7">-ms-</span><span style="color:#f38ba8">transition(opacity</span> <span style="color:#f38ba8">0.25s</span> <span style="color:#f38ba8">linear</span> <span style="color:#f38ba8">0s)</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#f38ba8">transition(opacity</span> <span style="color:#f38ba8">0.25s</span> <span style="color:#f38ba8">linear</span> <span style="color:#f38ba8">0s)</span>;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>&lt;/<span style="color:#cba6f7">style</span>&gt;
</span></span></code></pre></div><p>In this example we will use jQuery which provides us with a rather handy syntax for changing CSS properties on an element or calling an animation on an element.  The syntax for each
actually matches exactly when used which allows us to use a pretty simple idiom to transition with.</p>
<div class="highlight"><pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic">// Fade out .transition-me elements
</span></span></span><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic"></span><span style="color:#f38ba8">var</span> method <span style="color:#89dceb;font-weight:bold">=</span> (css_transitions) <span style="color:#89dceb;font-weight:bold">?</span> <span style="color:#a6e3a1">&#39;css&#39;</span> <span style="color:#89dceb;font-weight:bold">:</span> <span style="color:#a6e3a1">&#39;method&#39;</span>;
</span></span><span style="display:flex;"><span>$(<span style="color:#a6e3a1">&#39;.transition-me&#39;</span>)[method]({
</span></span><span style="display:flex;"><span>    opacity<span style="color:#89dceb;font-weight:bold">:</span> <span style="color:#fab387">0</span>
</span></span><span style="display:flex;"><span>});
</span></span></code></pre></div><p>If you visit the jQuery documentation both the <a href="http://api.jquery.com/css/">css</a> and <a href="http://api.jquery.com/animate/">animate</a> support a map syntax which allows us to send an object to the
method call with a property we want to transition as the key and the value to transition to as the value. With this in mind, we can simply call the appropriate method (css or transition) on
the element we want to transition.</p>
<h2 id="a-note-on-progressive-enhancement">A note on Progressive Enhancement</h2>
<p>While this particular post discusses how to apply graceful degradation to CSS transitions there is still room for some progressive enhancement. What I mean by this is there are certain times where
a transition or animation is key to the user&rsquo;s experience. Transitions help guide the user through changes on the page. There are times however where transitions are just applied to add a certain level
of eye candy. It is this class of transition that I would simply not provide in browsers which do not support it since they are not key to the user&rsquo;s experience with the page.</p>
]]></content:encoded></item><item><title>Bringing back the image map</title><link>https://www.damiangalarza.com/posts/2010-12-27-bringing-back-the-image-map/</link><pubDate>Mon, 27 Dec 2010 18:34:59 +0000</pubDate><author>Damian Galarza</author><guid>https://www.damiangalarza.com/posts/2010-12-27-bringing-back-the-image-map/</guid><content:encoded><![CDATA[<p>I&rsquo;ve just finished working with an image map for the first time in a while. Now, you may be thinking, &ldquo;Why in the world would anyone want to touch an image map?&rdquo;, but they still do serve a purpose. Image maps are still in fact part of the <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-map-element.html#image-map">HTML5 specification</a>.</p>
<h3 id="case-study">Case Study</h3>
<p>So why the image map? Take a look at the following image:</p>
<p><img src="/images/map-case-study.gif" alt="Case Study"></p>
<p>So our image above is triangular, and is intended to be clickable.  The expectation is that only the triangular area should be clickable. So in order to accomplish this, I&rsquo;ve decided to move forward with using an image map.</p>
<p>Things get a bit more complicated, though. The image above is actually repeated many times on a page. It acts as a flag to being a favorite of sorts. Furthermore, we are not simply sending the user to a page link, we are looking to use JavaScript events on the image map (and unobtrusively at that). This unobtrusive JavaScript must send an ajax request to the server depending on which instance of the image is actually being clicked. So we have our work cut out for us.</p>
<h3 id="setting-up-the-image-map">Setting up the image map</h3>
<p>Getting the image map set up is pretty simple. Let&rsquo;s start with defining the map:</p>
<div class="highlight"><pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>&lt;<span style="color:#cba6f7">map</span> <span style="color:#89b4fa">name</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;my-map&#34;</span>&gt;
</span></span><span style="display:flex;"><span>    &lt;<span style="color:#cba6f7">area</span> <span style="color:#89b4fa">id</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;fav-area&#34;</span> <span style="color:#89b4fa">shape</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">poly,</span> <span style="color:#89b4fa">coords</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;0,0, 46,0, 46,46&#34;</span> <span style="color:#89b4fa">href</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;#fav&#34;</span>&gt; 
</span></span><span style="display:flex;"><span>&lt;/<span style="color:#cba6f7">map</span>&gt;
</span></span></code></pre></div><p>We&rsquo;ve defined a map named <code>my-map</code> with some coordinates. Note our shape is set to poly and the coordinates provided. In order to determine these coordinates I simply opened up Photoshop and grabbed the x and y coordinates of the 3 corners of the triangle. Along with that, since we have no intent on passing the user to an actual link we&rsquo;ve provided a dummy hash on the href.</p>
<h3 id="setting-up-the-image">Setting up the image</h3>
<p>So now the the map is defined we&rsquo;ll create an instance of the image and have it use the map we made:</p>
<div class="highlight"><pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>&lt;<span style="color:#cba6f7">img</span> <span style="color:#89b4fa">src</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;/images/map-case-study.gif&#34;</span> <span style="color:#89b4fa">usemap</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;#my-map&#34;</span>&gt;
</span></span></code></pre></div><h3 id="adding-an-event-handler">Adding an event handler</h3>
<p>Adding an event handler is pretty straight forward as you might expect. I&rsquo;ll be using jQuery for the demonstration.</p>
<div class="highlight"><pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span>$(<span style="color:#f38ba8">function</span>() {
</span></span><span style="display:flex;"><span>	$(<span style="color:#a6e3a1">&#39;map[name=my-map] #fave-area&#39;</span>).click(<span style="color:#f38ba8">function</span> (e) {
</span></span><span style="display:flex;"><span>		e.preventDefault();
</span></span><span style="display:flex;"><span>		alert(<span style="color:#a6e3a1">&#39;Clicked!&#39;</span>);
</span></span><span style="display:flex;"><span>	});
</span></span><span style="display:flex;"><span>});
</span></span></code></pre></div><p>So we can still target and add an event as you normally would to the area.</p>
<h3 id="multiple-instances-of-the-same-image-and-image-map">Multiple instances of the same image and image map</h3>
<p>Now that we have our image map set up, let&rsquo;s move forward with the more complicated setup.  Take the HTML structure below:</p>
<div class="highlight"><pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>&lt;<span style="color:#cba6f7">div</span> <span style="color:#89b4fa">id</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;node-1&#34;</span> <span style="color:#89b4fa">class</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;my-node&#34;</span>&gt;
</span></span><span style="display:flex;"><span>	&lt;<span style="color:#cba6f7">img</span> <span style="color:#89b4fa">id</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;study-1&#34;</span> <span style="color:#89b4fa">src</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;/images/map-case-study.gif&#34;</span> <span style="color:#89b4fa">usemap</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;#my-map&#34;</span>&gt;
</span></span><span style="display:flex;"><span>&lt;/<span style="color:#cba6f7">div</span>&gt;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>&lt;<span style="color:#cba6f7">div</span> <span style="color:#89b4fa">id</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;node-2&#34;</span> <span style="color:#89b4fa">class</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;my-node&#34;</span>&gt;
</span></span><span style="display:flex;"><span>	&lt;<span style="color:#cba6f7">img</span> <span style="color:#89b4fa">id</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;study-2&#34;</span> <span style="color:#89b4fa">src</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;/images/map-case-study.gif&#34;</span> <span style="color:#89b4fa">usemap</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;#my-map&#34;</span>&gt;
</span></span><span style="display:flex;"><span>&lt;/<span style="color:#cba6f7">div</span>&gt;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>&lt;<span style="color:#cba6f7">div</span> <span style="color:#89b4fa">id</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;node-3&#34;</span> <span style="color:#89b4fa">class</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;my-node&#34;</span>&gt;
</span></span><span style="display:flex;"><span>	&lt;<span style="color:#cba6f7">img</span> <span style="color:#89b4fa">id</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;study-3&#34;</span> <span style="color:#89b4fa">src</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;/images/map-case-study.gif&#34;</span> <span style="color:#89b4fa">usemap</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;#my-map&#34;</span>&gt;
</span></span><span style="display:flex;"><span>&lt;/<span style="color:#cba6f7">div</span>&gt;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>&lt;<span style="color:#cba6f7">map</span> <span style="color:#89b4fa">name</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;my-map&#34;</span>&gt;
</span></span><span style="display:flex;"><span>	&lt;<span style="color:#cba6f7">area</span> <span style="color:#89b4fa">id</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;fav-area&#34;</span> <span style="color:#89b4fa">shape</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">poly,</span> <span style="color:#89b4fa">coords</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;0,0, 46,0, 46,46&#34;</span> <span style="color:#89b4fa">href</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;#fav&#34;</span>&gt;
</span></span><span style="display:flex;"><span>&lt;/<span style="color:#cba6f7">map</span>&gt;
</span></span></code></pre></div><p>We have multiple nodes which aim to make use of the same case-study image and they all use the same image map to define the clickable area. Now the problem is, how do we determine which image was actually clicked?</p>
<p>Well first, we can make use of a DOM method called <code>elementFromPoint</code>. This method allows you to pass in x and y coordinates and retrieve the element that is found at the given coordinates. I never knew that this method existed until today and it&rsquo;s a pretty interesting find.</p>
<h3 id="putting-elementfrompoint-to-use">Putting elementFromPoint to use</h3>
<div class="highlight"><pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span>$(<span style="color:#f38ba8">function</span>() {
</span></span><span style="display:flex;"><span>	$(<span style="color:#a6e3a1">&#39;map[name=my-map] #fave-area&#39;</span>).click(<span style="color:#f38ba8">function</span> (e) {
</span></span><span style="display:flex;"><span>		e.preventDefault();
</span></span><span style="display:flex;"><span>		<span style="color:#f38ba8">var</span> trigger <span style="color:#89dceb;font-weight:bold">=</span> <span style="color:#89dceb">document</span>.elementFromPoint(e.clientX, e.clientY);
</span></span><span style="display:flex;"><span>		alert(trigger.id);
</span></span><span style="display:flex;"><span>	});
</span></span><span style="display:flex;"><span>});
</span></span></code></pre></div><p>So we take the coordinates of the actual click event and pass it to the elementFromPoint function to grab the actual element the user was trying to click.  One problem still exists though: This works fine in Firefox and Safari but Chrome (and IE as some have reported) will still return the map area when using elementFromPoint.  In order to counter this, I&rsquo;ve found that disabling the image map before running elementFromPoint will then yield our expected element. Of course, once we&rsquo;re done finding the element we must re-enable the image map.</p>
<p>So how do we do this? Take a look at the final JavaScript:</p>
<div class="highlight"><pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span>$(<span style="color:#f38ba8">function</span>() {
</span></span><span style="display:flex;"><span>	$(<span style="color:#a6e3a1">&#39;map[name=my-map] #fave-area&#39;</span>).click(<span style="color:#f38ba8">function</span> (e) {
</span></span><span style="display:flex;"><span>		e.preventDefault();
</span></span><span style="display:flex;"><span>		
</span></span><span style="display:flex;"><span>		<span style="color:#6c7086;font-style:italic">// Cache all instances of the image
</span></span></span><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic"></span>		<span style="color:#f38ba8">var</span> $all_instances <span style="color:#89dceb;font-weight:bold">=</span> $(<span style="color:#a6e3a1">&#39;.my-node img&#39;</span>);
</span></span><span style="display:flex;"><span>		
</span></span><span style="display:flex;"><span>		<span style="color:#6c7086;font-style:italic">// Store the usemap in order to re-enable later
</span></span></span><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic"></span>		<span style="color:#f38ba8">var</span> usemap <span style="color:#89dceb;font-weight:bold">=</span> $all_instances.attr(<span style="color:#a6e3a1">&#39;usemap&#39;</span>);
</span></span><span style="display:flex;"><span>		
</span></span><span style="display:flex;"><span>		<span style="color:#6c7086;font-style:italic">// Reset the use of an image map on all instances of it
</span></span></span><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic"></span>		$all_instances.attr(<span style="color:#a6e3a1">&#39;usemap&#39;</span>, <span style="color:#a6e3a1">&#39;&#39;</span>);
</span></span><span style="display:flex;"><span>		
</span></span><span style="display:flex;"><span>		<span style="color:#6c7086;font-style:italic">// Grap the actual trigger we were looking for
</span></span></span><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic"></span>		<span style="color:#f38ba8">var</span> trigger <span style="color:#89dceb;font-weight:bold">=</span> <span style="color:#89dceb">document</span>.elementFromPoint(e.clientX, e.clientY);
</span></span><span style="display:flex;"><span>		
</span></span><span style="display:flex;"><span>		<span style="color:#6c7086;font-style:italic">// Re-enable the image map on all the instances we disabled it on
</span></span></span><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic"></span>		$all_instances.attr(<span style="color:#a6e3a1">&#39;usemap&#39;</span>, usemap);
</span></span><span style="display:flex;"><span>		
</span></span><span style="display:flex;"><span>		<span style="color:#6c7086;font-style:italic">// Do something useful with the information
</span></span></span><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic"></span>		alert(trigger.id);
</span></span><span style="display:flex;"><span>	});
</span></span><span style="display:flex;"><span>});
</span></span></code></pre></div>]]></content:encoded></item><item><title>CSS Gradient Definitions</title><link>https://www.damiangalarza.com/posts/2010-12-23-css-gradient-definitions/</link><pubDate>Thu, 23 Dec 2010 03:26:19 +0000</pubDate><author>Damian Galarza</author><guid>https://www.damiangalarza.com/posts/2010-12-23-css-gradient-definitions/</guid><content:encoded><![CDATA[<p>I&rsquo;ve just released an update to the <a href="http://gradients.glrzad.com">CSS3 Gradient Generator</a> which changes the way the code sample is generated for users to copy and paste.</p>
<p>The sample has moved to using the <code>background-image</code> property instead of the <code>background</code> property alone. This change has been made to resolve issues that occur when defining a background with the CSS based gradient but leaving out the other properties common to a background such as position or repeat.  When these attributes are left out, browsers define default values which can yield unexpected results with the CSS gradients.</p>
<p>So, the following:</p>
<div class="highlight"><pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"><code class="language-css" data-lang="css"><span style="display:flex;"><span><span style="color:#cba6f7">background</span><span style="color:#89dceb;font-weight:bold">:</span> <span style="color:#cba6f7">-webkit-gradient</span><span style="color:#89dceb;font-weight:bold">(</span>
</span></span><span style="display:flex;"><span>    <span style="color:#cba6f7">linear</span><span style="color:#89dceb;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#cba6f7">left</span> <span style="color:#cba6f7">bottom</span><span style="color:#89dceb;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#cba6f7">left</span> <span style="color:#cba6f7">top</span><span style="color:#89dceb;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#cba6f7">color-stop</span><span style="color:#89dceb;font-weight:bold">(</span><span style="color:#cba6f7">0</span>.<span style="color:#f9e2af">33</span><span style="color:#89dceb;font-weight:bold">,</span> <span style="color:#cba6f7">rgb</span><span style="color:#89dceb;font-weight:bold">(</span><span style="color:#cba6f7">99</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">168</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">125</span><span style="color:#89dceb;font-weight:bold">)),</span>
</span></span><span style="display:flex;"><span>    <span style="color:#cba6f7">color-stop</span><span style="color:#89dceb;font-weight:bold">(</span><span style="color:#cba6f7">0</span>.<span style="color:#f9e2af">67</span><span style="color:#89dceb;font-weight:bold">,</span> <span style="color:#cba6f7">rgb</span><span style="color:#89dceb;font-weight:bold">(</span><span style="color:#cba6f7">129</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">202</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">163</span><span style="color:#89dceb;font-weight:bold">)),</span>
</span></span><span style="display:flex;"><span>    <span style="color:#cba6f7">color-stop</span><span style="color:#89dceb;font-weight:bold">(</span><span style="color:#cba6f7">0</span>.<span style="color:#f9e2af">84</span><span style="color:#89dceb;font-weight:bold">,</span> <span style="color:#cba6f7">rgb</span><span style="color:#89dceb;font-weight:bold">(</span><span style="color:#cba6f7">155</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">243</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">196</span><span style="color:#89dceb;font-weight:bold">))</span>
</span></span><span style="display:flex;"><span><span style="color:#89dceb;font-weight:bold">);</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#cba6f7">background</span><span style="color:#89dceb;font-weight:bold">:</span> <span style="color:#cba6f7">-moz-linear-gradient</span><span style="color:#89dceb;font-weight:bold">(</span>
</span></span><span style="display:flex;"><span>    <span style="color:#cba6f7">center</span> <span style="color:#cba6f7">bottom</span><span style="color:#89dceb;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#cba6f7">rgb</span><span style="color:#89dceb;font-weight:bold">(</span><span style="color:#cba6f7">99</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">168</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">125</span><span style="color:#89dceb;font-weight:bold">)</span> <span style="color:#cba6f7">33</span><span style="color:#89dceb;font-weight:bold">%,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#cba6f7">rgb</span><span style="color:#89dceb;font-weight:bold">(</span><span style="color:#cba6f7">129</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">202</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">163</span><span style="color:#89dceb;font-weight:bold">)</span> <span style="color:#cba6f7">67</span><span style="color:#89dceb;font-weight:bold">%,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#cba6f7">rgb</span><span style="color:#89dceb;font-weight:bold">(</span><span style="color:#cba6f7">155</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">243</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">196</span><span style="color:#89dceb;font-weight:bold">)</span> <span style="color:#cba6f7">84</span><span style="color:#89dceb;font-weight:bold">%</span>
</span></span><span style="display:flex;"><span><span style="color:#89dceb;font-weight:bold">);</span>
</span></span></code></pre></div><p>Becomes,</p>
<div class="highlight"><pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"><code class="language-css" data-lang="css"><span style="display:flex;"><span><span style="color:#cba6f7">background-image</span><span style="color:#89dceb;font-weight:bold">:</span> <span style="color:#cba6f7">-webkit-gradient</span><span style="color:#89dceb;font-weight:bold">(</span>
</span></span><span style="display:flex;"><span>    <span style="color:#cba6f7">linear</span><span style="color:#89dceb;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#cba6f7">left</span> <span style="color:#cba6f7">bottom</span><span style="color:#89dceb;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#cba6f7">left</span> <span style="color:#cba6f7">top</span><span style="color:#89dceb;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#cba6f7">color-stop</span><span style="color:#89dceb;font-weight:bold">(</span><span style="color:#cba6f7">0</span>.<span style="color:#f9e2af">33</span><span style="color:#89dceb;font-weight:bold">,</span> <span style="color:#cba6f7">rgb</span><span style="color:#89dceb;font-weight:bold">(</span><span style="color:#cba6f7">99</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">168</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">125</span><span style="color:#89dceb;font-weight:bold">)),</span>
</span></span><span style="display:flex;"><span>    <span style="color:#cba6f7">color-stop</span><span style="color:#89dceb;font-weight:bold">(</span><span style="color:#cba6f7">0</span>.<span style="color:#f9e2af">67</span><span style="color:#89dceb;font-weight:bold">,</span> <span style="color:#cba6f7">rgb</span><span style="color:#89dceb;font-weight:bold">(</span><span style="color:#cba6f7">129</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">202</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">163</span><span style="color:#89dceb;font-weight:bold">)),</span>
</span></span><span style="display:flex;"><span>    <span style="color:#cba6f7">color-stop</span><span style="color:#89dceb;font-weight:bold">(</span><span style="color:#cba6f7">0</span>.<span style="color:#f9e2af">84</span><span style="color:#89dceb;font-weight:bold">,</span> <span style="color:#cba6f7">rgb</span><span style="color:#89dceb;font-weight:bold">(</span><span style="color:#cba6f7">155</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">243</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">196</span><span style="color:#89dceb;font-weight:bold">))</span>
</span></span><span style="display:flex;"><span><span style="color:#89dceb;font-weight:bold">);</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#cba6f7">background-image</span><span style="color:#89dceb;font-weight:bold">:</span> <span style="color:#cba6f7">-moz-linear-gradient</span><span style="color:#89dceb;font-weight:bold">(</span>
</span></span><span style="display:flex;"><span>    <span style="color:#cba6f7">center</span> <span style="color:#cba6f7">bottom</span><span style="color:#89dceb;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#cba6f7">rgb</span><span style="color:#89dceb;font-weight:bold">(</span><span style="color:#cba6f7">99</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">168</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">125</span><span style="color:#89dceb;font-weight:bold">)</span> <span style="color:#cba6f7">33</span><span style="color:#89dceb;font-weight:bold">%,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#cba6f7">rgb</span><span style="color:#89dceb;font-weight:bold">(</span><span style="color:#cba6f7">129</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">202</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">163</span><span style="color:#89dceb;font-weight:bold">)</span> <span style="color:#cba6f7">67</span><span style="color:#89dceb;font-weight:bold">%,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#cba6f7">rgb</span><span style="color:#89dceb;font-weight:bold">(</span><span style="color:#cba6f7">155</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">243</span><span style="color:#89dceb;font-weight:bold">,</span><span style="color:#cba6f7">196</span><span style="color:#89dceb;font-weight:bold">)</span> <span style="color:#cba6f7">84</span><span style="color:#89dceb;font-weight:bold">%</span>
</span></span><span style="display:flex;"><span><span style="color:#89dceb;font-weight:bold">);</span>
</span></span></code></pre></div><p>The live sample on the page also makes use of background-image as well, so you can view that as another reference to this update as well.</p>
<p>Thanks to Avi Mahbubani for pointing out the issue and helping come to a resolution.</p>
]]></content:encoded></item><item><title>Gradient Generator Updated</title><link>https://www.damiangalarza.com/posts/2010-12-04-gradient-generator-updated/</link><pubDate>Sat, 04 Dec 2010 00:00:00 -0500</pubDate><author>Damian Galarza</author><guid>https://www.damiangalarza.com/posts/2010-12-04-gradient-generator-updated/</guid><content:encoded><![CDATA[<p>Along with these changes the public github repository has been restructured. Only the important things (the JavaScript source of course) are up in the repo. Meaning, you can go ahead and browse it, fork it, learn how it works or use in your own project. Be warned that a lot of the code is pretty specific to the HTML structure of the actual gradients.glrzad.com website. It was never intended to be used as a plugin, though perhaps</p>
<p>Check out the changes live, <a href="http://gradients.glrzad.com" title="CSS3 Gradient Generator">visit the CSS3 Gradient Generator</a>.</p>
<h2 id="release-notes">Release Notes</h2>
<dl class="release-notes">
    <dt>Color Format Selection</dt>
    <dd>Color format selection: Choose how your colors are formatted, either RGB or HEX.</dd>
    <dd>The gradient generator will store your preference for the next time you visit!</dd>
<pre><code>&lt;dt&gt;Copy the code!&lt;/dt&gt;
&lt;dd&gt;Copies the output code to your clipboard for you so you can quickly grab your generated code.&lt;/dd&gt;

&lt;dt&gt;UI Updates&lt;/dt&gt;
&lt;dd&gt;Stripped down page to the core components of the gradient generator, moving it to the top of the fold.&lt;/dd&gt;
</code></pre>
</dl>
]]></content:encoded></item><item><title>CSS3 Webkit Gradient Generator</title><link>https://www.damiangalarza.com/posts/2009-09-14-css3-webkit-gradient-generator/</link><pubDate>Mon, 14 Sep 2009 00:22:32 +0000</pubDate><author>Damian Galarza</author><guid>https://www.damiangalarza.com/posts/2009-09-14-css3-webkit-gradient-generator/</guid><content:encoded><![CDATA[<p><a href="http://gradients.glrzad.com" title="Visit the generator">Visit the CSS3 Webkit Gradient Generator</a></p>
<p>CSS gradients are quite powerful and very useful, but when taking a first look at the markup for writing a code based gradient it can appear daunting.  This is why I&rsquo;ve decided to create the CSS3 Webkit Gradient Generator.   Please note that the generator is intended to be viewed in a webkit browser. Live sampling of the gradient will not be available without a webkit browser.</p>
<p>The gradient generator has 2 goals. The first is to provide a showcase for the power of CSS gradients. The second, is to provide a graphical user interface in which a user can visually create gradient code to use in their CSS where they see fit.  In order to do this, I tried to create a UI that appears familiar, such as that of a graphic editing tool like Adobe Photoshop.  Providing color swatches to make up the gradient and a slider for each to determine the color&rsquo;s position in the gradient.</p>
<p><img src="/posts/css3/css3-webkit-gradient-generator/color-swatch-ss.png" alt="Color Swatch Control" title="Color Swatch Control"></p>
<h3>Color Swatch Control</h3>
<p>Once a color swatch is selected the user can use the color picker found on the right to adjust the swatch&rsquo;s color. The color picker is provided by the ColorPicker jQuery plugin from <a href="http://www.eyecon.ro/colorpicker/" title="jQuery ColorPicker">eyecon.ro</a>.</p>
<p><img src="/posts/css3/css3-webkit-gradient-generator/color-picker-ss.png" alt="jQuery ColorPicker Plugin" title="jQuery ColorPicker Plugin"></p>
<h3>Gradient Direction Control</h3>
<p>Along with this control, I have added the ability to set the direction of the gradient, allowing the user to take advantage of the keywords that are available (left, right, bottom, top) or use custom point locations.</p>
<p><img src="/posts/css3/css3-webkit-gradient-generator/gradient-direction-ss.png" alt="Gradient Direction Control" title="Gradient Direction Control"></p>
<h3>Live Sampling</h3>
The generator provides live sampling, meaning any changes that are made to the controls on the page will immediately update the color sample and the CSS code output.
<p class="disclaimer"><strong>Note:</strong> Live sampling of the gradient colors requires a webkit browser.</p>
<p><img src="/posts/css3/css3-webkit-gradient-generator/gradient-live-sample-ss.png" alt="Live Sampling" title="Live Sampling"></p>
<h3>Coming Soon</h3>
There are still more features to be implemented.  Currently, the gradient generator only supports linear gradients.  I'm working to provide radial gradient support in the near future. Also, currently the generator will only accept hex color values, I am planning on adding RGB support soon as well.
<p>Let me know what you think of the generator so far as well as any features you may like to see.</p>
<h3>Links</h3>
<ul>
<li><a href="http://www.github.com/dgalarza/css3-gradient-generator/" title="GitHub">Check out the code on GitHub</a></li>
<li><a href="http://webkit.org/blog/175/introducing-css-gradients/" title="Learn more about CSS3 Webkit Gradients">Learn more about CSS3 Gradients in Webkit</a></li>
<li><a href="http://gradients.glrzad.com/" title="CSS3 Gradient Generator">Visit the CSS3 Webkit Gradient Generator</a></li>
</ul>
]]></content:encoded></item><item><title>About iPhone Web Applications</title><link>https://www.damiangalarza.com/posts/2009-07-27-about-iphone-web-applications/</link><pubDate>Mon, 27 Jul 2009 13:53:37 +0000</pubDate><author>Damian Galarza</author><guid>https://www.damiangalarza.com/posts/2009-07-27-about-iphone-web-applications/</guid><content:encoded><![CDATA[<p>Let me start by this post by specifying that it actually originated from another post that I’m working on right now, but while writing it I went off on quite a tangent that I decided it was time to make it into a completely separate post, and start off with it. So this is part one of an iPhone web application piece that I am working on. While I am it, let me point out what the scope of this article is. This article is not about how to write an iPhone web application. It does not go into details on the syntax or use of technologies for the iPhone. It does explain some of the misconceptions between iPhone applications, iPhone targeted websites, and finally, iPhone Web Applications. I do plan to write more about the iPhone web application technologies and provide some examples and working code, but that is all currently beyond the scope of this article.</p>
<p>While researching on the topic over the last few weeks, I discovered what I believe is a misconception of an iPhone web application, and my goal is to hopefully, clear things up.</p>
<p>Let’s start by defining some of the possible ways of targeting an iPhone user, which actually diverges into two separate categories of its own.  The first and probably the most popular way of targeting an iPhone user is through an iPhone app, sold through the iTunes App store. Coding and compiling Objective C/Cocoa based native iPhone applications.</p>
<p>Yet there are still other ways of creating a custom user experience for a user on the iPhone.</p>
<h2>Mobile Web Sites and Web Applications</h2>
<p>With Smart Phones becoming so widespread companies are working harder towards providing users with access to their websites with mobile phone designed websites.</p>
<p>WAP (Wireless Application Protocol) sites have been around for several years; the WAP was established in 1998 and was created for less powerful, smaller phones that had limited web browsers. Today’s smart phones, however, are becoming more and more powerful and now provide users with a fully fledged web browser such as the iPhone’s mobile Safari.</p>
<p>So with this in mind, websites have two options. Leaving things alone and letting the phone’s browser do the work, which may work well in some cases; or create a smart phone targeted version of their website. One of the biggest issues though with leaving a website as is for mobile device users is the bandwidth that a user has. Sure, the page may render correctly and work just fine, but that doesn't mean it may not take a while to load all the resources used on the page. Many of those same resources just aren't needed on the mobile device.</p>
<p>Through the power of HTML 5, CSS 3, Javascript and CSS Webkit extensions a developer has incredible tools at their disposal to work with in order to make a mobile friendly page.</p>
<h2>Webkit</h2>
<p>One of the things I am most impressed with so far is the power that CSS3 and webkit extensions provide. More specifically, CSS based gradients, shadows, and animations. These are really amazing pieces of technology allowing to cut down on bandwidth issues created from using images for certain elements just because of a gradient or other effect, or eliminating the need of Flash or special javascript libraries for animations.</p>
<p>Let's take a closer look at the benefits of using CSS gradients to cut down on the number of images that are required to download. Perhaps you have a consistent gradient used on several buttons on a site. If you were to use images, you would have to re-cut each variation of button, which leads to longer page loads which is a major concern when working on a mobile device. Now with a CSS gradient, we can define it as a single class and apply it to any buttons that use the gradient, making much better use of our resources.</p>
<p>Finally, with these tools in hand we can diverge into two sections, the general purpose mobile website, or an iPhone web application. Now by no means do I mean to downplay the power of the mobile website, I simply want to talk about something that’s less known, and that’s the iPhone Web Application.</p>
<h2>So what is an iPhone Web Application</h2>
<p>An iPhone Web Application in its simplest form is actually a website which is created with the same technologies web developers are already familiar with, but are created with the goal of emulating a native application on the iPhone.</p>
<p>HTML5, CSS3, Javascript, and CSS Webkit extensions provide a developer with rich tools to create power applications for an iPhone. Users can bookmark a web page to their home screen and right there, they can see one of the first signs of a web application, a custom home screen icon. Just like the application icon created for the home screen for a native iPhone application, through the use of Meta tags a developer can define a custom icon to be shown on the home screen for their web application. Furthermore, the developer can define another Meta tag which can hide the whole Safari UI including the address bar, and the navigation bar at the bottom of the screen. These are only some of the simpler things a developer can do.</p>
<p>Through javascript alone a developer has access to many of the events that an iPhone application developer would have, such as touch events, gesture events orientation changes, viewport settings and more.</p>
<p>Furthermore, the local storage engine, powered by SQLite, allows local databases to be created from a web application, which can be accessed through javascript. A popular example of local database storage is Gmail's offline mode, which uses the local storage to keep emails stored locally.</p>
<p>Not only can we create a local database on the user’s phone, we can work with more powerful caching functionality through the use of Manifest files which we can use to define a set of files to cache on the phone which can then be accessed later if the user tries to access the web application without an internet connection. So a developer can specify to cache CSS files and images to make sure the user enjoys the same UI experience while offline just like a native application. Manifest caches and the SQLite local databases are what I consider some of the most important tools at a developer's belt when writing an iPhone web application because it really blurs the line between an iPhone application and an iPhone web application.</p>
<p>Stay tuned as I plan to get into some more specifics relating to all aspects of iPhone web application development.</p>]]></content:encoded></item></channel></rss>