ola3doc first release
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
# jQuery.line plugin
|
||||
|
||||
***
|
||||
|
||||
> jQuery plugin to draw lines using single DIV and pure CSS3
|
||||
|
||||
***
|
||||
|
||||
|
||||
## Demo:
|
||||
|
||||
[Demo](http://stopsopa.bitbucket.org/demos/jquery.line/demo.html)
|
||||
|
||||
|
||||
|
||||
### Using:
|
||||
|
||||
```js
|
||||
var linediv = $.line(x1, y1, x2, y2, opt, callback);
|
||||
var linediv = $('parent element').line(x1, y1, x2, y2, opt, callback);
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
radians and distance
|
||||
```js
|
||||
var linediv = $.line(x1, y1, {rad: Math.PI/4, dis: 200}, opt, callback);
|
||||
var linediv = $('parent element').line(x1, y1, {rad: Math.PI/4, dis: 200}, opt, callback);
|
||||
```
|
||||
or
|
||||
|
||||
|
||||
angle and distance
|
||||
```js
|
||||
var linediv = $.line(x1, y1, {ang: 45, dis: 200}, opt, callback);
|
||||
var linediv = $('parent element').line(x1, y1, {ang: 45, dis: 200}, opt, callback);
|
||||
```
|
||||
|
||||
|
||||
### Default options are:
|
||||
|
||||
|
||||
```js
|
||||
{
|
||||
create: $('<div></div>'), // default it's div, you can change to $('<span></span>')
|
||||
cls: '_line',
|
||||
id : false,
|
||||
css: {
|
||||
// you can change styles of div in js here through $(..).css()
|
||||
// but be careful that you can override here property used
|
||||
// to calculations ('width')
|
||||
// which is defined right below
|
||||
height: '0',
|
||||
zIndex: '999',
|
||||
zoom: 1
|
||||
},
|
||||
width: 1,
|
||||
style: 'solid',
|
||||
color: 'black'
|
||||
}
|
||||
```
|
||||
|
||||
### Callback:
|
||||
|
||||
In context of callback you have two parameters, one is div representing line, and second used options
|
||||
|
||||
```js
|
||||
$.line(x1, y1, x2, y2, opt, function (div, opt) {
|
||||
...
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
|
||||
# License
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Szymon Działowski
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
|
After Width: | Height: | Size: 595 B |
@@ -0,0 +1,263 @@
|
||||
/**
|
||||
* @author Szymon Działowski
|
||||
* @homepage https://bitbucket.org/stopsopa/jquery.line
|
||||
* @ver 1.0 2014-07-06
|
||||
* @ver 1.1 2014-07-07 upgrades, corrections
|
||||
* @ver 1.2 2015-05-01 drawing line by rad/ang and distance from point x and x, fix manual
|
||||
*/
|
||||
|
||||
(function( factory ) {
|
||||
if ( typeof define === "function" && define.amd ) {
|
||||
|
||||
// AMD. Register as an anonymous module.
|
||||
define([ "jquery" ], factory );
|
||||
} else {
|
||||
|
||||
// Browser globals
|
||||
factory( jQuery );
|
||||
}
|
||||
})((function (name, pi) {
|
||||
return function ($) {
|
||||
function log(l) {try {console.log(l);}catch (e) {}};
|
||||
function error(l) {try {console.error(l);}catch (e) {}};
|
||||
function _thw(message) {throw "plugin jQuery(...)."+name+"() : "+message};
|
||||
function _a(a) {
|
||||
return Array.prototype.slice.call(a, 0);
|
||||
}
|
||||
function isFunction (a) { // taken from underscore.js
|
||||
return typeof a == 'function' || false;
|
||||
};
|
||||
function isObject(obj) {
|
||||
var type = typeof obj;
|
||||
return type === 'function' || type === 'object' && !!obj;
|
||||
};
|
||||
function angToRad(ang) {
|
||||
return ang * (pi / 180);
|
||||
}
|
||||
function radToAng(rad) {
|
||||
return rad * (180 / pi) ;
|
||||
}
|
||||
// calc distance between two points
|
||||
function calcDistance(x1, y1, x2, y2) { // http://www.gwycon.com/calculating-the-distance-between-two-pixels/
|
||||
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
|
||||
}
|
||||
// count angle in radians
|
||||
function calcAngleRad(x1, y1, x2, y2) {
|
||||
return Math.atan2( (y2 - y1) , (x2 - x1) );
|
||||
}
|
||||
// count angle in degrees
|
||||
function calcAngle(x1, y1, x2, y2) {
|
||||
var a = calcAngleRad(x1, y1, x2, y2) * (180 / pi);
|
||||
return (a < 0) ? (a += 360) : a;
|
||||
}
|
||||
function calcXYOffsetByVectorAngleRad(rad, dis) {
|
||||
return { // http://stackoverflow.com/a/10962780
|
||||
x : Math.cos(rad) * dis,
|
||||
y : Math.sin(rad) * dis
|
||||
}
|
||||
}
|
||||
function calcXYOffsetByVectorAngle(ang, dis) {
|
||||
return calcXYOffsetByVectorAngleRad(angToRad(ang), dis);
|
||||
}
|
||||
// count correction
|
||||
function correct(x1, y1, x2, y2, o, ang) {
|
||||
ang || (ang = calcAngle(x1, y1, x2, y2));
|
||||
|
||||
var hw = o.width/2;
|
||||
var hwo = hw // originial
|
||||
|
||||
var sw = false;
|
||||
|
||||
if ($.isNumeric(o.correct)) {
|
||||
var c = o.correct;
|
||||
switch(true) {
|
||||
case o.correctpos == 'normal':
|
||||
hw += c;
|
||||
break;
|
||||
case o.correctpos == 'top' && (ang > 90 && ang < 270) :
|
||||
sw = true;
|
||||
c = - Math.abs(c);
|
||||
break;
|
||||
case o.correctpos == 'bottom' && (ang < 90 || ang > 270) :
|
||||
sw = true;
|
||||
c = - Math.abs(c);
|
||||
break;
|
||||
case o.correctpos == 'left' && (ang > 0 && ang < 180) :
|
||||
sw = true;
|
||||
c = - Math.abs(c);
|
||||
break;
|
||||
case o.correctpos == 'right' && (ang < 0 || ang > 180) :
|
||||
sw = true;
|
||||
c = - Math.abs(c);
|
||||
break;
|
||||
}
|
||||
hw += c;
|
||||
}
|
||||
|
||||
var rad = calcAngleRad(x1, y1, x2, y2); // radians
|
||||
var radminhalf = (rad - (pi / 2)); // radians minus half radian
|
||||
|
||||
var c = {};
|
||||
if (o.correct === false) {
|
||||
c.x = c.y = c.oy = c.ox = 0;
|
||||
}
|
||||
else {
|
||||
c.y = Math.sin(radminhalf) * hw;
|
||||
c.x = Math.cos(radminhalf) * hw;
|
||||
c.oy = Math.sin(radminhalf) * hwo; // without correction
|
||||
c.ox = Math.cos(radminhalf) * hwo; // without correction
|
||||
}
|
||||
c.ang = ang;
|
||||
c.rad = rad
|
||||
c.ox2 = c.ox * 2;
|
||||
c.oy2 = c.oy * 2;
|
||||
c.x1 = x1;
|
||||
c.y1 = y1;
|
||||
c.x2 = x2;
|
||||
c.y2 = y2;
|
||||
|
||||
if (sw) {
|
||||
c.ax = c.x1 - c.ox2;
|
||||
c.ay = c.y1 - c.oy2;
|
||||
|
||||
c.bx = c.ax + c.x;
|
||||
c.by = c.ay + c.y;
|
||||
|
||||
c.cx = c.x2 + c.x
|
||||
c.cy = c.y2 + c.y;
|
||||
|
||||
c.dx = c.cx - c.ox2;
|
||||
c.dy = c.cy - c.oy2;
|
||||
}
|
||||
else {
|
||||
c.bx = c.x1 + c.x;
|
||||
c.by = c.y1 + c.y;
|
||||
|
||||
c.ax = c.bx - c.ox2;
|
||||
c.ay = c.by - c.oy2;
|
||||
|
||||
c.dx = c.x2 + c.x;
|
||||
c.dy = c.y2 + c.y;
|
||||
|
||||
c.cx = c.dx - c.ox2
|
||||
c.cy = c.dy - c.oy2;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
/**
|
||||
* @returns jQuery object representing line
|
||||
* var linediv = $.line(x1, y1, x2, y2, opt, callback);
|
||||
* var linediv = $('parent element').line(x1, y1, x2, y2, opt, callback);
|
||||
* var linediv = $('parent element').line(x1, y1, {ang: 45, dis: 200}, opt, callback);
|
||||
* var linediv = $.line(x1, y1, {ang: 45, dis: 200}, opt, callback);
|
||||
*/ //0 1 2 3 4 5
|
||||
$.fn[name] = function (x1, y1, x2, y2, opt, callback) {
|
||||
|
||||
if (isObject(x2)) {
|
||||
var k = 0, a = _a(arguments);
|
||||
|
||||
if (typeof x2.ang != 'undefined')
|
||||
k = calcXYOffsetByVectorAngle(x2.ang, x2.dis);
|
||||
|
||||
else if (typeof x2.rad != 'undefined')
|
||||
k = calcXYOffsetByVectorAngleRad(x2.rad, x2.dis);
|
||||
|
||||
else _thw("Arguments incomplete: "+JSON.stringify(a));
|
||||
|
||||
a[5] = a[4];
|
||||
a[4] = a[3];
|
||||
a[2] = x1 + k.x;
|
||||
a[3] = y1 + k.y;
|
||||
log(a);
|
||||
|
||||
return $.fn[name].apply(this, a);
|
||||
}
|
||||
|
||||
if (isFunction(opt)) {
|
||||
callback = opt;
|
||||
}
|
||||
else if (isFunction(callback)) {
|
||||
opt = callback;
|
||||
}
|
||||
|
||||
opt || (opt = {});
|
||||
|
||||
if ($(this).length > 1)
|
||||
throw "$(this) is more then one element";
|
||||
|
||||
var o = {
|
||||
style: 'solid',
|
||||
width: 1,
|
||||
color: 'black',
|
||||
|
||||
cls: 'jqline',
|
||||
id: false,
|
||||
correct: true, // bool|int - corection of position, give integer to move
|
||||
correctpos: 'normal', // normal, top, bottom, left, right
|
||||
css: {
|
||||
height: '0',
|
||||
zIndex: '999',
|
||||
zoom: 1
|
||||
}
|
||||
}
|
||||
|
||||
if (opt.css) {
|
||||
$.extend(o.css, opt.css);
|
||||
opt.css = o.css;
|
||||
}
|
||||
|
||||
o = $.extend(true, o, opt || {});
|
||||
o.create = opt.create ? $(opt.create) : $('<div></div>');
|
||||
var ang = calcAngle(x1, y1, x2, y2); // degrees
|
||||
var c = correct(x1, y1, x2, y2, o/* half of line width */, ang);
|
||||
c.distance = calcDistance(x1, y1, x2, y2);
|
||||
|
||||
o.create
|
||||
.css({
|
||||
borderTop: o.width+'px '+o.style+' '+o.color,
|
||||
position: 'absolute',
|
||||
width: c.distance + 'px',
|
||||
'-webkit-transform': 'rotate(' + ang + 'deg)',
|
||||
'-moz-transform': 'rotate(' + ang + 'deg)',
|
||||
'-ms-transform': 'rotate(' + ang + 'deg)',
|
||||
'-o-transform': 'rotate(' + ang + 'deg)',
|
||||
transform: 'rotate(' + ang + 'deg)',
|
||||
|
||||
'transform-origin' : '0 0',
|
||||
'-ms-transform-origin' : '0 0', /* IE 9 */
|
||||
'-webkit-transform-origin' : '0 0', /* Chrome, Safari, Opera */
|
||||
|
||||
left : (x1 + c.x)+'px',
|
||||
top : (y1 + c.y)+'px'
|
||||
})
|
||||
.css(o.css)
|
||||
;
|
||||
|
||||
o.cls && o.create.addClass(o.cls);
|
||||
o.id && o.create.attr('id', o.id);
|
||||
|
||||
o.create.appendTo(this);
|
||||
|
||||
(isFunction(callback)) && callback(o.create, o, c);
|
||||
|
||||
return o.create;
|
||||
};
|
||||
/**
|
||||
* @returns jQuery object representing line
|
||||
*/
|
||||
$[name] = function () {
|
||||
var b = $('body');
|
||||
return b[name].apply(b, arguments);
|
||||
};
|
||||
|
||||
// expose tools to use outside
|
||||
$[name].radToAng = radToAng;
|
||||
$[name].angToRad = angToRad;
|
||||
$[name].calcDistance = calcDistance;
|
||||
$[name].calcAngleRad = calcAngleRad;
|
||||
$[name].calcAngle = calcAngle;
|
||||
$[name].calcXYOffsetByVectorAngle = calcXYOffsetByVectorAngle;
|
||||
$[name].calcXYOffsetByVectorAngleRad = calcXYOffsetByVectorAngleRad;
|
||||
}
|
||||
})('line', Math.PI)); // to change name of plugin simply change it in this place
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
$(document).ready(function(){
|
||||
var _$users = $('div.user');
|
||||
|
||||
function init(){
|
||||
|
||||
wrapHTML();
|
||||
getOutImages();
|
||||
|
||||
randomPosition($('div.user h1:first'));
|
||||
randomPosition($('div.user h2:first'));
|
||||
createLineHeader();
|
||||
createLineContent();
|
||||
createLineContentImages();
|
||||
createLineImages();
|
||||
}
|
||||
|
||||
function wrapHTML(){
|
||||
_$users.each(function(){
|
||||
var $header = $('<header />').append($('h1:first, h2:first', this));
|
||||
$header.prependTo(this)
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function getOutImages(){
|
||||
$('div.user img').each(function(){
|
||||
var cnt = $(this).parent('p').contents();
|
||||
$(this).parent('p').replaceWith(cnt);
|
||||
});
|
||||
}
|
||||
|
||||
function createLineHeader(){
|
||||
|
||||
_$users.each(function(){
|
||||
var h2Height = $(this).find('h2:first').outerHeight();
|
||||
|
||||
var h1Width = $(this).find('h1:first').outerWidth();
|
||||
|
||||
var x1 = $(this).find('h2:first').position().left + 50;
|
||||
var y1 = $(this).find('h2:first').position().top + h2Height;
|
||||
var x2 = $(this).find('h1:first').position().left + (h1Width / 2);
|
||||
var y2 = $(this).find('h1:first').position().top;
|
||||
// console.log(x1, x2, y1, y2);
|
||||
var linediv = $(this).line(x1, y1, x2, y2, {width: 2});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function createLineContent(){
|
||||
_$users.each(function(){
|
||||
var h1Height = $(this).find('h1:first').outerHeight();
|
||||
// var h1Width = $(this).find('h1').outerWidth();
|
||||
|
||||
var x1 = $(this).find('h1:first').position().left + 50;
|
||||
var y1 = $(this).find('h1:first').position().top + h1Height;
|
||||
var x2 = $(this).find('.content').position().left;
|
||||
var y2 = $(this).find('.content').position().top;
|
||||
// console.log(x1, x2, y1, y2);
|
||||
var linediv = $(this).line(x1, y1, x2, y2, {width: 2});
|
||||
});
|
||||
}
|
||||
|
||||
function createLineContentImages(){
|
||||
_$users.each(function(){
|
||||
var contentHeight = $(this).find('.content').outerHeight();
|
||||
// var h1Width = $(this).find('h1').outerWidth();
|
||||
|
||||
var x1 = $(this).find('.content').position().left;
|
||||
var y1 = $(this).find('.content').position().top + contentHeight;
|
||||
var x2 = $(this).find('.images').position().left + 100;
|
||||
var y2 = $(this).find('.images').position().top + 10;
|
||||
// console.log(x1, x2, y1, y2);
|
||||
|
||||
if($(this).find('.images').find('li').length){
|
||||
var linediv = $(this).line(x1, y1, x2, y2, {width: 2});
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function createLineImages(){
|
||||
_$users.each(function(){
|
||||
$(this).find('.images').find('li').each(function(){
|
||||
var height = $(this).outerHeight();
|
||||
var width = $(this).outerWidth();
|
||||
|
||||
if($(this).next().length){
|
||||
// console.log($(this));
|
||||
var x1 = $(this).position().left + width ;
|
||||
var y1 = $(this).position().top + height + 15;
|
||||
var x2 = $(this).next().position().left + width - 100;
|
||||
var y2 = $(this).next().position().top + 16;
|
||||
var linediv = $(this).line(x1, y1, x2, y2, {width: 2});
|
||||
// console.log(y1);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function randomPosition($element){
|
||||
$element.each(function(){
|
||||
var randomPos = Math.random() * (_$users.width()- $(this).width());
|
||||
var width = $(this).width();
|
||||
$(this).css({
|
||||
'left': randomPos,
|
||||
'width': width
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
init();
|
||||
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user