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