UNPKG

openstack-uicore-foundation

Version:

ui reactjs components for openstack marketing site

2 lines 5.8 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("openstack-uicore-foundation",[],t):"object"==typeof exports?exports["openstack-uicore-foundation"]=t():e["openstack-uicore-foundation"]=t()}(this,(()=>(()=>{"use strict";var e={8311:(e,t,i)=>{i.d(t,{default:()=>n});var s=i(1116),o=i.n(s);function r(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);t&&(s=s.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,s)}return i}class n{constructor(){this.originalHash="",this.hash={}}convertToHash(e){let t=(e=e.substr(1).toLowerCase()).split("&"),i={};for(let e of t){if(e=e.split("="),2!==e.length)continue;let t=e[1].trim();""!==t&&("true"!==t&&"false"!==t||(e[1]="true"==t),i[e[0]]=e[1])}return i}clearParams(){this.originalHash="",this.hash={}}getParam(e){return"undefined"!=typeof window&&this.originalHash!==window.location.hash&&(this.originalHash=window.location.hash,this.hash=this.convertToHash(this.originalHash)),this.hash.hasOwnProperty(e)?this.hash[e]:null}getParams(){return"undefined"!=typeof window&&this.originalHash!==window.location.hash&&(this.originalHash=window.location.hash,this.hash=this.convertToHash(this.originalHash)),function(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?r(Object(i),!0).forEach((function(t){o()(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):r(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}({},this.hash)}deleteParam(e){var t=this.getParams();this.clearParams();for(let i in t)i!=e&&(this.hash[i]=t[i])}deleteParams(e){var t=this.getParams();this.clearParams();for(let i in t)e.includes(i)||(this.hash[i]=t[i])}setParam(e,t){return"undefined"!=typeof window&&this.originalHash!==window.location.hash&&(this.originalHash=window.location.hash,this.hash=this.convertToHash(this.originalHash)),null!==t&&""!==t?this.hash[e]=t:delete this.hash[e],this}serialize(){let e="";for(let t in this.hash){""!==e&&(e+="&"),e+=t+"="+this.hash[t]}return e}}},9558:(e,t,i)=>{i.d(t,{getTimeServiceUrl:()=>s});i(5812),i(8041);const s=()=>"undefined"!=typeof window?window.TIMEINTERVALSINCE1970_API_URL||process.env.TIMEINTERVALSINCE1970_API_URL:null},1116:e=>{e.exports=require("@babel/runtime/helpers/defineProperty")},5812:e=>{e.exports=require("moment-timezone")},2015:e=>{e.exports=require("react")},8041:e=>{e.exports=require("urijs")}},t={};function i(s){var o=t[s];if(void 0!==o)return o.exports;var r=t[s]={exports:{}};return e[s](r,r.exports,i),r.exports}(()=>{i.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t}})(),(()=>{i.d=(e,t)=>{for(var s in t)i.o(t,s)&&!i.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})}})(),(()=>{i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})(),(()=>{i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}})();var s={};i.r(s),i.d(s,{default:()=>m});var o=i(1116),r=i.n(o),n=i(2015),a=i.n(n),h=i(5812),l=i.n(h),c=i(8311),p=i(9558);class u extends a().Component{constructor(e){super(e),r()(this,"processServerTimeResponse",((e,t)=>{const i=l()().unix();let s=i;e&&(s=e.timestamp+(i-t)),this._isMounted&&(console.log(`Clock::processServerTimeResponse setting timestamp ${s}`),this.setState({timestamp:s})),this.props.onTick&&this.props.onTick(s)})),r()(this,"processServerTimeResponseError",(()=>{let e=l()().unix();this._isMounted&&(console.log(`Clock::processServerTimeResponseError setting timestamp ${e}`),this.setState({timestamp:e})),this.props.onTick&&this.props.onTick(e)})),r()(this,"getServerTime",(()=>{const e=(0,p.getTimeServiceUrl)();return fetch(`${e}`).then((async e=>200===e.status?e.json():Promise.reject(null))).catch((e=>(console.log(e),Promise.reject(e))))})),r()(this,"tick",(()=>{const{timestamp:e}=this.state;null!==e&&(this.props.onTick&&this.props.onTick(e+1),this._isMounted&&this.setState({timestamp:e+1}))})),r()(this,"now",(()=>this.state.timestamp)),this.fragmentParser=new c.default,this.interval=null,this.state={timestamp:null,manualSet:!1},this._isMounted=!1,this.onVisibilityChange=this.onVisibilityChange.bind(this)}componentDidMount(){this._isMounted=!0;const{timezone:e="UTC",now:t}=this.props,i=this.fragmentParser.getParam("now"),s=l().tz(i,"YYYY-MM-DD,hh:mm:ss",e);let o=null,r=!1;if(s.isValid())o=s.valueOf()/1e3,console.log(`Clock::componentDidMount nowQS ${i} is valid setting timestamp ${o}`),r=!0;else if(t)o=t;else{const e=l()().unix();this.getServerTime().then((t=>this.processServerTimeResponse(t,e))).catch((()=>this.processServerTimeResponseError()))}o&&(this.setState({timestamp:o,manualSet:r}),this.props.onTick&&this.props.onTick(o)),this.interval=setInterval(this.tick,1e3),document.addEventListener("visibilitychange",this.onVisibilityChange,!1)}onVisibilityChange(){const e=document.visibilityState,{manualSet:t}=this.state;if("visible"===e){if(console.log(`Clock::onVisibilityChange manualSet ${t}`),t)return;const e=l()().unix();this.getServerTime().then((t=>this.processServerTimeResponse(t,e))).catch((()=>this.processServerTimeResponseError()))}}componentWillUnmount(){this._isMounted=!1,clearInterval(this.interval),document.removeEventListener("visibilitychange",this.onVisibilityChange),this.interval=null}render(){const{display:e,timezone:t="UTC"}=this.props,{timestamp:i}=this.state;return e&&i?a().createElement("div",{style:{marginTop:"50px",textAlign:"center",fontSize:"20px"}},l().tz(1e3*i,t).format("YYYY-MM-DD hh:mm:ss")):null}}const m=u;return s})())); //# sourceMappingURL=clock.js.map