Skip to content

Instantly share code, notes, and snippets.

View albburtsev's full-sized avatar
💭
🤔

Alexander Burtsev albburtsev

💭
🤔
View GitHub Profile

This example demonstrates how to create a gradient that follows a stroke. This technique is sometimes used to indicate directionality along a curved edge, such as with hierarchical edge bundling.

To start, take any SVG path element and uniformly sample points along the path using getPointAtLength. (This method can also be used for path tweening.) Then, for each segment between adjacent points, compute the miter joint via line-line intersection. Lastly fill each segment by interpolating the start and end colors, here green to red, using the normalized length t along the path. Although each segment is a constant color, there are many segments to give the appearance of a continuous gradient.

This example uses a thin stroke in addition to filling the segments. This avoids antialiasing artifacts due to most

@albburtsev
albburtsev / jquery.tabinsert.js
Last active December 12, 2015 04:19
jQuery textarea tab insert
/*
* Textarea tab insert
* @dependence jQuery>=1.4.2
* @dependence https://github.com/jeresig/jquery.hotkeys
* @author Alexander Burtsev
*/
$('textarea', _form).bind("keydown", "tab", function(e) {
if ( document.selection ) { // IE
var iesel = document.selection.createRange().duplicate();
iesel.text = "\t";
@albburtsev
albburtsev / test.js
Created January 28, 2013 19:20
Casperjs test for URL with auth basic
var casper = require("casper").create();
var argDomain = casper.cli.get("domain"),
argLogin = casper.cli.get("login"),
argPassword = casper.cli.get("password");
if ( !argDomain ) {
casper.echo('USAGE: casperjs login.js --domain=DOMAIN --login=AUTH_LOGIN --password=AUTH_PASSWORD');
casper.exit();
}
@albburtsev
albburtsev / all.profiler.js
Created September 14, 2012 09:46
all.profiler.js
(function() {
if (
!window.console ||
!console.log
) return;
var eventList = [
/* Список событий */
];
<!DOCTYPE html>
<html lang="ru-RU" class="noscroll index">
<head>
<meta charset="utf-8">
<title>POST</title>
<script src="http://maps.mail.ru/js/jquery-1.7.1.min.js"></script>
<script>
// Docs: http://api.jquery.com/jQuery.post/
jQuery.post('/url', { data: 'jsondata' }, function() {
alert('Success!');
/**
* @ignore
* @description Вычисление расстояния D от точки p, до отрезка, задаваемоого точками p1 и p2
* @description Также вычисляются координаты точки пересечения (xN, yN) перпендикуляра, проведенного из точки к отрезку
* @description Если точка пересечение лежит вне отрезка, или отрезок нулевой длины - вернется false
*/
vertical: function(p1, p2, p) {
var x1 = p1.lon,
y1 = p1.lat,
x2 = p2.lon,
var
/**
* @constructor
* @description Базовый класс, от которого наследуется деструктор объектов
*/
Root = function() {
};
Root.prototype = {
jQuery.fn.renew = function() {
return $(this.selector);
};
$('div').renew();
tools.htmlToText = function(html) {
var node = document.createElement('b');
node.innerHTML = html;
return node.innerText || node.textContent || '';
}
function fireCustomEvent(eventType) {
if ( document.dispatchEvent ) { // DOM browser
var e = document.createEvent("UIEvents");
e.initEvent(eventType, false, false);
document.dispatchEvent(e);
} else if ( document.attachEvent ) { // IE
if ( !document.documentElement[eventType] )
document.documentElement[eventType] = 1;
else
document.documentElement[eventType] += 1;