Export 0.1.61
[platform/framework/web/web-ui-fw.git] / src / widgets / common / js / jquery.mobile.tizen.core.js
1 /*
2  * jQuery Mobile Widget @VERSION
3  *
4  * TODO: remove unnecessary codes....
5  *
6  * This software is licensed under the MIT licence (as defined by the OSI at
7  * http://www.opensource.org/licenses/mit-license.php)
8  * 
9  * ***************************************************************************
10  * Copyright (C) 2011 by Intel Corporation Ltd.
11  * 
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:
18  * 
19  * The above copyright notice and this permission notice shall be included in
20  * all copies or substantial portions of the Software.
21  * 
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  * ***************************************************************************
30  *
31  * Authors: Kalyan Kondapally <kalyan.kondapally@intel.com>
32  */
33
34 ensureNS("jQuery.mobile.tizen");
35
36 (function () {
37 jQuery.extend(jQuery.mobile.tizen, {
38     disableSelection: function (element) {
39         var self = this;
40         $(element).find('*').each( function() {
41                 if( $(this).get(0).tagName !== 'INPUT' &&
42                         $(this).attr("type") !== 'text' ) {
43                         self.enableSelection( this, 'none' );
44                 }
45         } );
46         return true;
47     },
48
49     enableSelection: function (element, value) {
50         return $(element).each( function () {
51                 switch( value ) {
52                         case 'text' :
53                         case 'auto' :
54                         case 'none' :
55                                 val = value;
56                         break;
57
58                         default :
59                                 val = 'auto';
60                         break;
61                 }
62             $(this).css( {
63                         'user-select': val,
64                         '-moz-user-select': val,
65                         '-webkit-user-select': val,
66                         '-o-user-select': val,
67                         '-ms-transform': val
68                         } );
69         } );
70     },
71
72     disableContextMenu: function(element) {
73         var self = this;
74         $(element).find('*').each( function() {
75                 if( $(this).get(0).tagName !== 'INPUT'
76                         && $(this).attr("type") !== 'text' ) {
77                         self._disableContextMenu( this );
78                 }
79         } );
80     },
81
82     _disableContextMenu: function(element) {
83
84         $(element).each( function() {
85                 $(this).bind("contextmenu", function( event ) {
86                         return false;
87                 } );
88         } );
89     },
90
91     enableContextMenu: function(element) {
92         $(element).each( function() {
93                 $(this).unbind( "contextmenu" );
94         } );
95     },
96
97     // Get document-relative mouse coordinates from a given event
98     // From: http://www.quirksmode.org/js/events_properties.html#position
99     documentRelativeCoordsFromEvent: function(ev) {
100         var e = ev ? ev : window.event,
101             client = { x: e.clientX, y: e.clientY },
102             page   = { x: e.pageX,   y: e.pageY   },
103             posx = 0,
104             posy = 0;
105
106         // Grab useful coordinates from touch events
107         if (e.type.match(/^touch/)) {
108             page = {
109                 x: e.originalEvent.targetTouches[0].pageX,
110                 y: e.originalEvent.targetTouches[0].pageY
111             };
112             client = {
113                 x: e.originalEvent.targetTouches[0].clientX,
114                 y: e.originalEvent.targetTouches[0].clientY
115             };
116         }
117
118         if (page.x || page.y) {
119             posx = page.x;
120             posy = page.y;
121         }
122         else
123         if (client.x || client.y) {
124             posx = client.x + document.body.scrollLeft + document.documentElement.scrollLeft;
125             posy = client.y + document.body.scrollTop  + document.documentElement.scrollTop;
126         }
127
128         return { x: posx, y: posy };
129     },
130
131         // TODO : offsetX, offsetY. touch events don't have offsetX and offsetY. support for touch devices.
132     // check algorithm...
133     targetRelativeCoordsFromEvent: function(e) {
134         var coords = { x: e.offsetX, y: e.offsetY };
135
136         if (coords.x === undefined || isNaN(coords.x) ||
137             coords.y === undefined || isNaN(coords.y)) {
138             var offset = $(e.target).offset();
139             //coords = documentRelativeCoordsFromEvent(e);      // Old code. Must be checked again.
140             coords = $.mobile.tizen.documentRelativeCoordsFromEvent(e);
141             coords.x -= offset.left;
142             coords.y -= offset.top;
143         }
144
145         return coords;
146     }
147 });
148
149 })();