Web Notification API sample

http://caniuse.com/#feat=notifications - Chrome 26+ - Firefox 22+

by Yoshiharu Kamata

HTML

<button id="requestPermission">Request Permission</button>
<button id="checkPermission">Check Permission</button>
<div>
Permission: <span id="result">-</span>
</div>
<input name="title" placeholder="title"/>
<input name="tag" placeholder="tag"/>
<input name="icon" type="url" placeholder="icon"/ > 
<textarea name="body" placeholder="body">
</textarea>
<button id="show">show</button>

CSS

input, textarea {
    display: block;
}

CoffeeScript

$ ->
  if window.Notification
    $("#requestPermission").on "click", ->
      Notification.requestPermission()
    $("#checkPermission").on "click", ->
      if Notification.permission
        ## Firefox
        $("#result").text Notification.permission
      else
        ## Chrome
        $("#result").text (new Notification "check").permission
    
    $("#show").on "click", ->
      notification = new Notification $("[name=title]").val(),
                       tag: $("[name=tag]").val()
                       body: $("[name=body]").val()
                       iconUrl: $("[name=icon]").val()  ## Firefox
                       icon: $("[name=icon]").val()     ## Chrome
                        
      notification.onclick = ->
        notification.close()
        ## chrome only 
        ## If the window is minimized, restore the size of the window
        window.open().close()
        window.focus()