/*! dom-outliner - v0.1.3 - 2015-06-19 * https://github.com/vitorhsb/dom-outliner * Copyright (c) 2015 Vitor Barbosa; Licensed MIT */ !function(a){function b(){f(),h(),e()}function c(){r(),g(),i()}function d(a){var b=document.createElement("style");b.type="text/css",document.getElementsByTagName("head")[0].appendChild(b),b.styleSheet?b.styleSheet.cssText=a:b.innerHTML=a}function e(){var a="."+B+" {outline: "+A.outlineWidth+"px "+A.outlineStyle+" "+A.outlineColor+";}."+D+" {display: none;background: "+A.outlineColor+";color: #fff;font: bold 12px/12px Helvetica, Arial, sans-serif;padding: 5px;margin: 0;position: absolute;z-index: 1000001;}."+C+" {outline: "+A.outlineWidth+"px "+A.outlineStyle+" "+A.outlineSelectedColor+";}."+E+" {background: "+A.outlineSelectedColor+";z-index: 2000002;}."+F+" {opacity: "+A.glassOpacity+" !important;-moz-opacity: "+A.glassOpacity+" !important;filter: alpha(opacity="+A.glassOpacity+') !important;-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=('+A.glassOpacity+'*100))" !important;background: '+A.glassColor+";position: absolute;top: 0;left: 0;z-index: 2000001;min-height: 0 !important;min-width: 0 !important;}."+G+' {background: rgba(0, 0, 0, 0);opacity: 1.0 !important;-moz-opacity: 1 !important;filter: alpha(opacity=1) !important;-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=(1*100))" !important;}#'+B+"-glass-message {height: 100%;width: 100%;background: rgba(255, 255, 0, 0.4);cursor: pointer;}#"+B+"-glass-message > div {position: relative;top: 50%;transform: translateY(-50%);text-align: center;margin: 0 auto;}";d(a)}function f(){I={label:a("
").addClass(D).appendTo(K.getBody())}}function g(){a.each(I,function(a,b){b.remove()}),I={}}function h(){H={center:a('
').appendTo(K.getBody()),top:a('
').appendTo(K.getBody()),right:a('
').appendTo(K.getBody()),bottom:a('
').appendTo(K.getBody()),left:a('
').appendTo(K.getBody())}}function i(){a.each(H,function(a,b){b.off("click."+B).remove()}),H={}}function j(b){var c=K.getDocument(),d=c.height(),e=c.width();if(J=b,b.each(function(){a(this).addClass(C)}),A.showGlasses)try{var f=b.offset(),g=b.outerHeight(),h=b.outerWidth();H.center.css({top:f.top-A.outlineWidth,left:f.left-A.outlineWidth,height:g+2*A.outlineWidth,width:h+2*A.outlineWidth}).show(),H.top.css({top:0,left:0,height:f.top-A.outlineWidth,width:e}).show(),H.right.css({top:f.top-A.outlineWidth,left:f.left+h+A.outlineWidth,height:g+2*A.outlineWidth,width:e-f.left-h-A.outlineWidth}).show(),H.bottom.css({top:f.top+g+A.outlineWidth,left:0,height:d-f.top-g-A.outlineWidth,width:e}).show(),H.left.css({top:f.top-A.outlineWidth,left:0,height:g+2*A.outlineWidth,width:f.left-A.outlineWidth}).show()}catch(i){}finally{}A.showLabel&&I.label.addClass(E)}function k(a){a.removeClass(C).removeClass(B).off("."+B),a.trigger("deselect.outliner"),I.label.removeClass(E).hide(),r()}function l(b,c,d){j(b),b.trigger("select.outliner",c),a.isFunction(A.onSelection)&&A.onSelection(b.get(0),c,d)}function m(){a.each(H,function(a,b){b.hide()}),J&&(k(a(J)),y&&a.isFunction(A.onCancel)&&A.onCancel(J),J=null)}function n(b){var c=!1;if(y&&!z)return A.filter&&(c=!0,a.each(A.filter,function(a,d){c=c&&!b.is(d)})),c||!A.exclude.length&&!a.outliner.options.exclude.length||a.each(A.exclude.concat(a.outliner.options.exclude),function(a,d){return c=c||b.is(d),c?!1:!0}),!c&&J&&b.filter(":outliner").length&&(c=!0),c||!A.excludeClosest.length&&!a.outliner.options.excludeClosest.length||a.each(A.excludeClosest.concat(a.outliner.options.excludeClosest),function(a,d){return c=c||b.closest(d).length,c?!1:!0}),c}function o(b){var c=b.get(0),d=c.tagName.toLowerCase(),e=c.className;return e=e.replace(C,""),e=e.replace(B,""),d+=c.id?"#"+c.id:"",e&&(d+=("."+a.trim(e).replace(/ /g,".")).replace(/\.\.+/g,".")),d+" ("+Math.round(b.width())+"x"+Math.round(b.height())+")"}function p(b,c){var d="",e=b.offset();a("."+B).removeClass(B),b.toggleClass(B),b.hasClass(B)?(b.trigger("mouseover.outliner",c),a.isFunction(A.onMouseOver)&&A.onMouseOver(b.get(0),c)):(b.trigger("mouseout.outliner",c),a.isFunction(A.onMouseOut)&&A.onMouseOut(b.get(0),c)),A.showLabel&&(d=o(b),I.label.html(d).show().css({top:Math.max(0,e.top-A.outlineWidth-I.label.outerHeight()),left:Math.max(0,e.left-A.outlineWidth)}),b.hasClass(B)||I.label.hide())}function q(b,c){var d=a("#"+B+"-glass-center");b.hasClass(B)&&d.is(":visible")&&(d.html('
'+(c.text||"")+"
"),d.find("#"+B+"-glass-message").on("click.outliner-message",function(b){r(),c&&a.isFunction(c.callback)&&c.callback(b),b.preventDefault(),b.stopPropagation()}))}function r(){a("#"+B+"-glass-center").find("#"+B+"-glass-message").remove()}function s(a,b){return J?m():l(a,b)}function t(){var c;A.base=A.base||a("body"),c=a(A.base),x||b(),x=!0,y=!0,c.length&&v(c)}function u(b){A.base=A.base||a("body"),b=b||a(A.base),b.off("."+B),a.each(H,function(a,b){b.off("click."+B)}),z=!0}function v(b){A.base=A.base||a("body"),b=b||a(A.base),b.off("."+B).on("mouseover."+B+" mouseout."+B+" click."+B,function(b){var c=a(b.target);n(c)||("click"===b.type?(s(c,b),b.preventDefault(),b.stopPropagation()):p(c,b))}),a.each(H,function(a,b){b.off("click."+B).on("click."+B,function(){m()})}),z=!1}function w(b){A.base=A.base||a("body"),b=b||a(A.base),b.length&&b.off("."+B),y=!1,z=!0,m(),c()}var x=!1,y=!1,z=!1,A={},B="dom-outliner",C=B+"-selected",D=B+"-label",E=D+"-selected",F=B+"-glass",G=B+"-transparent-glass",H={},I={},J=null,K=function(){var b=a(),c=a(),d=a();return{getWindow:function(){return b.length?b:b=a(window)},getDocument:function(){return c.length?c:c=a(document)},getBody:function(){return d.length?d:d=a("body")}}}();a.fn.outliner=function(b){if(b&&"string"==typeof b)switch(b){case"outline-update":return this.each(function(){j(a(this))});case"outline-only":return this.each(function(){p(a(this),null)});case"outline-message-show":var c=Array.prototype.slice.call(arguments,1),d=c.length?c[0]:{};return this.each(function(){q(a(this),d)});case"outline-message-remove":return r();default:return null}return A=a.extend({},a.outliner.options,A,b||{}),t(),m(),this.each(function(){var b=a(this).addClass(B);l(b,null,A)})},a.outliner=function(b){if(!b||"string"!=typeof b)return A=a.extend({},a.outliner.options,A,b),t(),this;switch(b){case"selected":return a("."+C);case"pause":u();break;case"resume":v();break;case"stop":w();break;case"cancel":m()}},A=a.outliner.options={base:null,outlineWidth:2,outlineStyle:"solid",outlineColor:"#c00",outlineSelectedColor:"blue",showGlasses:!0,glassColor:"#F4F5F6",glassOpacity:.8,showLabel:!0,stopOnSelection:!1,onSelection:null,onCancel:null,onMouseOver:null,onMouseOut:null,filter:null,exclude:[],excludeClosest:[]},a.outliner.options.exclude=["."+B+"-glass","."+D,"."+B+"-item"],a.expr[":"].outliner=function(b){return a(b).hasClass(B)||a(b).hasClass(C)}}(jQuery);