﻿(function(d,q,v,w){function r(b,c){var f=d(c);f.data(e.dataKey)||(t(f),f.data(e.dataKey,{selFrom:!1,selTo:!1,isHighlighted:void 0,$currTR:d(),$currTH:d(),$currCell:d()}))}function t(b){b.addClass(f.selectableTableClass);(function(b){(function(b){b.on("mouseover."+e.eventNamespace,function(b){function c(){for(var b=1;0<b;)b=0,g.find("th, td").each(function(x,c){a.$elemX=d(c).offset().left;a.$elemXwidth=d(c).offset().left+d(c).width();a.$elemY=d(c).offset().top;a.$elemYheight=d(c).offset().top+d(c).height();
a.$elemX<a.$pointXmin&&a.$elemXwidth>=a.$pointXmin&&a.$elemXwidth<=a.$pointXwidth&&a.$elemYheight<=a.$pointYheight&&a.$elemYheight>a.$pointYmin&&(a.$temp=a.$elemX,a.$temp!=a.$pointXmin&&(a.$pointXmin=a.$temp,b=1));a.$elemX>=a.$pointXmin&&a.$elemX<a.$pointXwidth&&a.$elemXwidth>=a.$pointXwidth&&a.$elemYheight<=a.$pointYheight&&a.$elemYheight>a.$pointYmin&&(a.$temp=a.$elemXwidth,a.$temp!=a.$pointXwidth&&(a.$pointXwidth=a.$temp,b=1));a.$elemY<a.$pointYmin&&a.$elemYheight>=a.$pointYmin&&a.$elemYheight<=
a.$pointYheight&&a.$elemXwidth<=a.$pointXwidth&&a.$elemXwidth>a.$pointXmin&&(a.$temp=a.$elemY,a.$temp!=a.$pointYmin&&(a.$pointYmin=a.$temp,b=1));a.$elemY>=a.$pointYmin&&a.$elemY<a.$pointYheight&&a.$elemYheight>=a.$pointYheight&&a.$elemXwidth<=a.$pointXwidth&&a.$elemXwidth>a.$pointXmin&&(a.$temp=a.$elemYheight,a.$temp!=a.$pointYheight&&(a.$pointYheight=a.$temp,b=1));a.$elemX<a.$pointXmin&&a.$elemXwidth>=a.$pointXwidth&&a.$elemYheight<=a.$pointYheight&&a.$elemYheight>a.$pointYmin&&(a.$temp=a.$elemX,
a.$temp<a.$pointXmin&&(a.$pointXmin=a.$temp,b=1));a.$elemX>a.$pointXmin&&a.$elemX<a.$pointXwidth&&a.$elemY<a.$pointYheight&&a.$elemY>a.$pointYmin&&(a.$temp=a.$elemXwidth,a.$temp>a.$pointXwidth&&(a.$pointXwidth=a.$temp,b=1));a.$elemY<a.$pointYmin&&a.$elemYheight>=a.$pointYmin&&a.$elemYheight<=a.$pointYheight&&a.$elemXwidth<=a.$pointXwidth&&a.$elemXwidth>a.$pointXmin&&(a.$temp=a.$elemY,a.$temp<a.$pointYmin&&(a.$pointYmin=a.$temp,b=1));a.$elemY>a.$pointYmin&&a.$elemYheight<=a.$pointYheight&&a.$elemX<=
a.$pointXwidth&&(a.$temp=a.$elemYheight,a.$temp>a.$pointYheight&&(a.$pointYheight=a.$temp,b=1))})}function e(a,b){a.$pointX2=b.offset().left;a.$pointX2width=b.offset().left+b.width();a.$pointY2=b.offset().top;a.$pointY2height=b.offset().top+b.height();a.$pointX1<a.$pointX2?(a.$pointXmin=a.$pointX1,a.$pointXmax=a.$pointX2):(a.$pointXmin=a.$pointX2,a.$pointXmax=a.$pointX1);a.$pointXwidth=a.$pointX1width>a.$pointX2width?a.$pointX1width:a.$pointX2width;a.$pointY1<a.$pointY2?(a.$pointYmin=a.$pointY1,a.$pointYmax=
a.$pointY2):(a.$pointYmin=a.$pointY2,a.$pointYmax=a.$pointY1);a.$pointYheight=a.$pointY1height>a.$pointY2height?a.$pointY1height:a.$pointY2height}var h=l(b),g=h.$table;b=h.$cell;if(0!=b.length){var a=h.data;a.$currCell=b;if(!k)return!1;h=f.selectionEnabled;g.find("."+h).removeClass(h);a.selTo=n(b);e(a,b);c();u(g,a);g.data(a);return!0}}).on("mousedown."+e.eventNamespace,function(b){var c=l(b),d;b=b||q.event;"which"in b?d=3==b.which:"button"in b&&(d=2==b.button);if(d)return!0;d=c.$table;b=c.$cell;if(0!=
b.length){b.addClass(f.selectionEnabled);c=c.data;k=!0;c.selFrom=n(b);c.selFrom.$el=b;var e=f.selectedCellClass;b.hasClass(e)&&1===g(d)?b.removeClass(e):(g(d),b.addClass(e));c.$pointX1=b.offset().left;c.$pointX1width=b.offset().left+b.width();c.$pointY1=b.offset().top;c.$pointY1height=b.offset().top+b.height();c.isHighlighted=b.hasClass(e);d.data(c);return!0}}).on("mouseup."+e.eventNamespace,function(b){b=l(b);var c=b.data;k=!1;c.selFrom=!1;c.selTo=!1;b.$table.data(c)});d(b[0].ownerDocument).on("click."+
e.eventNamespace,function(c){k=!1;0==d(c.target).closest(b).length&&g(b)})})(b);(function(b){b.on("copy",function(b){b.originalEvent.clipboardData.setData("text/plain",handler.getSelectedDataAsText());b.preventDefault()})})(b)})(b)}function p(b){b.removeClass(f.selectableTableClass);var c=f.selectedCellClass;b.find("."+c).removeClass(c);c=f.selectionEnabled;b.find("."+c).removeClass(c)}function u(b,c){g(b);b.find("th, td").each(function(b,e){c.$elemX=d(e).offset().left;c.$elemXwidth=d(e).offset().left+
d(e).width();c.$elemY=d(e).offset().top;c.$elemXheight=d(e).offset().top+d(e).height();c.$elemX>=c.$pointXmin&&c.$elemXwidth<=c.$pointXwidth&&c.$elemXwidth<=c.$pointXwidth&&c.$elemY>=c.$pointYmin&&c.$elemY<=c.$pointYheight&&c.$elemYheight>=c.$pointYheight&&d(e).addClass(f.selectedCellClass)});b.trigger("selectionchange."+e.eventNamespace)}function n(b){return{x:parseInt(b.attr("data_x")),y:parseInt(b.parent("tr").attr("data_y")),colspan:b.attr("colspan")?parseInt(b.attr("colspan")):0,rowspan:b.attr("rowspan")?
parseInt(b.attr("rowspan")):0}}function g(b){b.find("."+f.selectedCellClass).removeClass(f.selectedCellClass);return 0}function l(b){b=d(b.target);var c=b.closest("table");return{$target:b,$table:c,$cell:b.closest("td,th"),data:c.data(e.dataKey)}}var f,e={dataKey:"cellsSelector",eventNamespace:"cellsselector"},k=!1,m={init:function(b){var c={selectableTableClass:"tcs",selectedCellClass:"tcs-selected",selectionEnabled:"tcs-selection-enabled"};f=b?d.extend(c,b):c;return this.filter("table").each(r)},
destroy:function(){return this.each(function(){var b=d(this);b.unbind("."+e.eventNamespace);b.removeData(e.dataKey);p(b)})},selectedCells:function(){return this.find("."+f.selectedCellClass)},removeDocumentHtmlChanges:function(b){b=b.find("table");p(b)},addDocumentHtmlChanges:function(b){b.find("table").addClass(f.selectableTableClass)}};d.fn.tableCellsSelection=function(b){if(m[b])return m[b].apply(this,Array.prototype.slice.call(arguments,1));if("object"!==typeof b&&b)d.error("Метод с именем "+
b+" не существует для jQuery.tooltip");else return m.init.apply(this,arguments)}})(jQuery,window,document);