/** https://github.com/ducksboard/gridster.js */ (function(e,t,n,r){function i(t){if(t[0]&&e.isPlainObject(t[0])){this.data=t[0]}else{this.el=t}this.isCoords=true;this.coords={};this.init();return this}var s=i.prototype;s.init=function(){this.set();this.original_coords=this.get()};s.set=function(e,t){var n=this.el;if(n&&!e){this.data=n.offset();this.data.width=n.width();this.data.height=n.height()}if(n&&e&&!t){var r=n.offset();this.data.top=r.top;this.data.left=r.left}var i=this.data;this.coords.x1=i.left;this.coords.y1=i.top;this.coords.x2=i.left+i.width;this.coords.y2=i.top+i.height;this.coords.cx=i.left+i.width/2;this.coords.cy=i.top+i.height/2;this.coords.width=i.width;this.coords.height=i.height;this.coords.el=n||false;return this};s.update=function(t){if(!t&&!this.el){return this}if(t){var n=e.extend({},this.data,t);this.data=n;return this.set(true,true)}this.set(true);return this};s.get=function(){return this.coords};e.fn.coords=function(){if(this.data("coords")){return this.data("coords")}var e=new i(this,arguments[0]);this.data("coords",e);return e}})(jQuery,window,document);(function(e,t,n,r){function s(t,n,r){this.options=e.extend(i,r);this.$element=t;this.last_colliders=[];this.last_colliders_coords=[];if(typeof n==="string"||n instanceof jQuery){this.$colliders=e(n,this.options.colliders_context).not(this.$element)}else{this.colliders=e(n)}this.init()}var i={colliders_context:n.body};var o=s.prototype;o.init=function(){this.find_collisions()};o.overlaps=function(e,t){var n=false;var r=false;if(t.x1>=e.x1&&t.x1<=e.x2||t.x2>=e.x1&&t.x2<=e.x2||e.x1>=t.x1&&e.x2<=t.x2){n=true}if(t.y1>=e.y1&&t.y1<=e.y2||t.y2>=e.y1&&t.y2<=e.y2||e.y1>=t.y1&&e.y2<=t.y2){r=true}return n&&r};o.detect_overlapping_region=function(e,t){var n="";var r="";if(e.y1>t.cy&&e.y1t.y1&&e.y2t.cx&&e.x1t.x1&&e.x2this.player_max_left){i=this.player_max_left}else if(i=o){t=n+30;if(t0){s.scrollTop(t);this.scrollOffset=this.scrollOffset-30}}};f.calculate_positions=function(e){this.window_height=s.height()};f.drag_handler=function(t){var n=t.target.nodeName;if(this.disabled||t.which!==1&&!o){return}if(this.ignore_drag(t)){return}var r=this;var i=true;this.$player=e(t.currentTarget);this.el_init_pos=this.get_actual_pos(this.$player);this.mouse_init_pos=this.get_mouse_pos(t);this.offsetY=this.mouse_init_pos.top-this.el_init_pos.top;this.on_pointer_events_move=function(e){var t=r.get_mouse_pos(e);var n=Math.abs(t.left-r.mouse_init_pos.left);var s=Math.abs(t.top-r.mouse_init_pos.top);if(!(n>r.options.distance||s>r.options.distance)){return false}if(i){i=false;r.on_dragstart.call(r,e);return false}if(r.is_dragging===true){r.on_dragmove.call(r,e)}return false};this.$body.on(u.move,this.on_pointer_events_move);return false};f.on_dragstart=function(t){t.preventDefault();this.drag_start=true;this.is_dragging=true;var r=this.$container.offset();this.baseX=Math.round(r.left);this.baseY=Math.round(r.top);this.doc_height=e(n).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,t,{helper:this.helper?this.$helper:this.$player})}return false};f.on_dragmove=function(e){var t=this.get_offset(e);this.options.autoscroll&&this.manage_scroll(t);(this.helper?this.$helper:this.$player).css({position:"absolute",left:t.left,top:t.top});var n={position:{left:t.left,top:t.top}};if(this.options.drag){this.options.drag.call(this.$player,e,n)}return false};f.on_dragstop=function(e){var t=this.get_offset(e);this.drag_start=false;var n={position:{left:t.left,top:t.top}};if(this.options.stop){this.options.stop.call(this.$player,e,n)}if(this.helper){this.$helper.remove()}return false};f.on_select_start=function(e){if(this.disabled){return}if(this.ignore_drag(e)){return}return false};f.enable=function(){this.disabled=false};f.disable=function(){this.disabled=true};f.destroy=function(){this.disable();this.$container.off("selectstart",this.proxied_on_select_start);this.$container.off(u.start,this.proxied_drag_handler);this.$body.off(u.end,this.proxied_pointer_events_end);this.$body.off(u.move,this.on_pointer_events_move);e(t).unbind("resize",this.on_window_resize);e.removeData(this.$container,"drag")};f.ignore_drag=function(t){if(this.options.handle){return!e(t.target).is(this.options.handle)}return e.inArray(t.target.nodeName,this.options.ignore_dragging)>=0};e.fn.dragg=function(t){return this.each(function(){if(!e.data(this,"drag")){e.data(this,"drag",new a(this,t))}})}})(jQuery,window,document);(function(e,t,n,r){function s(t,n){this.options=e.extend(true,i,n);this.$el=e(t);this.$wrapper=this.$el.parent();this.$widgets=this.$el.children(this.options.widget_selector).addClass("gs_w");this.widgets=[];this.$changed=e([]);this.w_queue={};this.wrapper_width=this.$wrapper.width();this.min_widget_width=this.options.widget_margins[0]*2+this.options.widget_base_dimensions[0];this.min_widget_height=this.options.widget_margins[1]*2+this.options.widget_base_dimensions[1];this.init()}var i={namespace:"",widget_selector:"li",static_class:"static",widget_margins:[10,10],widget_base_dimensions:[400,225],extra_rows:0,extra_cols:0,min_cols:1,max_cols:60,min_rows:15,max_rows:15,max_size_x:6,autogenerate_stylesheet:true,avoid_overlapped_widgets:true,shift_larger_widgets_down:true,serialize_params:function(e,t){return{col:t.col,row:t.row,size_x:t.size_x,size_y:t.size_y}},collision:{},draggable:{distance:4,items:".gs_w:not(.static)"}};s.generated_stylesheets=[];var o=s.prototype;o.init=function(){this.generate_grid_and_stylesheet();this.get_widgets_from_DOM();this.set_dom_grid_height();this.$wrapper.addClass("ready");this.draggable();e(t).bind("resize",throttle(e.proxy(this.recalculate_faux_grid,this),200))};o.disable=function(){this.$wrapper.find(".player-revert").removeClass("player-revert");this.drag_api.disable();return this};o.enable=function(){this.drag_api.enable();return this};o.add_widget=function(t,n,r,i,s){var o;n||(n=1);r||(r=1);if(!i&!s){o=this.next_position(n,r)}else{o={col:i,row:s};this.empty_cells(i,s,n,r)}var u=e(t).attr({"data-col":o.col,"data-row":o.row,"data-sizex":n,"data-sizey":r}).addClass("gs_w").appendTo(this.$el).hide();this.$widgets=this.$widgets.add(u);this.$changed=this.$changed.add(u);this.register_widget(u);this.add_faux_rows(o.size_y);this.set_dom_grid_height();return u.fadeIn()};o.resize_widget=function(t,n,r){var i=t.coords().grid;n||(n=i.size_x);r||(r=i.size_y);if(n>this.cols){n=this.cols}var s=this.get_cells_occupied(i);var o=i.size_x;var u=i.size_y;var a=i.col;var f=a;var l=n>o;var c=r>u;if(a+n-1>this.cols){var h=a+(n-1)-this.cols;var p=a-h;f=Math.max(1,p)}var d={col:f,row:i.row,size_x:n,size_y:r};var v=this.get_cells_occupied(d);var m=[];e.each(s.cols,function(t,n){if(e.inArray(n,v.cols)===-1){m.push(n)}});var g=[];e.each(v.cols,function(t,n){if(e.inArray(n,s.cols)===-1){g.push(n)}});var y=[];e.each(s.rows,function(t,n){if(e.inArray(n,v.rows)===-1){y.push(n)}});var b=[];e.each(v.rows,function(t,n){if(e.inArray(n,s.rows)===-1){b.push(n)}});this.remove_from_gridmap(i);if(g.length){var w=[f,i.row,n,Math.min(u,r),t];this.empty_cells.apply(this,w)}if(b.length){var E=[f,i.row,n,r,t];this.empty_cells.apply(this,E)}i.col=f;i.size_x=n;i.size_y=r;this.add_to_gridmap(d,t);t.data("coords").update({width:n*this.options.widget_base_dimensions[0]+(n-1)*this.options.widget_margins[0]*2,height:r*this.options.widget_base_dimensions[1]+(r-1)*this.options.widget_margins[1]*2});if(r>u){this.add_faux_rows(r-u)}if(n>o){this.add_faux_cols(n-o)}t.attr({"data-col":f,"data-sizex":n,"data-sizey":r});if(m.length){var S=[m[0],i.row,m.length,Math.min(u,r),t];this.remove_empty_cells.apply(this,S)}if(y.length){var x=[f,i.row,n,r,t];this.remove_empty_cells.apply(this,x)}return t};o.empty_cells=function(t,n,r,i,s){var o=this.widgets_below({col:t,row:n-i,size_x:r,size_y:i});o.not(s).each(e.proxy(function(t,r){var s=e(r).coords().grid;if(!(s.row<=n+i-1)){return}var o=n+i-s.row;this.move_widget_down(e(r),o)},this));this.set_dom_grid_height();return this};o.remove_empty_cells=function(e,t,n,r,i){var s=this.widgets_below({col:e,row:t,size_x:n,size_y:r});this.set_dom_grid_height();return this};o.next_position=function(e,t){e||(e=1);t||(t=1);var n=this.gridmap;var r=n.length;var i=[];var s;for(var o=1;o",{"class":"preview-holder","data-row":this.$player.attr("data-row"),"data-col":this.$player.attr("data-col"),css:{width:i.width,height:i.height}}).appendTo(this.$el);if(this.options.draggable.start){this.options.draggable.start.call(this,t,n)}};o.on_drag=function(e,t){if(this.$player===null){return false}var n={left:t.position.left+this.baseX,top:t.position.top+this.baseY};this.colliders_data=this.collision_api.get_closest_colliders(n);this.on_overlapped_column_change(this.on_start_overlapping_column,this.on_stop_overlapping_column);this.on_overlapped_row_change(this.on_start_overlapping_row,this.on_stop_overlapping_row);if(this.helper&&this.$player){this.$player.css({left:t.position.left,top:t.position.top})}if(this.options.draggable.drag){this.options.draggable.drag.call(this,e,t)}};o.on_stop_drag=function(e,t){this.$helper.add(this.$player).add(this.$wrapper).removeClass("dragging");t.position.left=t.position.left+this.baseX;t.position.top=t.position.top+this.baseY;this.colliders_data=this.collision_api.get_closest_colliders(t.position);this.on_overlapped_column_change(this.on_start_overlapping_column,this.on_stop_overlapping_column);this.on_overlapped_row_change(this.on_start_overlapping_row,this.on_stop_overlapping_row);this.$player.addClass("player-revert").removeClass("player").attr({"data-col":this.placeholder_grid_data.col,"data-row":this.placeholder_grid_data.row}).css({left:"",top:""});this.$changed=this.$changed.add(this.$player);this.cells_occupied_by_player=this.get_cells_occupied(this.placeholder_grid_data);this.set_cells_player_occupies(this.placeholder_grid_data.col,this.placeholder_grid_data.row);this.$player.coords().grid.row=this.placeholder_grid_data.row;this.$player.coords().grid.col=this.placeholder_grid_data.col;if(this.options.draggable.stop){this.options.draggable.stop.call(this,e,t)}this.$preview_holder.remove();this.$player=null;this.$helper=null;this.placeholder_grid_data={};this.player_grid_data={};this.cells_occupied_by_placeholder={};this.cells_occupied_by_player={};this.w_queue={};this.set_dom_grid_height()};o.on_overlapped_column_change=function(t,n){if(!this.colliders_data.length){return}var r=this.get_targeted_columns(this.colliders_data[0].el.data.col);var i=this.last_cols.length;var s=r.length;var o;for(o=0;oparseInt(this.options.max_rows)){i=true}if(u>parseInt(this.options.max_cols)){i=true}if(this.is_player_in(u,a)){i=true}}}return i};o.can_placeholder_be_set=function(e,t,n,r){var i=true;for(var s=0;sparseInt(this.options.max_rows)){i=false}if(u>parseInt(this.options.max_cols)){i=false}if(this.is_occupied(u,a)&&!this.is_widget_queued_and_can_move(l)){i=false}}}return i};o.queue_widget=function(e,t,n){var r=n;var i=r.coords().grid;var s=e+"_"+t;if(s in this.w_queue){return false}this.w_queue[s]=r;for(var o=0;on.row){return 1}return-1});return t};o.sort_by_row_and_col_asc=function(e){e=e.sort(function(e,t){if(e.row>t.row||e.row===t.row&&e.col>t.col){return 1}return-1});return e};o.sort_by_col_asc=function(e){e=e.sort(function(e,t){if(e.col>t.col){return 1}return-1});return e};o.sort_by_row_desc=function(e){e=e.sort(function(e,t){if(e.row+e.size_y=0&&e.inArray(n,r.rows)>=0};o.is_placeholder_in=function(t,n){var r=this.cells_occupied_by_placeholder||{};return this.is_placeholder_in_col(t)&&e.inArray(n,r.rows)>=0};o.is_placeholder_in_col=function(t){var n=this.cells_occupied_by_placeholder||[];return e.inArray(t,n.cols)>=0};o.is_empty=function(e,t){if(typeof this.gridmap[e]!=="undefined"&&typeof this.gridmap[e][t]!=="undefined"&&this.gridmap[e][t]===false){return true}return false};o.is_occupied=function(e,t){if(!this.gridmap[e]){return false}if(this.gridmap[e][t]){return true}return false};o.is_widget=function(e,t){var n=this.gridmap[e];if(!n){return false}n=n[t];if(n){return n}return false};o.is_static=function(e,t){var n=this.gridmap[e];if(!n){return false}n=n[t];if(n){if(n.hasClass(this.options.static_class)){return true}}return false};o.is_widget_under_player=function(e,t){if(this.is_widget(e,t)){return this.is_player_in(e,t)}return false};o.get_widgets_under_player=function(t){t||(t=this.cells_occupied_by_player||{cols:[],rows:[]});var n=e([]);e.each(t.cols,e.proxy(function(r,i){e.each(t.rows,e.proxy(function(e,t){if(this.is_widget(i,t)){n=n.add(this.gridmap[i][t])}},this))},this));return n};o.set_placeholder=function(t,n){var r=e.extend({},this.placeholder_grid_data);var i=this.widgets_below({col:r.col,row:r.row,size_y:r.size_y,size_x:r.size_x});var s=t+parseInt(r.size_x)-1;if(s>this.cols){t=t-(s-t)}var o=this.placeholder_grid_data.row0){if(this.is_empty(e,u)||this.is_player(e,u)||this.is_widget(e,u)&&o[u].is(s)){r[e].push(u);i=u0){if(this.is_widget(s,u)&&!this.is_player_in(s,u)){if(!o[u].is(e.el)){break}}if(!this.is_player(s,u)&&!this.is_placeholder_in(s,u)&&!this.is_player_in(s,u)){r[s].push(u)}if(u=t?e[r[0]]:false};o.get_widgets_overlapped=function(){var t;var n=e([]);var r=[];var i=this.cells_occupied_by_player.rows.slice(0);i.reverse();e.each(this.cells_occupied_by_player.cols,e.proxy(function(t,s){e.each(i,e.proxy(function(t,i){if(!this.gridmap[s]){return true}var o=this.gridmap[s][i];if(this.is_occupied(s,i)&&!this.is_player(o)&&e.inArray(o,r)===-1){n=n.add(o);r.push(o)}},this))},this));return n};o.on_start_overlapping_column=function(e){this.set_player(e,false)};o.on_start_overlapping_row=function(e){this.set_player(false,e)};o.on_stop_overlapping_column=function(e){var t=this;if(this.options.shift_larger_widgets_down){this.for_each_widget_below(e,this.cells_occupied_by_player.rows[0],function(e,n){t.move_widget_up(this,t.player_grid_data.size_y)})}};o.on_stop_overlapping_row=function(e){var t=this;var n=this.cells_occupied_by_player.cols;if(this.options.shift_larger_widgets_down){for(var r=0,i=n.length;r0){this.move_widget_down(r,s)}},this));u.row=a;this.update_widget_position(u,t);t.attr("data-row",u.row);this.$changed=this.$changed.add(t);s.push(t)}};o.can_go_up_to_row=function(t,n,r){var i=this.gridmap;var s=true;var o=[];var u=t.row;var a;this.for_each_column_occupied(t,function(e){var t=i[e];o[e]=[];a=u;while(a--){if(this.is_empty(e,a)&&!this.is_placeholder_in(e,a)){o[e].push(a)}else{break}}if(!o[e].length){s=false;return true}});if(!s){return false}a=r;for(a=1;a0?n:0};o.widgets_below=function(t){var n=e.isPlainObject(t)?t:t.coords().grid;var r=this;var i=this.gridmap;var s=n.row+n.size_y-1;var o=e([]);this.for_each_column_occupied(n,function(t){r.for_each_widget_below(t,s,function(t,n){if(!r.is_player(this)&&e.inArray(this,o)===-1){o=o.add(this);return true}})});return this.sort_by_row_asc(o)};o.set_cells_player_occupies=function(e,t){this.remove_from_gridmap(this.placeholder_grid_data);this.placeholder_grid_data.col=e;this.placeholder_grid_data.row=t;this.add_to_gridmap(this.placeholder_grid_data,this.$player);return this};o.empty_cells_player_occupies=function(){this.remove_from_gridmap(this.placeholder_grid_data);return this};o.can_go_down=function(t){var n=true;var r=this;if(t.hasClass(this.options.static_class)){n=false}this.widgets_below(t).each(function(){if(e(this).hasClass(r.options.static_class)){n=false}});return n};o.can_go_up=function(e){var t=e.coords().grid;var n=t.row;var r=n-1;var i=this.gridmap;var s=[];var o=true;if(n===1){return false}this.for_each_column_occupied(t,function(e){var t=this.is_widget(e,r);if(this.is_occupied(e,r)||this.is_player(e,r)||this.is_placeholder_in(e,r)||this.is_player_in(e,r)){o=false;return true}});return o};o.can_move_to=function(e,t,n,r){var i=this.gridmap;var s=e.el;var o={size_y:e.size_y,size_x:e.size_x,col:t,row:n};var u=true;var a=t+e.size_x-1;if(a>this.cols){return false}if(r&&r0&&this.is_widget(r,h)&&e.inArray(o[r][h],c)===-1){u=s.call(o[r][h],r,h);c.push(o[r][h]);if(u){break}}}},"for_each/below":function(){for(h=i+1,a=o[r].length;h=1;i--){for(e=t[i].length-1;e>=1;e--){if(this.is_widget(i,e)){n.push(e);r[e]=i;break}}}var s=Math.max.apply(Math,n);this.highest_occupied_cell={col:r[s],row:s};return this.highest_occupied_cell};o.get_widgets_from=function(t,n){var r=this.gridmap;var i=e();if(t){i=i.add(this.$widgets.filter(function(){var n=e(this).attr("data-col");return n===t||n>t}))}if(n){i=i.add(this.$widgets.filter(function(){var t=e(this).attr("data-row");return t===n||t>n}))}return i};o.set_dom_grid_height=function(){var e=this.get_highest_occupied_cell().row;this.$el.css("height",e*this.min_widget_height);return this};o.generate_stylesheet=function(t){var n="";var r=this.options.max_size_x;var i=0;var o=0;var u;var a;t||(t={});t.cols||(t.cols=this.cols);t.rows||(t.rows=this.rows);t.namespace||(t.namespace=this.options.namespace);t.widget_base_dimensions||(t.widget_base_dimensions=this.options.widget_base_dimensions);t.widget_margins||(t.widget_margins=this.options.widget_margins);t.min_widget_width=t.widget_margins[0]*2+t.widget_base_dimensions[0];t.min_widget_height=t.widget_margins[1]*2+t.widget_base_dimensions[1];var f=e.param(t);if(e.inArray(f,s.generated_stylesheets)>=0){return false}s.generated_stylesheets.push(f);for(u=t.cols;u>=0;u--){n+=t.namespace+' [data-col="'+(u+1)+'"] { left:'+(u*t.widget_base_dimensions[0]+u*t.widget_margins[0]+(u+1)*t.widget_margins[0])+"px;} "}for(u=t.rows;u>=0;u--){n+=t.namespace+' [data-row="'+(u+1)+'"] { top:'+(u*t.widget_base_dimensions[1]+u*t.widget_margins[1]+(u+1)*t.widget_margins[1])+"px;} "}for(var l=1;l<=t.rows;l++){n+=t.namespace+' [data-sizey="'+l+'"] { height:'+(l*t.widget_base_dimensions[1]+(l-1)*t.widget_margins[1]*2)+"px;}"}for(var c=1;c<=r;c++){n+=t.namespace+' [data-sizex="'+c+'"] { width:'+(c*t.widget_base_dimensions[0]+(c-1)*t.widget_margins[0]*2)+"px;}"}return this.add_style_tag(n)};o.add_style_tag=function(e){var t=n;var r=t.createElement("style");t.getElementsByTagName("head")[0].appendChild(r);r.setAttribute("type","text/css");if(r.styleSheet){r.styleSheet.cssText=e}else{r.appendChild(n.createTextNode(e))}return this};o.generate_faux_grid=function(e,t){this.faux_grid=[];this.gridmap=[];var n;var r;for(n=t;n>0;n--){this.gridmap[n]=[];for(r=e;r>0;r--){this.add_faux_cell(r,n)}}return this};o.add_faux_cell=function(t,n){var r=e({left:this.baseX+(n-1)*this.min_widget_width,top:this.baseY+(t-1)*this.min_widget_height,width:this.min_widget_width,height:this.min_widget_height,col:n,row:t,original_col:n,original_row:t}).coords();if(!e.isArray(this.gridmap[n])){this.gridmap[n]=[]}this.gridmap[n][t]=false;this.faux_grid.push(r);return this};o.add_faux_rows=function(e){var t=this.rows;var n=t+(e||1);for(var r=n;r>t;r--){for(var i=this.cols;i>=1;i--){this.add_faux_cell(r,i)}}this.rows=n;if(this.options.autogenerate_stylesheet){this.generate_stylesheet()}return this};o.add_faux_cols=function(e){var t=this.cols;var n=t+(e||1);for(var r=t;r=1;i--){this.add_faux_cell(i,r)}}this.cols=n;if(this.options.autogenerate_stylesheet){this.generate_stylesheet()}return this};o.recalculate_faux_grid=function(){var n=this.$wrapper.width();this.baseX=(e(t).width()-n)/2;this.baseY=this.$wrapper.offset().top;e.each(this.faux_grid,e.proxy(function(e,t){this.faux_grid[e]=t.update({left:this.baseX+(t.data.col-1)*this.min_widget_width,top:this.baseY+(t.data.row-1)*this.min_widget_height})},this));return this};o.get_widgets_from_DOM=function(){this.$widgets.each(e.proxy(function(t,n){this.register_widget(e(n))},this));return this};o.generate_grid_and_stylesheet=function(){var n=this.$wrapper.width();var r=this.$wrapper.height();var i=Math.floor(n/this.min_widget_width)+this.options.extra_cols;var s=this.$widgets.map(function(){return e(this).attr("data-col")});s=Array.prototype.slice.call(s,0);s.length||(s=[0]);var o=Math.max.apply(Math,s);var u=this.options.extra_rows;this.$widgets.each(function(t,n){u+=+e(n).attr("data-sizey")});this.cols=Math.max(o,i,this.options.min_cols);this.rows=this.options.max_rows;this.baseX=(e(t).width()-n)/2;this.baseY=this.$wrapper.offset().top;if(this.options.autogenerate_stylesheet){this.generate_stylesheet()}return this.generate_faux_grid(this.rows,this.cols)};e.fn.gridster=function(t){return this.each(function(){if(!e(this).data("gridster")){e(this).data("gridster",new s(this,t))}})};e.Gridster=o})(jQuery,window,document)