!function(a){if("function"==typeof define&&define.amd)define(["jquery","lodash","jquery-ui/core","jquery-ui/widget","jquery-ui/mouse","jquery-ui/draggable","jquery-ui/resizable"],a);else if("undefined"!=typeof exports){try{jQuery=require("jquery")}catch(b){}try{_=require("lodash")}catch(b){}a(jQuery,_)}else a(jQuery,_)}(function(a,b){var c=window,d={is_intercepted:function(a,b){return!(a.x+a.width<=b.x||b.x+b.width<=a.x||a.y+a.height<=b.y||b.y+b.height<=a.y)},sort:function(a,c,d){return d=d||b.chain(a).map(function(a){return a.x+a.width}).max().value(),c=-1!=c?1:-1,b.sortBy(a,function(a){return c*(a.x+a.y*d)})},create_stylesheet:function(a){var b=document.createElement("style");return b.setAttribute("type","text/css"),b.setAttribute("data-gs-id",a),b.styleSheet?b.styleSheet.cssText="":b.appendChild(document.createTextNode("")),document.getElementsByTagName("head")[0].appendChild(b),b.sheet},remove_stylesheet:function(b){a("STYLE[data-gs-id="+b+"]").remove()},insert_css_rule:function(a,b,c,d){"function"==typeof a.insertRule?a.insertRule(b+"{"+c+"}",d):"function"==typeof a.addRule&&a.addRule(b,c,d)},toBool:function(a){return"boolean"==typeof a?a:"string"==typeof a?(a=a.toLowerCase(),!(""==a||"no"==a||"false"==a||"0"==a)):Boolean(a)}},e=0,f=function(a,b,c,d,e){this.width=a,this["float"]=c||!1,this.height=d||0,this.nodes=e||[],this.onchange=b||function(){},this._update_counter=0,this._float=this["float"]};f.prototype.batch_update=function(){this._update_counter=1,this["float"]=!0},f.prototype.commit=function(){this._update_counter=0,0==this._update_counter&&(this["float"]=this._float,this._pack_nodes(),this._notify())},f.prototype._fix_collisions=function(a){this._sort_nodes(-1);var c=a,e=Boolean(b.find(this.nodes,function(a){return a.locked}));for(this["float"]||e||(c={x:0,y:a.y,width:this.width,height:a.height});;){var f=b.find(this.nodes,b.bind(function(b){return b!=a&&d.is_intercepted(b,c)},this));if("undefined"==typeof f)return;this.move_node(f,f.x,a.y+a.height,f.width,f.height,!0)}},f.prototype.is_area_empty=function(a,c,e,f){var g={x:a||0,y:c||0,width:e||1,height:f||1},h=b.find(this.nodes,b.bind(function(a){return d.is_intercepted(a,g)},this));return null==h},f.prototype._sort_nodes=function(a){this.nodes=d.sort(this.nodes,a,this.width)},f.prototype._pack_nodes=function(){this._sort_nodes(),this["float"]?b.each(this.nodes,b.bind(function(a,c){if(!a._updating&&"undefined"!=typeof a._orig_y&&a.y!=a._orig_y)for(var e=a.y;e>=a._orig_y;){var f=b.chain(this.nodes).find(function(b){return a!=b&&d.is_intercepted({x:a.x,y:e,width:a.width,height:a.height},b)}).value();f||(a._dirty=!0,a.y=e),--e}},this)):b.each(this.nodes,b.bind(function(a,c){if(!a.locked)for(;a.y>0;){var e=a.y-1,f=0==c;if(c>0){var g=b.chain(this.nodes).take(c).find(function(b){return d.is_intercepted({x:a.x,y:e,width:a.width,height:a.height},b)}).value();f="undefined"==typeof g}if(!f)break;a._dirty=a.y!=e,a.y=e}},this))},f.prototype._prepare_node=function(a,c){return a=b.defaults(a||{},{width:1,height:1,x:0,y:0}),a.x=parseInt(""+a.x),a.y=parseInt(""+a.y),a.width=parseInt(""+a.width),a.height=parseInt(""+a.height),a.auto_position=a.auto_position||!1,a.no_resize=a.no_resize||!1,a.no_move=a.no_move||!1,a.width>this.width?a.width=this.width:a.width<1&&(a.width=1),a.height<1&&(a.height=1),a.x<0&&(a.x=0),a.x+a.width>this.width&&(c?a.width=this.width-a.x:a.x=this.width-a.width),a.y<0&&(a.y=0),a},f.prototype._notify=function(){if(!this._update_counter){var a=Array.prototype.slice.call(arguments,1).concat(this.get_dirty_nodes());a=a.concat(this.get_dirty_nodes()),this.onchange(a)}},f.prototype.clean_nodes=function(){b.each(this.nodes,function(a){a._dirty=!1})},f.prototype.get_dirty_nodes=function(){return b.filter(this.nodes,function(a){return a._dirty})},f.prototype.add_node=function(a){if(a=this._prepare_node(a),"undefined"!=typeof a.max_width&&(a.width=Math.min(a.width,a.max_width)),"undefined"!=typeof a.max_height&&(a.height=Math.min(a.height,a.max_height)),"undefined"!=typeof a.min_width&&(a.width=Math.max(a.width,a.min_width)),"undefined"!=typeof a.min_height&&(a.height=Math.max(a.height,a.min_height)),a._id=++e,a._dirty=!0,a.auto_position){this._sort_nodes();for(var c=0;;++c){var f=c%this.width,g=Math.floor(c/this.width);if(!(f+a.width>this.width||b.find(this.nodes,function(b){return d.is_intercepted({x:f,y:g,width:a.width,height:a.height},b)}))){a.x=f,a.y=g;break}}}return this.nodes.push(a),this._fix_collisions(a),this._pack_nodes(),this._notify(),a},f.prototype.remove_node=function(a){a._id=null,this.nodes=b.without(this.nodes,a),this._pack_nodes(),this._notify(a)},f.prototype.can_move_node=function(c,d,e,g,h){var i=Boolean(b.find(this.nodes,function(a){return a.locked}));if(!this.height&&!i)return!0;var j,k=new f(this.width,null,this["float"],0,b.map(this.nodes,function(b){return b==c?j=a.extend({},b):a.extend({},b)}));k.move_node(j,d,e,g,h);var l=!0;return i&&(l&=!Boolean(b.find(k.nodes,function(a){return a!=j&&Boolean(a.locked)&&Boolean(a._dirty)}))),this.height&&(l&=k.get_grid_height()<=this.height),l},f.prototype.can_be_placed_with_respect_to_height=function(c){if(!this.height)return!0;var d=new f(this.width,null,this["float"],0,b.map(this.nodes,function(b){return a.extend({},b)}));return d.add_node(c),d.get_grid_height()<=this.height},f.prototype.move_node=function(a,b,c,d,e,f){if("number"!=typeof b&&(b=a.x),"number"!=typeof c&&(c=a.y),"number"!=typeof d&&(d=a.width),"number"!=typeof e&&(e=a.height),"undefined"!=typeof a.max_width&&(d=Math.min(d,a.max_width)),"undefined"!=typeof a.max_height&&(e=Math.min(e,a.max_height)),"undefined"!=typeof a.min_width&&(d=Math.max(d,a.min_width)),"undefined"!=typeof a.min_height&&(e=Math.max(e,a.min_height)),a.x==b&&a.y==c&&a.width==d&&a.height==e)return a;var g=a.width!=d;return a._dirty=!0,a.x=b,a.y=c,a.width=d,a.height=e,a=this._prepare_node(a,g),this._fix_collisions(a),f||(this._pack_nodes(),this._notify()),a},f.prototype.get_grid_height=function(){return b.reduce(this.nodes,function(a,b){return Math.max(a,b.y+b.height)},0)},f.prototype.begin_update=function(a){b.each(this.nodes,function(a){a._orig_y=a.y}),a._updating=!0},f.prototype.end_update=function(){b.each(this.nodes,function(a){a._orig_y=a.y});var a=b.find(this.nodes,function(a){return a._updating});a&&(a._updating=!1)};var g=function(c,d){var e,g=this;d=d||{},this.container=a(c),d.item_class=d.item_class||"grid-stack-item";var h=this.container.closest("."+d.item_class).size()>0;if(this.opts=b.defaults(d||{},{width:parseInt(this.container.attr("data-gs-width"))||12,height:parseInt(this.container.attr("data-gs-height"))||0,item_class:"grid-stack-item",placeholder_class:"grid-stack-placeholder",placeholder_text:"",handle:".grid-stack-item-content",handle_class:null,cell_height:60,vertical_margin:20,auto:!0,min_width:768,"float":!1,static_grid:!1,_class:"grid-stack-instance-"+(1e4*Math.random()).toFixed(0),animate:Boolean(this.container.attr("data-gs-animate"))||!1,always_show_resize_handle:d.always_show_resize_handle||!1,resizable:b.defaults(d.resizable||{},{autoHide:!d.always_show_resize_handle,handles:"se"}),draggable:b.defaults(d.draggable||{},{handle:(d.handle_class?"."+d.handle_class:d.handle?d.handle:"")||".grid-stack-item-content",scroll:!1,appendTo:"body"})}),this.opts.is_nested=h,this.container.addClass(this.opts._class),this._set_static_class(),h&&this.container.addClass("grid-stack-nested"),this._init_styles(),this.grid=new f(this.opts.width,function(a){var c=0;b.each(a,function(a){null==a._id?a.el.remove():(a.el.attr("data-gs-x",a.x).attr("data-gs-y",a.y).attr("data-gs-width",a.width).attr("data-gs-height",a.height),c=Math.max(c,a.y+a.height))}),g._update_styles(c+10)},this.opts["float"],this.opts.height),this.opts.auto){var i=[],j=this;this.container.children("."+this.opts.item_class+":not(."+this.opts.placeholder_class+")").each(function(b,c){c=a(c),i.push({el:c,i:parseInt(c.attr("data-gs-x"))+parseInt(c.attr("data-gs-y"))*j.opts.width})}),b.chain(i).sortBy(function(a){return a.i}).each(function(a){g._prepare_element(a.el)}).value()}this.set_animation(this.opts.animate),this.placeholder=a('<div class="'+this.opts.placeholder_class+" "+this.opts.item_class+'"><div class="placeholder-content">'+this.opts.placeholder_text+"</div></div>").hide(),this.container.height(this.grid.get_grid_height()*(this.opts.cell_height+this.opts.vertical_margin)-this.opts.vertical_margin),this.on_resize_handler=function(){if(g._is_one_column_mode()){if(e)return;e=!0,g.grid._sort_nodes(),b.each(g.grid.nodes,function(a){g.container.append(a.el),g.opts.static_grid||(a.no_move||a.el.draggable("disable"),a.no_resize||a.el.resizable("disable"))})}else{if(!e)return;if(e=!1,g.opts.static_grid)return;b.each(g.grid.nodes,function(a){a.no_move||a.el.draggable("enable"),a.no_resize||a.el.resizable("enable")})}},a(window).resize(this.on_resize_handler),this.on_resize_handler()};return g.prototype._trigger_change_event=function(a){var b=this.grid.get_dirty_nodes(),c=!1,d=[];b&&b.length&&(d.push(b),c=!0),(c||a===!0)&&this.container.trigger("change",d)},g.prototype._init_styles=function(){this._styles_id&&a('[data-gs-id="'+this._styles_id+'"]').remove(),this._styles_id="gridstack-style-"+(1e5*Math.random()).toFixed(),this._styles=d.create_stylesheet(this._styles_id),null!=this._styles&&(this._styles._max=0)},g.prototype._update_styles=function(a){if(null!=this._styles){var b="."+this.opts._class+" ."+this.opts.item_class;if("undefined"==typeof a&&(a=this._styles._max,this._init_styles(),this._update_container_height()),0==this._styles._max&&d.insert_css_rule(this._styles,b,"min-height: "+this.opts.cell_height+"px;",0),a>this._styles._max){for(var c=this._styles._max;a>c;++c)d.insert_css_rule(this._styles,b+'[data-gs-height="'+(c+1)+'"]',"height: "+(this.opts.cell_height*(c+1)+this.opts.vertical_margin*c)+"px;",c),d.insert_css_rule(this._styles,b+'[data-gs-min-height="'+(c+1)+'"]',"min-height: "+(this.opts.cell_height*(c+1)+this.opts.vertical_margin*c)+"px;",c),d.insert_css_rule(this._styles,b+'[data-gs-max-height="'+(c+1)+'"]',"max-height: "+(this.opts.cell_height*(c+1)+this.opts.vertical_margin*c)+"px;",c),d.insert_css_rule(this._styles,b+'[data-gs-y="'+c+'"]',"top: "+(this.opts.cell_height*c+this.opts.vertical_margin*c)+"px;",c);this._styles._max=a}}},g.prototype._update_container_height=function(){this.grid._update_counter||this.container.height(this.grid.get_grid_height()*(this.opts.cell_height+this.opts.vertical_margin)-this.opts.vertical_margin)},g.prototype._is_one_column_mode=function(){return(window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth)<=this.opts.min_width},g.prototype._prepare_element=function(c){var e=this;c=a(c),c.addClass(this.opts.item_class);var f=e.grid.add_node({x:c.attr("data-gs-x"),y:c.attr("data-gs-y"),width:c.attr("data-gs-width"),height:c.attr("data-gs-height"),max_width:c.attr("data-gs-max-width"),min_width:c.attr("data-gs-min-width"),max_height:c.attr("data-gs-max-height"),min_height:c.attr("data-gs-min-height"),auto_position:d.toBool(c.attr("data-gs-auto-position")),no_resize:d.toBool(c.attr("data-gs-no-resize")),no_move:d.toBool(c.attr("data-gs-no-move")),locked:d.toBool(c.attr("data-gs-locked")),el:c});if(c.data("_gridstack_node",f),!e.opts.static_grid){var g,h,i=function(a,b){var c,d,i=Math.round(b.position.left/g),j=Math.floor((b.position.top+h/2)/h);"drag"!=a.type&&(c=Math.round(b.size.width/g),d=Math.round(b.size.height/h)),e.grid.can_move_node(f,i,j,c,d)&&(e.grid.move_node(f,i,j,c,d),e._update_container_height())},j=function(b,d){e.container.append(e.placeholder);var i=a(this);e.grid.clean_nodes(),e.grid.begin_update(f),g=i.outerWidth()/i.attr("data-gs-width"),h=e.opts.cell_height+e.opts.vertical_margin,e.placeholder.attr("data-gs-x",i.attr("data-gs-x")).attr("data-gs-y",i.attr("data-gs-y")).attr("data-gs-width",i.attr("data-gs-width")).attr("data-gs-height",i.attr("data-gs-height")).show(),f.el=e.placeholder,c.resizable("option","minWidth",Math.round(g*(f.min_width||1))),c.resizable("option","minHeight",e.opts.cell_height*(f.min_height||1)),"resizestart"==b.type&&i.find(".grid-stack-item").trigger("resizestart")},k=function(b,c){e.placeholder.detach();var d=a(this);f.el=d,e.placeholder.hide(),d.attr("data-gs-x",f.x).attr("data-gs-y",f.y).attr("data-gs-width",f.width).attr("data-gs-height",f.height).removeAttr("style"),e._update_container_height(),e._trigger_change_event(),e.grid.end_update();var g=d.find(".grid-stack");g.length&&"resizestop"==b.type&&(g.each(function(b,c){a(c).data("gridstack").on_resize_handler()}),d.find(".grid-stack-item").trigger("resizestop"))};c.draggable(b.extend(this.opts.draggable,{containment:this.opts.is_nested?this.container.parent():null,start:j,stop:k,drag:i})).resizable(b.extend(this.opts.resizable,{start:j,stop:k,resize:i})),(f.no_move||this._is_one_column_mode())&&c.draggable("disable"),(f.no_resize||this._is_one_column_mode())&&c.resizable("disable"),c.attr("data-gs-locked",f.locked?"yes":null)}},g.prototype.set_animation=function(a){a?this.container.addClass("grid-stack-animate"):this.container.removeClass("grid-stack-animate")},g.prototype.add_widget=function(b,c,d,e,f,g){return b=a(b),"undefined"!=typeof c&&b.attr("data-gs-x",c),"undefined"!=typeof d&&b.attr("data-gs-y",d),"undefined"!=typeof e&&b.attr("data-gs-width",e),"undefined"!=typeof f&&b.attr("data-gs-height",f),"undefined"!=typeof g&&b.attr("data-gs-auto-position",g?"yes":null),this.container.append(b),this._prepare_element(b),this._update_container_height(),this._trigger_change_event(!0),b},g.prototype.make_widget=function(b){return b=a(b),this._prepare_element(b),this._update_container_height(),this._trigger_change_event(!0),b},g.prototype.will_it_fit=function(a,b,c,d,e){var f={x:a,y:b,width:c,height:d,auto_position:e};return this.grid.can_be_placed_with_respect_to_height(f)},g.prototype.remove_widget=function(b,c){c="undefined"==typeof c?!0:c,b=a(b);var d=b.data("_gridstack_node");this.grid.remove_node(d),b.removeData("_gridstack_node"),this._update_container_height(),c&&b.remove(),this._trigger_change_event(!0)},g.prototype.remove_all=function(a){b.each(this.grid.nodes,b.bind(function(b){this.remove_widget(b.el,a)},this)),this.grid.nodes=[],this._update_container_height()},g.prototype.destroy=function(){a(window).off("resize",this.on_resize_handler),this.disable(),this.container.remove(),d.remove_stylesheet(this._styles_id),this.grid&&(this.grid=null)},g.prototype.resizable=function(b,c){var d=this;return b=a(b),b.each(function(b,e){e=a(e);var f=e.data("_gridstack_node");"undefined"!=typeof f&&null!=f&&(f.no_resize=!c,f.no_resize||d._is_one_column_mode()?e.resizable("disable"):e.resizable("enable"))}),this},g.prototype.movable=function(b,c){var d=this;return b=a(b),b.each(function(b,e){e=a(e);var f=e.data("_gridstack_node");"undefined"!=typeof f&&null!=f&&(f.no_move=!c,f.no_move||d._is_one_column_mode()?(e.draggable("disable"),e.removeClass("ui-draggable-handle")):(e.draggable("enable"),e.addClass("ui-draggable-handle")))}),this},g.prototype.disable=function(){this.movable(this.container.children("."+this.opts.item_class),!1),this.resizable(this.container.children("."+this.opts.item_class),!1),this.container.trigger("disable")},g.prototype.enable=function(){this.movable(this.container.children("."+this.opts.item_class),!0),this.resizable(this.container.children("."+this.opts.item_class),!0),this.container.trigger("enable")},g.prototype.locked=function(b,c){return b=a(b),b.each(function(b,d){d=a(d);var e=d.data("_gridstack_node");"undefined"!=typeof e&&null!=e&&(e.locked=c||!1,d.attr("data-gs-locked",e.locked?"yes":null))}),this},g.prototype.min_height=function(b,c){return b=a(b),b.each(function(b,d){d=a(d);var e=d.data("_gridstack_node");"undefined"!=typeof e&&null!=e&&(isNaN(c)||(e.min_height=c||!1,d.attr("data-gs-min-height",c)))}),this},g.prototype.min_width=function(b,c){return b=a(b),b.each(function(b,d){d=a(d);var e=d.data("_gridstack_node");"undefined"!=typeof e&&null!=e&&(isNaN(c)||(e.min_width=c||!1,d.attr("data-gs-min-width",c)))}),this},g.prototype._update_element=function(b,c){b=a(b).first();var d=b.data("_gridstack_node");if("undefined"!=typeof d&&null!=d){var e=this;e.grid.clean_nodes(),e.grid.begin_update(d),c.call(this,b,d),e._update_container_height(),e._trigger_change_event(),e.grid.end_update()}},g.prototype.resize=function(a,b,c){this._update_element(a,function(a,d){b=null!=b&&"undefined"!=typeof b?b:d.width,c=null!=c&&"undefined"!=typeof c?c:d.height,this.grid.move_node(d,d.x,d.y,b,c)})},g.prototype.move=function(a,b,c){this._update_element(a,function(a,d){b=null!=b&&"undefined"!=typeof b?b:d.x,c=null!=c&&"undefined"!=typeof c?c:d.y,this.grid.move_node(d,b,c,d.width,d.height)})},g.prototype.update=function(a,b,c,d,e){this._update_element(a,function(a,f){b=null!=b&&"undefined"!=typeof b?b:f.x,c=null!=c&&"undefined"!=typeof c?c:f.y,d=null!=d&&"undefined"!=typeof d?d:f.width,e=null!=e&&"undefined"!=typeof e?e:f.height,this.grid.move_node(f,b,c,d,e)})},g.prototype.cell_height=function(a){return"undefined"==typeof a?this.opts.cell_height:(a=parseInt(a),void(a!=this.opts.cell_height&&(this.opts.cell_height=a||this.opts.cell_height,this._update_styles())))},g.prototype.cell_width=function(){var a=this.container.children("."+this.opts.item_class).first();return Math.ceil(a.outerWidth()/a.attr("data-gs-width"))},g.prototype.get_cell_from_pixel=function(a){var b=this.container.position(),c=a.left-b.left,d=a.top-b.top,e=Math.floor(this.container.width()/this.opts.width),f=this.opts.cell_height+this.opts.vertical_margin;return{x:Math.floor(c/e),y:Math.floor(d/f)}},g.prototype.batch_update=function(){this.grid.batch_update()},g.prototype.commit=function(){this.grid.commit(),this._update_container_height()},g.prototype.is_area_empty=function(a,b,c,d){return this.grid.is_area_empty(a,b,c,d)},g.prototype.set_static=function(a){this.opts.static_grid=a===!0,this._set_static_class()},g.prototype._set_static_class=function(){var a="grid-stack-static";this.opts.static_grid===!0?this.container.addClass(a):this.container.removeClass(a)},c.GridStackUI=g,c.GridStackUI.Utils=d,a.fn.gridstack=function(b){return this.each(function(){var c=a(this);c.data("gridstack")||c.data("gridstack",new g(this,b))})},c.GridStackUI});
//# sourceMappingURL=gridstack.min.map