forked from paulkinzett/toolbar
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjquery.toolbar.min.js
More file actions
2 lines (2 loc) · 5.04 KB
/
jquery.toolbar.min.js
File metadata and controls
2 lines (2 loc) · 5.04 KB
1
2
/*! toolbar.js 2016-04-13 */
"function"!=typeof Object.create&&(Object.create=function(o){function t(){}return t.prototype=o,new t}),function(o,t,e,i){var n={init:function(t,e){var i=this;i.elem=e,i.$elem=o(e),i.options=o.extend({},o.fn.toolbar.options,t),i.metadata=i.$elem.data(),i.overrideOptions(),i.toolbar=o('<div class="tool-container" />').addClass("tool-"+i.options.position).addClass("toolbar-"+i.options.style).append('<div class="tool-items" />').append('<div class="arrow" />').appendTo("body").css("opacity",0).hide(),i.toolbar_arrow=i.toolbar.find(".arrow"),i.$elem.on("remove",function(){i.toolbar.remove()}),i.initializeToolbar()},overrideOptions:function(){var t=this;o.each(t.options,function(o){"undefined"!=typeof t.$elem.data("toolbar-"+o)&&(t.options[o]=t.$elem.data("toolbar-"+o))})},initializeToolbar:function(){var o=this;o.populateContent(),o.setTrigger(),o.toolbarWidth=o.toolbar.width()},setTrigger:function(){function e(){i.$elem.hasClass("pressed")?n=setTimeout(function(){i.hide()},150):clearTimeout(n)}function e(){i.$elem.hasClass("pressed")?n=setTimeout(function(){i.hide()},150):clearTimeout(n)}var i=this;if("click"!=i.options.event){var n;i.$elem.on({mouseenter:function(o){i.$elem.hasClass("pressed")?clearTimeout(n):i.show()}}),i.$elem.parent().on({mouseleave:function(o){e()}}),o(".tool-container").on({mouseenter:function(o){clearTimeout(n)},mouseleave:function(o){e()}})}if("click"==i.options.event&&(i.$elem.on("click",function(o){o.preventDefault(),i.$elem.hasClass("pressed")?i.hide():i.show()}),i.options.hideOnClick&&o("html").on("click.toolbar",function(o){o.target!=i.elem&&0===i.$elem.has(o.target).length&&0===i.toolbar.has(o.target).length&&i.toolbar.is(":visible")&&i.hide()})),i.options.hover){var n;i.$elem.on({mouseenter:function(o){i.$elem.hasClass("pressed")?clearTimeout(n):i.show()}}),i.$elem.parent().on({mouseleave:function(o){e()}}),o(".tool-container").on({mouseenter:function(o){clearTimeout(n)},mouseleave:function(o){e()}})}o(t).resize(function(o){o.stopPropagation(),i.toolbar.is(":visible")&&(i.toolbarCss=i.getCoordinates(i.options.position,20),i.collisionDetection(),i.toolbar.css(i.toolbarCss),i.toolbar_arrow.css(i.arrowCss))})},populateContent:function(){var t=this,e=t.toolbar.find(".tool-items");if(t.options.inline)var i=o(t.options.content).find("a").addClass("tool-item");else var i=o(t.options.content).clone(!0).find("a").addClass("tool-item");e.html(i),e.find(".tool-item").on("click",function(o){o.preventDefault(),t.$elem.trigger("toolbarItemClick",this)})},calculatePosition:function(){var o=this;o.arrowCss={},o.toolbarCss=o.getCoordinates(o.options.position,o.options.adjustment),o.toolbarCss.position="absolute",o.toolbarCss.zIndex=o.options.zIndex,o.collisionDetection(),o.toolbar.css(o.toolbarCss),o.toolbar_arrow.css(o.arrowCss)},getCoordinates:function(o,t){var e=this;switch(e.coordinates=e.$elem.offset(),e.options.adjustment&&e.options.adjustment[e.options.position]&&(t=e.options.adjustment[e.options.position]+t),e.options.position){case"top":return{left:e.coordinates.left-e.toolbar.width()/2+e.$elem.outerWidth()/2,top:e.coordinates.top-e.$elem.outerHeight()-t,right:"auto"};case"left":return{left:e.coordinates.left-e.toolbar.width()/2-e.$elem.outerWidth()/2-t,top:e.coordinates.top-e.toolbar.height()/2+e.$elem.outerHeight()/2,right:"auto"};case"right":return{left:e.coordinates.left+e.toolbar.width()/2+e.$elem.outerWidth()/2+t,top:e.coordinates.top-e.toolbar.height()/2+e.$elem.outerHeight()/2,right:"auto"};case"bottom":return{left:e.coordinates.left-e.toolbar.width()/2+e.$elem.outerWidth()/2,top:e.coordinates.top+e.$elem.outerHeight()+t,right:"auto"}}},collisionDetection:function(){var e=this,i=20;("top"==e.options.position||"bottom"==e.options.position)&&(e.arrowCss={left:"50%",right:"50%"},e.toolbarCss.left<i?(e.toolbarCss.left=i,e.arrowCss.left=e.$elem.offset().left+e.$elem.width()/2-i):o(t).width()-(e.toolbarCss.left+e.toolbarWidth)<i&&(e.toolbarCss.right=i,e.toolbarCss.left="auto",e.arrowCss.left="auto",e.arrowCss.right=o(t).width()-e.$elem.offset().left-e.$elem.width()/2-i-5))},remove:function(){this.toolbar.remove()},show:function(){var o=this;o.$elem.addClass("pressed"),o.calculatePosition(),o.toolbar.show().css({opacity:1}).addClass("animate-"+o.options.animation),o.$elem.trigger("toolbarShown")},hide:function(){var o=this,t={opacity:0};switch(o.$elem.removeClass("pressed"),o.options.position){case"top":t.top="+=20";break;case"left":t.left="+=20";break;case"right":t.left="-=20";break;case"bottom":t.top="-=20"}o.toolbar.animate(t,200,function(){o.toolbar.hide()}),o.$elem.trigger("toolbarHidden")},getToolbarElement:function(){return this.toolbar.find(".tool-items")}};o.fn.toolbar=function(t){if(o.isPlainObject(t))return this.each(function(){var e=Object.create(n);e.init(t,this),o(this).data("toolbarObj",e)});if("string"==typeof t&&0!==t.indexOf("_")){var e=o(this).data("toolbarObj"),i=e[t];return i.apply(e,o.makeArray(arguments).slice(1))}},o.fn.toolbar.options={content:"#myContent",inline:!1,position:"top",hideOnClick:!1,zIndex:120,hover:!1,style:"default",animation:"standard",adjustment:10}}(jQuery,window,document);