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) {
199 return $(element).each(function () {
200 jQuery(element).css('-webkit-user-select', 'none');
204 enableSelection: function (element, value) {
205 return $(element).each(function () {
206 val = value == "text" ? val = 'text' : val = 'auto';
207 jQuery(element).css('-webkit-user-select', val);
211 // Set the height of the content area to fill the space between a
212 // page's header and footer
213 fillPageWithContentArea: function (page) {
215 var $content = $page.children(".ui-content:first");
216 var hh = $page.children(".ui-header").outerHeight(); hh = hh ? hh : 0;
217 var fh = $page.children(".ui-footer").outerHeight(); fh = fh ? fh : 0;
218 var pt = parseFloat($content.css("padding-top"));
219 var pb = parseFloat($content.css("padding-bottom"));
220 var wh = window.innerHeight;
221 var height = wh - (hh + fh) - (pt + pb);
222 $content.height(height);
225 // Get document-relative mouse coordinates from a given event
226 // From: http://www.quirksmode.org/js/events_properties.html#position
227 documentRelativeCoordsFromEvent: function(ev) {
228 var e = ev ? ev : window.event,
229 client = { x: e.clientX, y: e.clientY },
230 page = { x: e.pageX, y: e.pageY },
234 // Grab useful coordinates from touch events
235 if (e.type.match(/^touch/)) {
237 x: e.originalEvent.targetTouches[0].pageX,
238 y: e.originalEvent.targetTouches[0].pageY
241 x: e.originalEvent.targetTouches[0].clientX,
242 y: e.originalEvent.targetTouches[0].clientY
246 if (page.x || page.y) {
251 if (client.x || client.y) {
252 posx = client.x + document.body.scrollLeft + document.documentElement.scrollLeft;
253 posy = client.y + document.body.scrollTop + document.documentElement.scrollTop;
256 return { x: posx, y: posy };
259 // TODO : offsetX, offsetY. touch events don't have offsetX and offsetY. support for touch devices.
260 // check algorithm...
261 targetRelativeCoordsFromEvent: function(e) {
262 var coords = { x: e.offsetX, y: e.offsetY };
264 if (coords.x === undefined || isNaN(coords.x) ||
265 coords.y === undefined || isNaN(coords.y)) {
266 var offset = $(e.target).offset();
267 //coords = documentRelativeCoordsFromEvent(e); // Old code. Must be checked again.
268 coords = $.mobile.tizen.documentRelativeCoordsFromEvent(e);
269 coords.x -= offset.left;
270 coords.y -= offset.top;