summaryrefslogtreecommitdiff
path: root/templates/project/assets/javascripts/gridster
diff options
context:
space:
mode:
Diffstat (limited to 'templates/project/assets/javascripts/gridster')
-rwxr-xr-xtemplates/project/assets/javascripts/gridster/jquery.collision.js224
-rwxr-xr-xtemplates/project/assets/javascripts/gridster/jquery.coords.js108
-rwxr-xr-xtemplates/project/assets/javascripts/gridster/jquery.draggable.js327
-rw-r--r--[-rwxr-xr-x]templates/project/assets/javascripts/gridster/jquery.gridster.js0
-rwxr-xr-xtemplates/project/assets/javascripts/gridster/utils.js41
5 files changed, 0 insertions, 700 deletions
diff --git a/templates/project/assets/javascripts/gridster/jquery.collision.js b/templates/project/assets/javascripts/gridster/jquery.collision.js
deleted file mode 100755
index 5d37c61..0000000
--- a/templates/project/assets/javascripts/gridster/jquery.collision.js
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * jquery.collision
- * https://github.com/ducksboard/gridster.js
- *
- * Copyright (c) 2012 ducksboard
- * Licensed under the MIT licenses.
- */
-
-;(function($, window, document, undefined){
-
- var defaults = {
- colliders_context: document.body
- // ,on_overlap: function(collider_data){},
- // on_overlap_start : function(collider_data){},
- // on_overlap_stop : function(collider_data){}
- };
-
-
- /**
- * Detects collisions between a DOM element against other DOM elements or
- * Coords objects.
- *
- * @class Collision
- * @uses Coords
- * @param {HTMLElement} el The jQuery wrapped HTMLElement.
- * @param {HTMLElement|Array} colliders Can be a jQuery collection
- * of HTMLElements or an Array of Coords instances.
- * @param {Object} [options] An Object with all options you want to
- * overwrite:
- * @param {Function} [options.on_overlap_start] Executes a function the first
- * time each `collider ` is overlapped.
- * @param {Function} [options.on_overlap_stop] Executes a function when a
- * `collider` is no longer collided.
- * @param {Function} [options.on_overlap] Executes a function when the
- * mouse is moved during the collision.
- * @return {Object} Collision instance.
- * @constructor
- */
- function Collision(el, colliders, options) {
- this.options = $.extend(defaults, options);
- this.$element = el;
- this.last_colliders = [];
- this.last_colliders_coords = [];
- if (typeof colliders === 'string' || colliders instanceof jQuery) {
- this.$colliders = $(colliders,
- this.options.colliders_context).not(this.$element);
- }else{
- this.colliders = $(colliders);
- }
-
- this.init();
- }
-
-
- var fn = Collision.prototype;
-
-
- fn.init = function() {
- this.find_collisions();
- };
-
-
- fn.overlaps = function(a, b) {
- var x = false;
- var y = false;
-
- if ((b.x1 >= a.x1 && b.x1 <= a.x2) ||
- (b.x2 >= a.x1 && b.x2 <= a.x2) ||
- (a.x1 >= b.x1 && a.x2 <= b.x2)
- ) { x = true; }
-
- if ((b.y1 >= a.y1 && b.y1 <= a.y2) ||
- (b.y2 >= a.y1 && b.y2 <= a.y2) ||
- (a.y1 >= b.y1 && a.y2 <= b.y2)
- ) { y = true; }
-
- return (x && y);
- };
-
-
- fn.detect_overlapping_region = function(a, b){
- var regionX = '';
- var regionY = '';
-
- if (a.y1 > b.cy && a.y1 < b.y2) { regionX = 'N'; }
- if (a.y2 > b.y1 && a.y2 < b.cy) { regionX = 'S'; }
- if (a.x1 > b.cx && a.x1 < b.x2) { regionY = 'W'; }
- if (a.x2 > b.x1 && a.x2 < b.cx) { regionY = 'E'; }
-
- return (regionX + regionY) || 'C';
- };
-
-
- fn.calculate_overlapped_area_coords = function(a, b){
- var x1 = Math.max(a.x1, b.x1);
- var y1 = Math.max(a.y1, b.y1);
- var x2 = Math.min(a.x2, b.x2);
- var y2 = Math.min(a.y2, b.y2);
-
- return $({
- left: x1,
- top: y1,
- width : (x2 - x1),
- height: (y2 - y1)
- }).coords().get();
- };
-
-
- fn.calculate_overlapped_area = function(coords){
- return (coords.width * coords.height);
- };
-
-
- fn.manage_colliders_start_stop = function(new_colliders_coords, start_callback, stop_callback){
- var last = this.last_colliders_coords;
-
- for (var i = 0, il = last.length; i < il; i++) {
- if ($.inArray(last[i], new_colliders_coords) === -1) {
- start_callback.call(this, last[i]);
- }
- }
-
- for (var j = 0, jl = new_colliders_coords.length; j < jl; j++) {
- if ($.inArray(new_colliders_coords[j], last) === -1) {
- stop_callback.call(this, new_colliders_coords[j]);
- }
-
- }
- };
-
-
- fn.find_collisions = function(player_data_coords){
- var self = this;
- var colliders_coords = [];
- var colliders_data = [];
- var $colliders = (this.colliders || this.$colliders);
- var count = $colliders.length;
- var player_coords = self.$element.coords()
- .update(player_data_coords || false).get();
-
- while(count--){
- var $collider = self.$colliders ?
- $($colliders[count]) : $colliders[count];
- var $collider_coords_ins = ($collider.isCoords) ?
- $collider : $collider.coords();
- var collider_coords = $collider_coords_ins.get();
- var overlaps = self.overlaps(player_coords, collider_coords);
-
- if (!overlaps) {
- continue;
- }
-
- var region = self.detect_overlapping_region(
- player_coords, collider_coords);
-
- //todo: make this an option
- if (region === 'C'){
- var area_coords = self.calculate_overlapped_area_coords(
- player_coords, collider_coords);
- var area = self.calculate_overlapped_area(area_coords);
- var collider_data = {
- area: area,
- area_coords : area_coords,
- region: region,
- coords: collider_coords,
- player_coords: player_coords,
- el: $collider
- };
-
- if (self.options.on_overlap) {
- self.options.on_overlap.call(this, collider_data);
- }
- colliders_coords.push($collider_coords_ins);
- colliders_data.push(collider_data);
- }
- }
-
- if (self.options.on_overlap_stop || self.options.on_overlap_start) {
- this.manage_colliders_start_stop(colliders_coords,
- self.options.on_overlap_stop, self.options.on_overlap_start);
- }
-
- this.last_colliders_coords = colliders_coords;
-
- return colliders_data;
- };
-
-
- fn.get_closest_colliders = function(player_data_coords){
- var colliders = this.find_collisions(player_data_coords);
- var min_area = 100;
- colliders.sort(function(a, b){
- if (a.area <= min_area) {
- return 1;
- }
-
- /* if colliders are being overlapped by the "C" (center) region,
- * we have to set a lower index in the array to which they are placed
- * above in the grid. */
- if (a.region === 'C' && b.region === 'C') {
- if (a.coords.y1 < b.coords.y1 || a.coords.x1 < b.coords.x1) {
- return - 1;
- }else{
- return 1;
- }
- }
-
- if (a.area < b.area){
- return 1;
- }
-
- return 1;
- });
- return colliders;
- };
-
-
- //jQuery adapter
- $.fn.collision = function(collider, options) {
- return new Collision( this, collider, options );
- };
-
-
-}(jQuery, window, document));
diff --git a/templates/project/assets/javascripts/gridster/jquery.coords.js b/templates/project/assets/javascripts/gridster/jquery.coords.js
deleted file mode 100755
index e3bd5e6..0000000
--- a/templates/project/assets/javascripts/gridster/jquery.coords.js
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * jquery.coords
- * https://github.com/ducksboard/gridster.js
- *
- * Copyright (c) 2012 ducksboard
- * Licensed under the MIT licenses.
- */
-
-;(function($, window, document, undefined){
- /**
- * Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height)
- * to simulate DOM elements on the screen.
- * Coords is used by Gridster to create a faux grid with any DOM element can
- * collide.
- *
- * @class Coords
- * @param {HTMLElement|Object} obj The jQuery HTMLElement or a object with: left,
- * top, width and height properties.
- * @return {Object} Coords instance.
- * @constructor
- */
- function Coords(obj) {
- if (obj[0] && $.isPlainObject(obj[0])) {
- this.data = obj[0];
- }else {
- this.el = obj;
- }
-
- this.isCoords = true;
- this.coords = {};
- this.init();
- return this;
- }
-
-
- var fn = Coords.prototype;
-
-
- fn.init = function(){
- this.set();
- this.original_coords = this.get();
- };
-
-
- fn.set = function(update, not_update_offsets) {
- var el = this.el;
-
- if (el && !update) {
- this.data = el.offset();
- this.data.width = el.width();
- this.data.height = el.height();
- }
-
- if (el && update && !not_update_offsets) {
- var offset = el.offset();
- this.data.top = offset.top;
- this.data.left = offset.left;
- }
-
- var d = this.data;
-
- this.coords.x1 = d.left;
- this.coords.y1 = d.top;
- this.coords.x2 = d.left + d.width;
- this.coords.y2 = d.top + d.height;
- this.coords.cx = d.left + (d.width / 2);
- this.coords.cy = d.top + (d.height / 2);
- this.coords.width = d.width;
- this.coords.height = d.height;
- this.coords.el = el || false ;
-
- return this;
- };
-
-
- fn.update = function(data){
- if (!data && !this.el) {
- return this;
- }
-
- if (data) {
- var new_data = $.extend({}, this.data, data);
- this.data = new_data;
- return this.set(true, true);
- }
-
- this.set(true);
- return this;
- };
-
-
- fn.get = function(){
- return this.coords;
- };
-
-
- //jQuery adapter
- $.fn.coords = function() {
- if (this.data('coords') ) {
- return this.data('coords');
- }
-
- var ins = new Coords(this, arguments[0]);
- this.data('coords', ins);
- return ins;
- };
-
-}(jQuery, window, document));
diff --git a/templates/project/assets/javascripts/gridster/jquery.draggable.js b/templates/project/assets/javascripts/gridster/jquery.draggable.js
deleted file mode 100755
index 52a18d4..0000000
--- a/templates/project/assets/javascripts/gridster/jquery.draggable.js
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * jquery.draggable
- * https://github.com/ducksboard/gridster.js
- *
- * Copyright (c) 2012 ducksboard
- * Licensed under the MIT licenses.
- */
-
-;(function($, window, document, undefined){
-
- var defaults = {
- items: '.gs_w',
- distance: 1,
- limit: true,
- offset_left: 0,
- autoscroll: true
- // ,drag: function(e){},
- // start : function(e, ui){},
- // stop : function(e){}
- };
-
- var $window = $(window);
- var isTouch = !!('ontouchstart' in window);
- var pointer_events = {
- start: isTouch ? 'touchstart' : 'mousedown.draggable',
- move: isTouch ? 'touchmove' : 'mousemove.draggable',
- end: isTouch ? 'touchend' : 'mouseup.draggable'
- };
-
- /**
- * Basic drag implementation for DOM elements inside a container.
- * Provide start/stop/drag callbacks.
- *
- * @class Draggable
- * @param {HTMLElement} el The HTMLelement that contains all the widgets
- * to be dragged.
- * @param {Object} [options] An Object with all options you want to
- * overwrite:
- * @param {HTMLElement|String} [options.items] Define who will
- * be the draggable items. Can be a CSS Selector String or a
- * collection of HTMLElements.
- * @param {Number} [options.distance] Distance in pixels after mousedown
- * the mouse must move before dragging should start.
- * @param {Boolean} [options.limit] Constrains dragging to the width of
- * the container
- * @param {offset_left} [options.offset_left] Offset added to the item
- * that is being dragged.
- * @param {Number} [options.drag] Executes a callback when the mouse is
- * moved during the dragging.
- * @param {Number} [options.start] Executes a callback when the drag
- * starts.
- * @param {Number} [options.stop] Executes a callback when the drag stops.
- * @return {Object} Returns `el`.
- * @constructor
- */
- function Draggable(el, options) {
- this.options = $.extend({}, defaults, options);
- this.$body = $(document.body);
- this.$container = $(el);
- this.$dragitems = $(this.options.items, this.$container);
- this.is_dragging = false;
- this.player_min_left = 0 + this.options.offset_left;
- this.init();
- }
-
- var fn = Draggable.prototype;
-
- fn.init = function() {
- this.calculate_positions();
- this.$container.css('position', 'relative');
- this.enable();
-
- $(window).bind('resize',
- throttle($.proxy(this.calculate_positions, this), 200));
- };
-
-
- fn.get_actual_pos = function($el) {
- var pos = $el.position();
- return pos;
- };
-
-
- fn.get_mouse_pos = function(e) {
- if (isTouch) {
- var oe = e.originalEvent;
- e = oe.touches.length ? oe.touches[0] : oe.changedTouches[0];
- };
-
- return {
- left: e.clientX,
- top: e.clientY
- };
- };
-
-
- fn.get_offset = function(e) {
- e.preventDefault();
- var mouse_actual_pos = this.get_mouse_pos(e);
- var diff_x = Math.round(
- mouse_actual_pos.left - this.mouse_init_pos.left);
- var diff_y = Math.round(mouse_actual_pos.top - this.mouse_init_pos.top);
-
- var left = Math.round(this.el_init_offset.left + diff_x - this.baseX);
- var top = Math.round(
- this.el_init_offset.top + diff_y - this.baseY + this.scrollOffset);
-
- if (this.options.limit) {
- if (left > this.player_max_left) {
- left = this.player_max_left;
- }else if(left < this.player_min_left) {
- left = this.player_min_left;
- }
- }
-
- return {
- left: left,
- top: top,
- mouse_left: mouse_actual_pos.left,
- mouse_top: mouse_actual_pos.top
- };
- };
-
-
- fn.manage_scroll = function(offset) {
- /* scroll document */
- var nextScrollTop;
- var scrollTop = $window.scrollTop();
- var min_window_y = scrollTop;
- var max_window_y = min_window_y + this.window_height;
-
- var mouse_down_zone = max_window_y - 50;
- var mouse_up_zone = min_window_y + 50;
-
- var abs_mouse_left = offset.mouse_left;
- var abs_mouse_top = min_window_y + offset.mouse_top;
-
- var max_player_y = (this.doc_height - this.window_height +
- this.player_height);
-
- if (abs_mouse_top >= mouse_down_zone) {
- nextScrollTop = scrollTop + 30;
- if (nextScrollTop < max_player_y) {
- $window.scrollTop(nextScrollTop);
- this.scrollOffset = this.scrollOffset + 30;
- }
- };
-
- if (abs_mouse_top <= mouse_up_zone) {
- nextScrollTop = scrollTop - 30;
- if (nextScrollTop > 0) {
- $window.scrollTop(nextScrollTop);
- this.scrollOffset = this.scrollOffset - 30;
- }
- };
- }
-
-
- fn.calculate_positions = function(e) {
- this.window_height = $window.height();
- }
-
-
- fn.drag_handler = function(e) {
- var node = e.target.nodeName;
-
- if (e.which !== 1 && !isTouch) {
- return;
- }
-
- if (node === 'INPUT' || node === 'TEXTAREA' || node === 'SELECT' ||
- node === 'BUTTON') {
- return;
- };
-
- var self = this;
- var first = true;
- this.$player = $(e.currentTarget);
-
- this.el_init_pos = this.get_actual_pos(this.$player);
- this.mouse_init_pos = this.get_mouse_pos(e);
- this.offsetY = this.mouse_init_pos.top - this.el_init_pos.top;
-
- this.$body.on(pointer_events.move, function(mme){
- var mouse_actual_pos = self.get_mouse_pos(mme);
- var diff_x = Math.abs(
- mouse_actual_pos.left - self.mouse_init_pos.left);
- var diff_y = Math.abs(
- mouse_actual_pos.top - self.mouse_init_pos.top);
- if (!(diff_x > self.options.distance ||
- diff_y > self.options.distance)
- ) {
- return false;
- }
-
- if (first) {
- first = false;
- self.on_dragstart.call(self, mme);
- return false;
- }
-
- if (self.is_dragging == true) {
- self.on_dragmove.call(self, mme);
- }
-
- return false;
- });
- };
-
-
- fn.on_dragstart = function(e) {
- e.preventDefault();
- this.drag_start = true;
- this.is_dragging = true;
- var offset = this.$container.offset();
- this.baseX = Math.round(offset.left);
- this.baseY = Math.round(offset.top);
- this.doc_height = $(document).height();
-
- if (this.options.helper === 'clone') {
- this.$helper = this.$player.clone()
- .appendTo(this.$container).addClass('helper');
- this.helper = true;
- }else{
- this.helper = false;
- }
- this.scrollOffset = 0;
- this.el_init_offset = this.$player.offset();
- this.player_width = this.$player.width();
- this.player_height = this.$player.height();
- this.player_max_left = (this.$container.width() - this.player_width +
- this.options.offset_left);
-
- if (this.options.start) {
- this.options.start.call(this.$player, e, {
- helper: this.helper ? this.$helper : this.$player
- });
- }
- return false;
- };
-
-
- fn.on_dragmove = function(e) {
- var offset = this.get_offset(e);
-
- this.options.autoscroll && this.manage_scroll(offset);
-
- (this.helper ? this.$helper : this.$player).css({
- 'position': 'absolute',
- 'left' : offset.left,
- 'top' : offset.top
- });
-
- var ui = {
- 'position': {
- 'left': offset.left,
- 'top': offset.top
- }
- };
-
- if (this.options.drag) {
- this.options.drag.call(this.$player, e, ui);
- }
- return false;
- };
-
-
- fn.on_dragstop = function(e) {
- var offset = this.get_offset(e);
- this.drag_start = false;
-
- var ui = {
- 'position': {
- 'left': offset.left,
- 'top': offset.top
- }
- };
-
- if (this.options.stop) {
- this.options.stop.call(this.$player, e, ui);
- }
-
- if (this.helper) {
- this.$helper.remove();
- }
-
- return false;
- };
-
-
- fn.enable = function(){
- this.$container.on(pointer_events.start, this.options.items, $.proxy(
- this.drag_handler, this));
-
- this.$body.on(pointer_events.end, $.proxy(function(e) {
- this.is_dragging = false;
- this.$body.off(pointer_events.move);
- if (this.drag_start) {
- this.on_dragstop(e);
- }
- }, this));
- };
-
-
- fn.disable = function(){
- this.$container.off(pointer_events.start);
- this.$body.off(pointer_events.end);
- };
-
-
- fn.destroy = function(){
- this.disable();
- $.removeData(this.$container, 'draggable');
- };
-
-
- //jQuery adapter
- $.fn.drag = function ( options ) {
- return this.each(function () {
- if (!$.data(this, 'drag')) {
- $.data(this, 'drag', new Draggable( this, options ));
- }
- });
- };
-
-
-}(jQuery, window, document));
diff --git a/templates/project/assets/javascripts/gridster/jquery.gridster.js b/templates/project/assets/javascripts/gridster/jquery.gridster.js
index 9099177..9099177 100755..100644
--- a/templates/project/assets/javascripts/gridster/jquery.gridster.js
+++ b/templates/project/assets/javascripts/gridster/jquery.gridster.js
diff --git a/templates/project/assets/javascripts/gridster/utils.js b/templates/project/assets/javascripts/gridster/utils.js
deleted file mode 100755
index 5f340b3..0000000
--- a/templates/project/assets/javascripts/gridster/utils.js
+++ /dev/null
@@ -1,41 +0,0 @@
-;(function(window, undefined) {
- /* Debounce and throttle functions taken from underscore.js */
- window.debounce = function(func, wait, immediate) {
- var timeout;
- return function() {
- var context = this, args = arguments;
- var later = function() {
- timeout = null;
- if (!immediate) func.apply(context, args);
- };
- if (immediate && !timeout) func.apply(context, args);
- clearTimeout(timeout);
- timeout = setTimeout(later, wait);
- };
- };
-
-
- window.throttle = function(func, wait) {
- var context, args, timeout, throttling, more, result;
- var whenDone = debounce(
- function(){ more = throttling = false; }, wait);
- return function() {
- context = this; args = arguments;
- var later = function() {
- timeout = null;
- if (more) func.apply(context, args);
- whenDone();
- };
- if (!timeout) timeout = setTimeout(later, wait);
- if (throttling) {
- more = true;
- } else {
- result = func.apply(context, args);
- }
- whenDone();
- throttling = true;
- return result;
- };
- };
-
-})(window);