1 line
5.8 KiB
JavaScript
1 line
5.8 KiB
JavaScript
|
|
!function(l,h,e){var d={model:{},collection:{},view:{},fn:{}},n=function(e,t){for(var s=[],i=SPECIFICITY.calculate(e),r=0;r<i.length;r++){var o=i[r];if(t)for(var c=0;c<o.parts.length;c++){var a=o.parts[c];s=s.concat(n(a.selector))}else s.push({selector:o.selector.trim(),specificity:parseInt(o.specificity.replace(/,/g,""))})}return s};d.view.inspector=Backbone.View.extend({active:!1,hl:!1,hoverEl:!1,pageSelectors:[],selectorTemplate:h.template('<div class="socss-selector"><%= selector %></div>'),initialize:function(){var t=this;this.hl=new d.view.highlighter,this.hl.initialize(),this.pageSelectors=d.fn.pageSelectors(),l("body").on("mouseover","*",function(e){if(!t.active)return!0;0===l(this).closest(".socss-element").length&&(e.stopPropagation(),t.setHoverEl(l(this)))}),l("body *").click(function(e){if(!t.active||t.$el.is(":hover"))return!0;e.preventDefault(),e.stopPropagation(),l(this).blur(),t.setActiveEl(t.hoverEl)}),this.$(".socss-enable-inspector").click(function(){t.toggleActive()}),this.$el.mouseenter(function(){t.hl.clear()});try{parent.socss.mainEditor.setInspector(this)}catch(e){console.log("No editor to register this inspector with")}},setHoverEl:function(e){this.hoverEl=e,this.hl.highlight(e)},activate:function(){this.active=!0,l("body").addClass("socss-active"),l("body").removeClass("socss-inactive")},deactivate:function(){this.active=!1,l("body").addClass("socss-inactive"),l("body").removeClass("socss-active"),this.hl.clear(),this.$(".socss-hierarchy").empty()},toggleActive:function(){this.active?this.deactivate():this.activate()},setActiveEl:function(t){var s=this,e=this.$(".socss-hierarchy");if(e.empty(),t){if("body"!==t.prop("tagName").toLowerCase()){for(var i=l(t);l(this.selectorTemplate({selector:d.fn.elSelector(i)})).prependTo(e).data("el",i),"body"!==(i=i.parent()).prop("tagName").toLowerCase(););l(this.selectorTemplate({selector:"body"})).prependTo(e).data("el",l("body")),this.$(".socss-hierarchy .socss-selector").hover(function(){s.hl.highlight(l(this).data("el"))}).click(function(e){e.preventDefault(),e.stopPropagation(),s.setActiveEl(l(this).data("el"))})}e.scrollLeft(99999);var r=this.pageSelectors.filter(function(e){try{return t.is(e.selector)}catch(e){return!1}}),o=this.$(".socss-selectors-window").empty();h.each(r,function(e){o.append(l(s.selectorTemplate(e)).data(e))}),o.find("> div").mouseenter(function(){s.hl.highlight(l(this).data("selector"))}).click(function(e){e.preventDefault(),e.stopPropagation(),s.trigger("click_selector",l(this).data("selector"))});var c=d.fn.elementAttributes(t);o=this.$(".socss-properties-window").empty(),h.each(c,function(e,t){o.append(l(s.selectorTemplate({selector:"<strong>"+t+"</strong>: "+e})).data("property",t+": "+e))}),o.find("> div").click(function(e){e.preventDefault(),e.stopPropagation(),s.trigger("click_property",l(this).data("property"))});var a=t.closest("a[href]"),n=this.$(".socss-link");a.length?n.show().find("a").html(a.attr("href").replace(/[\?&]*so_css_preview=1/,"")).attr("href",a.attr("href")):n.hide(),this.trigger("set_active_element",t,r)}}}),d.view.highlighter=Backbone.View.extend({template:h.template(l("#socss-template-hover").html().trim()),highlighted:[],highlight:function(e){this.clear();var a=this;l(e).each(function(e,t){if(!(t=l(t)).is(":visible"))return!0;var s,i=l(a.template());i.css({top:t.offset().top,left:t.offset().left,width:t.outerWidth(),height:t.outerHeight()}).appendTo("body");var r=t.padding();for(var o in r)0<parseInt(r[o])&&(s=i.find(".socss-guide-padding.socss-guide-"+o).show(),"top"===o||"bottom"===o?s.css("height",r[o]):(s.css("width",r[o]),s.css({width:r[o],top:r.top,bottom:r.bottom})));var c=t.margin();for(var o in c)0<parseInt(c[o])&&(s=i.find(".socss-guide-margin.socss-guide-"+o).show(),"top"===o||"bottom"===o?s.css("height",c[o]):s.css("width",c[o]));a.highlighted.push(i)})},clear:function(){for(;this.highlighted.length;)this.highlighted.pop().remove()}}),d.parsedCss={},d.fn.getParsedCss=function(){if(0===Object.keys(d.parsedCss).length){var s=window.css;l(".socss-theme-styles").each(function(){var e=l(this),t=s
|