framework7
Version:
Full featured mobile HTML framework for building iOS & Android apps
2 lines (1 loc) • 5.95 kB
JavaScript
(function framework7ComponentLoader(t,o){void 0===o&&(o=!0);document,window;var e=t.$,i=(t.Template7,t.utils),a=(t.device,t.support),r=t.Class,s=(t.Modal,t.ConstructorMethods),n=(t.ModalMethods,function(t){function o(o,r){void 0===r&&(r={}),t.call(this,r,[o]);var s=this,n=i.extend({},o.params.tooltip);s.useModulesParams(n),s.params=i.extend(n,r);var l=s.params.targetEl;if(!l)return s;var p=e(l);if(0===p.length)return s;if(p[0].f7Tooltip)return p[0].f7Tooltip;var h=e(s.render()).eq(0);i.extend(s,{app:o,$targetEl:p,targetEl:p&&p[0],$el:h,el:h&&h[0],text:s.params.text||"",visible:!1,opened:!1}),p[0].f7Tooltip=s;var f,u={};function d(t){f||(f=!0,u.x="touchstart"===t.type?t.targetTouches[0].pageX:t.pageX,u.y="touchstart"===t.type?t.targetTouches[0].pageY:t.pageY,s.show(this))}function c(t){if(f){var o="touchmove"===t.type?t.targetTouches[0].pageX:t.pageX,e="touchmove"===t.type?t.targetTouches[0].pageY:t.pageY;Math.pow(Math.pow(o-u.x,2)+Math.pow(e-u.y,2),.5)>50&&(f=!1,s.hide())}}function v(){f&&(f=!1,s.hide())}function g(){s.show(this)}function m(){s.hide()}function y(){h.hasClass("tooltip-in")||h.removeClass("tooltip-out").remove()}return s.attachEvents=function(){if(h.on("transitionend",y),a.touch){var t=!!a.passiveListener&&{passive:!0};p.on(o.touchEvents.start,d,t),o.on("touchmove",c),o.on("touchend:passive",v)}else p.on("mouseenter",g),p.on("mouseleave",m)},s.detachEvents=function(){if(h.off("transitionend",y),a.touch){var t=!!a.passiveListener&&{passive:!0};p.off(o.touchEvents.start,d,t),o.off("touchmove",c),o.off("touchend:passive",v)}else p.off("mouseenter",g),p.off("mouseleave",m)},s.useModules(),s.init(),s}return t&&(o.__proto__=t),o.prototype=Object.create(t&&t.prototype),o.prototype.constructor=o,o.prototype.position=function(t){var o=this.$el,i=this.app;o.css({left:"",top:""});var a,r,s,n,l=e(t||this.targetEl),p=[o.width(),o.height()],h=p[0],f=p[1];if(o.css({left:"",top:""}),l&&l.length>0){a=l.outerWidth(),r=l.outerHeight();var u=l.offset();s=u.left-i.left,n=u.top-i.top;var d=l.parents(".page");d.length>0&&(n-=d[0].scrollTop)}var c=[0,0,0],v=c[0],g=c[1],m="top";f<n?g=n-f:f<i.height-n-r?(m="bottom",g=n+r):(m="middle",(g=r/2+n-f/2)<=0?g=8:g+f>=i.height&&(g=i.height-f-8)),"top"===m||"bottom"===m?((v=a/2+s-h/2)<8&&(v=8),v+h>i.width&&(v=i.width-h-8),v<0&&(v=0)):"middle"===m&&((v=s-h)<8||v+h>i.width)&&(v<8&&(v=s+a),v+h>i.width&&(v=i.width-h-8)),o.css({top:g+"px",left:v+"px"})},o.prototype.show=function(t){var o=this.app,i=this.$el,a=this.$targetEl;o.root.append(i),this.position(t);var r=e(t);return this.visible=!0,this.opened=!0,a.trigger("tooltip:show",this),i.trigger("tooltip:show",this),r.length&&r[0]!==a[0]&&r.trigger("tooltip:show",this),this.emit("local::show tooltipShow",this),i.removeClass("tooltip-out").addClass("tooltip-in"),this},o.prototype.hide=function(){var t=this.$el,o=this.$targetEl;return this.visible=!1,this.opened=!1,o.trigger("tooltip:hide",this),t.trigger("tooltip:hide",this),this.emit("local::hide tooltipHide",this),t.addClass("tooltip-out").removeClass("tooltip-in"),this},o.prototype.render=function(){if(this.params.render)return this.params.render.call(this,this);var t=this.params;return('\n <div class="tooltip '+(t.cssClass||"")+'">\n <div class="tooltip-content">'+(t.text||"")+"</div>\n </div>\n ").trim()},o.prototype.setText=function(t){return void 0===t?this:(this.params.text=t,this.text=t,this.$el&&this.$el.children(".tooltip-content").html(t),this.opened&&this.position(),this)},o.prototype.init=function(){this.attachEvents()},o.prototype.destroy=function(){this.$targetEl&&!this.destroyed&&(this.$targetEl.trigger("tooltip:beforedestroy",this),this.emit("local::beforeDestroy tooltipBeforeDestroy",this),this.$el.remove(),delete this.$targetEl[0].f7Tooltip,this.detachEvents(),i.deleteProps(this),this.destroyed=!0)},o}(r)),l={name:"tooltip",static:{Tooltip:n},create:function(){this.tooltip=s({defaultSelector:".tooltip",constructor:n,app:this,domProp:"f7Tooltip"}),this.tooltip.show=function(t){var o=e(t);if(0!==o.length){var i=o[0].f7Tooltip;if(i)return i.show(o[0]),i}},this.tooltip.hide=function(t){var o=e(t);if(0!==o.length){var i=o[0].f7Tooltip;if(i)return i.hide(),i}},this.tooltip.setText=function(t,o){var i=e(t);if(0!==i.length){var a=i[0].f7Tooltip;if(a)return a.setText(o),a}}},params:{tooltip:{targetEl:null,text:null,cssClass:null,render:null}},on:{tabMounted:function(t){var o=this;e(t).find(".tooltip-init").each(function(t,i){var a=e(i).attr("data-tooltip");a&&o.tooltip.create({targetEl:i,text:a})})},tabBeforeRemove:function(t){e(t).find(".tooltip-init").each(function(t,o){o.f7Tooltip&&o.f7Tooltip.destroy()})},pageInit:function(t){var o=this;t.$el.find(".tooltip-init").each(function(t,i){var a=e(i).attr("data-tooltip");a&&o.tooltip.create({targetEl:i,text:a})}),"ios"===o.theme&&t.view&&t.view.router.separateNavbar&&t.$navbarEl&&t.$navbarEl.length>0&&t.$navbarEl.find(".tooltip-init").each(function(t,i){var a=e(i).attr("data-tooltip");a&&o.tooltip.create({targetEl:i,text:a})})},pageBeforeRemove:function(t){t.$el.find(".tooltip-init").each(function(t,o){o.f7Tooltip&&o.f7Tooltip.destroy()}),"ios"===this.theme&&t.view&&t.view.router.separateNavbar&&t.$navbarEl&&t.$navbarEl.length>0&&t.$navbarEl.find(".tooltip-init").each(function(t,o){o.f7Tooltip&&o.f7Tooltip.destroy()})}},vnode:{"tooltip-init":{insert:function(t){var o=t.elm,i=e(o).attr("data-tooltip");i&&this.tooltip.create({targetEl:o,text:i})},update:function(t){var o=t.elm;o.f7Tooltip&&t&&t.data&&t.data.attrs&&t.data.attrs["data-tooltip"]&&o.f7Tooltip.setText(t.data.attrs["data-tooltip"])},destroy:function(t){var o=t.elm;o.f7Tooltip&&o.f7Tooltip.destroy()}}}};if(o){if(t.prototype.modules&&t.prototype.modules[l.name])return;t.use(l),t.instance&&(t.instance.useModuleParams(l,t.instance.params),t.instance.useModule(l))}return l}(Framework7, typeof Framework7AutoInstallComponent === 'undefined' ? undefined : Framework7AutoInstallComponent))