Current Path : /var/www/www-root/data/www/info.monolith-realty.ru/local/templates/monolitsochi/js/ |
Current File : /var/www/www-root/data/www/info.monolith-realty.ru/local/templates/monolitsochi/js/rating_likes.js |
if (!BXRL) { var BXRL = {}; var BXRLW = null; } RatingLikes = function(likeId, entityTypeId, entityId, available, userId, localize, template, pathToUserProfile, pathToAjax) { this.enabled = true; this.likeId = likeId; this.entityTypeId = entityTypeId; this.entityId = entityId; this.available = (available == 'Y'); this.userId = userId; this.localize = localize; this.template = template; this.pathToUserProfile = pathToUserProfile; this.pathToAjax = typeof(pathToAjax) == "string"? pathToAjax: '/bitrix/components/bitrix/rating.vote/vote.ajax.php'; this.box = BX('bx-ilike-button-'+likeId); if (this.box === null) { this.enabled = false; return false; } this.button = BX.findChild(this.box, {className:'bx-ilike-left-wrap'}, true, false); this.wrapp = BX.findChild(this.box, {className:'all-wrapper'}, true, false); this.buttonText = BX.findChild(this.button, {className:'bx-ilike-text'}, true, false); this.count = BX.findChild(this.box, {tagName:'span', className:'bx-ilike-right-wrap'}, true, false); this.countText = BX.findChild(this.count, {tagName:'span', className:'bx-ilike-right'}, true, false); this.popup = null; this.popupId = null; this.popupOpenId = null; this.popupTimeoutId = null; this.popupContent = BX.findChild(BX('bx-ilike-popup-cont-'+likeId), {tagName:'span', className:'bx-ilike-popup'}, true, false); this.popupContentPage = 1; this.popupListProcess = false; this.popupTimeout = false; this.likeTimeout = false; this.lastVote = BX.hasClass(template == 'standart'? this.button: this.count, 'bx-you-like')? 'plus': 'cancel'; }; RatingLikes.LiveUpdate = function(params) { if (params.USER_ID == BX.message('USER_ID')) return false; for(var i in BXRL) { if (BXRL.hasOwnProperty(i)) { if (BXRL[i].entityTypeId == params.ENTITY_TYPE_ID && BXRL[i].entityId == params.ENTITY_ID) { var element = BXRL[i]; element.countText.innerHTML = parseInt(params.TOTAL_POSITIVE_VOTES); element.count.insertBefore( BX.create("span", { props : { className : "bx-ilike-plus-one" }, style: {width: (element.countText.clientWidth-8)+'px', height: (element.countText.clientHeight-8)+'px'}, html: (params.TYPE == 'ADD'? '+1': '-1')}) , element.count.firstChild); if (element.popup) { element.popup.close(); element.popupContentPage = 1; } } } } }; RatingLikes.Set = function(likeId, entityTypeId, entityId, available, userId, localize, template, pathToUserProfile, pathToAjax) { if (template === undefined) template = 'standart'; if (!BXRL[likeId] || BXRL[likeId].tryToSet <= 5) { var tryToSend = BXRL[likeId] && BXRL[likeId].tryToSet? BXRL[likeId].tryToSet: 1; BXRL[likeId] = new RatingLikes(likeId, entityTypeId, entityId, available, userId, localize, template, pathToUserProfile, pathToAjax); if (BXRL[likeId].enabled) { RatingLikes.Init(likeId); } else { setTimeout(function(){ BXRL[likeId].tryToSet = tryToSend+1; RatingLikes.Set(likeId, entityTypeId, entityId, available, userId, localize, template, pathToUserProfile, pathToAjax); }, 500); } } }; RatingLikes.Init = function(likeId) { // like/unlike button if (BXRL[likeId].available) { BX.bind(BXRL[likeId].template == 'standart'? BXRL[likeId].button: BXRL[likeId].buttonText, 'click' ,function(e) { clearTimeout(BXRL[likeId].likeTimeout); if (BX.hasClass(BXRL[likeId].template == 'standart'? this: BXRL[likeId].count, 'bx-you-like')) { BXRL[likeId].buttonText.innerHTML = BXRL[likeId].localize['LIKE_N']; BXRL[likeId].countText.innerHTML = parseInt(BXRL[likeId].countText.innerHTML)-1; BX.removeClass(BXRL[likeId].template == 'standart'? this: BXRL[likeId].count, 'bx-you-like'); BXRL[likeId].likeTimeout = setTimeout(function(){ if (BXRL[likeId].lastVote != 'cancel') RatingLikes.Vote(likeId, 'cancel'); }, 1000); } else { BXRL[likeId].buttonText.innerHTML = BXRL[likeId].localize['LIKE_Y']; BXRL[likeId].countText.innerHTML = parseInt(BXRL[likeId].countText.innerHTML)+1; BX.addClass(BXRL[likeId].template == 'standart'? this: BXRL[likeId].count, 'bx-you-like'); BXRL[likeId].likeTimeout = setTimeout(function(){ if (BXRL[likeId].lastVote != 'plus') RatingLikes.Vote(likeId, 'plus'); }, 1000); } BX.removeClass(this.box, 'bx-ilike-button-hover'); BX.PreventDefault(e); }); // Hover/unHover like-button BX.bind(BXRL[likeId].box, 'mouseover', function() {BX.addClass(this, 'bx-ilike-button-hover')}); BX.bind(BXRL[likeId].box, 'mouseout', function() {BX.removeClass(this, 'bx-ilike-button-hover')}); } else { if (BXRL[likeId].buttonText != undefined) BXRL[likeId].buttonText.innerHTML = BXRL[likeId].localize['LIKE_D']; } // get like-user-list RatingLikes.PopupScroll(likeId); console.log(); BX.bind(BXRL[likeId].wrapp, 'mouseover' , function() { clearTimeout(BXRL[likeId].popupTimeoutId); BXRL[likeId].popupTimeoutId = setTimeout(function(){ if (BXRLW == likeId) return false; if (BXRL[likeId].popupContentPage == 1) RatingLikes.List(likeId, 1); BXRL[likeId].popupTimeoutId = setTimeout(function() { RatingLikes.OpenWindow(likeId); }, 400); }, 400); }); BX.bind(BXRL[likeId].wrapp, 'mouseout' , function() { clearTimeout(BXRL[likeId].popupTimeoutId); }); /*BX.bind(BXRL[likeId].count, 'click' , function() { clearTimeout(BXRL[likeId].popupTimeoutId); if (BXRL[likeId].popupContentPage == 1) RatingLikes.List(likeId, 1); RatingLikes.OpenWindow(likeId); });*/ BX.bind(BXRL[likeId].box, 'mouseover' , function() { clearTimeout(BXRL[likeId].popupTimeout); }); BX.bind(BXRL[likeId].box, 'mouseout' , function() { clearTimeout(BXRL[likeId].popupTimeout); BXRL[likeId].popupTimeout = setTimeout(function(){ if (BXRL[likeId].popup !== null) { BXRL[likeId].popup.close(); BXRLW = null; } }, 1000); }); }; RatingLikes.OpenWindow = function(likeId) { if (parseInt(BXRL[likeId].countText.innerHTML) == 0) return false; if (BXRL[likeId].popup == null) { BXRL[likeId].popup = new BX.PopupWindow('ilike-popup-'+likeId, (BXRL[likeId].template == 'standart'? BXRL[likeId].count: BXRL[likeId].box), { lightShadow : true, offsetLeft: 5, autoHide: true, closeByEsc: true, zIndex: 2005, bindOptions: {position: "top"}, events : { onPopupClose : function() { BXRLW = null; }, onPopupDestroy : function() { } }, content : BX('bx-ilike-popup-cont-'+likeId) }); BXRL[likeId].popup.setAngle({}); BX.bind(BX('ilike-popup-'+likeId), 'mouseout' , function() { clearTimeout(BXRL[likeId].popupTimeout); BXRL[likeId].popupTimeout = setTimeout(function(){ BXRL[likeId].popup.close(); }, 1000); }); BX.bind(BX('ilike-popup-'+likeId), 'mouseover' , function() { clearTimeout(BXRL[likeId].popupTimeout); }); } if (BXRLW != null) BXRL[BXRLW].popup.close(); BXRLW = likeId; BXRL[likeId].popup.show(); RatingLikes.AdjustWindow(likeId); }; RatingLikes.Vote = function(likeId, voteAction) { BX.ajax({ url: BXRL[likeId].pathToAjax, method: 'POST', dataType: 'json', data: {'RATING_VOTE' : 'Y', 'RATING_VOTE_TYPE_ID' : BXRL[likeId].entityTypeId, 'RATING_VOTE_ENTITY_ID' : BXRL[likeId].entityId, 'RATING_VOTE_ACTION' : voteAction, 'sessid': BX.bitrix_sessid()}, onsuccess: function(data) { BXRL[likeId].lastVote = data.action; BXRL[likeId].countText.innerHTML = data.items_all; BXRL[likeId].popupContentPage = 1; BXRL[likeId].popupContent.innerHTML = ''; spanTag0 = document.createElement("span"); spanTag0.className = "bx-ilike-wait"; BXRL[likeId].popupContent.appendChild(spanTag0); RatingLikes.AdjustWindow(likeId); if(BX('ilike-popup-'+likeId) && BX('ilike-popup-'+likeId).style.display == "block") RatingLikes.List(likeId, null); }, onfailure: function(data) {} }); return false; }; RatingLikes.List = function(likeId, page) { if (parseInt(BXRL[likeId].countText.innerHTML) == 0) return false; if (page == null) page = BXRL[likeId].popupContentPage; BXRL[likeId].popupListProcess = true; BX.ajax({ url: BXRL[likeId].pathToAjax, method: 'POST', dataType: 'json', data: {'RATING_VOTE_LIST' : 'Y', 'RATING_VOTE_TYPE_ID' : BXRL[likeId].entityTypeId, 'RATING_VOTE_ENTITY_ID' : BXRL[likeId].entityId, 'RATING_VOTE_LIST_PAGE' : page, 'PATH_TO_USER_PROFILE' : BXRL[likeId].pathToUserProfile, 'sessid': BX.bitrix_sessid()}, onsuccess: function(data) { BXRL[likeId].countText.innerHTML = data.items_all; if ( parseInt(data.items_page) == 0 ) return false; if (page == 1) { BXRL[likeId].popupContent.innerHTML = ''; spanTag0 = document.createElement("span"); spanTag0.className = "bx-ilike-bottom_scroll"; BXRL[likeId].popupContent.appendChild(spanTag0); } BXRL[likeId].popupContentPage += 1; var avatarNode = null; for (var i = 0; i < data.items.length; i++) { if (data.items[i]['PHOTO_SRC'].length > 0) { avatarNode = BX.create("IMG", { attrs: {src: data.items[i]['PHOTO_SRC']}, props: {className: "bx-ilike-popup-avatar-img"} }); } else { avatarNode = BX.create("IMG", { attrs: {src: '/bitrix/images/main/blank.gif'}, props: {className: "bx-ilike-popup-avatar-img bx-ilike-popup-avatar-img-default"} }); } BXRL[likeId].popupContent.appendChild( BX.create("div", { /*attrs: { href: data.items[i]['URL'], target: '_blank' },*/ props: { className: "bx-ilike-popup-img" + (!!data.items[i]['USER_TYPE'] ? " bx-ilike-popup-img-" + data.items[i]['USER_TYPE'] : "") }, children: [ BX.create("SPAN", { props: { className: "bx-ilike-popup-avatar-new" }, children: [ avatarNode, BX.create("SPAN", { props: {className: "bx-ilike-popup-avatar-status-icon"} }) ] }), BX.create("SPAN", { props: { className: "bx-ilike-popup-name-new" }, html: data.items[i]['FULL_NAME'] }) ] }) ); } RatingLikes.AdjustWindow(likeId); RatingLikes.PopupScroll(likeId); BXRL[likeId].popupListProcess = false; }, onfailure: function(data) {} }); return false; }; RatingLikes.AdjustWindow = function(likeId) { if (BXRL[likeId].popup != null) { BXRL[likeId].popup.bindOptions.forceBindPosition = true; BXRL[likeId].popup.adjustPosition(); BXRL[likeId].popup.bindOptions.forceBindPosition = false; } }; RatingLikes.PopupScroll = function(likeId) { BX.bind(BXRL[likeId].popupContent, 'scroll' , function() { if (this.scrollTop > (this.scrollHeight - this.offsetHeight) / 1.5) { RatingLikes.List(likeId, null); BX.unbindAll(this); } }); };