2 * jQuery Mobile Widget @VERSION
4 * TODO: remove unnecessary codes....
6 * This software is licensed under the MIT licence (as defined by the OSI at
7 * http://www.opensource.org/licenses/mit-license.php)
9 * ***************************************************************************
10 * Copyright (C) 2011 by Intel Corporation Ltd.
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
19 * The above copyright notice and this permission notice shall be included in
20 * all copies or substantial portions of the Software.
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 * DEALINGS IN THE SOFTWARE.
29 * ***************************************************************************
31 * Authors: Kalyan Kondapally <kalyan.kondapally@intel.com>
34 ensureNS("jQuery.mobile.tizen");
37 jQuery.extend(jQuery.mobile.tizen, {
38 Point: function (x, y) {
39 var X = isNaN(x) ? 0 : x;
40 var Y = isNaN(y) ? 0 : y;
42 this.add = function (Point) {
43 this.setX(X + Point.x());
44 this.setY(Y + Point.y());
48 this.subtract = function (Point) {
49 this.setX(X - Point.x());
50 this.setY(Y - Point.y());
54 this.multiply = function (Point) {
55 this.setX(Math.round(X * Point.x()));
56 this.setY(Math.round(Y * Point.y()));
60 this.divide = function (Point) {
61 this.setX(Math.round(X / Point.x()));
62 this.setY(Math.round(Y / Point.y()));
66 this.isNull = function () {
67 return (X === 0 && Y === 0);
70 this.x = function () {
74 this.setX = function (val) {
75 isNaN(val) ? X = 0 : X = val;
78 this.y = function () {
82 this.setY = function (val) {
83 isNaN(val) ? Y = 0 : Y = val;
86 this.setNewPoint = function (point) {
91 this.isEqualTo = function (point) {
92 return (X === point.x() && Y === point.y());
96 Rect: function (left,top,width,height) {
99 var Right = Left+width;
100 var Bottom = Top+height;
102 this.setRect = function(varL,varR,varT,varB) {
106 this.setBottom(varB);
109 this.right = function () {
113 this.setRight = function (val) {
117 this.top = function () {
121 this.setTop = function (val) {
125 this.bottom = function () {
129 this.setBottom = function (val) {
133 this.left = function () {
137 this.setLeft = function (val) {
141 this.moveTop = function(valY) {
142 var h = this.height();
147 this.isNull = function () {
148 return Right === Left && Bottom === Top;
151 this.isValid = function () {
152 return Left <= Right && Top <= Bottom;
155 this.isEmpty = function () {
156 return Left > Right || Top > Bottom;
159 this.contains = function (valX,valY) {
160 if (this.containsX(valX) && this.containsY(valY))
165 this.width = function () {
169 this.height = function () {
173 this.containsX = function(val) {
180 if (l > val || r < val)
185 this.containsY = function(val) {
192 if (t > val || b < val)
198 disableSelection: function (element) {
200 return self.enableSelection( element, 'none' );
203 enableSelection: function (element, value) {
204 return $(element).each( function () {
218 '-moz-user-select': val,
219 '-webkit-user-select': val,
220 '-o-user-select': val,
226 disableContextMenu: function(element) {
227 $(element).each( function() {
228 $(this).bind("contextmenu", function( event ) {
234 enableContextMenu: function(element) {
235 $(element).each( function() {
236 $(this).unbind( "contextmenu" );
240 // Set the height of the content area to fill the space between a
241 // page's header and footer
242 fillPageWithContentArea: function (page) {
244 var $content = $page.children(".ui-content:first");
245 var hh = $page.children(".ui-header").outerHeight(); hh = hh ? hh : 0;
246 var fh = $page.children(".ui-footer").outerHeight(); fh = fh ? fh : 0;
247 var pt = parseFloat($content.css("padding-top"));
248 var pb = parseFloat($content.css("padding-bottom"));
249 var wh = window.innerHeight;
250 var height = wh - (hh + fh) - (pt + pb);
251 $content.height(height);
254 // Get document-relative mouse coordinates from a given event
255 // From: http://www.quirksmode.org/js/events_properties.html#position
256 documentRelativeCoordsFromEvent: function(ev) {
257 var e = ev ? ev : window.event,
258 client = { x: e.clientX, y: e.clientY },
259 page = { x: e.pageX, y: e.pageY },
263 // Grab useful coordinates from touch events
264 if (e.type.match(/^touch/)) {
266 x: e.originalEvent.targetTouches[0].pageX,
267 y: e.originalEvent.targetTouches[0].pageY
270 x: e.originalEvent.targetTouches[0].clientX,
271 y: e.originalEvent.targetTouches[0].clientY
275 if (page.x || page.y) {
280 if (client.x || client.y) {
281 posx = client.x + document.body.scrollLeft + document.documentElement.scrollLeft;
282 posy = client.y + document.body.scrollTop + document.documentElement.scrollTop;
285 return { x: posx, y: posy };
288 // TODO : offsetX, offsetY. touch events don't have offsetX and offsetY. support for touch devices.
289 // check algorithm...
290 targetRelativeCoordsFromEvent: function(e) {
291 var coords = { x: e.offsetX, y: e.offsetY };
293 if (coords.x === undefined || isNaN(coords.x) ||
294 coords.y === undefined || isNaN(coords.y)) {
295 var offset = $(e.target).offset();
296 //coords = documentRelativeCoordsFromEvent(e); // Old code. Must be checked again.
297 coords = $.mobile.tizen.documentRelativeCoordsFromEvent(e);
298 coords.x -= offset.left;
299 coords.y -= offset.top;