Regions

Ojay comes with a class called Ojay.Region, which is a decorator for the YAHOO.util.Region class. It is used to represent the area occupied by an element on a web page. All region objects have four properties: top, bottom, left and right, which specify the edges of the rectangle containing the element, measured in pixels. All dimensions returned by region objects are in pixels.

Required files

  • http://yui.yahooapis.com/2.7.0/build/yahoo-dom-event/yahoo-dom-event.js
  • http://yui.yahooapis.com/2.7.0/build/selector/selector-beta.js
  • http://yoursite.com/ojay/js-class.js
  • http://yoursite.com/ojay/core.js

Region API

Region objects are returned by the Ojay('#myElement').getRegion() method. Region objects have the following methods:

  • getWidth() – returns the width of the region
  • getHeight() – returns the height of the region
  • getDiagonal() – returns the diagonal length of the region
  • getArea() – returns the area of the region in square pixels
  • getCenter() – returns an object with left and top properties describing the center of the region.
  • contains(region) – returns true iff the receiver completely contains region.
  • intersects(region) – returns true iff the receiver overlaps region.
  • intersection(region) – returns the region occupied by both the receiver and region.
  • union(region) – returns the region that just contains both the receiver and region.