jQuery postMessage: Cross-domain scripting goodness

jQuery postMessage: Cross-domain scripting goodness:

jQuery postMessage: Cross-domain scripting goodness

Version: 0.5, Last updated: 9/11/2009

Project Home http://benalman.com/projects/jquery-postmessage-plugin/
GitHub http://github.com/cowboy/jquery-postmessage/
Source http://github.com/cowboy/jquery-postmessage/raw/master/jquery.ba-postmessage.js
(Minified) http://github.com/cowboy/jquery-postmessage/raw/master/jquery.ba-postmessage.min.js (0.9kb)
Summary
jQuery postMessage: Cross-domain scripting goodness Version: 0.5, Last updated: 9/11/2009
License Copyright © 2009 “Cowboy” Ben Alman, Dual licensed under the MIT and GPL licenses.
Examples This working example, complete with fully commented code, illustrates one way in which this plugin can be used.
Support and Testing Information about what version or versions of jQuery this plugin has been tested with and what browsers it has been tested in.
Release History
Functions
jQuery.postMessage This method will call window.postMessage if available, setting the targetOrigin parameter to the base of the target_url parameter for maximum security in browsers that support it.
jQuery.receiveMessage Register a single callback for either a window.postMessage call, if supported, or if unsupported, for any change in the current window location.hash.

License

Copyright © 2009 “Cowboy” Ben Alman, Dual licensed under the MIT and GPL licenses.  http://benalman.com/about/license/

Examples

This working example, complete with fully commented code, illustrates one way in which this plugin can be used.

Iframe resizing http://benalman.com/code/projects/jquery-postmessage/examples/iframe/

Support and Testing

Information about what version or versions of jQuery this plugin has been tested with and what browsers it has been tested in.

jQuery Versions 1.3.2
Browsers Tested Internet Explorer 6-8, Firefox 3, Safari 3-4, Chrome, Opera 9.

Release History

0.5 (9/11/2009) Improved cache-busting
0.4 (8/25/2009) Initial release

Functions

jQuery.postMessage

This method will call window.postMessage if available, setting the targetOrigin parameter to the base of the target_url parameter for maximum security in browsers that support it.  If window.postMessage is not available, the target window’s location.hash will be used to pass the message.  If an object is passed as the message param, it will be serialized into a string using the jQuery.param method.

Usage

jQuery.postMessage( message, target_url [, target ] );

Arguments

message (String) A message to be passed to the other frame.
message (Object) An object to be serialized into a params string, using the jQuery.param method.
target_url (String) The URL of the other frame this window is attempting to communicate with.  This must be the exact URL (including any query string) of the other window for this script to work in browsers that don’t support window.postMessage.
target (Object) A reference to the other frame this window is attempting to communicate with.  If omitted, defaults to `parent`.

Returns

Nothing.

jQuery.receiveMessage

Register a single callback for either a window.postMessage call, if supported, or if unsupported, for any change in the current window location.hash.  If window.postMessage is supported and source_origin is specified, the source window will be checked against this for maximum security.  If window.postMessage is unsupported, a polling loop will be started to watch for changes to the location.hash.

Note that for simplicity’s sake, only a single callback can be registered at one time.  Passing no params will unbind this event (or stop the polling loop), and calling this method a second time with another callback will unbind the event (or stop the polling loop) first, before binding the new callback.

Also note that if window.postMessage is available, the optional source_origin param will be used to test the event.origin property.  From the MDC window.postMessage docs: This string is the concatenation of the protocol and “://”, the host name if one exists, and “:” followed by a port number if a port is present and differs from the default port for the given protocol.  Examples of typical origins are https://example.org (implying port 443), http://example.net (implying port 80), and http://example.com:8080.

Usage

jQuery.receiveMessage( callback [, source_origin ] [, delay ] );

Arguments

callback (Function) This callback will execute whenever a jQuery.postMessage message is received, provided the source_origin matches.  If callback is omitted, any existing receiveMessage event bind or polling loop will be canceled.
source_origin (String) If window.postMessage is available and this value is not equal to the event.origin property, the callback will not be called.
source_origin (Function) If window.postMessage is available and this function returns false when passed the event.origin property, the callback will not be called.
delay (Number) An optional zero-or-greater delay in milliseconds at which the polling loop will execute (for browser that don’t support window.postMessage).  If omitted, defaults to 100.

Returns

Nothing!

0

0
 

Cross-domain, cross-browser Iframe communcation, made easy!

Ben Alman » jQuery postMessage » Examples » Iframe resizing:

Note that both parent and child need to include the jQuery postMessage javascript, and for communication to be enabled in browsers that don’t support window.postMessage, the child page must know the exact parent URL (in this example, that is done by passing the parent location into the Iframe using a hash param in the Iframe src attribute).

The parent window code

01.$(function(){
02.   
03.  // Keep track of the iframe height.
04.  var if_height,
05.   
06.    // Pass the parent page URL into the Iframe in a meaningful way (this URL could be
07.    // passed via query string or hard coded into the child page, it depends on your needs).
08.    src = 'http://rj3.net/code/projects/jquery-postmessage/examples/iframe/child/#' + encodeURIComponent( document.location.href ),
09.     
10.    // Append the Iframe into the DOM.
11.    iframe = $( '<iframe " src="' + src + '" width="700" height="1000" scrolling="no" frameborder="0"><\/iframe>' )
12.      .appendTo( '#iframe' );
13.   
14.  // Setup a callback to handle the dispatched MessageEvent event. In cases where
15.  // window.postMessage is supported, the passed event will have .data, .origin and
16.  // .source properties. Otherwise, this will only have the .data property.
17.  $.receiveMessage(function(e){
18.     
19.    // Get the height from the passsed data.
20.    var h = Number( e.data.replace( /.*if_height=(\d+)(?:&|$)/, '$1' ) );
21.     
22.    if ( !isNaN( h ) && h > 0 && h !== if_height ) {
23.      // Height has changed, update the iframe.
24.      iframe.height( if_height = h );
25.    }
26.     
27.  // An optional origin URL (Ignored where window.postMessage is unsupported).
28.  }, 'http://rj3.net' );
29.   
30.  // And for good measure, let's send a toggle_content message to the child.
31.  $( '<a href="#">Show / hide Iframe content<\/a>' )
32.    .appendTo( '#nav' )
33.    .click(function(){
34.      $.postMessage( 'toggle_content', src, iframe.get(0).contentWindow );
35.      return false;
36.    });
37.   
38.});

0

0
 

HTML5 resouces

HTML5Rocks – Home:

HTML5Rocks

Reference

Tools

  • Modernizr : Javascript library for feature detection and control fallback cases of HTML5.
  • html5 shiv : Javascript patch to make IE support, and print, the new tag elements.
  • CSS Button Maker : Preview CSS buttons with a fancy interface to play with the parameters.
  • CSS3 Generator : Preview CSS buttons with a fancy interface to play with the parameters.
  • CSS3 Sandbox : Test and get the code of the fanciest CSS features.
  • CSS3 Gradient Generator : Generate CSS code for gradients on the fly.
  • CSS3 Please : Use CSS3 without having to worry about xbrowser differences.
  • Font Dragr : Test your fonts using drag and drop.
  • Font Squirrel Generator : Most complete tool to generate code for you font-face support.
  • Let’s make the web faster : Complete list of tools related to web performance.

Community

Books

Made by Google |

HomeTermsPrivacyFeedbackMake a SuggestionReport BugFollow us on Twitter This site contains information on APIs that are not part of the current W3C HTML5 specification.

0

0
 

BlueDojo: Editor Online HTML5 identico a Flash

Blue Dojo:

<img src=”./images/site/noJavascriptMain.png” width=875 height=250>

“Our Goal Is For Cooties To Kill Flash”
– Jim Nguyen, CEO Blue Dojo
Main Features

  • Cooties mimics Flash Using HTML5
  • IDE runs completely in browser
  • Draw and export animations
  • Animations run on iPad/iPhone
  • Add animations to any website
  • Many, many more features
  • View Examples

  • Moving shapes
  • Having fun with text
  • Using imported images
  • Web Application Screenshot
    http://cooties.bluedojo.com


     Follow us on Facebook

    0

    0
     

    HTML5 Local Storage

    HTML5 Local Storage | HTML5 Samples, Tutorials and News:

    HTML5 Local Storage

    Simple Example of HTML5 Local Storage

    In this video, we’re going to show you how to create a working, though very basic, to-do list in just a few minutes. We can create advanced browsers “remember” what we type, even after it is closed or is refreshed using HTML5’s local storage.

    While obviously not supported across all browsers, we can expect this method to work, most notably, in Internet Explorer 8, Safari 4, and Firefox 3.5. Note that, to compensate for older browsers that won’t recognize local storage, you should first test to determine whether window.localStorage exists.

    HTML5 support

    HTML5 support

    Source Code: http://jsbin.com/iqura/4/

    0

    0
     

    Open Standard Media (OSM) Player

    Open Standard Media (OSM) Player | MediaFront:

    Open Standard Media (OSM) Player

    With the onset of HTML5, there is a dramatic paradigm shift in the wake for online media content delivery. For well over 6 years, this industry has been dominated by the proprietary Adobe Flash Player, which has been used to deliver high quality media to audiences far and wide. This reign is coming to a dramatic end as new Open Standard technology takes its place. Yes, HTML5 is here, and we present to you the Open Standard Media (OSM) Player!

    Built by Alethia Inc., the Open Standard Media (OSM) Player is an all-in-one media player for the web. It is an industry changing, open source (GPLv3) media player that is written in jQuery to dynamically deliver any type of web media, including HTML5, YouTube, Vimeo, and Flash.

    Click here to see this player in action!

    This media player is much different than any other media player on the market, and we are sure you will be happy with the following list of features it offers.

    • 100% Open Source and 100% free!
    • Written in the popular jQuery framework.
    • Dynamic HTML5 content delivery.
    • Audio and Video support with the most popular media formats.
    • Automatic Flash fallback for non-standard media.
    • Easily themable using the incredible ThemeRoller system.
    • Seamless Vimeo and YouTube integration.
    • Playlist support
    • Player to Player communication.

    Version Description Download Date Notes Issues Project
    0.97 Stand Alone Player 2010-Jul-2 Notes
    HEAD Latest Development Snapshot 2010-Apr-1 Notes

    View all p

    0

    0
     

    Tools para seleccion de colores

    Design News @ ColorJack:

     
    DHTML Color Picker v2.0
    Thursday, April 17, 2008
    Today, we have a few new updates for you. First off, the Color Conversion Library has been expanded to include HEX, RGB, HSV, CMYK, XYZ, Lab color spaces. On the same note, I’d like to introduce the DHTML Color Picker v2.0 — another Open Source product (GPL & CC) by the ColorJack crew. This color picker was developed for one of our upcoming products: an online vector editing package.
     
    Color Galaxy (beta)
    Monday, April 21, 2008
    Color Galaxy is a online color library visualizer. We’ve amassed a collection of 27 color databases. There is a lot of variety in the data, everything from Crayola’s historical set of standard crayons, to Munsell’s scientific renotational data. Requires a <canvas> enabled browser: Firefox, Opera, or Safari.

    Here’s a list of what’s included: CNE, Crayola Crayons (since 1903), NBS/ISCC (Dye Colors, Colour Terminology in Biology, Centroids of the NBS/ISCC catalog, Colors for Ready-Mixed Paints, Horticultural Colour Charts, Dictionary of Color, Plochere Color System, Color Standards and Color Nomenclature, Rock-Color Chart, Postage-Stamp Color Names, Soil Color Charts, Standard Color Card of America), Resene (2001 & 2007 catalog’s from Resene paint company), Munsell 1929 (Colors physically appearing in the 1929 Munsell Book of Color), Munsell 1943 (Colors listed the original 1943 renotation article, lying inside the Macadam limits), Standards (Named colors in Internet Explorer, Mozilla, Netscape, SVG, Windows, & X11), Tango Color Palette & finally the VisiBone Anglo-Centric Color Code. Special thanks to Robert Krimen, MCSL, Jaffer, and Wikipedia for providing the data for this project!

     

    0

    0
     

    Cubo 3D en HTML5

    Taking the canvas to another dimension

    , ,

    Recently Opera published an experimental build on Opera Labs, with support for the video element and video in SVG. This build also includes an experimental addition to the canvas element, the 3d canvas. In order to view the demos presented here you will need to get the Opera Labs build. The build is currently only available for Windows. Mac and Linux versions should be available soon.

    Since this is my first post I guess I should introduce myself. My name is Tim Johansson, and I am a core technology developer at Opera Software. I am responsible for, among other things, canvas (including the underlying vector graphics library) and image decoding.

    A new addition to HTML5 is the canvas. The canvas is more or less a bitmap that you can draw on using JavaScript. The actual drawing is done by a (rendering) context. The specification includes a 2d context that must be implemented, but also allows browser vendors to add their own contexts. When I first implemented the canvas tag in Opera I though it would be cool to have a 3d context, so I added one.

    In this post I will describe the 3d context I added, which is available in the recently released Opera Labs build. The context is called opera-3d and is basically Opera’s version of the 3d canvas. For those of you not familiar with the canvas tag here is a crash course in using it.

    1. Add a <canvas></canvas> tag to your page
    2. Get the canvas element from a JavaScript using getElementById or something similar.
    3. Call canvas.getContext(<name>); to get the context

    That’s it. Once you have the context in your script you can just call its rendering functions.

    The opera-3d context

    Opera’s 3d context, unlike Mozilla’s, is not a straight mapping to OpenGL. We keep it on a more abstract level. The main reasons for doing this are:

    • It makes it easier to implement on non-OpenGL platforms (such as D3D)
    • We wanted to have some form of collision detection available

    The main concept is that you work with 3D models. You create 3D models, add vertices and triangles to them and finally render them to the canvas. This is what the interface looks like.

    
    interface CanvasRenderingContextOpera3D {
    
      // state
      void save(); // push state on state stack
      void restore(); // pop state stack and restore state
    
      // scene/frame
      void beginScene(); // start rendering a new frame
      void endScene(); // finish rendering of the scene and present the result
    
      // transformations
      void translate(in float x, in float y, in float z);
      void scale(in float x, in float y, in float z);
      void rotateX(in float rotation);
      void rotateY(in float rotation);
      void rotateZ(in float rotation);
    
      // rendering operation
      void drawTriangle(in float x1, in float y1, in float z1, in float tex_s1, in float tex_t1, 
          in float x2, in float y2, in float z2, in float tex_s2, in float tex_t2, 
          in float x3, in float y3, in float z3, in float tex_s3, in float tex_t3);
      void draw3DModel(in Canvas3DModel model);
    
      // create objects
      CanvasTexture createTexture(in Image img);
      Canvas3DModel create3DModel();
    
      // collision detection
      string checkIntersection(in float x, in float y, in float z, in float radius, in Canvas3DModel model);
    
      // rendering state
      attribute CanvasTexture texture; // current texture or null for no texture, default is null
      attribute string color; // current color, default is transparent black
      attribute float fov; // field of view of the scene in degrees, default is 45
      attribute float nearPlane; // distance to the near clipping plane, default is 0.1
      attribute float farPlane; // distance to the far clipping plane, default is 100
      attribute string ztest; // "none", "less", "lessequal", "greater", "greaterequal", "equal", "notequal". Default is "lessequal"
      attribute string blend; // "replace", "add", "srcalpha", "multiply". Default is "replace"
    };
    
    interface Canvas3DModel {
      void addVertex(in float x, in float y, in float z, in float s, in float t);
      void addTriangle(in integer vertex1, in integer vertex2, in integer vertex3);
    };
    
    interface CanvasTexture{
    };
    

    Let’s go through the different functions in the order they appear above:

    • The save and restore functions save and restore the current rendering state. They are very similar to save and restore in the 2D context.
    • The translate, scale and rotate functions modify the transformation matrix. The current transformation matrix will transform all vertices rendered with the 3D canvas. This includes Canvas3DModel objects.
    • beginScene and endScene are used to distinguish a frame. The canvas is only updated when endScene is called. When it is, the rendered image is copied to the canvas. Only the commands issued between beginScene and endScene are drawn to the canvas.
    • drawTriangle draws a single triangle. This method is usually slow and should not be used for rendering a lot of triangles.
    • draw3DModel renders a model previously created with create3DModel to the canvas. This function is much better suited for rendering large batches of triangles.
    • createTexture creates a texture object from an image object. This method will fail if the image object’s dimensions are not powers of two (1, 2, 4, 8, 16, 32 etc.) As with the regular canvas you can create textures from images (including SVG) or other canvases.
    • create3DModel creates a 3DModel object that can be built (by adding vertices and triangles) and rendered by the script.
    • checkIntersection is a simple sphere/model collision detection function. The parameters are the sphere (centre and radius) and the model to check for collisions with the sphere. The function returns the collision point as a string when a collision occurs (the point of deepest penetration is coosen as collision point). If no collision was found the function returns an empty string instead.

    The collision detection has some bugs in this build, and I would recomend that you do not use it yet. We will write more about collision detection when it is fixed.

    Example – a rotating cube

    This is the first example ever written for the opera-3d context. It creates a model, adds vertices and triangles for a cube and then renders it with different transforms. If you are using an Opera build with 3d canvas enabled you can also see the rotating cube in action. The files used for this example are the HTML file shown below and an image to use as the texture (operalogo.png in this case).

    
    <canvas id="canvas" width="200" height="200">
      Canvas not supported!
    </canvas>
    <script>
      var canvas;
      var context3d;
      var rotation;
      var texture;
      var cube;
      function render(){
        context3d.beginScene();
        context3d.translate(0,0,-5);
        context3d.rotateY(rotation);
        context3d.rotateX(rotation);
        rotation += 2;
        context3d.color = "white";
        context3d.draw3DModel(cube);
        context3d.endScene();
      }
      function onTick(){
        render();
      }
      function onload(){
        canvas = document.getElementById("canvas");
        context3d = canvas.getContext("opera-3d");
        if (!context3d)
        {
          alert("3d canvas not supported");
          return;
        }
        logo = new Image();
        logo.src = "operalogo.png";
        texture = context3d.createTexture(logo);
        context3d.texture = texture;
    
        cube = context3d.create3DModel();
        cube.addVertex(-1, 1, 1, 0, 0);
        cube.addVertex(1, 1, 1, 1, 0);
        cube.addVertex(-1, -1, 1, 0, 1);
        cube.addVertex(1, -1, 1, 1, 1);
        cube.addVertex(-1, 1, -1, 1, 1);
        cube.addVertex(1, 1, -1, 0, 1);
        cube.addVertex(-1, -1, -1, 1, 0);
        cube.addVertex(1, -1, -1, 0, 0);
    
        cube.addTriangle(0,1,2);
        cube.addTriangle(2,1,3);
        cube.addTriangle(4,5,6);
        cube.addTriangle(6,5,7);
        cube.addTriangle(0,4,2);
        cube.addTriangle(2,4,6);
        cube.addTriangle(1,5,3);
        cube.addTriangle(3,5,7);
        cube.addTriangle(0,4,1);
        cube.addTriangle(1,4,5);
        cube.addTriangle(2,6,3);
        cube.addTriangle(3,6,7);
    
        setInterval(onTick, 10);
      }
      document.onload = onload();
    </script>
    

    More advanced techniques

    In the example above a plain textured cube, which was hard-coded in the script, was rendered. It is possible to do much more than this using the opera-3d context. Below I will describe some techniques that can be used to make more advanced examples.

    DOM3 Load and save

    Hard-coding models is fine for small objects, but as the objects grow it becomes more and more difficult to hard-code them in the script. It is possible to get around this by converting the models to an XML format and then loading them into the script using DOM3 load and save to parse the XML. Here is a modified version of the rotating cube.

    Lightmapping

    Lightmapping is one of the most famous lighting techniques. It is used in many popular games, for example the quake series. The principle is that you multiply each rendered pixel with the light value at that pixel. The light value for each pixel is pre-calculated and stored in a texture.

    The opera-3d context does not have multi-texturing yet, so it is not possible to do lightmapping in one step, but you can achieve this effect by doing multi pass rendering. In the first pass the scene is rendered as usual. In the second pass ztest is set to equal and blend is set to multiply. The scene is now rendered with the lightmap instead of the textures and the result is a lightmapped scene.

    Summary

    That’s it! This article has given you an introduction to the fundamentals of using the Opera 3d canvas. After reading all of this you should know enough to create some cool 3d-canvas demos. If you want to see a more advanced example you can have a look at the 3d snake implementation done by Mathieu ‘p01′ HENRI. I’m looking forward to seeing all the cool demos people will make! Get in touch with us to share your creations.

    0

    0
     

    Showdown: a JavaScript port of Markdown

    Showdown – Markdown in JavaScript:

    Showdown Demo

    Showdown

    You can try out Showdown on this page:

    • Type some Markdown text on the left side.
    • See the corresponding HTML on the right.

    For a Markdown cheat-sheet, switch the right-hand window from Preview to Syntax Guide.

    Showdown is a JavaScript port of the original Perl version of Markdown. You can get the full source code by clicking on the version number at the bottom of the page.

    Also check out WMD, the Wysiwym Markdown Editor. It’ll be open source soon; email me at the address below if you’d like to help me test the standalone version.

    Start with a blank page or edit this document in the left window

    Download Showdown v0.9

    0

    0