//разбирает строку на запросы, разделенные "?" и "&" и возвращает объект с их индексами/ключами //var q = query('setting?wd=640&hg=480&noresize=false&noscroll=true&top=100&left=200'); console.log(q.wd + 'x' + q.hg); //>>> 640x480 function query(a,b,c,d,e){for(b=/([^=?&]+)=([^&]*)/g,c={},e=decodeURIComponent;d=b.exec(a.replace(/\+/g,' '));c[e(d[1])]=e(d[2]));return c;} //поиск по имени класса (нужен для IE) if(document.getElementsByClassName) { getElementsByClass = function(classList, node) { return (node || document).getElementsByClassName(classList) } } else { getElementsByClass = function(classList, node) { var node = node || document, list = node.getElementsByTagName('*'), length = list.length, classArray = classList.split(/\s+/), classes = classArray.length, result = [], i,j for(i = 0; i < length; i++) { for(j = 0; j < classes; j++) { if(list[i].className.search('\\b' + classArray[j] + '\\b') != -1) { result.push(list[i]) break } } } return result } } //манипуляция с классами: classManipulation( elem, 'has/add/remove/toggle', class_name ) function classManipulation(e,v,n,c,r){r=e[c='className'].replace(eval('/\\b'+n+'\\b/g'),'');return'has'==v?r!=e[c]:e[c]={add:1,toggle:r==e[c]}[v]?r+' '+n:r} //модальные окошки <a href="#" onclick="createModal('содержание', 'заголовок'[, 'настройки'])" >создать</a> function createModal(content, title, settings) { content = content || 'Содержимое окна'; title = title || 'Заголовок по умолчанию'; settings = settings || '0'; var q = query(settings); //q.wd, q.hg, q.noresize, q.overflow, q.top, q.left, q.zindex, q.parentID var parent = document.body; var whereCreateClass = 'drag-window' if (q.parentID && document.getElementById(q.parentID)) { parent = document.getElementById(q.parentID); whereCreateClass += ' is-parent'; } var elDiv = document.createElement('div'); elDiv.className = whereCreateClass; if (q.wd) elDiv.style.width = parseFloat(q.wd) + 'px'; if (q.hg) elDiv.style.height = parseFloat(q.hg) + 'px'; if (q.top) elDiv.style.top = parseFloat(q.top) + 'px'; if (q.left) elDiv.style.left = parseFloat(q.left) + 'px'; if (q.bottom) elDiv.style.bottom = parseFloat(q.bottom) + 'px'; if (q.right) elDiv.style.right = parseFloat(q.right) + 'px'; elDiv.onmousedown = function(){activeModal(this);}; parent.appendChild(elDiv); activeModal(elDiv); elSpn = document.createElement('div'); elDiv.appendChild(elSpn); elSpn.className = 'title'; elSpn.innerHTML = title + ' <span title="свернуть/развернуть" class="min-button" onmousedown="minModal(this.parentNode.parentNode)">-</span> <span title="закрыть" class="close-button" onmousedown="deleteModal(this.parentNode.parentNode)">x</span>'; elSpn.onmousedown = function(event){dragObject(event || window.event, this.parentNode);}; elContent = document.createElement('div'); elDiv.appendChild(elContent); elContent.className = 'content'; contentHeight(elDiv); if (q.overflow) elContent.style.overflow = q.overflow; elContent.innerHTML = content; if(!q.noresize && q.noresize !='true') { elResize = document.createElement('div'); elDiv.appendChild(elResize); elResize.className = 'resizeButton'; elResize.onmousedown = function(event){resizeObject(event || window.event, this.parentNode);}; } } function dragObject(evt, obj) { activeModal(obj); var isParent = classManipulation(obj,'has','is-parent'); evt = evt || window.event; obj.clicked = true; obj.mousePosX = evt.clientX; obj.mousePosY = evt.clientY; if( evt.preventDefault ) evt.preventDefault(); else evt.returnValue = false; document.onmouseup = function(){ obj.clicked = false } document.onmousemove = function( evt ) { evt = evt || window.event; if( obj.clicked ) { posLeft = !obj.style.left ? obj.offsetLeft : parseInt( obj.style.left ); posTop = !obj.style.top ? obj.offsetTop : parseInt( obj.style.top ); mousePosX = evt.clientX; mousePosY = evt.clientY; var newX = posLeft + mousePosX - obj.mousePosX; var newY = posTop + mousePosY - obj.mousePosY; var newXright = newX + obj.offsetWidth; var newYbottom = newY + obj.offsetHeight; var scrollHeight = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight); var scrollWidth = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth); if (isParent) { scrollHeight = obj.parentNode.offsetHeight; scrollWidth = obj.parentNode.offsetWidth; } newX = newX < 0 ? 0 : newX; newY = newY < 0 ? 0 : newY; newX = newXright > scrollWidth ? scrollWidth - obj.offsetWidth : newX; newY = newYbottom > scrollHeight ? scrollHeight - obj.offsetHeight : newY; obj.style.left = newX + 'px'; obj.style.top = newY + 'px'; obj.mousePosX = mousePosX; obj.mousePosY = mousePosY; if(mousePosX < 0 || mousePosY < 0 || mousePosX > scrollWidth || mousePosY > scrollHeight) obj.clicked = false; } } } function resizeObject(evt, obj) { var scrollHeight = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight); var scrollWidth = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth); if (classManipulation(obj,'has','is-parent')) { scrollHeight = obj.parentNode.offsetHeight; scrollWidth = obj.parentNode.offsetWidth; } var borderH = 0; var borderW = 0; if (obj.currentStyle) { borderH += parseFloat(obj.currentStyle.borderTopWidth) + parseFloat(obj.currentStyle.borderBottomWidth); borderW += parseFloat(obj.currentStyle.borderLeftWidth) + parseFloat(obj.currentStyle.borderRightWidth); } else if (window.getComputedStyle) { borderH += parseFloat(document.defaultView.getComputedStyle(obj,null).borderTopWidth) + parseFloat(document.defaultView.getComputedStyle(obj,null).borderBottomWidth); borderW += parseFloat(document.defaultView.getComputedStyle(obj,null).borderLeftWidth) + parseFloat(document.defaultView.getComputedStyle(obj,null).borderRightWidth); } var posibleW = scrollWidth - obj.offsetLeft - borderW; var posibleH = scrollHeight - obj.offsetTop - borderH; evt = evt || window.event; obj.resize = true; obj.mousePosX = evt.clientX; obj.mousePosY = evt.clientY; if( evt.preventDefault ) evt.preventDefault(); else evt.returnValue = false; document.onmouseup = function(){ obj.resize = false } document.onmousemove = function( evt ) { evt = evt || window.event; if( obj.resize ) { objWidth = !obj.style.width ? obj.offsetWidth : parseInt( obj.style.width ); objHeight = !obj.style.height ? obj.offsetHeight : parseInt( obj.style.height ); mousePosX = evt.clientX; mousePosY = evt.clientY; var newW = objWidth + mousePosX - obj.mousePosX; var newH = objHeight + mousePosY - obj.mousePosY; newW = newW > posibleW ? posibleW : newW; newH = newH > posibleH ? posibleH : newH; contentHeight(obj, newH); obj.style.width = newW + 'px'; obj.style.height = newH + 'px'; obj.mousePosX = mousePosX; obj.mousePosY = mousePosY; if(mousePosX < 0 || mousePosY < 0 || mousePosX > scrollWidth || mousePosY > scrollHeight) obj.resize = false; } } } function minModal(elem) { var divResize = getElementsByClass('resizeButton', elem)[0]; var divTitle = getElementsByClass('title', elem)[0]; if (elem.style.minHeight == '0px') { elem.style.maxHeight = '10000px'; elem.style.minHeight = '100px'; if(divResize) divResize.style.display = 'block'; } else { elem.style.maxHeight = divTitle.offsetHeight + 'px'; elem.style.minHeight = '0'; if(divResize) divResize.style.display = 'none'; } } function activeModal(elem) { objs = getElementsByClass('modal-active'); for (i = 0; i < objs.length; i++) { objs[i].style.zIndex = 1039; classManipulation(objs[i], 'remove', 'modal-active'); } classManipulation(elem, 'add', 'modal-active'); elem.style.zIndex = 1040; } function deleteModal(elem) { elem.parentNode.removeChild(elem); } function contentHeight(elem, newH) { if (!newH) newH = !elem.style.height ? elem.offsetHeight : parseInt( elem.style.height ); var title_div = getElementsByClass('title', elem)[0]; var content_div = getElementsByClass('content', elem)[0]; var titleHeight = !title_div.style.height ? title_div.offsetHeight : parseInt( title_div.style.height ); content_div.style.height = (newH - titleHeight - 25) + 'px'; }
function close_webcam(obj1, my) { var webcam_window = obj1.parentNode.parentNode; if (classManipulation( webcam_window, 'has', 'drag-window')) webcam_window.parentNode.removeChild(webcam_window); if (my) { parent.gettime=new Date().getTime(); parent.setstatus(0); } } function loadvideo(obj, host, share, rec, key) { var sharekey = ""; if(share) sharekey = share; if(key) sharekey += "_" + key; var nickid = 0; for(var i = 0; i < sharekey.length; i++) nickid += sharekey.charCodeAt(i) * (i+1); var camid = "mpchat-" + parent.chatlogin + "_"+nickid; var obj1 = document.getElementById(obj); if (!obj1) { if(host != '') { createModal('<div id="' + obj + '" style="height: 100%"><div id=flash' + obj + '><a href=http://get.adobe.com/flashplayer/ target=_blank><font size=1>Установите Flash Player!</font></a><br></div><div id=closer' + obj + '></div></div>', 'Вещание ' + share, 'setting?wd=300&hg=250&top=45&right=500'); var flashvars = 'host=' + host + '&m=4&q=80&r=12&sharefile=' + camid + '&sharelive=' + camid + '&shareplay=#' + camid; if(rec == 1) flashvars += '&rec=1'; swfobject.embedSWF("http://mpchat.com/blank/webcam-new.swf?v4.1", "flash" + obj, '100%', '100%', "9", "http://mpchat.com/blank/expressInstall.swf", {}, {allowfullscreen:"true",wmode:"transparent",flashvars:flashvars},{}); var webcam_window = document.getElementById(obj).parentNode.parentNode; if (classManipulation( webcam_window, 'has', 'drag-window')) { var close_button = getElementsByClass('close-button', webcam_window)[0]; if (close_button) { if (rec) { if (close_button.addEventListener) { close_button.onmousedown = function() { // Назначение onclcik для хрома и лисы deleteModal(webcam_window); parent.gettime=new Date().getTime(); parent.setstatus(0) }; } else { close_button.onclick=function() { //Назначение onclcik для IE deleteModal(webcam_window); parent.gettime=new Date().getTime(); parent.setstatus(0) }; } } else { if (close_button.addEventListener) { close_button.onmousedown = function() { // Назначение onclcik для хрома и лисы deleteModal(webcam_window); }; } else { close_button.onclick=function() { //Назначение onclcik для IE deleteModal(webcam_window); }; } } } } } } else if (host == '') { if (rec) close_webcam(obj1, rec); else close_webcam(obj1); } }
.drag-window { position: absolute; top: 60px; z-index:1039; overflow: hidden; min-width: 100px; min-height: 100px; max-height: 10000px; width: 400px; border: 3px double #333; background: #dbdbdb; -webkit-box-shadow: 4px 3px 5px rgba(0, 0, 0, 0.5); -moz-box-shadow: 4px 3px 5px rgba(0, 0, 0, 0.5); box-shadow: 4px 3px 5px rgba(0, 0, 0, 0.5); } .drag-window .title { position: relative; display: block; padding: 10px 30px 10px 10px; background: #666; color: white; cursor: move; } .drag-window.modal-active .title { background: #333; } .drag-window .title .close-button, .drag-window .title .min-button { position: absolute; right: 5px; cursor: pointer; } .drag-window .title .min-button { right: 20px; } .drag-window .content { padding:5px; height:100%; } .resizeButton { position: absolute; right: 0; bottom: 0; width: 18px; height: 18px; background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9gFDw4YJviym2oAAAAIdEVYdENvbW1lbnQA9syWvwAAAFtJREFUOMvd0LkVwDAIBNHdzpfKUSo/6wBM5CngBwP8Mnd3diBmBnYgAOrQjEgiO5DSoxWSfrRDUo9OSPjRDQk9iiDXR1Hk+CiDbB9lkeWjCvJ6VEUej74gkjgAV5gAB94+0ZcAAAAASUVORK5CYII=); cursor: se-resize; }
// в настройки var privatcamkey = 0; // код для доступа к приватному вещанию //... if(webcam) { icqopt[97] = 'вещаю лично'; icqopt[98] = 'вещаю открыто'; icqopt[99] = 'вещаю приватно'; } icqtxt[98] = "вещаю публично <img src=/ico/stat/webcam.png title=публично>"; icqtxt[99] = "вещаю приватно <img src=/ico/stat/webcam_access.png title=приватно>"; //... /* Включение вебкамер */ if (webcam) { if (stat2 == 98) icqst = "<a href=# onclick='loadvideo(\"webcam" + nick + "\",webcamhost,\"" + nick + "\",0); return false;'>" + icqst + "</a>"; if (stat2 == 99) icqst = "<a href=# onclick='parent.hidden.location.href=\"index.php?inc=write&" + yourkey + "&r=" + Math.random() + "&text=/privat " + nick + ": privatcam\";return false;'>" + icqst + "</a>"; if(nick == mynick && loaded) { if(stat2 == 97) { loadvideo("mywebcam", webcamhost, nick, 1, privatcamkey); window.setTimeout('parent.hidden.location.href = "index.php?inc=write&" + yourkey + "&r=" + Math.random() + "&text=/privat " + document.fmsg.tonick.value + ": sendcam" + privatcamkey;', 2 * 1000); } else if(stat2 == 98) loadvideo("mywebcam", webcamhost, nick, 1); else if(stat2 == 99) loadvideo("mywebcam", webcamhost, nick, 1, privatcamkey); else loadvideo("mywebcam", ""); }} //.. /* Разрешение на приватный просмотр вебкамеры */ if(webcam && cmd == 1) { if(text.indexOf("sendcam") != -1) { var key = text.split("sendcam"); text = text.replace("sendcam" + key[1], "Приглашаю посмотреть вещание."); if(tonick == mynick) text += " <a href=# onclick='parent.loadvideo(\"webcam" + nick + "\",\"" + webcamhost + "\",\"" + nick + "\",0,\"" + key[1] + "\"); return false;'>Начать просмотр</a>"; } if(text.indexOf("nocam") != -1) text = text.replace("nocam", "Просмотр не разрешен."); if(text.indexOf("yescam") != -1) { var key = text.split("yescam"); text = text.replace("yescam" + key[1], "Просмотр разрешен."); if(tonick == mynick) text += " (<a href=# onclick='parent.loadvideo(\"webcam" + nick + "\",\"" + webcamhost + "\",\"" + nick + "\",0,\"" + key[1] + "\"); return false;'>Начать просмотр</a>)"; } if(text.indexOf("privatcam") != -1) { text = text.replace("privatcam", "Прошу разрешить просмотр вещания."); if(tonick == mynick) text += " (<a href=# onclick='parent.hidden.location.href = \"index.php?inc=write&" + yourkey + "&r=" + Math.random() + "&text=/privat " + nick + ": yescam\"+parent.privatcamkey;return false;'>Да</a> | <a href=# onclick='parent.hidden.location.href = \"index.php?inc=write&" + yourkey + "&r="+Math.random() + "&text=/privat " + nick + ": nocam\";return false;'>Нет</a>)"; } }
<div id=cams> <div id=mywebcam style="display:none;"> </div> </div>
var vidregxp = []; //через запятую - название, регэксп, реплэйс, метод внедрения (1 - embed, 2 - iframe, 3 - embed через x-mplayer2) vidregxp[0] = ["videofile", "(http:\/\/(.*\\.)(rmi|wmv|midi|mid|mpg|wav|snd|wma|mpeg|avi|mpe|m1v|mpa|aifc|aiff|au|aif|swf))", "$1", 3]; vidregxp[1] = ["flv", "(http:\/\/.*\\.flv)", '"http://mpchat.com/blank/player.swf" flashvars="file=$1&autostart=false"', 1]; vidregxp[2] = ["rutube.ru", "(http:\/\/)(rutube\.ru\/)\\S+\\?v=(\\S+)", "$1video.$2$3", 1]; vidregxp[3] = ["youtube.com", "(http:\/\/www\.youtube\.com\/)\\S+(\\?v|&v)=(\\S+)", "$1v/$3&hl=ru_RU&fs=1", 1]; vidregxp[4] = ["youtu.be", "(http:\/\/youtu\.be\/)(\\S+)", "http://www.youtube.com/embed/$2", 2]; //............. t = text.split('[media]'); if (t[1]) { var viwidth = 400, //ширина видеоокна viheight = 300, //высота видеоокна content = '', window_name = ''; t2 = t[1].split('[/media]'); if (t2[0]) { var src = t2[0]; var expr; for (var i = 0; i < vidregxp.length; i++) { expr = new RegExp(vidregxp[i][1]); if (src.match(expr)) { src = src.replace(expr, vidregxp[i][2]); window_name = nick + ': см. ' + time; if (vidregxp[i][3] == 1) { //грузим в embed через x-shockwave-flash text = text.replace('[media]' + t2[0] + '[/media]', '<a href="' + t2[0] + '" target="_blank" title="ссылка откроется в новом окне">Видеоролик загружен!</a>'); content = '<embed width="100%" height="100%" src=' + src + ' type="application/x-shockwave-flash" allowscriptaccess=always allowfullscreen=true></embed>'; } if (vidregxp[i][3] == 2) { //грузим в iframe text = text.replace('[media]' + t2[0] + '[/media]', '<a href="' + t2[0] + '" target="_blank" title="ссылка откроется в новом окне">Видеоролик загружен!</a>'); content = '<iframe width="100%" height="100%" src=' + src + ' frameborder=0 allowfullscreen></iframe>'; } if (vidregxp[i][3] == 3) { //грузим в embed через x-mplayer2 text = text.replace('[media]' + t2[0] + '[/media]', '<a href="' + t2[0] + '" target="_blank" title="ссылка откроется в новом окне">Видеоролик загружен!</a>'); content = '<embed width="100%" height="100%" src=' + src + ' type="application/x-mplayer2" allowscriptaccess=always allowfullscreen=true></embed>'; } if(loaded) createModal(content, window_name, 'setting?wd=' + viwidth + '&hg=' + viheight + '&top=45&right=230') } } text = text.replace('[media]' + t2[0] + '[/media]', '<a href="' + t2[0] + '" target="_blank" title="ссылка откроется в новом окне">' + t2[0] + '</a>'); } }
console.log(flashvars);
document.write("<"+"script src=http://mpchat.com/blank/webcam-new.js></"+"script>");
wr(set_time+symbol+set_nick+text+"<a href=# style='text-decoration: underline !important;' onclick='var pnick1=\""+pnick+"\"; parent.pu[pnick1]=\""+pnick+"\"; parent.pu[pnick1]=createModal(\"<iframe src=index.php?inc=privat&\"+parent.yourkey+\"&pnick=\"+pnick1+\" width=100% height=100% scrolling=no frameborder=0>Ваш браузер не поддерживает плавающие фреймы!</iframe>\", \"Приват с "+pnick+"\", \"setting?wd=500&hg=500&top=50&right=50\");'>приват окне</a>");