Ajout d'une extension

This commit is contained in:
Gauvain Boiché
2020-04-04 18:27:27 +02:00
parent c3ed8cc1c1
commit 3a964fe237
387 changed files with 58921 additions and 0 deletions

View File

@@ -0,0 +1,640 @@
jQuery(function($) {
let studio = {
body: '.aps-body',
link: '[data-shop-link]',
ajax: {
alert: $('#phpbb_alert'),
data: $('#darkenwrapper'),
spinner: $('#studio_spinner'),
timer: null
},
carousel: {
items: $('[data-shop-carousel]'),
item: $('[data-shop-carousel-data]'),
data: {
dotsClass: 'shop-carousel-dots',
nextArrow: '<button class="aps-button-blue shop-carousel-next" type="button"><i class="icon fa-chevron-right fa-fw"></i></button>',
prevArrow: '<button class="aps-button-blue shop-carousel-prev" type="button"><i class="icon fa-chevron-left fa-fw"></i></button>',
draggable: true
}
},
inventory: {
card: $('.shop-inventory-card'),
info: $('.shop-inventory-info'),
items: $('.shop-inventory-list .shop-inventory-panel'),
proxy: $('.shop-inventory-proxy'),
classes: {
card: '.shop-inventory-card',
cardActive: 'shop-inventory-card-active',
cardPaused: 'shop-inventory-card-paused',
item: '.shop-inventory-item',
itemAnimate: 'shop-inventory-item-animate',
itemCount: '.shop-inventory-item-count',
itemTime: '.shop-inventory-item-time',
link: '.shop-inventory-link',
panel: '.shop-inventory-panel',
refund: '.shop-inventory-refund',
row: '.shop-inventory-row',
stack: '.shop-inventory-stack'
}
},
sketch: {
dots: [],
pool: [],
limit: 280,
timer: null,
timeout: 1500,
colours: ['#12a3eb', '#12a3eb', '#2172b8', '#18a39b', '#82c545', '#f8b739', '#f06045', '#ed2861', '#c12680', '#5d3191'],
drawing: null,
overlay: $('.shop-inventory-overlay'),
}
};
/**
* Set up carousel items.
*
* @return {void}
*/
studio.carousel.setup = function() {
let none = false,
data = studio.carousel.item.data();
if (data) {
none = !data.dots && !data.arrows;
delete data['shopCarouselData'];
}
// Register all carousel items
studio.carousel.items.each(function() {
let $footer = $(this).parent().next('.aps-panel-footer');
let slickData = $.extend({}, data, studio.carousel.data);
if ($(this).data('shop-carousel') === 'images') {
$.extend(slickData, {
arrows: false,
asNavFor: $footer,
dots: false,
fade: true,
slidesToScroll: 1,
slidesToShow: 1
});
} else {
$.extend(slickData, {
appendDots: $footer,
appendArrows: $footer
});
}
// Initiate a Slick instance
$(this).slick(slickData);
if ($(this).data('shop-carousel') === 'images') {
$footer.slick({
arrows: false,
asNavFor: this,
centerMode: true,
dots: false,
focusOnSelect: true,
slidesToScroll: 1,
slidesToShow: 3
});
}
// If there are no navigation arrows or dots, remove the footer
if (none) {
$footer.remove();
}
});
/**
* Remove the carousel data element.
*/
studio.carousel.item.remove();
};
studio.carousel.setup();
/**
* Show the loader for Shop AJAX requests.
*
* @return {void}
*/
studio.ajax.loading = function() {
if (!studio.ajax.spinner.is(':visible')) {
studio.ajax.spinner.fadeIn(100);
studio.ajax.clear();
studio.ajax.timer = setTimeout(studio.ajax.timeout, 60000)
}
};
/**
* Show the time out message for Shop AJAX requests.
*
* @return {void}
*/
studio.ajax.timeout = function() {
studio.ajax.message({
title: studio.ajax.alert.attr('data-l-err'),
html: studio.ajax.alert.attr('data-l-timeout-processing-req'),
type: 'error'
});
};
/**
* Get the localised message for Shop AJAX request errors.
*
* @param {string} attribute
* @return {string}
*/
studio.ajax.data.get = function(attribute) {
return $(this).attr(`data-ajax-error-${attribute}`);
};
/**
* Clear the timer for Shop AJAX requests.
*
* @return {void}
*/
studio.ajax.clear = function() {
if (studio.ajax.timer !== null) {
clearTimeout(studio.ajax.timer);
studio.ajax.timer = null;
}
};
/**
* The error handler for Shop AJAX requests.
*
* @param {Object} jqXHR
* @param {Object} jqXHR.responseJSON
* @param {String} jqXHR.responseText
* @param {string} textStatus
* @param {string} errorThrown
* @return {void}
*/
studio.ajax.error = function(jqXHR, textStatus, errorThrown) {
if (typeof console !== 'undefined' && console.log) {
console.log(`AJAX error. status: ${textStatus}, message: ${errorThrown}`);
}
studio.ajax.clear();
let responseText, errorText = '';
try {
responseText = JSON.parse(jqXHR.responseText);
responseText = responseText.message;
} catch (e) {}
if (typeof responseText === 'string' && responseText.length > 0) {
errorText = responseText;
} else if (typeof errorThrown === 'string' && errorThrown.length > 0) {
errorText = errorThrown;
} else {
errorText = studio.ajax.data.get(`text-${textStatus}`);
if (typeof errorText !== 'string' || !errorText.length) {
errorText = studio.ajax.data.get('text');
}
}
studio.ajax.message({
title: typeof jqXHR.responseJSON !== 'undefined' ? jqXHR.responseJSON.title : studio.ajax.data.get('title', false),
html: errorText,
type: 'error'
});
};
/**
* The success handler for Shop AJAX requests.
*
* @param {Object} r
* @param {function} callback
* @return {void}
*/
studio.ajax.success = function(r, callback) {
studio.ajax.clear();
/**
* @param {string} r.MESSAGE_BODY The message template body
* @param {string} r.YES_VALUE The "yes" language string
* @param {string} r.S_CONFIRM_ACTION The confirm_box() action
* @param {string} r.S_HIDDEN_FIELDS The confirm_box() hidden fields
*/
// If there is no confirm action (not a confirm_box())
if (typeof r.S_CONFIRM_ACTION === 'undefined') {
// Call the callback
if (typeof phpbb.ajaxCallbacks[callback] === 'function') {
phpbb.ajaxCallbacks[callback].call(this, r);
}
// Show the message
studio.ajax.message({
title: r.MESSAGE_TITLE,
html: r.MESSAGE_TEXT
});
} else {
// Show the confirm box
studio.ajax.message({
title: r.MESSAGE_TITLE,
html: r.MESSAGE_BODY,
type: 'question',
showCancelButton: true,
confirmButtonText: r.YES_VALUE
}).then((result) => {
// A button was pressed, was it the Confirm button?
if (result.value) {
let data = $('form', swal.getContent()).serialize();
data = data ? `${data}&` : '';
data = data + $(`<form>${r.S_HIDDEN_FIELDS}</form>`).serialize() + `&confirm=${r.YES_VALUE}`;
// Make the request
studio.ajax.request(r.S_CONFIRM_ACTION, callback, 'POST', data);
}
});
$('input', swal.getContent()).on('keydown', function(e) {
if (e.which === 13) {
swal.clickConfirm();
e.preventDefault();
return false;
}
});
}
};
/**
* Show a message for Shop AJAX requests.
*
* @param {Object} options
* @return {swal}
*/
studio.ajax.message = function(options) {
return swal.fire($.extend({
type: 'success',
cancelButtonClass: 'aps-button-alert aps-button-red',
confirmButtonClass: 'aps-button-alert aps-button-green shop-button-active',
showCloseButton: true,
buttonsStyling: false,
}, options));
};
/**
* Make a Shop AJAX request.
*
* @param {string} url
* @param {function} callback
* @param {string=} type
* @param {Object=} data
* @return {void}
*/
studio.ajax.request = function(url, callback, type, data) {
// Start the loading function
studio.ajax.loading();
// Make the request
let request = $.ajax({
url: url,
type: type || 'GET',
data: data || '',
error: studio.ajax.error,
success: function(r) {
studio.ajax.success(r, callback)
},
});
// No matter what the request returns, always stop the spinner
request.always(function() {
if (studio.ajax.spinner.is(':visible')){
studio.ajax.spinner.fadeOut(100);
}
});
};
/**
* Register all shop links for Shop AJAX requests.
*/
$(studio.body).on('click', studio.link, function(e) {
studio.ajax.request($(this).attr('href'), $(this).data('shop-link'));
e.preventDefault();
});
/**
* Remove an inventory item.
*
* @param {Object} r
* @return {void}
*/
studio.inventory.remove = function(r) {
let $items = $(`[data-shop-item="${r.id}"]`),
$section = $items.parents(studio.inventory.classes.panel),
$column = $section.parent('.aps-col'),
$row = $column.parent(studio.inventory.classes.row);
let $stack = $section.find(studio.inventory.classes.stack),
stack = typeof $stack !== 'undefined' ? parseInt($stack.text()) : false;
if (stack === false) {
$items.remove();
$section.remove();
$column.remove();
if ($row.children().length === 0) {
$row.remove();
}
} else {
$items.not($section.find($items)).remove();
if (r.index > 1) {
let replaceUrl = location.href.slice(0, -r.index.toString().length) + '1';
$section.find(studio.inventory.classes.link).attr('href', replaceUrl);
phpbb.history.replaceUrl(replaceUrl);
}
if (stack === 2) {
$stack.parent().remove();
} else {
$stack.text(stack - 1);
}
if (r.item) {
$items.replaceWith(r.item);
} else {
$section.draggable('destroy');
$section.addClass('shop-cursor-pointer');
}
}
};
/**
* Add AJAX callback for purchasing a Shop item.
*
* @param {Object} r The response object
* @param {string} r.points The new points value
* @param {number|bool} r.stock The new stock value
* @return {void}
*/
phpbb.addAjaxCallback('shop_purchase', function(r) {
$('.aps-menu > .aps-list-right > :first-child > span').text(r.points);
if (r.stock !== false) {
let $item = $(`[data-shop-item="${r.id}"]`);
$item.find('.shop-item-stock').text(r.stock);
if (r.stock === 0) {
$item.find('[data-shop-link="shop_purchase"]').remove();
}
}
});
/**
* Add AJAX callback for deleting a Shop item.
*
* @return {void}
*/
phpbb.addAjaxCallback('shop_inventory_delete', studio.inventory.remove);
/**
* Add AJAX callback for using a Shop item.
*
* @param {Object} r The response object
* @param {number} r.id The item identifier
* @param {Object} r.data The item data
* @param {number} r.data.use_count The item use count
* @param {string} r.data.use_time The item use time
* @param {bool} r.delete The delete indicator
* @param {bool} r.success The success indicator
* @param {string} r.file A window location for downloading a file
* @param {int} r.index The item stack index
* @return {void}
*/
phpbb.addAjaxCallback('shop_inventory_use', function(r) {
if (r.success) {
if (r.delete) {
studio.inventory.remove(r);
} else {
let $item = $(`[data-shop-item="${r.id}"]`),
$refund = $item.find(studio.inventory.classes.refund).remove();
$refund.remove();
$refund.next().removeClass('s2').addClass('s4');
if (r.data) {
$item.find(studio.inventory.classes.itemCount).text(r.data['use_count']);
$item.find(studio.inventory.classes.itemTime).text(r.data['use_time']).parent().show();
}
if (r.limit) {
let notice = '<div class="aps-col s12 shop-no-pad"><div class="aps-button-red shop-button-active shop-cursor-normal">' + r.limit + '</div></div>';
$item.find('> .aps-row > :first-child').after(notice);
$item.find('[data-shop-link="shop_inventory_use"]').remove();
}
}
if (r.file) {
setTimeout(function() {
window.location = r.file;
}, 1500);
}
}
});
/**
* Register the inventory items as draggables.
*
* @return {void}
*/
studio.inventory.items.each(function() {
$(this).draggable({
appendTo: studio.body,
containment: studio.body,
helper: 'clone',
scope: 'inventory',
snap: studio.inventory.classes.card,
snapMode: 'inner',
start: function(e, ui) {
studio.inventory.info.children().not(studio.inventory.proxy).remove();
$(this).draggable('instance').offset.click = {
left: Math.floor(ui.helper.width() / 2),
top: Math.floor(ui.helper.height() / 2)
};
studio.sketch.create(ui.helper);
},
stop: function() {
studio.sketch.timer = setTimeout(studio.sketch.destroy, studio.sketch.timeout);
}
});
});
/**
* Register the inventory 'placeholder card' as droppable.
*
* @return {void}
*/
studio.inventory.card.each(function() {
$(this).droppable({
activeClass: studio.inventory.classes.cardActive,
hoverClass: studio.inventory.classes.cardPaused,
scope: 'inventory',
drop: function(e, ui) {
let clone = ui.draggable.clone(false),
link = clone.find(studio.inventory.classes.link),
item = clone.find(studio.inventory.classes.item);
studio.inventory.info.append(clone);
clone.removeClass('ui-draggable ui-draggable-handle');
link.remove();
item.addClass(studio.inventory.classes.itemAnimate);
},
})
});
studio.sketch.dot = function(x, y, radius) {
this.init(x, y, radius);
};
studio.sketch.dot.prototype = {
init: function(x, y, radius) {
this.alive = true;
this.radius = radius || 10;
this.wander = 0.15;
this.theta = random(TWO_PI);
this.drag = 0.92;
this.color = '#12a3eb';
this.x = x || 0.0;
this.y = y || 0.0;
this.vx = 0.0;
this.vy = 0.0;
},
move: function() {
this.x += this.vx;
this.y += this.vy;
this.vx *= this.drag;
this.vy *= this.drag;
this.theta += random(-0.5, 0.5) * this.wander;
this.vx += Math.sin(this.theta) * 0.1;
this.vy += Math.cos(this.theta) * 0.1;
this.radius *= 0.96;
this.alive = this.radius > 0.5;
},
draw: function( ctx ) {
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius, 0, TWO_PI);
ctx.fillStyle = this.color;
ctx.fill();
}
};
studio.sketch.create = function(helper) {
studio.sketch.clear();
studio.sketch.drawing = Sketch.create({
container: studio.sketch.overlay[0],
eventTarget: helper[0],
retina: 'auto'
});
studio.sketch.drawing.spawn = function(x, y) {
let dot, theta, force;
if (studio.sketch.dots.length >= studio.sketch.limit) {
studio.sketch.pool.push(studio.sketch.dots.shift());
}
dot = studio.sketch.pool.length ? studio.sketch.pool.pop() : new studio.sketch.dot();
dot.init( x, y, random(5, 40));
dot.wander = random(0.5, 2.0);
dot.color = random(studio.sketch.colours);
dot.drag = random(0.9, 0.99);
theta = random(TWO_PI);
force = random(2, 8);
dot.vx = Math.sin(theta) * force;
dot.vy = Math.cos(theta) * force;
studio.sketch.dots.push(dot);
};
studio.sketch.drawing.update = function() {
let i, dot;
for (i = studio.sketch.dots.length - 1; i >= 0; i--) {
dot = studio.sketch.dots[i];
if (dot.alive) {
dot.move();
} else {
studio.sketch.pool.push(studio.sketch.dots.splice(i, 1)[0]);
}
}
};
studio.sketch.drawing.draw = function() {
studio.sketch.drawing.globalCompositeOperation = 'lighter';
for (let i = studio.sketch.dots.length - 1; i >= 0; i--) {
studio.sketch.dots[i].draw(studio.sketch.drawing);
}
};
studio.sketch.drawing.mousemove = function() {
let touch, max, i, j, n;
for (i = 0, n = studio.sketch.drawing.touches.length; i < n; i++) {
touch = studio.sketch.drawing.touches[i];
max = random(1, 4);
for (j = 0; j < max; j++) {
studio.sketch.drawing.spawn(touch.x, touch.y);
}
}
};
};
studio.sketch.clear = function() {
if (studio.sketch.timer !== null) {
clearTimeout(studio.sketch.timer);
studio.sketch.timer = null;
}
studio.sketch.destroy();
};
studio.sketch.destroy = function() {
if (studio.sketch.drawing !== null) {
studio.sketch.drawing.clear();
studio.sketch.drawing.destroy();
studio.sketch.drawing = null;
}
};
});

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,631 @@
/* Copyright (C) 2013 Justin Windle, http://soulwire.co.uk */
(function ( root, factory ) {
if ( typeof exports === 'object' ) {
// CommonJS like
module.exports = factory(root, root.document);
} else if ( typeof define === 'function' && define.amd ) {
// AMD
define( function() { return factory( root, root.document ); });
} else {
// Browser global
root.Sketch = factory( root, root.document );
}
}( typeof window !== "undefined" ? window : this, function ( window, document ) {
"use strict";
/*
----------------------------------------------------------------------
Config
----------------------------------------------------------------------
*/
var MATH_PROPS = 'E LN10 LN2 LOG2E LOG10E PI SQRT1_2 SQRT2 abs acos asin atan ceil cos exp floor log round sin sqrt tan atan2 pow max min'.split( ' ' );
var HAS_SKETCH = '__hasSketch';
var M = Math;
var CANVAS = 'canvas';
var WEBGL = 'webgl';
var DOM = 'dom';
var doc = document;
var win = window;
var instances = [];
var defaults = {
fullscreen: true,
autostart: true,
autoclear: true,
autopause: true,
container: doc.body,
interval: 1,
globals: true,
retina: false,
type: CANVAS
};
var keyMap = {
8: 'BACKSPACE',
9: 'TAB',
13: 'ENTER',
16: 'SHIFT',
27: 'ESCAPE',
32: 'SPACE',
37: 'LEFT',
38: 'UP',
39: 'RIGHT',
40: 'DOWN'
};
/*
----------------------------------------------------------------------
Utilities
----------------------------------------------------------------------
*/
function isArray( object ) {
return Object.prototype.toString.call( object ) == '[object Array]';
}
function isFunction( object ) {
return typeof object == 'function';
}
function isNumber( object ) {
return typeof object == 'number';
}
function isString( object ) {
return typeof object == 'string';
}
function keyName( code ) {
return keyMap[ code ] || String.fromCharCode( code );
}
function extend( target, source, overwrite ) {
for ( var key in source )
if ( overwrite || !( key in target ) )
target[ key ] = source[ key ];
return target;
}
function proxy( method, context ) {
return function() {
method.apply( context, arguments );
};
}
function clone( target ) {
var object = {};
for ( var key in target ) {
if ( key === 'webkitMovementX' || key === 'webkitMovementY' )
continue;
if ( isFunction( target[ key ] ) )
object[ key ] = proxy( target[ key ], target );
else
object[ key ] = target[ key ];
}
return object;
}
/*
----------------------------------------------------------------------
Constructor
----------------------------------------------------------------------
*/
function constructor( context ) {
var request, handler, target, parent, bounds, index, suffix, clock, node, copy, type, key, val, min, max, w, h;
var counter = 0;
var touches = [];
var resized = false;
var setup = false;
var ratio = win.devicePixelRatio || 1;
var isDiv = context.type == DOM;
var is2D = context.type == CANVAS;
var mouse = {
x: 0.0, y: 0.0,
ox: 0.0, oy: 0.0,
dx: 0.0, dy: 0.0
};
var eventMap = [
context.eventTarget || context.element,
pointer, 'mousedown', 'touchstart',
pointer, 'mousemove', 'touchmove',
pointer, 'mouseup', 'touchend',
pointer, 'click',
pointer, 'mouseout',
pointer, 'mouseover',
doc,
keypress, 'keydown', 'keyup',
win,
active, 'focus', 'blur',
resize, 'resize'
];
var keys = {}; for ( key in keyMap ) keys[ keyMap[ key ] ] = false;
function trigger( method ) {
if ( isFunction( method ) )
method.apply( context, [].splice.call( arguments, 1 ) );
}
function bind( on ) {
for ( index = 0; index < eventMap.length; index++ ) {
node = eventMap[ index ];
if ( isString( node ) )
target[ ( on ? 'add' : 'remove' ) + 'EventListener' ].call( target, node, handler, false );
else if ( isFunction( node ) )
handler = node;
else target = node;
}
}
function update() {
cAF( request );
request = rAF( update );
if ( !setup ) {
trigger( context.setup );
setup = isFunction( context.setup );
}
if ( !resized ) {
trigger( context.resize );
resized = isFunction( context.resize );
}
if ( context.running && !counter ) {
context.dt = ( clock = +new Date() ) - context.now;
context.millis += context.dt;
context.now = clock;
trigger( context.update );
// Pre draw
if ( is2D ) {
if ( context.retina ) {
context.save();
if (context.autoclear) {
context.scale( ratio, ratio );
}
}
if ( context.autoclear )
context.clear();
}
// Draw
trigger( context.draw );
// Post draw
if ( is2D && context.retina )
context.restore();
}
counter = ++counter % context.interval;
}
function resize() {
target = isDiv ? context.style : context.canvas;
suffix = isDiv ? 'px' : '';
w = context.width;
h = context.height;
if ( context.fullscreen ) {
h = context.height = win.innerHeight;
w = context.width = win.innerWidth;
}
if ( context.retina && is2D && ratio ) {
target.style.height = h + 'px';
target.style.width = w + 'px';
w *= ratio;
h *= ratio;
}
if ( target.height !== h )
target.height = h + suffix;
if ( target.width !== w )
target.width = w + suffix;
if ( is2D && !context.autoclear && context.retina )
context.scale( ratio, ratio );
if ( setup ) trigger( context.resize );
}
function align( touch, target ) {
bounds = target.getBoundingClientRect();
touch.x = touch.pageX - bounds.left - (win.scrollX || win.pageXOffset);
touch.y = touch.pageY - bounds.top - (win.scrollY || win.pageYOffset);
return touch;
}
function augment( touch, target ) {
align( touch, context.element );
target = target || {};
target.ox = target.x || touch.x;
target.oy = target.y || touch.y;
target.x = touch.x;
target.y = touch.y;
target.dx = target.x - target.ox;
target.dy = target.y - target.oy;
return target;
}
function process( event ) {
event.preventDefault();
copy = clone( event );
copy.originalEvent = event;
if ( copy.touches ) {
touches.length = copy.touches.length;
for ( index = 0; index < copy.touches.length; index++ )
touches[ index ] = augment( copy.touches[ index ], touches[ index ] );
} else {
touches.length = 0;
touches[0] = augment( copy, mouse );
}
extend( mouse, touches[0], true );
return copy;
}
function pointer( event ) {
event = process( event );
min = ( max = eventMap.indexOf( type = event.type ) ) - 1;
context.dragging =
/down|start/.test( type ) ? true :
/up|end/.test( type ) ? false :
context.dragging;
while( min )
isString( eventMap[ min ] ) ?
trigger( context[ eventMap[ min-- ] ], event ) :
isString( eventMap[ max ] ) ?
trigger( context[ eventMap[ max++ ] ], event ) :
min = 0;
}
function keypress( event ) {
key = event.keyCode;
val = event.type == 'keyup';
keys[ key ] = keys[ keyName( key ) ] = !val;
trigger( context[ event.type ], event );
}
function active( event ) {
if ( context.autopause )
( event.type == 'blur' ? stop : start )();
trigger( context[ event.type ], event );
}
// Public API
function start() {
context.now = +new Date();
context.running = true;
}
function stop() {
context.running = false;
}
function toggle() {
( context.running ? stop : start )();
}
function clear() {
if ( is2D )
context.clearRect( 0, 0, context.width * ratio, context.height * ratio );
}
function destroy() {
parent = context.element.parentNode;
index = instances.indexOf( context );
if ( parent ) parent.removeChild( context.element );
if ( ~index ) instances.splice( index, 1 );
bind( false );
stop();
}
extend( context, {
touches: touches,
mouse: mouse,
keys: keys,
dragging: false,
running: false,
millis: 0,
now: NaN,
dt: NaN,
destroy: destroy,
toggle: toggle,
clear: clear,
start: start,
stop: stop
});
instances.push( context );
return ( context.autostart && start(), bind( true ), resize(), update(), context );
}
/*
----------------------------------------------------------------------
Global API
----------------------------------------------------------------------
*/
var element, context, Sketch = {
CANVAS: CANVAS,
WEB_GL: WEBGL,
WEBGL: WEBGL,
DOM: DOM,
instances: instances,
install: function( context ) {
if ( !context[ HAS_SKETCH ] ) {
for ( var i = 0; i < MATH_PROPS.length; i++ )
context[ MATH_PROPS[i] ] = M[ MATH_PROPS[i] ];
extend( context, {
TWO_PI: M.PI * 2,
HALF_PI: M.PI / 2,
QUARTER_PI: M.PI / 4,
random: function( min, max ) {
if ( isArray( min ) )
return min[ ~~( M.random() * min.length ) ];
if ( !isNumber( max ) )
max = min || 1, min = 0;
return min + M.random() * ( max - min );
},
lerp: function( min, max, amount ) {
return min + amount * ( max - min );
},
map: function( num, minA, maxA, minB, maxB ) {
return ( num - minA ) / ( maxA - minA ) * ( maxB - minB ) + minB;
}
});
context[ HAS_SKETCH ] = true;
}
},
create: function( options ) {
options = extend( options || {}, defaults );
if ( options.globals ) Sketch.install( self );
element = options.element = options.element || doc.createElement( options.type === DOM ? 'div' : 'canvas' );
context = options.context = options.context || (function() {
switch( options.type ) {
case CANVAS:
return element.getContext( '2d', options );
case WEBGL:
return element.getContext( 'webgl', options ) || element.getContext( 'experimental-webgl', options );
case DOM:
return element.canvas = element;
}
})();
( options.container || doc.body ).appendChild( element );
return Sketch.augment( context, options );
},
augment: function( context, options ) {
options = extend( options || {}, defaults );
options.element = context.canvas || context;
options.element.className += ' sketch';
extend( context, options, true );
return constructor( context );
}
};
/*
----------------------------------------------------------------------
Shims
----------------------------------------------------------------------
*/
var vendors = [ 'ms', 'moz', 'webkit', 'o' ];
var scope = self;
var then = 0;
var a = 'AnimationFrame';
var b = 'request' + a;
var c = 'cancel' + a;
var rAF = scope[ b ];
var cAF = scope[ c ];
for ( var i = 0; i < vendors.length && !rAF; i++ ) {
rAF = scope[ vendors[ i ] + 'Request' + a ];
cAF = scope[ vendors[ i ] + 'Cancel' + a ];
}
scope[ b ] = rAF = rAF || function( callback ) {
var now = +new Date();
var dt = M.max( 0, 16 - ( now - then ) );
var id = setTimeout( function() {
callback( now + dt );
}, dt );
then = now + dt;
return id;
};
scope[ c ] = cAF = cAF || function( id ) {
clearTimeout( id );
};
/*
----------------------------------------------------------------------
Output
----------------------------------------------------------------------
*/
return Sketch;
}));

View File

@@ -0,0 +1,2 @@
/* Copyright (C) 2013 Justin Windle, http://soulwire.co.uk */
!function(e,t){"object"==typeof exports?module.exports=t(e,e.document):"function"==typeof define&&define.amd?define(function(){return t(e,e.document)}):e.Sketch=t(e,e.document)}("undefined"!=typeof window?window:this,function(e,t){"use strict";function n(e){return"[object Array]"==Object.prototype.toString.call(e)}function o(e){return"function"==typeof e}function r(e){return"number"==typeof e}function i(e){return"string"==typeof e}function u(e){return C[e]||String.fromCharCode(e)}function a(e,t,n){for(var o in t)!n&&o in e||(e[o]=t[o]);return e}function c(e,t){return function(){e.apply(t,arguments)}}function l(e){var t={};for(var n in e)"webkitMovementX"!==n&&"webkitMovementY"!==n&&(o(e[n])?t[n]=c(e[n],e):t[n]=e[n]);return t}function s(e){function t(t){o(t)&&t.apply(e,[].splice.call(arguments,1))}function n(e){for(_=0;_<ee.length;_++)B=ee[_],i(B)?S[(e?"add":"remove")+"EventListener"].call(S,B,N,!1):o(B)?N=B:S=B}function r(){I(A),A=R(r),K||(t(e.setup),K=o(e.setup)),U||(t(e.resize),U=o(e.resize)),e.running&&!q&&(e.dt=(z=+new Date)-e.now,e.millis+=e.dt,e.now=z,t(e.update),Z&&(e.retina&&(e.save(),e.autoclear&&e.scale(V,V)),e.autoclear&&e.clear()),t(e.draw),Z&&e.retina&&e.restore()),q=++q%e.interval}function c(){S=J?e.style:e.canvas,D=J?"px":"",Y=e.width,j=e.height,e.fullscreen&&(j=e.height=v.innerHeight,Y=e.width=v.innerWidth),e.retina&&Z&&V&&(S.style.height=j+"px",S.style.width=Y+"px",Y*=V,j*=V),S.height!==j&&(S.height=j+D),S.width!==Y&&(S.width=Y+D),Z&&!e.autoclear&&e.retina&&e.scale(V,V),K&&t(e.resize)}function s(e,t){return L=t.getBoundingClientRect(),e.x=e.pageX-L.left-(v.scrollX||v.pageXOffset),e.y=e.pageY-L.top-(v.scrollY||v.pageYOffset),e}function f(t,n){return s(t,e.element),n=n||{},n.ox=n.x||t.x,n.oy=n.y||t.y,n.x=t.x,n.y=t.y,n.dx=n.x-n.ox,n.dy=n.y-n.oy,n}function d(e){if(e.preventDefault(),G=l(e),G.originalEvent=e,G.touches)for(Q.length=G.touches.length,_=0;_<G.touches.length;_++)Q[_]=f(G.touches[_],Q[_]);else Q.length=0,Q[0]=f(G,$);return a($,Q[0],!0),G}function p(n){for(n=d(n),M=(X=ee.indexOf(W=n.type))-1,e.dragging=!!/down|start/.test(W)||!/up|end/.test(W)&&e.dragging;M;)i(ee[M])?t(e[ee[M--]],n):i(ee[X])?t(e[ee[X++]],n):M=0}function g(n){F=n.keyCode,H="keyup"==n.type,te[F]=te[u(F)]=!H,t(e[n.type],n)}function m(n){e.autopause&&("blur"==n.type?E:y)(),t(e[n.type],n)}function y(){e.now=+new Date,e.running=!0}function E(){e.running=!1}function k(){(e.running?E:y)()}function P(){Z&&e.clearRect(0,0,e.width*V,e.height*V)}function T(){O=e.element.parentNode,_=b.indexOf(e),O&&O.removeChild(e.element),~_&&b.splice(_,1),n(!1),E()}var A,N,S,O,L,_,D,z,B,G,W,F,H,M,X,Y,j,q=0,Q=[],U=!1,K=!1,V=v.devicePixelRatio||1,J=e.type==w,Z=e.type==h,$={x:0,y:0,ox:0,oy:0,dx:0,dy:0},ee=[e.eventTarget||e.element,p,"mousedown","touchstart",p,"mousemove","touchmove",p,"mouseup","touchend",p,"click",p,"mouseout",p,"mouseover",x,g,"keydown","keyup",v,m,"focus","blur",c,"resize"],te={};for(F in C)te[C[F]]=!1;return a(e,{touches:Q,mouse:$,keys:te,dragging:!1,running:!1,millis:0,now:NaN,dt:NaN,destroy:T,toggle:k,clear:P,start:y,stop:E}),b.push(e),e.autostart&&y(),n(!0),c(),r(),e}for(var f,d,p="E LN10 LN2 LOG2E LOG10E PI SQRT1_2 SQRT2 abs acos asin atan ceil cos exp floor log round sin sqrt tan atan2 pow max min".split(" "),g="__hasSketch",m=Math,h="canvas",y="webgl",w="dom",x=t,v=e,b=[],E={fullscreen:!0,autostart:!0,autoclear:!0,autopause:!0,container:x.body,interval:1,globals:!0,retina:!1,type:h},C={8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",27:"ESCAPE",32:"SPACE",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN"},k={CANVAS:h,WEB_GL:y,WEBGL:y,DOM:w,instances:b,install:function(e){if(!e[g]){for(var t=0;t<p.length;t++)e[p[t]]=m[p[t]];a(e,{TWO_PI:2*m.PI,HALF_PI:m.PI/2,QUARTER_PI:m.PI/4,random:function(e,t){return n(e)?e[~~(m.random()*e.length)]:(r(t)||(t=e||1,e=0),e+m.random()*(t-e))},lerp:function(e,t,n){return e+n*(t-e)},map:function(e,t,n,o,r){return(e-t)/(n-t)*(r-o)+o}}),e[g]=!0}},create:function(e){return e=a(e||{},E),e.globals&&k.install(self),f=e.element=e.element||x.createElement(e.type===w?"div":"canvas"),d=e.context=e.context||function(){switch(e.type){case h:return f.getContext("2d",e);case y:return f.getContext("webgl",e)||f.getContext("experimental-webgl",e);case w:return f.canvas=f}}(),(e.container||x.body).appendChild(f),k.augment(d,e)},augment:function(e,t){return t=a(t||{},E),t.element=e.canvas||e,t.element.className+=" sketch",a(e,t,!0),s(e)}},P=["ms","moz","webkit","o"],T=self,A=0,N="AnimationFrame",S="request"+N,O="cancel"+N,R=T[S],I=T[O],L=0;L<P.length&&!R;L++)R=T[P[L]+"Request"+N],I=T[P[L]+"Cancel"+N];return T[S]=R=R||function(e){var t=+new Date,n=m.max(0,16-(t-A)),o=setTimeout(function(){e(t+n)},n);return A=t+n,o},T[O]=I=I||function(e){clearTimeout(e)},k});

File diff suppressed because one or more lines are too long