/*! ViewportResizer - v0.3.0 - 2013-10-28 * https://github.com/KaptinLin/ViewportResizer * Copyright (c) 2013 amazingSurge; Licensed GPL */ !function(a,b,c,d){"use strict";function e(a){return("string"==typeof a||"number"==typeof a)&&!isNaN(a-0)&&""!==a}function f(a){for(var b in a)if(a.hasOwnProperty(b))return!1;return!0}function g(a){return e(a)?a/2:"string"==typeof a&&"%"===a.charAt(a.length-1)?a.substr(0,a.length-1)/2+"%":void 0}function h(a){return"string"==typeof a&&"%"===a.charAt(a.length-1)?!0:!1}function i(){var a=jQuery('
test
'),b=jQuery('
').append(a),c=a[0],d=b[0];jQuery("body").append(d);var e=c.offsetWidth;b.css("overflow","scroll");var f=d.clientWidth;return b.remove(),e-f}var j=c.ViewportResizer=function(b){function d(){j.current={},j.initialization={},j.$viewport=c("
").addClass(u).appendTo(j.settings.container.viewport),j.$viewport.on("change",function(a,b){"undefined"!=typeof b&&("undefined"!=typeof b.viewport&&(j.current.viewport=b.viewport,"optional"!==b.viewport&&(b.dimensions=k(b.viewport)),j.current.width=b.dimensions.width,j.current.height=b.dimensions.height),"undefined"!=typeof b.target&&(j.current.target=b.target),j.$viewport.trigger("resize",{width:j.current.width,height:j.current.height}))}),j.$viewport.on("init",function(a,b){"undefined"!=typeof b&&("undefined"!=typeof b.viewport&&(j.initialization.viewport=b.viewport),"undefined"!=typeof b.target&&(j.initialization.target=b.target),f(b.dimensions)||(j.initialization.dimensions=b.dimensions))}),j.$viewport.trigger("init",{target:j.settings.target,viewport:j.settings.viewport,dimensions:j.settings.dimensions}),j.settings.components.inputer&&r.init(),j.settings.components.switcher&&l.init(),j.settings.components.iframe&&m.init(),j.settings.components.resizable&&o.init(),j.settings.components.axis&&p.init(),j.settings.components.info&&q.init(),j.settings.components.history&&n.init(),f(j.initialization)||j.$viewport.trigger("change",j.initialization)}function k(a){return"auto"===a?{width:"100%",height:"100%"}:{width:j.settings.viewports[a].width,height:j.settings.viewports[a].height}}c.extend(!0,j.settings,b);var l,m,n,o,p,q,r,s=i(),t=j.settings.namespace+"-switcher",u=j.settings.namespace+"-viewport",v=j.settings.namespace+"-iframe",w=j.settings.namespace+"-resizable",x=j.settings.namespace+"-axis",y=j.settings.namespace+"-info",z=j.settings.namespace+"-inputer";n={query:{},init:function(){c.extend(n.query,n.getQuery()),j.$viewport.on("init",function(a,b){if("undefined"!=typeof b){var c={};"undefined"!=typeof b.width&&(c.width=parseInt(b.width,10)),"undefined"!=typeof b.height&&(c.height=parseInt(b.height,10)),j.initialization.dimensions=c}}),f(n.query)||j.$viewport.trigger("init",n.query),a.onpopstate=function(b){a.onpopstateing=!0;var c={};null!==b.state&&("undefined"!=typeof b.state.viewport&&(c.viewport=b.state.viewport,"optional"===c.viewport&&(c.dimensions={width:b.state.width?parseInt(b.state.width,10):j.settings.min.width,height:b.state.height?parseInt(b.state.height,10):j.settings.min.height})),"undefined"!=typeof b.state.target&&(c.target=b.state.target),j.$viewport.trigger("change",c)),a.onpopstateing=!1,b.preventDefault()},j.$viewport.on("change",function(a,b){if("undefined"!=typeof b){var c={};"undefined"!=typeof b.viewport&&(c.viewport=b.viewport,"optional"===b.viewport&&"undefined"!==b.dimensions?(c.width=b.dimensions.width,c.height=b.dimensions.height):n.query.viewport!==b.viewport&&(c.width=null,c.height=null)),c.target="undefined"!=typeof b.target?b.target:j.current.target,n.setQuery(c)}})},pushState:function(b){if(a.onpopstateing!==!0&&a.history&&a.history.pushState&&a.history.replaceState){var d=[];c.each(b,function(a,b){null!=b&&d.push(a+"="+b)});var e="?"+d.join("&");a.history.pushState(b,"",e)}},getQuery:function(){var b=a.location.href,d={},e=b.replace(/#[^\s]+/,"").split("?")[1];return"undefined"!=typeof e&&(e=e.split("&"),c.each(e,function(a,b){var c=b.split("=");d[c[0]]=c[1]})),d},setQuery:function(a){a=c.extend(n.query,a),n.pushState(a)}},r={init:function(){r.build(),r.bind()},build:function(){j.$inputer=c("
").addClass(z),r.input=c('').addClass(z+"-input").val(j.settings.inputerPlaceholder).appendTo(j.$inputer),r.enter=c("").addClass(z+"-enter").appendTo(j.$inputer),j.$inputer.appendTo(j.settings.container.inputer)},bind:function(){r.input.on("focus",function(){this.value===j.settings.inputerPlaceholder&&(this.value="")}).on("blur",function(){""===this.value&&(this.value=j.settings.inputerPlaceholder)}),r.input.on("change",function(){r.go(this.value)}),r.input.autoGrowInput({comfortZone:15,maxWidth:2e3}),j.$viewport.on("change",function(a,b){"undefined"!=typeof b&&"undefined"!=typeof b.target&&r.set(b.target)})},set:function(a){r.input.val(a)},go:function(a){j.$viewport.trigger("change",{target:a})}},l={init:function(){l.build(),l.bind(),j.settings.viewports.optional!==!1&&l.optional.init()},build:function(){j.$switcher=c("
    ").addClass(t);var a=[];c.each(j.settings.viewports,function(b,c){c&&(a+="
  • "+c.description+"
  • ")}),j.$switcher.append(a).appendTo(j.settings.container.switcher)},to:function(a){j.$switcher.children('[data-current="true"]').attr("data-current",null),j.$switcher.children('[data-viewport="'+a+'"]').attr("data-current","true")},bind:function(){j.$switcher.delegate("a","click",function(a){var b=c(this).parent().data("viewport");"optional"===b||j.$viewport.trigger("change",{viewport:b}),a.preventDefault()}),j.$viewport.on("change",function(a,b){"undefined"!=typeof b&&"undefined"!=typeof b.viewport&&("optional"===b.viewport&&"undefined"!=typeof b.dimensions?(l.to("optional",b.dimensions),l.optional.activeMatch(b.dimensions)):l.to(b.viewport))})}},l.optional={init:function(){l.optional.build(),l.optional.bind()},build:function(){l.$optional=j.$switcher.children('[data-viewport="optional"]'),l.optional.$container=c("
    ").addClass(t+"-optional-container"),l.optional.$custom=c("
    "+"
    "+"
    "+"
    "+"
    ").appendTo(l.optional.$container),l.optional.$width=l.optional.$custom.find("#optional_width"),l.optional.$height=l.optional.$custom.find("#optional_height"),l.optional.$add=l.optional.$custom.find("#optional_add"),l.optional.$saved=c("
      ").appendTo(l.optional.$container),l.optional.$container.appendTo(l.$optional)},activeMatch:function(a){var b=!1;return c(l.optional.$saved).children().each(function(){parseInt(c(this).data("width"),10)===a.width&&parseInt(c(this).data("height"),10)===a.height&&(c(this).attr("data-current","true"),c(this).siblings('[data-current="true"]').attr("data-current",null),b=!0)}),b},addToSaved:function(a){e(a.width)&&e(a.height)&&l.optional.activeMatch(a)===!1&&c("
    • Width: "+a.width+"
      Height: "+a.height+"
    • ").data("width",a.width).data("height",a.height).appendTo(l.optional.$saved).trigger("click")},active:function(a){c(a).attr("data-current","true"),c(a).siblings('[data-current="true"]').attr("data-current",null),j.$viewport.trigger("change",{viewport:"optional",dimensions:{width:parseInt(c(a).data("width"),10),height:parseInt(c(a).data("height"),10)}})},deactive:function(){l.optional.$saved.find('[data-current="true"]').attr("data-current",null)},bind:function(){l.$optional.hover(function(){l.$optional.attr("data-show","true"),e(j.current.width)&&l.optional.$width.val(j.current.width),e(j.current.height)&&l.optional.$height.val(j.current.height)},function(){l.$optional.attr("data-show","false")}),l.optional.$width.on("change",function(){e(this.value)&&(this.value').addClass(v).appendTo(j.$viewport)},bind:function(){j.$viewport.delegate(j.$iframe,"resize",function(a,b){if("undefined"!=typeof b){var c={};"undefined"!=typeof b.width&&(c.width=j.settings.scrollbarInWidth||!e(b.width)?b.width:b.width+s,j.current.width=b.width),"undefined"!=typeof b.height&&(c.height=b.height,j.current.height=b.height),a.data.css(c)}}),j.$viewport.on("change",function(a,b){"undefined"!=typeof b&&"undefined"!=typeof b.target&&m.load(b.target)})},load:function(a){-1===a.search(/http(s){0,1}:\/\//)&&(a="http://"+a),j.$iframe.attr("src",a)}},q={init:function(){q.build(),q.bind()},build:function(){j.$info=c('
      Width:
      '+'
      Height:
      '+"
      ").addClass(y).appendTo(j.$viewport),j.$infoWidth=j.$info.find("."+y+"-width ."+y+"-value"),j.$infoHeight=j.$info.find("."+y+"-height ."+y+"-value")},bind:function(){j.$viewport.delegate(j.$info,"resize",function(a,b){if("undefined"!=typeof b){var c={};"undefined"!=typeof b.width&&(c.marginLeft=g(b.width),j.$infoWidth.text(b.width)),"undefined"!=typeof b.height&&(c.top=b.height,j.$infoHeight.text(b.height)),a.data.css(c)}})}},p={init:function(){p.build(),p.bind()},build:function(){j.$axis=c("
      ").addClass(x),j.$axisX=c("
      ").addClass(x+"-x").prependTo(j.$axis),j.$axisY=c("
      ").addClass(x+"-y").prependTo(j.$axis),j.$axis.prependTo(j.$viewport)},bind:function(){j.$viewport.delegate(j.$axisX,"resize",function(a,b){if("undefined"!=typeof b&&"undefined"!=typeof b.width){var c=b.width;j.settings.scrollbarInWidth&&e(b.width)||(c=b.width+s),a.data.css({marginLeft:g(c)})}}),j.$viewport.delegate(j.$axisY,"resize",function(a,b){"undefined"!=typeof b&&"undefined"!=typeof b.height&&a.data.css({top:b.height})})}},o={init:function(){o.build(),o.bind()},build:function(){j.$resizable=c("
      ").addClass(w),j.$resizableX=c("
      ").addClass(w+"-x").prependTo(j.$resizable),j.$resizableY=c("
      ").addClass(w+"-y").prependTo(j.$resizable),j.$resizableXY=c("
      ").addClass(w+"-xy").prependTo(j.$resizable),j.$resizable.appendTo(j.$viewport)},bind:function(){j.$viewport.delegate(j.$resizable,"resize",function(a,b){if("undefined"!=typeof b){var c={};if("undefined"!=typeof b.width){var d=b.width;h(d)||j.settings.scrollbarInWidth&&e(b.width)||(d=b.width+s),c.width=d,c.marginLeft=g("-"+d)}"undefined"!=typeof b.height&&(c.height=b.height),a.data.css(c)}}),j.$resizableX.drag("start",function(a,b){b.width=j.current.width,j.$viewport.attr("data-resizing","onx")}).drag(function(a,b){j.$viewport.trigger("resize",{width:Math.max(j.settings.min.width,b.width+2*parseInt(b.deltaX,10))})}).drag("dragend",function(){j.$viewport.attr("data-resizing",null)}),j.$resizableY.drag("start",function(a,b){b.height=j.current.height,j.$viewport.attr("data-resizing","ony")}).drag(function(a,b){j.$viewport.trigger("resize",{height:Math.max(j.settings.min.height,b.height+parseInt(b.deltaY,10))})}).drag("dragend",function(){j.$viewport.attr("data-resizing",null)}),j.$resizableXY.drag("start",function(a,b){b.width=j.current.width,b.height=j.current.height,j.$viewport.attr("data-resizing","onxy")}).drag(function(a,b){j.$viewport.trigger("resize",{width:Math.max(j.settings.min.width,b.width+2*parseInt(b.deltaX,10)),height:Math.max(j.settings.min.height,b.height+parseInt(b.deltaY,10))})}).drag("dragend",function(){j.$viewport.attr("data-resizing",null)})}},d()};j.settings={viewport:"auto",target:d,dimensions:{},components:{history:!0,inputer:!0,switcher:!0,iframe:!0,resizable:!0,axis:!0,info:!0},namespace:"resizer",container:{switcher:"header",inputer:"header",viewport:"article"},viewports:{auto:{width:"100%",height:"100%",description:"Auto"},optional:{description:"Optional"},mobile:{width:320,height:480,description:"Mobile"},tablet:{width:480,height:640,description:"Tablet"},notebook:{width:768,height:1024,description:"Notebook"},desktop:{width:1200,height:800,description:"Desktop"}},min:{width:240,height:320},step:5,inputerPlaceholder:"Type your url here",scrollbarInWidth:!0},j.getIframe=function(){return j.$iframe},j.addViewport=function(a,b){j.viewports.slug=b},j.go=function(a){j.$viewport.trigger("change",{target:a})},j.use=function(a){j.$viewport.trigger("change",{viewport:a})},j.change=function(a){j.$viewport.trigger("change",a)},j.resize=function(a){j.$viewport.trigger("resize",a)},j.resizeWidth=function(a){j.$viewport.trigger("resize",{width:a})},j.resizeHeight=function(a){j.$viewport.trigger("resize",{height:a})}}(window,document,jQuery),function(a,b){b.fn.autoGrowInput=function(a){return a=b.extend({maxWidth:1e3,minWidth:0,comfortZone:70},a),this.filter("input:text").each(function(){var c=a.minWidth||b(this).width(),d="",e=b(this),f=b("").css({position:"absolute",top:-9999,left:-9999,width:"auto",fontSize:e.css("fontSize"),fontFamily:e.css("fontFamily"),fontWeight:e.css("fontWeight"),letterSpacing:e.css("letterSpacing"),whiteSpace:"nowrap"}),g=function(){if(d!==(d=e.val())){var b=d.replace(/&/g,"&").replace(/\s/g," ").replace(//g,">");f.html(b);var g=f.width(),h=g+a.comfortZone>=c?g+a.comfortZone:c,i=e.width(),j=i>h&&h>=c||h>c&&h