1;(function(window) { 2 if (window.JCIblockVoteStars) 3 return; 4 5 /** @param {{ 6 progressId: string, 7 ratingId: string, 8 starsId: string, 9 ajaxUrl: string, 10 checkVoteUrl: string, 11 ajaxParams: {}, 12 siteId: string, 13 voteData: { 14 element: int, 15 percent: int, 16 count: int 17 }, 18 readOnly: bool 19 }} params 20 */ 21 window.JCIblockVoteStars = function (params) 22 { 23 this.progressObj = null; 24 this.ratingObj = null; 25 this.starsObj = null; 26 27 this.progressId = ''; 28 this.ratingId = ''; 29 this.starsId = ''; 30 31 this.ajaxParams = {}; 32 this.siteId = ''; 33 34 this.voteData = { 35 element: 0, 36 percent: 0, 37 count: 0 38 }; 39 40 this.config = { 41 readOnly: false, 42 alreadyVoted: true, 43 request: false 44 }; 45 46 if (BX.type.isPlainObject(params)) 47 { 48 if (BX.type.isNotEmptyString(params.progressId)) 49 this.progressId = params.progressId; 50 if (BX.type.isNotEmptyString(params.ratingId)) 51 this.ratingId = params.ratingId; 52 if (BX.type.isNotEmptyString(params.starsId)) 53 this.starsId = params.starsId; 54 if (BX.type.isNotEmptyString(params.ajaxUrl)) 55 this.ajaxUrl = params.ajaxUrl; 56 if (BX.type.isNotEmptyString(params.checkVoteUrl)) 57 this.checkVoteUrl = params.checkVoteUrl; 58 if (BX.type.isPlainObject(params.ajaxParams)) 59 this.ajaxParams = params.ajaxParams; 60 if (BX.type.isNotEmptyString(params.siteId)) 61 this.siteId = params.siteId; 62 if (BX.type.isPlainObject(params.voteData)) 63 { 64 if (BX.type.isNumber(params.voteData.element)) 65 this.voteData.element = params.voteData.element; 66 if (BX.type.isNumber(params.voteData.percent)) 67 this.voteData.percent = this.preparePercent(params.voteData.percent); 68 if (BX.type.isNumber(params.voteData.count)) 69 this.voteData.count = params.voteData.count; 70 } 71 if (BX.type.isBoolean(params.readOnly)) 72 this.config.readOnly = params.readOnly; 73 } 74 75 BX.ready(BX.proxy(this.init, this)); 76 }; 77 78 window.JCIblockVoteStars.prototype.init = function() 79 { 80 if (BX.type.isNotEmptyString(this.progressId)) 81 this.progressObj = BX(this.progressId); 82 83 if (BX.type.isNotEmptyString(this.ratingId)) 84 this.ratingObj = BX(this.ratingId); 85 86 if (BX.type.isNotEmptyString(this.starsId)) 87 this.starsObj = BX(this.starsId); 88 89 this.showProgress(this.voteData.percent); 90 this.showVotes(); 91 92 this.checkVote(); 93 }; 94 95 window.JCIblockVoteStars.prototype.checkVote = function() 96 { 97 if (this.config.readOnly || this.voteData.element <= 0) 98 return; 99 100 BX.ajax({ 101 'timeout': 30, 102 'method': 'POST', 103 'dataType': 'json', 104 'url': this.checkVoteUrl, 105 'data': { 106 sessid: BX.bitrix_sessid(), 107 checkVote: 'Y', 108 vote_id: this.voteData.element, 109 site_id: this.siteId 110 }, 111 'onsuccess': BX.proxy(this.checkVoteResult, this) 112 }); 113 }; 114 115 window.JCIblockVoteStars.prototype.checkVoteResult = function(result) 116 { 117 if (BX.type.isPlainObject(result)) 118 { 119 if (result.success) 120 this.config.alreadyVoted = result.voted; 121 } 122 123 if (this.config.readOnly || this.config.alreadyVoted || this.voteData.element <= 0) 124 return; 125 126 if (BX.type.isElementNode(this.starsObj)) 127 { 128 129 BX.bind(this.starsObj, 'mousemove', BX.proxy(this.handlerMouseMove, this)); 130 BX.bind(this.starsObj, 'mouseout', BX.proxy(this.handlerMouseOut, this)); 131 BX.bind(this.starsObj, 'click', BX.proxy(this.handlerClick, this)); 132 } 133 }; 134 135 window.JCIblockVoteStars.prototype.destroy = function() 136 { 137 if (BX.type.isElementNode(this.progressObj)) 138 BX.unbindAll(this.progressObj); 139 this.progressObj = null; 140 141 if (BX.type.isElementNode(this.ratingObj)) 142 BX.unbindAll(this.ratingObj); 143 this.ratingObj = null; 144 145 if (BX.type.isElementNode(this.starsObj)) 146 BX.unbindAll(this.starsObj); 147 this.starsObj = null; 148 }; 149 150 window.JCIblockVoteStars.prototype.preparePercent = function(percent) 151 { 152 percent = parseInt(percent, 10); 153 if (isNaN(percent)) 154 percent = 0; 155 else if(percent > 100) 156 percent = 100; 157 else if(percent < 0) 158 percent = 0; 159 return percent; 160 }; 161 162 window.JCIblockVoteStars.prototype.showProgress = function(percent) 163 { 164 if (!BX.type.isElementNode(this.progressObj)) 165 return; 166 167 BX.style(this.progressObj, 'width', percent.toString() + '%'); 168 }; 169 170 window.JCIblockVoteStars.prototype.showVotes = function() 171 { 172 if (!BX.type.isElementNode(this.ratingObj)) 173 return; 174 175 this.ratingObj.innerHTML = "ÐолиÑеÑÑво голоÑов: " + this.voteData.count + ""; 176 }; 177 178 window.JCIblockVoteStars.prototype.handlerMouseMove = function(e) 179 { 180 var starsPos, 181 newPercent; 182 183 if (this.config.readOnly || this.config.alreadyVoted || this.config.request) 184 return; 185 186 e = e || window.event; 187 188 if (!BX.type.isElementNode(this.starsObj)) 189 return; 190 191 starsPos = BX.pos(this.starsObj); 192 newPercent = ((e.pageX - starsPos.left)/starsPos.width)*5; 193 this.showProgress(this.preparePercent(Math.ceil(newPercent)*20)); 194 }; 195 196 window.JCIblockVoteStars.prototype.handlerMouseOut = function() 197 { 198 if (this.config.readOnly || this.config.alreadyVoted || this.config.request) 199 return; 200 this.showProgress(this.voteData.percent); 201 }; 202 203 window.JCIblockVoteStars.prototype.handlerClick = function(e) 204 { 205 var starsPos, 206 newValue; 207 208 if (this.config.readOnly || this.config.alreadyVoted || this.config.request) 209 return; 210 this.config.request = true; 211 212 e = e || window.event; 213 214 if (!BX.type.isElementNode(this.starsObj)) 215 return; 216 217 starsPos = BX.pos(this.starsObj); 218 newValue = parseInt(Math.ceil(((e.pageX - starsPos.left)/starsPos.width)*5), 10); 219 if (isNaN(newValue)) 220 return; 221 222 this.ajaxParams.rating = newValue - 1; 223 this.ajaxParams.vote = 'Y'; 224 this.ajaxParams.vote_id = this.voteData.element; 225 this.ajaxParams.sessid = BX.bitrix_sessid(); 226 this.ajaxParams.site_id = this.siteId; 227 228 BX.ajax({ 229 timeout: 30, 230 method: 'POST', 231 dataType: 'json', 232 url: this.ajaxUrl, 233 data: this.ajaxParams, 234 onsuccess: BX.proxy(this.clickResult, this) 235 }); 236 }; 237 238 /** @param {{ 239 value: int, 240 votes: int 241 }} result 242 */ 243 window.JCIblockVoteStars.prototype.clickResult = function(result) 244 { 245 this.config.request = false;
246 if (BX.type.isPlainObject(result)) 247 { 248 this.config.alreadyVoted = true; 249 this.voteData.percent = this.preparePercent((result.value)*20); 250 this.voteData.count = result.votes; 251 this.showProgress(this.voteData.percent) 252 this.showVotes(); 253 } 254 }; 255})(window);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.