Skip to content

Commit 101f013

Browse files
committedFeb 3, 2012
add MIT license
1 parent a6effb0 commit 101f013

File tree

5 files changed

+231
-181
lines changed

5 files changed

+231
-181
lines changed
 

‎MIT-LICENSE.txt

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
Copyright (c) 2012 Egor Khmelev
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
SOFTWARE.

‎index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html xmlns="http://www.w3.org/1999/xhtml">
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
5-
<title>Слайдер</title>
5+
<title>jSlider</title>
66
<link rel="stylesheet" href="./stylesheets/jslider.css" type="text/css">
77
<link rel="stylesheet" href="./stylesheets/jslider.blue.css" type="text/css">
88
<link rel="stylesheet" href="./stylesheets/jslider.plastic.css" type="text/css">
@@ -13,8 +13,8 @@
1313
<script type="text/javascript" src="./javascripts/jshashtable-2.1_src.js"></script>
1414
<script type="text/javascript" src="./javascripts/jquery.numberformatter-1.2.2.js"></script>
1515
<script type="text/javascript" src="./javascripts/tmpl.js"></script>
16-
<script type="text/javascript" src="./javascripts/jquery.dependClass.js"></script>
17-
<script type="text/javascript" src="./javascripts/draggable.js"></script>
16+
<script type="text/javascript" src="./javascripts/jquery.dependClass-0.1.js"></script>
17+
<script type="text/javascript" src="./javascripts/draggable-0.1.js"></script>
1818
<script type="text/javascript" src="./javascripts/jquery.slider.js"></script>
1919

2020
<style type="text/css" media="screen">

‎javascripts/draggable-0.1.js

+196
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
/**
2+
* draggable - Class allows to make any element draggable
3+
*
4+
* Written by
5+
* Egor Khmelev (hmelyoff@gmail.com)
6+
*
7+
* Licensed under the MIT (MIT-LICENSE.txt).
8+
*
9+
* @author Egor Khmelev
10+
* @version 0.1.0-BETA ($Id$)
11+
*
12+
**/
13+
14+
(function( $ ){
15+
16+
function Draggable(){
17+
this._init.apply( this, arguments );
18+
};
19+
20+
Draggable.prototype.oninit = function(){
21+
22+
};
23+
24+
Draggable.prototype.events = function(){
25+
26+
};
27+
28+
Draggable.prototype.onmousedown = function(){
29+
this.ptr.css({ position: "absolute" });
30+
};
31+
32+
Draggable.prototype.onmousemove = function( evt, x, y ){
33+
this.ptr.css({ left: x, top: y });
34+
};
35+
36+
Draggable.prototype.onmouseup = function(){
37+
38+
};
39+
40+
Draggable.prototype.isDefault = {
41+
drag: false,
42+
clicked: false,
43+
toclick: true,
44+
mouseup: false
45+
};
46+
47+
Draggable.prototype._init = function(){
48+
if( arguments.length > 0 ){
49+
this.ptr = $(arguments[0]);
50+
this.outer = $(".draggable-outer");
51+
52+
this.is = {};
53+
$.extend( this.is, this.isDefault );
54+
55+
var _offset = this.ptr.offset();
56+
this.d = {
57+
left: _offset.left,
58+
top: _offset.top,
59+
width: this.ptr.width(),
60+
height: this.ptr.height()
61+
};
62+
63+
this.oninit.apply( this, arguments );
64+
65+
this._events();
66+
}
67+
};
68+
69+
Draggable.prototype._getPageCoords = function( event ){
70+
if( event.targetTouches && event.targetTouches[0] ){
71+
return { x: event.targetTouches[0].pageX, y: event.targetTouches[0].pageY };
72+
} else
73+
return { x: event.pageX, y: event.pageY };
74+
};
75+
76+
Draggable.prototype._bindEvent = function( ptr, eventType, handler ){
77+
var self = this;
78+
79+
if( this.supportTouches_ )
80+
ptr.get(0).addEventListener( this.events_[ eventType ], handler, false );
81+
82+
else
83+
ptr.bind( this.events_[ eventType ], handler );
84+
};
85+
86+
Draggable.prototype._events = function(){
87+
var self = this;
88+
89+
this.supportTouches_ = ( $.browser.webkit && navigator.userAgent.indexOf("Mobile") != -1 );
90+
this.events_ = {
91+
"click": this.supportTouches_ ? "touchstart" : "click",
92+
"down": this.supportTouches_ ? "touchstart" : "mousedown",
93+
"move": this.supportTouches_ ? "touchmove" : "mousemove",
94+
"up" : this.supportTouches_ ? "touchend" : "mouseup"
95+
};
96+
97+
this._bindEvent( $( document ), "move", function( event ){
98+
if( self.is.drag ){
99+
event.stopPropagation();
100+
event.preventDefault();
101+
self._mousemove( event );
102+
}
103+
});
104+
this._bindEvent( $( document ), "down", function( event ){
105+
if( self.is.drag ){
106+
event.stopPropagation();
107+
event.preventDefault();
108+
}
109+
});
110+
this._bindEvent( $( document ), "up", function( event ){
111+
self._mouseup( event );
112+
});
113+
114+
this._bindEvent( this.ptr, "down", function( event ){
115+
self._mousedown( event );
116+
return false;
117+
});
118+
this._bindEvent( this.ptr, "up", function( event ){
119+
self._mouseup( event );
120+
});
121+
122+
this.ptr.find("a")
123+
.click(function(){
124+
self.is.clicked = true;
125+
126+
if( !self.is.toclick ){
127+
self.is.toclick = true;
128+
return false;
129+
}
130+
})
131+
.mousedown(function( event ){
132+
self._mousedown( event );
133+
return false;
134+
});
135+
136+
this.events();
137+
};
138+
139+
Draggable.prototype._mousedown = function( evt ){
140+
this.is.drag = true;
141+
this.is.clicked = false;
142+
this.is.mouseup = false;
143+
144+
var _offset = this.ptr.offset();
145+
var coords = this._getPageCoords( evt );
146+
this.cx = coords.x - _offset.left;
147+
this.cy = coords.y - _offset.top;
148+
149+
$.extend(this.d, {
150+
left: _offset.left,
151+
top: _offset.top,
152+
width: this.ptr.width(),
153+
height: this.ptr.height()
154+
});
155+
156+
if( this.outer && this.outer.get(0) ){
157+
this.outer.css({ height: Math.max(this.outer.height(), $(document.body).height()), overflow: "hidden" });
158+
}
159+
160+
this.onmousedown( evt );
161+
};
162+
163+
Draggable.prototype._mousemove = function( evt ){
164+
this.is.toclick = false;
165+
var coords = this._getPageCoords( evt );
166+
this.onmousemove( evt, coords.x - this.cx, coords.y - this.cy );
167+
};
168+
169+
Draggable.prototype._mouseup = function( evt ){
170+
var oThis = this;
171+
172+
if( this.is.drag ){
173+
this.is.drag = false;
174+
175+
if( this.outer && this.outer.get(0) ){
176+
177+
if( $.browser.mozilla ){
178+
this.outer.css({ overflow: "hidden" });
179+
} else {
180+
this.outer.css({ overflow: "visible" });
181+
}
182+
183+
if( $.browser.msie && $.browser.version == '6.0' ){
184+
this.outer.css({ height: "100%" });
185+
} else {
186+
this.outer.css({ height: "auto" });
187+
}
188+
}
189+
190+
this.onmouseup( evt );
191+
}
192+
};
193+
194+
window.Draggable = Draggable;
195+
196+
})( jQuery );

‎javascripts/draggable.js

-172
This file was deleted.

‎javascripts/jquery.dependClass.js ‎javascripts/jquery.dependClass-0.1.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
/*
2-
* Depend Class v0.1b : attach class based on first class in list of current element
3-
* File: jquery.dependClass.js
4-
* Copyright (c) 2009 Egor Hmelyoff, hmelyoff@gmail.com
5-
*/
6-
1+
/**
2+
* jquery.dependClass - Attach class based on first class in list of current element
3+
*
4+
* Written by
5+
* Egor Khmelev (hmelyoff@gmail.com)
6+
*
7+
* Licensed under the MIT (MIT-LICENSE.txt).
8+
*
9+
* @author Egor Khmelev
10+
* @version 0.1.0-BETA ($Id$)
11+
*
12+
**/
713

814
(function($) {
915
$.baseClass = function(obj){

0 commit comments

Comments
 (0)
Please sign in to comment.