var tg=[]; var co=0; setInterval(function(){ co++; }, 1000); var raychat_start_loading_at = new Date().getTime(); var raychat_body = document.getElementsByTagName('body')[0]; String.prototype.toDOM = function () { var d = document, i, a = d.createElement("div"), b = d.createDocumentFragment(); a.innerHTML = this; while (i = a.firstChild) b.appendChild(i); return b; }; var b = document.getElementsByTagName("body")[0]; var s = document.createElement("iframe"); s.style.border = 0; s.style.transition = "none !important"; s.id = "raychatFrame"; b.appendChild(s); var raychat_btn = document.createElement('div'); raychat_btn.className = "raychat_main_button raychat_bgc bottom right raychat_animated"; raychat_btn.id = "raychat_main_button_id"; var raychat_is_iframe_loaded = false; var raychat_pending_for_ifram_load = false; var opened = false; function raychat_check_for_load() { raychat_is_iframe_loaded = true; raychat_btn.classList.remove("loading"); if (opened) { opened = false; raychat_open_container(); } } var _el = document.getElementById('raychatFrame'); var raychat_onlineAgents = "undefined"; var channelPhoto; var channelAuthorName = "ایران وب - میزبان"; if (raychat_onlineAgents != "undefined") { channelPhoto = raychat_onlineAgents; } else { channelPhoto = "uploads/channel-photos/channel-web.png"; } function detectmob() { return !!(navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/Windows Phone/i)); } function raychat_setCounterOn(count) { if (!opened) { raychat_btn.querySelector('#raychat_main_button_count').className += " active"; raychat_btn.querySelector('#raychat_main_button_count_s').innerHTML = count; } } function raychat_setCounterOff() { raychat_btn.querySelector('#raychat_main_button_count').classList.remove("active"); raychat_btn.querySelector('#raychat_main_button_count_s').innerHTML = ''; } function raychat_toggle_container() { var raychat_iframe = document.getElementById('raychatFrame'); if (opened) { raychat_btn.style.display = "block"; raychat_iframe.style.display = "none"; raychat_btn.classList.remove("active"); opened = false; Raychat.trigger("close", true); raychat_iframe.contentWindow.opened = true; } else { if (raychat_is_iframe_loaded) { raychat_close_automessage_preview(); raychat_setCounterOff(); raychat_btn.className += " active"; opened = true; raychat_iframe.contentWindow.raychat_reset_counter(); raychat_btn.style.display = "none"; raychat_iframe.style.display = "block"; raychat_iframe.contentWindow.opened = false; raychat_iframe.contentWindow.raychatBtnClicked(); raychat_iframe.style.height = '90%'; raychat_iframe.style.backgroundColor = "rgba(200, 98, 98, 0)!important"; raychat_iframe.style.filter = "alpha(opacity=5000)"; raychat_iframe.frameBorder = "0"; raychat_iframe.allowTransparency = "false"; Raychat.trigger("open", true); } else { raychat_btn.className += " loading"; opened = true; } } } function raychat_send_message_me_open(data) { if (data) { _el.contentWindow.snd(data, false); } if (!opened) { raychat_toggle_container(); } } function raychat_send_message_open_without_check(data) { _el.contentWindow.appendMsgAgent(data, channelPhoto); if (!opened) { raychat_toggle_container(); } } // don`t use this for public function raychat_send_message_open(data, id, mute, justOnce) { if (mute === "true" || mute === "false") { mute = JSON.parse(mute); } if (justOnce === "true" || justOnce === "false") { justOnce = JSON.parse(justOnce); } if (_el) { if (_el.contentWindow) { if (_el.contentWindow.raychat_user_me_message_count() == 0) { if (!mute) { _el.contentWindow.raychat_new_message_notification(); } if (justOnce) { _el.contentWindow.closeAutomessage(id); } if (data) { _el.contentWindow.appendMsgAgent(data, channelPhoto); } if (!opened) { raychat_toggle_container(); } } } } } // dont use this for public function raychat_send_message(data, id, mute, justOnce) { if (mute === "true" || mute === "false") { mute = JSON.parse(mute); } if (justOnce === "true" || justOnce === "false") { justOnce = JSON.parse(justOnce); } if (_el) { if (_el.contentWindow) { if (_el.contentWindow.raychat_user_me_message_count() == 0) { if (!opened) { raychat_set_automessage_preview(data, channelAuthorName, 'https://app.raychat.io/' + channelPhoto, id); } if (!mute) { _el.contentWindow.raychat_new_message_notification(); } if (justOnce) { _el.contentWindow.closeAutomessage(id); } if (data) { _el.contentWindow.appendMsgAgent(data, channelPhoto); } } } } } function raychat_send_message_without_check(data) { _el.contentWindow.raychat_new_message_notification(); _el.contentWindow.appendMsgAgent(data); } function raychat_btn_shake() { if (!opened) { raychat_btn.className += " raychat_shake"; raychat_btn.className += " raychat_animated"; setTimeout(function () { raychat_btn.classList.remove('raychat_shake'); raychat_btn.classList.remove('raychat_animated'); }, 1000); } } function raychat_set_automessage_preview(content, author, photo, id) { if (opened) return false; raychat_close_automessage_preview(); document.getElementById('raychat_automessage_preview_container').className += " active"; document.getElementById('raychat_automessage_preview_container').className += " flipInX raychat_animated"; document.getElementById('raychat_automessage_preview_container').setAttribute('data-id', id); var time = new Date(); document.getElementById('raychat_automessage_date').innerHTML = time.getHours() + ":" + time.getMinutes(); if (author) { document.getElementById('raychat_automessage_title').innerHTML = author; } if (content) { document.getElementById('raychat_automessage_content').innerHTML = content; } if (photo) { document.getElementById('raychat_automessage_user_avatar').style.backgroundImage = "url('" + photo + "')"; } else { document.getElementById('raychat_automessage_user_avatar').style.backgroundImage = "url('" + 'https://app.raychat.io/' + channelPhoto + "')"; } setTimeout(function () { document.getElementById('raychat_automessage_preview_container').classList.remove('flipInX'); document.getElementById('raychat_automessage_preview_container').classList.remove('raychat_animated'); }, 1000); } function findAncestor(el, cls) { while ((el = el.parentElement) && !el.classList.contains(cls)) ; return el; } function raychat_open_container_from_automessage(e) { if (e.target.className.match(/\braychat_close_automessage\b/)) { _el.contentWindow.closeAutomessage(document.getElementById('raychat_automessage_preview_container').getAttribute('data-id')); raychat_close_automessage_preview(); return false; } if (findAncestor(e.target, 'raychat_reply_to_automessage')) { var raychat_automessage_textarea = document.getElementById('raychat_main_reply_texarea'); var raychat_reply_to_automessage_send_btn = document.getElementById('raychat_reply_to_automessage_send_btn'); if (!findAncestor(e.target, 'raychat_reply_to_automessage').className.match(/\bactive\b/)) { findAncestor(e.target, 'raychat_reply_to_automessage').className += " active"; raychat_automessage_textarea.focus(); } raychat_automessage_textarea.addEventListener('focusout', function (el) { findAncestor(e.target, 'raychat_reply_to_automessage').classList.remove("active"); }); raychat_automessage_textarea.addEventListener('keydown', function (el) { if (el.which == 13 || el.keyCode == 13) { if (raychat_automessage_textarea.value.length === 0 || !raychat_automessage_textarea.value.trim()) { raychat_automessage_textarea.focus(); return; } raychat_send_message_me_open(raychat_automessage_textarea.value); raychat_automessage_textarea.value = ""; } }); raychat_reply_to_automessage_send_btn.addEventListener('click', function (el) { if (raychat_automessage_textarea.value.length === 0 || !raychat_automessage_textarea.value.trim()) { return; } raychat_send_message_me_open(raychat_automessage_textarea.value); raychat_automessage_textarea.value = ""; }); return false; } if (!opened) { raychat_toggle_container(); } } function raychat_close_automessage_preview() { if (raychat_close_automessage_preview) { document.getElementById('raychat_automessage_preview_container').classList.remove('active'); } } function raychat_open_container() { if (!opened) { raychat_toggle_container(); } } function raychat_close_container() { if (opened) { raychat_toggle_container(); } } function EventDispatcher() { // Create a dummy DOM element var dummy = document.createTextNode(''); // Create custom wrappers with nicer names this.off = dummy.removeEventListener.bind(dummy); this.on = dummy.addEventListener.bind(dummy); this.trigger = function (eventName, data) { if (!eventName) return; var e = new CustomEvent(eventName, { "detail": data }); dummy.dispatchEvent(e); }; } var Raychat = {}; Raychat.user = {}; Raychat.frame; Raychat.isWidgetOpenVar = false; Raychat.animations = []; // initialize the event dispatcher by creating an instance in an isolated way Raychat = new EventDispatcher(); Raychat.__checkStatus = function () { if (raychat_btn.className.match(/\bactive\b/) && this.frame.d.className.match(/\bactive\b/)) { this.isWidgetOpenVar = true; return true; } this.isWidgetOpenVar = false; return false; }; Raychat.__profile_updated = function (user) { var u = user; delete u.conversation; delete u.success; delete u.status; this.user = u; this.trigger('raychat_user_profile_updated', this.user); }; Raychat.setUser = function (user) { user.other = true; this.frame.raychat_setUser(user); }; Raychat.getUser = function () { var user = this.user; delete user.agent; delete user.channel; delete user.chatCount; delete user.lname; delete user.type; return user; }; Raychat.open = function () { raychat_close_automessage_preview(); raychat_setCounterOff(); raychat_open_container(); this.__checkStatus(); }; Raychat.close = function () { raychat_toggle_container(); this.__checkStatus(); this.trigger("close", true); }; Raychat.toggle = function () { raychat_toggle_container(); }; Raychat.load = function (entity) { this.frame = document.getElementById('raychatFrame').contentWindow || (document.getElementById('raychatFrame').contentDocument.document || document.getElementById('raychatFrame').contentDocument); this.frameDom = document.getElementById('raychatFrame'); this.animations = ['bounce', 'wobble', 'tada', 'shake', 'rubberBand', 'swing', 'jello', 'rotateIn']; this.__checkStatus(); console.log('Evenet:ready: Raychat is ready to use, load time per milliseconds:', new Date().getTime() - raychat_start_loading_at); if (entity && entity.load) { this.trigger("userLoaded", true); } else if (entity && !entity.load) { this.trigger("userUnloaded", true); } else { this.trigger("ready", true); } // var innerDoc = this.frameDom.contentDocument || this.frameDom.contentWindow.document; // console.log(innerDoc) // innerDoc.getElementById('raychat_main_container_body').addEventListener("drop", function (e) { // e.preventDefault() // e.stopPropagation() // }); }; Raychat.animate = function (animation) { if (this.animations.indexOf(animation) === -1) { console.warn('invalid animation name, available animations: ' + this.animations.toString()); return; } raychat_btn.className += " raychat_" + animation; raychat_btn.className += " raychat_animated"; setTimeout(function () { raychat_btn.classList.remove('raychat_' + animation); raychat_btn.classList.remove('raychat_animated'); }, 1000); }; Raychat.isWidgetOpen = function () { this.__checkStatus(); return this.isWidgetOpenVar; }; Raychat.sendOfflineMessage = function (message) { raychat_set_automessage_preview(message); raychat_send_message_without_check(message); }; Raychat.loadUser = function (userId) { this.frame.raychat_load_user(userId); }; Raychat.unloadUser = function () { this.frame.raychat_unload_user(); }; var viewport = document.querySelector("meta[name=viewport]"); if (viewport) { viewport.setAttribute('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0'); } // responsive in ios devices start var scrollTopPositionValue = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; if (navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod' || navigator.platform == 'Linux armv6l') { document.getElementById('raychatFrame').style.position = "absolute"; document.getElementById('raychatFrame').style.top = 0; window.onscroll = function () { scrollTopPositionValue = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; document.getElementById('raychatFrame').style.top = scrollTopPositionValue + "px"; }; } /** * iframe component start */ var iframe = document.getElementById('raychatFrame'); iframe.setAttribute('allowfullscreen', 'true'); iframe.setAttribute('webkitallowfullscreen', 'true'); iframe.setAttribute('mozallowfullscreen', 'true'); iframe = iframe.contentWindow || (iframe.contentDocument.document || iframe.contentDocument); iframe.document.open(); iframe.document.write('
'); iframe.document.close(); /** * automessage component start */ raychat_body.appendChild(' '.toDOM()); /** * btn component start */ raychat_btn.innerHTML = ' '; raychat_btn.setAttribute("onclick", "raychat_toggle_container()"); raychat_btn.id = "raychatBtn"; raychat_body.appendChild(raychat_btn); Raychat.on('ready', function (e) { var evt = new CustomEvent('raychat_ready', { loadTime: new Date().getTime() - raychat_start_loading_at }); window.dispatchEvent(evt); window.Raychat = Raychat; }); Raychat.on('userLoaded', function (e) { var evt = new CustomEvent('raychat_new_user_loaded'); window.dispatchEvent(evt); }); // Raychat.on('userUnloaded', function (e) { // var evt = new CustomEvent('raychat_new_user_unloaded'); // window.dispatchEvent(evt); // })