1/** 2 * @package T2G Reaktions 3 * Script for the Qantumthemes Love It plugin 4 */ 5 6 7(function($) { 8 "use strict"; 9 $.qtWebsiteObj = {}; 10 $.qtWebsiteObj.body = $("body"); 11 12 $.fn.ttgReaktionsLoveitAjax = function(){ 13 var post_id, heart; 14 $.qtWebsiteObj.body.on("click","a.ttg_reaktions-link", function(e){ 15 e.preventDefault(); 16 heart = $(this); 17 // Retrieve post ID from data attribute 18 post_id = heart.data("post_id"); 19 // Ajax call 20 $.ajax({ 21 type: "post", 22 url: ajax_var.url, 23 data: "action=post-like&nonce="+ajax_var.nonce+"&post_like=&post_id="+post_id, 24 success: function(count){ 25 // If vote successful 26 if(count != "already") { 27 heart.addClass("ttg-reaktions-btn-disabled"); 28 heart.find(".count").text(count); 29 heart.find('i').removeClass('reakticons-heart').addClass('reakticons-heart-full'); 30 } 31 } 32 }); 33 return false; 34 }); 35 }; 36 37 38 $.fn.ttgRatingCounterAjax = function(){ 39 40 var post_id, rating, single, multi, container, label; 41 42 $.qtWebsiteObj.viewCounterAjax = $(".ttg-reactions-viewconuterajax"); 43 if($.qtWebsiteObj.viewCounterAjax == 0){ 44 return; 45 } 46 47 $.qtWebsiteObj.body.on("change","input[name='ttg-reaktions-star']", function(e){ 48 e.preventDefault(); 49 50 var that = $(this), 51 form = that.closest("form"), 52 post_id = form.attr("data-postid"), 53 rating = that.attr("value"); 54 55 var data = "action=ttg_rating_submit&nonce="+ajax_var.nonce+"&ttg_rating_submit="+rating+"&post_id="+post_id; 56 var ajaxurl = ajax_var.url; 57 var responsearray, avg, count, label_novote,rating_container, before, rating_feedback,feedback_msg; 58 $.ajax({ 59 type: "post", 60 url: ajaxurl, 61 data: data, 62 success: function(response){ 63 container = $(".ttg-Ratings-Amount"); 64 rating_container = $(".ttg-Ratings-Avg"); 65 rating_feedback = $(".ttg-Ratings-Feedback"); 66 label_novote = container.attr("data-novote"); 67 responsearray = response.split("|avg="); 68 label = container.attr("data-single"); 69 before = container.attr("data-before"); 70 feedback_msg = rating_feedback.attr("data-thanks"); 71 if(response === 'novote'){ 72 // container.html(label_novote); 73 rating_feedback.html(label_novote); 74 return; 75 } 76 count = responsearray[0]; 77 avg = responsearray[1]; 78 if(count > 1){ 79 label = container.attr("data-multi"); 80 } 81 rating_container.html(parseFloat(avg).toFixed(2) ); 82 rating_feedback.html(feedback_msg); 83 container.html(before+' '+count+ ' ' +label); 84 }, 85 error: function(result){ 86 // console.log("Ajax rating error"); 87 } 88 }); 89 }); 90 } 91 $.fn.ttgViewCounterAjax = function(){ 92 $.qtWebsiteObj.viewCounterAjax = $(".ttg-reactions-viewconuterajax"); 93 var single, multi, container, label; 94 if($.qtWebsiteObj.viewCounterAjax.length == 0){ 95 return; 96 } 97 var post_id = $.qtWebsiteObj.viewCounterAjax.attr("data-id"); 98 var data = "action=ttg_post_views&nonce="+ajax_var.nonce+"&ttg_post_views=&post_id="+post_id; 99 var ajaxurl = ajax_var.url; 100 101 $.ajax({ 102 type: "post", 103 url: ajaxurl, 104 data: data, 105 success: function(count){ 106 container = $(".ttg-Reaktions-Views-Amount"); 107 label = container.attr("data-single"); 108 if(count > 1){ 109 label = container.attr("data-multi"); 110 } 111 container.html(count+ ' ' +label); 112 }, 113 error: function(result){ 114 // console.log("Ajax count error"); 115 } 116 }); 117 } 118 119 /* activates 120 * Adds and removes the class "wpcast-active" from the target item 121 ====================================================================*/ 122 $.fn.ttgReactionsActivates= function(){ 123 124 var t, // target 125 o = $.qtWebsiteObj, 126 s = false;
127 o.body.off("click", "[data-ttg-reaktions-activates]"); 128 o.body.on("click", "[data-ttg-reaktions-activates]", function(e){ 129 e.preventDefault(); 130 s = $(this).attr("data-ttg-reaktions-activates") 131 t = $(s); 132 if(!s || s === ''){ 133 t = $(this); 134 } 135 if( s == 'parent'){ 136 t = $(this).parent(); 137 } 138 t.toggleClass("ttg-reaktions-active"); 139 return; 140 }); 141 }, 142 143 144 145 146 147 /**==================================================================== 148 * 149 * 150 * Popup opener (requires library component) 151 * 152 * 153 ====================================================================*/ 154 $.fn.ttgReaktionPopupwindow = function() { 155 if(typeof($.fn.popupwindow) !== "undefined"){ 156 $.fn.popupwindow(); 157 } 158 }; 159 160 $(document).ready(function() { 161 $.fn.ttgReaktionPopupwindow(); 162 $.fn.ttgReaktionsLoveitAjax(); 163 $.fn.ttgViewCounterAjax(); 164 $.fn.ttgRatingCounterAjax(); 165 $.fn.ttgReactionsActivates(); 166 }); 167 168 169})(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.