1/** 2 * EC-stars-rating 3 * Copyright (C) 2015 Emilio Cobos Ãlvarez (http://emiliocobos.me) 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, see http://github.com/ecoal95/kobe-stars-rating/blob/master/LICENSE 17 */ 18;(function ($) { 19 20 var globaldata = window.kobe_ajax_data || null; 21 22 $.fn.wpAjaxRating = function() { 23 return this.each(function() { 24 var el = this, 25 post_id = parseInt(this.getAttribute('data-post-id'), 10); 26 $(this).on('click', 'a', function(e) { 27 var rating = parseInt(this.getAttribute('data-value'), 10), 28 data = { 29 "action": "kobe_stars_rating", 30 "rating": rating, 31 "post_id": post_id 32 }, 33 update_value = function(result, count) { 34 $(el).addClass("is-voted") 35 .find('.kobe-stars-overlay').css({ 36 "width": (100 - result * 100 / 5) + '%' 37 }) 38 .end().parent() 39 .find('.kobe-stars-rating-count').html(count) 40 .end().parent() 41 .find('.kobe-stars-rating-value').html(parseInt(result * 100) / 100); 42 43 }, 44 show_message = function(message) { 45 el.setAttribute('data-tooltip', message); 46 }; 47 48 if( globaldata === null ) { 49 globaldata = window.kobe_ajax_data || null; 50 } 51 e.preventDefault(); 52 if( (/\bis-voted\b/).test(el.className) === null || rating > 5 || rating < 1) { 53 return; 54 } 55 56 $.post(globaldata.ajax_url, data, function(response) { 57 switch(response.status) { 58 case globaldata.codes.PREVIOUSLY_VOTED: 59 show_message(globaldata.messages.previously_voted); 60 break; 61 case globaldata.codes.REQUEST_ERROR: 62 show_message(globaldata.messages.request_error); 63 break; 64 case globaldata.codes.SUCCESS: 65 update_value(response.result, response.votes); 66 show_message(globaldata.messages.success); 67 break; 68 default: 69 show_message(globaldata.messages.unknown); 70 // break; 71 } 72 73 74 }, "json") 75 }); 76 }); 77 }; 78 79 $(function() { 80 $('.kobe-stars-wrapper').wpAjaxRating(); 81 }) 82}(window.jQuery))
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.