<?xml version="1.0" encoding="iso-8859-1"?><rss version="0.91">
    <channel>
        <title>phpguru.org - Richard Heyes' ramblings and code</title>
        <link>http://www.phpguru.org/</link>
        <description>
            Quality PHP and Javascript code, along with a mild smattering of humour. Also second home of the RGraph HTML5 canvas graph library.
        </description>

                    <item>
                <title>A canvas "Please wait..."</title>
                <link>http://www.phpguru.org/article/484</link>
                <pubDate>Tue, 20 Jul 2010 02:06:24 +0100</pubDate>
                <description>
                    <![CDATA[<p class="firstLetter">Haven't you seen this before? If not you should stay in more. Or something like that. This, it seems, is a common "Please wait..."
component for Flash, and now here it is in a &lt;canvas&gt; version. It's quite simple to use, simply call the function:

<div style="text-align: center">
    <canvas id="myc" width="200" height="200" style="border: 1px dotted #aaa"></canvas>
</div>

<script>
    PleaseWait('myc');
</script>


<pre class="code">
&lt;script src="PleaseWait.js"&gt;&lt;/script&gt;

&lt;script&gt;
    PleaseWait(id);
&lt;/script&gt;</pre>

The library is here:

<ul>
    <li><a href="/javascript/PleaseWait.js"><b>PleaseWait.js</b></a></li>
</ul>

Bear in mind that you may need to clear the canvas before and/or after using it. You can do this by setting
the width or height to itself. Eg:

<pre class="code">document.getElementById("myCanvas").width = document.getElementById("myCanvas").width;</pre>]]>
                </description>
            </item>
                    <item>
                <title>WebKit/CSS Reflections</title>
                <link>http://www.phpguru.org/article/479</link>
                <pubDate>Thu, 24 Jun 2010 18:40:39 +0100</pubDate>
                <description>
                    <![CDATA[<p class="firstLetter"><ul>
    <li><a href="#intro">Introduction</a></li>
    <li><a href="#format">Format</a></li>
    <li><a href="#example1">Example 1</a></li>
    <li><a href="#example2">Example 2</a></li>
    <li><a href="#example3">Example 3</a></li>
    <li><a href="#example4">Example 4</a></li>
    <li><a href="#example5">Example 5</a></li>
    <li><a href="#links">Related links</a></li>
</ul>

<a name="intro"></a>
<h4>Introduction</h4>

CSS Reflections are as their name suggests - refections of elements provided by CSS. They're very easy to accomplish and provide
simple but effective effects which you could use, for example, in a photo gallery. Currently these appear to be WebKit only - so
Google Chrome and Safari.

<!-- 
         direction: above, below, left or right
            offset: Is a length or percentage
    mask-box-image: Can be omitted
-->

<a name="format"></a>
<h4>The format</h4>

    The CSS identifier is <i>-webkit-box-reflect</i>, and it takes either two or three values:
    
    <ul>
        <li>The direction of the reflection. This can be <i>left</i>, <i>right</i>, <i>top</i> or <i>bottom</i>.</li>
        <li>The offset. This can be in pixels or a percentage. Bear in mind that the size and offset of the reflection does not affect the page layout.</li>
        <li>A color mask for the gradient (optional). Using this you can achieve graduated reflections, as shown below.</li>
    </ul>

<a name="example1"></a>
<h4>Example 1</h4>

    <p>
        This shows a basic reflection on the right of an image:
    </p>

    <img src="/images/ajax.jpg" style="-webkit-box-reflect: right 0" width="74" height="160"/>

    <pre class="code">
-webkit-box-reflect: right 0;
</pre>

<a name="example2"></a>
<h4>Example 2</h4>

    <p>
        This is the same image but with the reflection on the left hand side and offset a little. Note that the layout of the
        page is not affected by the reflection (much like <i>box-shadow</i> in this respect).
    </p>
    
    <img src="/images/ajax.jpg" style="-webkit-box-reflect: left 5" width="74" height="160"/>
    
    <pre class="code">
-webkit-box-reflect: left 5;
</pre>

<a name="example3"></a>
<h4>Example 3</h4>
    <p>
        This example has a mask applied using a gradient.
    </p>

    <img src="/images/ajax.jpg" style="-webkit-box-reflect: right 0 -webkit-gradient(linear, right top, left top, from(rgba(255,255,255,0.7)), to(transparent))" width="74" height="160"/>
    
    <pre class="code">
-webkit-box-reflect: right 0 -webkit-gradient(linear, right top, left top, from(rgba(255,255,255,0.7)), to(transparent))
</pre>

    <p>
        As you can see, this example uses a gradient mask to produce a fade out effect.
    </p>

<a name="example4"></a>
<h4>Example 4</h4>
    
    <p>
        As you can see below, reflections work on just about any element, not just images.
    </p>
    
    <p style="border: 2px solid gray; padding: 5px; width: 230px; -webkit-box-reflect: right 0">
        lorem ipsum delore lorem ipsum
        lorem ipsum delore lorem ipsum
        lorem ipsum delore lorem ipsum
        lorem ipsum delore lorem ipsum
    </p>
    
    <pre class="code">
border: 2px solid gray; padding: 5px; width: 230px; -webkit-box-reflect: right 0
</pre>

<a name="example5"></a>
<h4>Example 5</h4>
    
    <p>
        You even use CSS reflections on video elements if you wish. This shows a short video reflected to the right. It only plays
        in Google Chrome, (Safari doesn't support the video).
    </p>
    
    <video src="/html5/video.webm" style="width: 300px; -webkit-box-reflect: right 5px -webkit-gradient(linear, right top, left top, from(white), to(transparent))" controls></video>


<a name="links"></a>
<h4>Related links</h4>

<ul>
    <li><a href="http://webkit.org/blog/182/css-reflections/">http://webkit.org/blog/182/css-reflections/</a></li>
</ul>]]>
                </description>
            </item>
                    <item>
                <title>19th June RGraph release</title>
                <link>http://www.phpguru.org/article/477</link>
                <pubDate>Sat, 19 Jun 2010 22:22:24 +0100</pubDate>
                <description>
                    <![CDATA[<p class="firstLetter">Back online and fully plugged in; this weeks release incorporates a 
new layout for the documentation pages, making them easier to read and 
navigate.

<ul>
  <li>Documented grid autofit properties for the Bar, Gantt, Hbar, Line 
and Scatter charts</li>
  <li>Reorganized the documentation pages</li>
  <li>Added a warning to the website for MSIE 6 & 7</li>
</ul>

<a href="http://www.rgraph.net" style="float: right; font-weight: bold">Go to the RGraph website &raquo;</a>]]>
                </description>
            </item>
                    <item>
                <title>CSS3 Gradients</title>
                <link>http://www.phpguru.org/article/476</link>
                <pubDate>Mon, 07 Jun 2010 01:54:06 +0100</pubDate>
                <description>
                    <![CDATA[<p class="firstLetter"><style>
    .myGradient {
        background: -webkit-gradient(linear, 0 0, 0 100, from(#f00), to(#000));
        background: -moz-linear-gradient(top,  red,  black);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#ff0000, endColorstr=black);
        
        border: 2px solid black;
    }
</style>

WebKit has supported CSS gradients for a while now. Though now that Firefox 3.6 supports them too, and along with Internet Explorers
filter: CSS option, they are quite usable. Here's a lil' intro to them.

<p />

<b>First, for webkit you can do this:</b>

<pre class="code">background: -webkit-gradient(linear, left top, right bottom, from(#f00), to(#000));</pre>

<div style="width: 100px; height: 100px; background: -webkit-gradient(linear, 50 0, 100 100, from(#f00), to(#000)); float: left; border: 2px solid black"></div>

<div style="float: left; margin-left: 15px">
    The definitions are:
    
    <ul>
        <li><i>linear</i> - The gradient type - can be linear or radial</li>
        <li><i>left top</i> - The start point of the gradient (can be left/right or percentages)</li>
        <li><i>right bottom</i> - The end point of the gradient (can be left/right or percentages)</li>
        <li><i>from(#f00)</i> The start color</li>
        <li><i>to(#000)</i> - The end color</li>
    </ul>
</div>

<br clear="all" />

<b>For Firefox you can do this:</b>

<pre class="code">background: -moz-linear-gradient(top,  red,  black);</pre>

<div style="width: 100px; height: 100px; background: -moz-linear-gradient(top,  red,  black); float: left; border: 2px solid black"></div>

<div style="float: left; margin-left: 15px">
    The definitions are:

    <ul>
        <li><i>top</i> - The start point of the gradient (or the axis) - <br />to get information on this see the Mozilla more info link</li>
        <li><i>red</i> - The start color</li>
        <li><i>#000</i> - The end color</li>
    </ul>
</div>

<br clear="all" />

<b>In MSIE (!) you can do this:</b>

<pre class="code" title="background: filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#ff0000, endColorstr=black)">background: filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#ff0000, ...</pre>

<div style="width: 100px; height: 100px; filter: ; float: left; border: 2px solid black; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#ff0000, endColorstr=black);"></div>

<div style="float: left; margin-left: 15px">
    The definitions are available on the MSDN site (link below).
</div>

<br clear="all" /><br />

<hr>

So to combine them, you could add them all to a CSS class:

<br />
<br />

<div class="myGradient" style="width: 100px; height: 100px"></div>

<pre class="code">&lt;style&gt;
    .myGradient {
        background: -webkit-gradient(linear, 0 0, 0 100, from(#f00), to(#000));
        background: -moz-linear-gradient(top,  red,  black);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#ff0000, ...
    }
&lt;/style&gt;
</pre>

<br />

<h4>More information</h4>

<p>
    The gradients have many more options for defining colors, color stops, directions etc So You are advised to get more information
    at the links below.
</p>

<ul>
    <li><a href="http://webkit.org/blog/175/introducing-css-gradients/" target="_blank" rel="nofollow">http://webkit.org/blog/175/introducing-css-gradients/</a><br /></li>
    <li><a href="https://developer.mozilla.org/en/CSS/-moz-linear-gradient" target="_blank" rel="nofollow">https://developer.mozilla.org/en/CSS/-moz-linear-gradient</a></li>
    <li><a href="http://msdn.microsoft.com/en-us/library/ms532847(VS.85).aspx" target="_blank" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms532847(VS.85).aspx</a></li>
</ul>
]]>
                </description>
            </item>
                    <item>
                <title>5th June 2010 RGraph release</title>
                <link>http://www.phpguru.org/article/475</link>
                <pubDate>Sun, 06 Jun 2010 01:56:57 +0100</pubDate>
                <description>
                    <![CDATA[<p class="firstLetter">Not too many changes this week:

<ul>
  <li>Added properties to the Horizontal Bar chart: <i>chart.title.xaxis</i>, <i>chart.title.yaxis</i>, <i>chart.title.xaxis.pos</i>, <i>chart.title.yaxis.pos</i>
</li>
  <li>Slightly increased the area recognised to initiate resizing the Rose (ie the size of the hotspot)</li>
  <li>Added adjusting to the TRadar</li>
</ul>

<p>

On a separate note - I've updated the <a href="http://www.phpguru.org/geolocation.html"><b>HTML5 GeoLocation example</b></a> with an embedded Google map. This will probably be more useful to you. Also, if you have the Google Toolbar installed, MSIE appears to have GeoLocation support (!).]]>
                </description>
            </item>
                    <item>
                <title>29th May 2010 RGraph release</title>
                <link>http://www.phpguru.org/article/474</link>
                <pubDate>Sat, 29 May 2010 23:32:39 +0100</pubDate>
                <description>
                    <![CDATA[<p class="firstLetter">Back to crappy rain here. Still, at least I'm not melting. Not entirely sure which I prefer - melting or freezing. It does however mean I've spent more time on RGraph. Here's this weeks skinny:

<ul>
  <li>Added adjusting to the Bar chart</li>
  <li>Added gray border effect to the Odometer</li>
  <li>Added chart.tickmarks.highlight to the Odometer</li>
  <li>Added adjusting to the Progress bar</li>
  <li>Added adjusting to the Rose chart</li>
  <li>Added chart.ymin to the Scatter chart</li>
</ul>

<a href="http://www.rgraph.net" style="float: right; font-weight: bold">Go to the RGraph website &raquo;</a>

<br clear="all" /><br />

As you can see below, there's also an article that may be of interest detailing the new notification system that is a part of Google Chrome. It allows non-modal dialogs, which may be more useful to you and your application than a simple alert().]]>
                </description>
            </item>
                    <item>
                <title>HTML5/Webkit desktop notifications example</title>
                <link>http://www.phpguru.org/article/473</link>
                <pubDate>Sat, 29 May 2010 04:18:16 +0100</pubDate>
                <description>
                    <![CDATA[<p class="firstLetter"><script>
    if (navigator.userAgent.indexOf('Chrome') == -1) {
        document.write('<div style="border: 2px dashed red; background-color: #fdd; padding: 3px; text-align: center">Currently, you need to be using <a href="http://www.google.com/chrome" target="_blank">Google Chrome</a>!</div><br clear="all" />');
    }
</script>

<img src="/images/desktop-notifications.png" style="float: right; -webkit-box-shadow: black 0 0 15px; box-shadow: black 0 0 15px; -moz-box-shadow: black 0 0 15px" width="351" height="175" alt="Webkit desktop notifications" />

This a demo of the WebKit desktop notifications feature. I think this was added to Chrome 4, but I guess I must have
been asleep. A bit. Still, press the button to see a notification. From what I can garner, this isn't strictly speaking an
HTML5 thing, rather, a feature of webkit. As such this will probably make it into Safari too (eventually).


<br /><br />

<p style="text-align: center">
    <button id="b1" onclick="ShowNotification()">Notify me!</button>
    <button id="b2" onclick="ShowHTMLNotification()">Notify me! (HTML)</button>
</p>

<script>

    if (!window.webkitNotifications) {
        document.getElementById("b1").disabled = true;
        document.getElementById("b2").disabled = true;
    }


    /**
    * Request permission to show desktop notifications. This will block adoption IMO.
    */
    function RequestPermission (callback)
    {
        window.webkitNotifications.requestPermission(callback);
    }


    /**
    * The function which shows the desktop notification
    */
    function ShowNotification ()
    {
        if (window.webkitNotifications.checkPermission() > 0) {
            RequestPermission(ShowNotification);
        }

        // Some variables - nothing special
        var icon  = 'http://www.rgraph.net/images/logo.png';
        var title = 'Try RGraph';
        var msg   = 'Cut the load on your server whilst showing pretty charts.';

        // Show the popup
        var popup = window.webkitNotifications.createNotification(icon, title, msg);
        popup.show();
    }


    /**
    * This show a HTML notification
    */
    function ShowHTMLNotification ()
    {
        if (window.webkitNotifications.checkPermission() > 0) {
            RequestPermission(ShowHTMLNotification);
        }

        // Show the popup
        var popup = window.webkitNotifications.createHTMLNotification('/WebkitNotification.html');
        popup.show();
    }
</script>

<h4>Browser support</h4>

Currently I've only had this working in Google Chrome 6. Chrome 4 and 5 may support it too, but I've not tried it.
From what I've read, it originated in Chrome 4.

<h4>Code</h4>

<pre class="code">&lt;script&gt;

    if (!window.webkitNotifications) {
        alert('Sorry - no support for desktop notifications found. Try Google Chrome.');
    }


    <span style="color: #FF8000">/**
    * Request permission to show desktop notifications. This will block adoption IMO.
    */</span>
    function RequestPermission (callback)
    {
        window.webkitNotifications.requestPermission(callback);
    }


    <span style="color: #FF8000">/**
    * The function which shows the desktop notification
    */</span>
    function ShowNotification ()
    {
        if (window.webkitNotifications.checkPermission() > 0) {
            RequestPermission(ShowNotification);
        }

        // Some variables - nothing special
        var icon  = 'http://www.rgraph.net/images/logo.png';
        var title = 'Try RGraph';
        var msg   = 'Cut the load on your server whilst showing pretty charts.';

        // Show the popup
        var popup = window.webkitNotifications.createNotification(icon, title, msg);
        popup.show();
    }


    <span style="color: #FF8000">/**
    * This show a HTML notification
    */</span>
    function ShowHTMLNotification ()
    {
        if (window.webkitNotifications.checkPermission() > 0) {
            RequestPermission(ShowHTMLNotification);
        }

        // Show the popup
        var popup = window.webkitNotifications.createHTMLNotification('WebkitNotification.html');
        popup.show();
    } 
&lt;/script&gt;

&lt;button onclick="ShowNotification()"&gt;Notify me!&lt;/button&gt;
&lt;button onclick="ShowHTMLNotification()"&gt;Notify me! (HTML)&lt;/button&gt;
</pre>


<h4>Checking for support</h4>

    <p>
        Checking for support is quite simple. You can do it like this:
    </p>
    
    <pre class="code">
if (!window.webkitNotifications) {
    alert('Sorry - no support found. Try Google Chrome.');
}
</pre>

<h4>API</h4>

    <p>
        Note that this is what I've worked out and gleaned from various sources - there doesn't appear to be a definitive reference at the
        current time. Or at least I've not found one.
    </p>

    <p>
        <ul>
            <li>
                <b>window.webkitNotifications.requestPermission(callback)</b><br /><br />
                This is the function to call to request permission from the user to show notifications. The callback is called if
                permission is granted. This callback could, for example, subsequently show the notification.
                <p />
            </li>

            <li><b>window.webkitNotifications.checkPermission()</b><br /><br />
                Returns an number indicating the current state of permission.
                
                <ol>
                    <li>Permission granted</li>
                    <li>Permission state not yet determined</li>
                    <li>Permission denied</li>
                </ol>
                
                <p />
            </li>

            <li>
                <b>window.webkitNotifications.createNotification(icon, title, text)</b><br /><br />
                The real meat and two veg of the whole thing. This shows a notification if permission has been granted. It accepts three
                arguments:
                    <ol>
                        <li>A URL of an image to use in the notification</li>
                        <li>The title of the notification</li>
                        <li>The text to show in the notification</li>
                    </ol>
                
                <p />
            </li>
            
            <li>
                <b>window.createHTMLNotification(file)</b><br /><br />
                Creates an HTML notification. This allows you to use mutiple images and also links in your notifications. Doesn't appear to be
                restricted to the current domain.
            </li>
        </ul>
    </p>


<h4>Notes</h4>

    <ol>
        <li>
            Sometimes the non-HTML notification appears bigger than it needs to. I can only assume that this is a bug.
            The HTML variant seems to be fine.
        </li>

        <li>
            Should it be required to request permission from the user? This will block adoption IMO
            and, in the case of non-HTML notifications, shouldn't be required. Actually, I've now remembered that I read somewhere
            that this is in place to try and avoid tricking the user, because the notifications could look like IM notifications.
            Ho-hum.
        </li>
        
        <li>
            It would be nice to be able to dismiss the notification by right clicking on it, instead of going through the utter chore
            of making sure the mouse is over the rather small cross.
        </li>
    </ol>


<h4>Related links</h4>
    
    <p>
        There's what looks like an implementor document <a href="http://www.chromium.org/developers/design-documents/desktop-notifications" target="_blank">here</a>.
    </p>]]>
                </description>
            </item>
            </channel>
</rss>