[TemporaryStorage] add files required for SDK build
[samples/web/TemporaryStorage.git] / tizen-web-ui-fw / latest / js / src / jquery.mobile.tizen.core.js
1
2 /*
3  * jQuery Mobile Widget @VERSION
4  *
5  * TODO: remove unnecessary codes....
6  *
7  * This software is licensed under the MIT licence (as defined by the OSI at
8  * http://www.opensource.org/licenses/mit-license.php)
9  * 
10  * ***************************************************************************
11  * Copyright (C) 2011 by Intel Corporation Ltd.
12  * 
13  * Permission is hereby granted, free of charge, to any person obtaining a
14  * copy of this software and associated documentation files (the "Software"),
15  * to deal in the Software without restriction, including without limitation
16  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  * and/or sell copies of the Software, and to permit persons to whom the
18  * Software is furnished to do so, subject to the following conditions:
19  * 
20  * The above copyright notice and this permission notice shall be included in
21  * all copies or substantial portions of the Software.
22  * 
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29  * DEALINGS IN THE SOFTWARE.
30  * ***************************************************************************
31  *
32  * Authors: Kalyan Kondapally <kalyan.kondapally@intel.com>
33  */
34
35 ensureNS("jQuery.mobile.tizen");
36
37 (function () {
38 jQuery.extend(jQuery.mobile.tizen, {
39         disableSelection: function (element) {
40                 this.enableSelection(
41                         $(element).find('*').not( 'input, [type="text"], textarea' ),
42                         'none'
43                 );
44                 return true;
45         },
46
47         enableSelection: function (element, value) {
48                 var val;
49                 switch ( value ) {
50                         case 'text' :
51                         case 'auto' :
52                         case 'none' :
53                                 val = value;
54                         break;
55                         default :
56                                 val = 'auto';
57                         break;
58                 }
59                 return $(element).css( {
60                         'user-select': val,
61                         '-moz-user-select': val,
62                         '-webkit-user-select': val,
63                         '-o-user-select': val,
64                         '-ms-transform': val
65                 } );
66     },
67
68     disableContextMenu: function(element) {
69         var self = this;
70         $(element).find('*').each( function() {
71                 if( ( $(this).get(0).tagName !== 'INPUT' &&
72                         $(this).attr("type") !== 'text' ) &&
73                         $(this).get(0).tagName !== 'TEXTAREA' ) {
74                         self._disableContextMenu( this );
75                 }
76         } );
77     },
78
79     _disableContextMenu: function(element) {
80
81         $(element).each( function() {
82                 $(this).bind("contextmenu", function( event ) {
83                         return false;
84                 } );
85         } );
86     },
87
88     enableContextMenu: function(element) {
89         $(element).each( function() {
90                 $(this).unbind( "contextmenu" );
91         } );
92     },
93
94     // Get document-relative mouse coordinates from a given event
95     // From: http://www.quirksmode.org/js/events_properties.html#position
96     documentRelativeCoordsFromEvent: function(ev) {
97         var e = ev ? ev : window.event,
98             client = { x: e.clientX, y: e.clientY },
99             page   = { x: e.pageX,   y: e.pageY   },
100             posx = 0,
101             posy = 0;
102
103         // Grab useful coordinates from touch events
104         if (e.type.match(/^touch/)) {
105             page = {
106                 x: e.originalEvent.targetTouches[0].pageX,
107                 y: e.originalEvent.targetTouches[0].pageY
108             };
109             client = {
110                 x: e.originalEvent.targetTouches[0].clientX,
111                 y: e.originalEvent.targetTouches[0].clientY
112             };
113         }
114
115         if (page.x || page.y) {
116             posx = page.x;
117             posy = page.y;
118         }
119         else
120         if (client.x || client.y) {
121             posx = client.x + document.body.scrollLeft + document.documentElement.scrollLeft;
122             posy = client.y + document.body.scrollTop  + document.documentElement.scrollTop;
123         }
124
125         return { x: posx, y: posy };
126     },
127
128         // TODO : offsetX, offsetY. touch events don't have offsetX and offsetY. support for touch devices.
129     // check algorithm...
130     targetRelativeCoordsFromEvent: function(e) {
131         var coords = { x: e.offsetX, y: e.offsetY };
132
133         if (coords.x === undefined || isNaN(coords.x) ||
134             coords.y === undefined || isNaN(coords.y)) {
135             var offset = $(e.target).offset();
136             //coords = documentRelativeCoordsFromEvent(e);      // Old code. Must be checked again.
137             coords = $.mobile.tizen.documentRelativeCoordsFromEvent(e);
138             coords.x -= offset.left;
139             coords.y -= offset.top;
140         }
141
142         return coords;
143     }
144 });
145
146 })();
147