Πρόβλημα με Likes σε blog

Επισκόπηση προηγούμενης Θ.Ενότητας Επισκόπηση επόμενης Θ.Ενότητας Πήγαινε κάτω

Λύθηκε Πρόβλημα με Likes σε blog

Δημοσίευση από Giotis Τετ Ιουλ 06, 2016 3:39 pm

Καλησπέρα.
Χρησιμοποιώ αυτό το javascript για Likes/Dislikes.
http://help.forumotion.com/t142870-improve-the-reputation-system-so-it-counts-votes#972462

Τώρα όμως που έφτιαξα ένα blog στο φόρουμ μου, συμβαίνει αυτό:
Πρόβλημα με Likes σε blog 10d7ek9

Για κάθε σχόλιο που γίνεται κάτω από κάποιο θέμα του blog εμφανίζεται ένα νέο ζευγάρι κουμπιών Like/Dislike στην κορυφή της πρώτης δημοσίευσης.
Μπορεί να διορθωθεί ή να αφαιρεθούν τελείως τα Likes στο συγκεκριμένο τομέα που χρησιμοποιώ σε μορφή blog;
Giotis

Giotis
Νικητής διαγωνισμού
Νικητής διαγωνισμού

Δημοσιεύσεις : 90



Giotis ο/η συγγραφέας σας ευχαριστήσε για την απάντησή σας.

Λύθηκε Απ: Πρόβλημα με Likes σε blog

Δημοσίευση από Nemo Τετ Ιουλ 06, 2016 10:51 pm

Καλησπέρα,

Ποιος είναι ο σύνδεσμος του φόρουμ σας;

Hello
Nemo

Nemo
Υπεύθυνος Φόρουμ
Υπεύθυνος Φόρουμ

Άντρας
Τόπος : Αθήνα, Ελλάδα
Δημοσιεύσεις : 1206



Nemo ο/η συγγραφέας σας ευχαριστήσε για την απάντησή σας.

Λύθηκε Απ: Πρόβλημα με Likes σε blog

Δημοσίευση από Giotis Πεμ Ιουλ 07, 2016 2:44 pm

Nemo έγραψε:Καλησπέρα,

Ποιος είναι ο σύνδεσμος του φόρουμ σας;

Hello
http://www.vandicted.com/forum
Το blog το έχω ορατό μόνο για διαχειριστές προς το παρόν. Να το ανοίξω;
Giotis

Giotis
Νικητής διαγωνισμού
Νικητής διαγωνισμού

Δημοσιεύσεις : 90



Giotis ο/η συγγραφέας σας ευχαριστήσε για την απάντησή σας.

Λύθηκε Απ: Πρόβλημα με Likes σε blog

Δημοσίευση από Van-Helsing Δευ Ιουλ 11, 2016 11:51 pm

Καλησπέρα @Giotis,
Ναι καλό θα ήταν να είναι ανοιχτό για να δούμε που παρουσιάζει σφάλμα το javascript και το εμφανίζει πολλές φορές το like.
Van-Helsing

Van-Helsing
Διαχειριστής
Διαχειριστής

Άντρας
Ηλικία : 49
Δημοσιεύσεις : 1990



Van-Helsing ο/η συγγραφέας σας ευχαριστήσε για την απάντησή σας.

Λύθηκε Απ: Πρόβλημα με Likes σε blog

Δημοσίευση από Giotis Τρι Ιουλ 12, 2016 6:33 pm

Van-Helsing έγραψε:Καλησπέρα @Giotis,
Ναι καλό θα ήταν να είναι ανοιχτό για να δούμε που παρουσιάζει σφάλμα το javascript και το εμφανίζει πολλές φορές το like.
Καλησπέρα! Το άνοιξα.
Μπορείτε να το δείτε εδώ: http://www.vandicted.com/f2-forum
Giotis

Giotis
Νικητής διαγωνισμού
Νικητής διαγωνισμού

Δημοσιεύσεις : 90



Giotis ο/η συγγραφέας σας ευχαριστήσε για την απάντησή σας.

Λύθηκε Απ: Πρόβλημα με Likes σε blog

Δημοσίευση από Van-Helsing Πεμ Ιουλ 14, 2016 3:08 am

Καλησπέρα,
Το javascript που χρησιμοποιείς είναι για έκδοση Punbb ενώ το φόρουμ σου είναι phpbb2/3 με αποτέλεσμα να μην λειτουργεί σωστά εφόσον από έκδοση σε έκδοση φόρουμ διαφέρουν τα πρότυπα.

Τρέχον Javascript:
Κώδικας:
$(function(){var config={position_left:true,negative_vote:true,vote_bar:true,icon_plus:'<img src="http://i18.servimg.com/u/f18/18/21/41/30/plus10.png" alt="+"/>',icon_minus:'<img src="http://i18.servimg.com/u/f18/18/21/41/30/minus10.png" alt="-"/>',title_plus:'Like %{USERNAME}\'s post',title_minus:'Dislike %{USERNAME}\'s post',title_like_singular:'%{VOTES} person likes %{USERNAME}\'s post',title_like_plural:'%{VOTES} people like %{USERNAME}\'s post',title_dislike_singular:'%{VOTES} person dislikes %{USERNAME}\'s post',title_dislike_plural:'%{VOTES} people dislike %{USERNAME}\'s post',title_vote_bar:'%{VOTES} people liked %{USERNAME}\'s post %{PERCENT}'},submit_vote=function(){var next=this.nextSibling,box=this.parentNode,bar=box.getElementsByTagName('DIV'),vote=box.getElementsByTagName('A'),mode=/eval=plus/.test(this.href)?1:0,i=0,j=vote.length,pos,neg,percent;$.get(this.href,function(){next.innerHTML=+next.innerHTML+1;next.title=next.title.replace(/(\d+)/,function(M,$1){return+$1+1});pos=+vote[0].nextSibling.innerHTML;neg=vote[1]?+vote[1].nextSibling.innerHTML:0;percent=pos==0?'0%':pos==neg?'50%':Math.round(pos/(pos+neg)*100)+'%';if(bar[0]){bar[0].style.display='';bar[0].firstChild.style.width=percent;box.title=box.title.replace(/\d+\/\d+/,pos+'/'+(pos+neg)).replace(/\(\d+%\)/,'('+percent+')')}});
for(;i<j;i++){vote[i].href='#';
vote[i].className=vote[i].className.replace(/fa_vote/,'fa_voted');
vote[i].onclick=function(){return false}}return false},vote=$('.vote'),i=0,j=vote.length,version=$('.bodylinewidth')[0]?0:document.getElementById('wrap')?1:$('.pun')[0]?2:document.getElementById('ipbwrapper')?3:'badapple',vdata={tag:['SPAN','LI','SPAN','LI'][version],name:['.name','.postprofile dt > strong','.username','.popmenubutton'][version],actions:['.post-options','.profile-icons','.post-options','.posting-icons'][version],},post,plus,minus,n_pos,n_neg,title_pos,title_neg,li,ul,bar,button,total,percent,span,pseudo,vote_bar;if(version=='badapple'){if(window.console)console.warn('This plugin is not optimized for your forum version. Please contact the support for further assistance.');return}for(;i<j;i++){post=$(vote[i]).parentsUntil('.post').parent()[0];bar=$('.vote-bar',vote[i])[0];button=$('.vote-button',vote[i]);pseudo=$(vdata.name,post).text()||'MISSING_STRING';ul=$(vdata.actions,post)[0];li=document.createElement(vdata.tag);li.className='fa_reputation';if(li.tagName=='SPAN')li.style.display='inline-block';if(bar){total=+bar.title.replace(/.*?\((\d+).*/,'$1');percent=+bar.title.replace(/.*?(\d+)%.*/,'$1');n_pos=Math.round(total*(percent/100));n_neg=total-n_pos}else{n_pos=0;n_neg=0}title_pos=(n_pos==1?config.title_like_singular:config.title_like_plural).replace(/%\{USERNAME\}/g,pseudo).replace(/%\{VOTES\}/g,n_pos);title_neg=(n_neg==1?config.title_dislike_singular:config.title_dislike_plural).replace(/%\{USERNAME\}/g,pseudo).replace(/%\{VOTES\}/g,n_neg);li.innerHTML='<span class="fa_count fa_positive" title="'+title_pos+'">'+n_pos+'</span>'+(config.negative_vote?' <span class="fa_count fa_negative" title="'+title_neg+'">'+n_neg+'</span>':'');span=li.getElementsByTagName('SPAN');plus=document.createElement('A');plus.href=button[0]?button[0].firstChild.href:'#';plus.onclick=button[0]?submit_vote:function(){return false};plus.className='fa_vote'+(button[0]?'':'d')+' fa_plus';plus.innerHTML=config.icon_plus;plus.title=(button[0]?config.title_plus:title_pos).replace(/%\{USERNAME\}/g,pseudo);span[0]&&li.insertBefore(plus,span[0]);if(config.negative_vote){minus=document.createElement('A');minus.href=button[1]?button[1].firstChild.href:'#';minus.onclick=button[1]?submit_vote:function(){return false};minus.className='fa_vote'+(button[1]?'':'d')+' fa_minus';minus.innerHTML=config.icon_minus;minus.title=(button[1]?config.title_minus:title_neg).replace(/%\{USERNAME\}/g,pseudo);span[1]&&li.insertBefore(minus,span[1])}if(config.vote_bar){vote_bar=document.createElement('DIV');vote_bar.className='fa_votebar';vote_bar.innerHTML='<div class="fa_votebar_inner" style="width:'+percent+'%;"></div>';vote_bar.style.display=bar?'':'none';li.title=config.title_vote_bar.replace(/%\{USERNAME\}/,pseudo).replace(/%\{VOTES\}/,n_pos+'/'+(n_pos+n_neg)).replace(/%\{PERCENT\}/,'('+percent+'%)');li.appendChild(vote_bar)}config.position_left?ul.insertBefore(li,ul.firstChild):ul.appendChild(li);vote[i].parentNode.removeChild(vote[i])}});

Δοκίμασε το παρακάτω javascript:

Κώδικας:
        $(function() {
          // General Configuration of the plugin
          var config = {
            position_left : true, // true for left || false for right
            negative_vote : true, // true for negative votes || false for positive only
            vote_bar : true, // display a small bar under the vote buttons
         
            // button config
            icon_plus : '<img src="http://i18.servimg.com/u/f18/18/21/41/30/plus10.png" alt="+"/>',
            icon_minus : '<img src="http://i18.servimg.com/u/f18/18/21/41/30/minus10.png" alt="-"/>',
         
            // language config
            title_plus : 'Like %{USERNAME}\'s post',
            title_minus : 'Dislike %{USERNAME}\'s post',
         
            title_like_singular : '%{VOTES} person likes %{USERNAME}\'s post',
            title_like_plural : '%{VOTES} people like %{USERNAME}\'s post',
         
            title_dislike_singular : '%{VOTES} person dislikes %{USERNAME}\'s post',
            title_dislike_plural : '%{VOTES} people dislike %{USERNAME}\'s post',
         
            title_vote_bar : '%{VOTES} people liked %{USERNAME}\'s post %{PERCENT}'
          },
           
           
          // function bound to the onclick handler of the vote buttons
          submit_vote = function() {
            var next = this.nextSibling, // the counter next to the vote button that was clicked
                box = this.parentNode,
                bar = box.getElementsByTagName('DIV'),
                vote = box.getElementsByTagName('A'),
                mode = /eval=plus/.test(this.href) ? 1 : 0,
                i = 0, j = vote.length, pos, neg, percent;
         
            // submit the vote asynchronously
            $.get(this.href, function() {
              next.innerHTML = +next.innerHTML + 1; // add to the vote count
              next.title = next.title.replace(/(\d+)/, function(M, $1) { return +$1 + 1 });
           
              pos = +vote[0].nextSibling.innerHTML;
              neg = vote[1] ? +vote[1].nextSibling.innerHTML : 0;
              percent = pos == 0 ? '0%' : pos == neg ? '50%' : Math.round(pos / (pos + neg) * 100) + '%';
           
              if (bar[0]) {
                bar[0].style.display = '';
                bar[0].firstChild.style.width = percent;
                box.title = box.title.replace(/\d+\/\d+/, pos + '/' + ( pos + neg )).replace(/\(\d+%\)/, '(' + percent + ')');
              }
            });
         
            // revoke voting capabilities on the post once the vote is cast
            for (; i < j; i++) {
              vote[i].href = '#';
              vote[i].className = vote[i].className.replace(/fa_vote/, 'fa_voted');
              vote[i].onclick = function() { return false };
            }
         
            return false;
          },
           
          vote = $('.vote'), i = 0, j = vote.length,
          version = $('.bodylinewidth')[0] ? 0 : document.getElementById('wrap') ? 1 : $('.pun')[0] ? 2 : document.getElementById('ipbwrapper') ? 3 : 'badapple', // version check
       
          // version data so we don't have to redefine these arrays during the loop
          vdata = {
            tag : ['SPAN', 'LI', 'SPAN', 'LI'][version],
            name : ['.name', '.postprofile dt > strong', '.username', '.popmenubutton'][version],
            actions : ['.post-options', '.profile-icons', '.post-options', '.posting-icons'][version],
          },
       
          post, plus, minus, n_pos, n_neg, title_pos, title_neg, li, ul, bar, button, total, percent, span, pseudo, vote_bar; // startup variables for later use in the loop
       
          // prevent execution if the version cannot be determined
          if (version == 'badapple') {
            if (window.console) console.warn('This plugin is not optimized for your forum version. Please contact the support for further assistance.');
            return;
          }
       
          for (; i < j; i++) {
            post = $(vote[i]).parentsUntil('.post').parent()[0];
            bar = $('.vote-bar', vote[i])[0]; // vote bar
            button = $('.vote-button', vote[i]); // plus and minus buttons
            pseudo = $(vdata.name, post).text() || 'MISSING_STRING'; // username of the poster
            ul = $(vdata.actions, post)[0]; // post actions
            li = document.createElement(vdata.tag); // vote system container
            li.className = 'fa_reputation';
         
            if (li.tagName == 'SPAN') li.style.display = 'inline-block';
         
            // calculate votes
            if (bar) {
              total = +bar.title.replace(/.*?\((\d+).*/, '$1');
              percent = +bar.title.replace(/.*?(\d+)%.*/, '$1');
           
              n_pos = Math.round(total * (percent / 100));
              n_neg = total - n_pos;
            } else {
              n_pos = 0;
              n_neg = 0;
            }
         
            // set up negative and positive titles with the correct grammar, votes, and usernames
            title_pos = (n_pos == 1 ? config.title_like_singular : config.title_like_plural).replace(/%\{USERNAME\}/g, pseudo).replace(/%\{VOTES\}/g, n_pos);
            title_neg = (n_neg == 1 ? config.title_dislike_singular : config.title_dislike_plural).replace(/%\{USERNAME\}/g, pseudo).replace(/%\{VOTES\}/g, n_neg);
         
            // define the vote counts
            li.innerHTML = '<span class="fa_count fa_positive" title="' + title_pos + '">' + n_pos + '</span>' + (config.negative_vote ? '&nbsp;<span class="fa_count fa_negative" title="' + title_neg + '">' + n_neg + '</span>' : '');
            span = li.getElementsByTagName('SPAN'); // get the vote count containers for use as insertion points
         
            // create positive vote button
            plus = document.createElement('A');
            plus.href = button[0] ? button[0].firstChild.href : '#';
            plus.onclick = button[0] ? submit_vote : function() { return false };
            plus.className = 'fa_vote' + (button[0] ? '' : 'd') + ' fa_plus';
            plus.innerHTML = config.icon_plus;
            plus.title = (button[0] ? config.title_plus : title_pos).replace(/%\{USERNAME\}/g, pseudo);
         
            span[0] && li.insertBefore(plus, span[0]);
         
            // create negative vote button
            if (config.negative_vote) {
              minus = document.createElement('A');
              minus.href = button[1] ? button[1].firstChild.href : '#';
              minus.onclick = button[1] ? submit_vote : function() { return false };
              minus.className = 'fa_vote' + (button[1] ? '' : 'd') + ' fa_minus';
              minus.innerHTML = config.icon_minus;
              minus.title = (button[1] ? config.title_minus : title_neg).replace(/%\{USERNAME\}/g, pseudo);
           
              span[1] && li.insertBefore(minus, span[1]);
            }
         
            // create vote bar
            if (config.vote_bar) {
              vote_bar = document.createElement('DIV');
              vote_bar.className = 'fa_votebar';
              vote_bar.innerHTML = '<div class="fa_votebar_inner" style="width:' + percent + '%;"></div>';
              vote_bar.style.display = bar ? '' : 'none';
              li.title = config.title_vote_bar.replace(/%\{USERNAME\}/, pseudo).replace(/%\{VOTES\}/, n_pos + '/' + (n_pos + n_neg)).replace(/%\{PERCENT\}/, '(' + percent + '%)');
              li.appendChild(vote_bar);
            }
         
            // finally insert the vote system and remove the default one
            config.position_left ? ul.insertBefore(li, ul.firstChild) : ul.appendChild(li);
            vote[i].parentNode.removeChild(vote[i]);
          }
        });

Αν δεν δουλέψει και αυτό σημαίνει ότι δεν υποστηρίζει το javascript τα πρότυπα του blog.
Van-Helsing

Van-Helsing
Διαχειριστής
Διαχειριστής

Άντρας
Ηλικία : 49
Δημοσιεύσεις : 1990



Van-Helsing ο/η συγγραφέας σας ευχαριστήσε για την απάντησή σας.

Λύθηκε Απ: Πρόβλημα με Likes σε blog

Δημοσίευση από Giotis Πεμ Ιουλ 14, 2016 9:32 pm

Δυστυχώς δεν άλλαξε κάτι. Αν θέλετε αφήστε λίγο ακόμα το θέμα ανοιχτό μήπως βρω κάποια λύση.
Giotis

Giotis
Νικητής διαγωνισμού
Νικητής διαγωνισμού

Δημοσιεύσεις : 90



Giotis ο/η συγγραφέας σας ευχαριστήσε για την απάντησή σας.

Λύθηκε Απ: Πρόβλημα με Likes σε blog

Δημοσίευση από Giotis Δευ Σεπ 05, 2016 12:27 am

Καλησπέρα. Έκανα μια αλλαγή στον κώδικα ώστε να μην εμφανίζει τα κουμπιά Like/Dislike στα blogs αλλά τα κλασικά +/-.
Ουσιαστικά έτσι το script εξαιρεί τα blogs και τρέχει μόνο στα forums με την κλασική μορφή.

Παραθέτω τον κώδικα...

Κώδικας:
       $(function() {
         //blog exception
         var myElem = document.getElementById('blog_comments');
         if (myElem == null){

          // General Configuration of the plugin
          var config = {
            position_left : true, // true for left || false for right
            negative_vote : true, // true for negative votes || false for positive only
            vote_bar : true, // display a small bar under the vote buttons
          
            // button config
            icon_plus : '<img src="http://i18.servimg.com/u/f18/18/21/41/30/plus10.png" alt="+"/>',
            icon_minus : '<img src="http://i18.servimg.com/u/f18/18/21/41/30/minus10.png" alt="-"/>',
          
            // language config
            title_plus : 'Like %{USERNAME}\'s post',
            title_minus : 'Dislike %{USERNAME}\'s post',
          
            title_like_singular : '%{VOTES} person likes %{USERNAME}\'s post',
            title_like_plural : '%{VOTES} people like %{USERNAME}\'s post',
          
            title_dislike_singular : '%{VOTES} person dislikes %{USERNAME}\'s post',
            title_dislike_plural : '%{VOTES} people dislike %{USERNAME}\'s post',
          
            title_vote_bar : '%{VOTES} people liked %{USERNAME}\'s post %{PERCENT}'
          },
            
            
          // function bound to the onclick handler of the vote buttons
          submit_vote = function() {
            var next = this.nextSibling, // the counter next to the vote button that was clicked
                box = this.parentNode,
                bar = box.getElementsByTagName('DIV'),
                vote = box.getElementsByTagName('A'),
                mode = /eval=plus/.test(this.href) ? 1 : 0,
                i = 0, j = vote.length, pos, neg, percent;
          
            // submit the vote asynchronously
            $.get(this.href, function() {
              next.innerHTML = +next.innerHTML + 1; // add to the vote count
              next.title = next.title.replace(/(\d+)/, function(M, $1) { return +$1 + 1 });
            
              pos = +vote[0].nextSibling.innerHTML;
              neg = vote[1] ? +vote[1].nextSibling.innerHTML : 0;
              percent = pos == 0 ? '0%' : pos == neg ? '50%' : Math.round(pos / (pos + neg) * 100) + '%';
            
              if (bar[0]) {
                bar[0].style.display = '';
                bar[0].firstChild.style.width = percent;
                box.title = box.title.replace(/\d+\/\d+/, pos + '/' + ( pos + neg )).replace(/\(\d+%\)/, '(' + percent + ')');
              }
            });
          
            // revoke voting capabilities on the post once the vote is cast
            for (; i < j; i++) {
              vote[i].href = '#';
              vote[i].className = vote[i].className.replace(/fa_vote/, 'fa_voted');
              vote[i].onclick = function() { return false };
            }
          
            return false;
          },
            
          vote = $('.vote'), i = 0, j = vote.length,
          version = $('.bodylinewidth')[0] ? 0 : document.getElementById('wrap') ? 1 : $('.pun')[0] ? 2 : document.getElementById('ipbwrapper') ? 3 : 'badapple', // version check
        
          // version data so we don't have to redefine these arrays during the loop
          vdata = {
            tag : ['SPAN', 'LI', 'SPAN', 'LI'][version],
            name : ['.name', '.postprofile dt > strong', '.username', '.popmenubutton'][version],
            actions : ['.post-options', '.profile-icons', '.post-options', '.posting-icons'][version],
          },
        
          post, plus, minus, n_pos, n_neg, title_pos, title_neg, li, ul, bar, button, total, percent, span, pseudo, vote_bar; // startup variables for later use in the loop
        
          // prevent execution if the version cannot be determined
          if (version == 'badapple') {
            if (window.console) console.warn('This plugin is not optimized for your forum version. Please contact the support for further assistance.');
            return;
          }
        
          for (; i < j; i++) {
            post = $(vote[i]).parentsUntil('.post').parent()[0];
            bar = $('.vote-bar', vote[i])[0]; // vote bar
            button = $('.vote-button', vote[i]); // plus and minus buttons
            pseudo = $(vdata.name, post).text() || 'MISSING_STRING'; // username of the poster
            ul = $(vdata.actions, post)[0]; // post actions
            li = document.createElement(vdata.tag); // vote system container
            li.className = 'fa_reputation';
          
            if (li.tagName == 'SPAN') li.style.display = 'inline-block';
          
            // calculate votes
            if (bar) {
              total = +bar.title.replace(/.*?\((\d+).*/, '$1');
              percent = +bar.title.replace(/.*?(\d+)%.*/, '$1');
            
              n_pos = Math.round(total * (percent / 100));
              n_neg = total - n_pos;
            } else {
              n_pos = 0;
              n_neg = 0;
            }
          
            // set up negative and positive titles with the correct grammar, votes, and usernames
            title_pos = (n_pos == 1 ? config.title_like_singular : config.title_like_plural).replace(/%\{USERNAME\}/g, pseudo).replace(/%\{VOTES\}/g, n_pos);
            title_neg = (n_neg == 1 ? config.title_dislike_singular : config.title_dislike_plural).replace(/%\{USERNAME\}/g, pseudo).replace(/%\{VOTES\}/g, n_neg);
          
            // define the vote counts
            li.innerHTML = '<span class="fa_count fa_positive" title="' + title_pos + '">' + n_pos + '</span>' + (config.negative_vote ? '&nbsp;<span class="fa_count fa_negative" title="' + title_neg + '">' + n_neg + '</span>' : '');
            span = li.getElementsByTagName('SPAN'); // get the vote count containers for use as insertion points
          
            // create positive vote button
            plus = document.createElement('A');
            plus.href = button[0] ? button[0].firstChild.href : '#';
            plus.onclick = button[0] ? submit_vote : function() { return false };
            plus.className = 'fa_vote' + (button[0] ? '' : 'd') + ' fa_plus';
            plus.innerHTML = config.icon_plus;
            plus.title = (button[0] ? config.title_plus : title_pos).replace(/%\{USERNAME\}/g, pseudo);
          
            span[0] && li.insertBefore(plus, span[0]);
          
            // create negative vote button
            if (config.negative_vote) {
              minus = document.createElement('A');
              minus.href = button[1] ? button[1].firstChild.href : '#';
              minus.onclick = button[1] ? submit_vote : function() { return false };
              minus.className = 'fa_vote' + (button[1] ? '' : 'd') + ' fa_minus';
              minus.innerHTML = config.icon_minus;
              minus.title = (button[1] ? config.title_minus : title_neg).replace(/%\{USERNAME\}/g, pseudo);
            
              span[1] && li.insertBefore(minus, span[1]);
            }
          
            // create vote bar
            if (config.vote_bar) {
              vote_bar = document.createElement('DIV');
              vote_bar.className = 'fa_votebar';
              vote_bar.innerHTML = '<div class="fa_votebar_inner" style="width:' + percent + '%;"></div>';
              vote_bar.style.display = bar ? '' : 'none';
              li.title = config.title_vote_bar.replace(/%\{USERNAME\}/, pseudo).replace(/%\{VOTES\}/, n_pos + '/' + (n_pos + n_neg)).replace(/%\{PERCENT\}/, '(' + percent + '%)');
              li.appendChild(vote_bar);
            }
          
            // finally insert the vote system and remove the default one
            config.position_left ? ul.insertBefore(li, ul.firstChild) : ul.appendChild(li);
            vote[i].parentNode.removeChild(vote[i]);
          }
  
  
 }//end blog exception
        });
Giotis

Giotis
Νικητής διαγωνισμού
Νικητής διαγωνισμού

Δημοσιεύσεις : 90



Giotis ο/η συγγραφέας σας ευχαριστήσε για την απάντησή σας.

Λύθηκε Απ: Πρόβλημα με Likes σε blog

Δημοσίευση από Luffy Δευ Σεπ 05, 2016 11:33 am

Giotis έγραψε:Καλησπέρα. Έκανα μια αλλαγή στον κώδικα ώστε να μην εμφανίζει τα κουμπιά Like/Dislike στα blogs αλλά τα κλασικά +/-.
Ουσιαστικά έτσι το script εξαιρεί τα blogs και τρέχει μόνο στα forums με την κλασική μορφή.

Παραθέτω τον κώδικα...

Κώδικας:
       $(function() {
         //blog exception
         var myElem = document.getElementById('blog_comments');
         if (myElem == null){

          // General Configuration of the plugin
          var config = {
            position_left : true, // true for left || false for right
            negative_vote : true, // true for negative votes || false for positive only
            vote_bar : true, // display a small bar under the vote buttons
          
            // button config
            icon_plus : '<img src="http://i18.servimg.com/u/f18/18/21/41/30/plus10.png" alt="+"/>',
            icon_minus : '<img src="http://i18.servimg.com/u/f18/18/21/41/30/minus10.png" alt="-"/>',
          
            // language config
            title_plus : 'Like %{USERNAME}\'s post',
            title_minus : 'Dislike %{USERNAME}\'s post',
          
            title_like_singular : '%{VOTES} person likes %{USERNAME}\'s post',
            title_like_plural : '%{VOTES} people like %{USERNAME}\'s post',
          
            title_dislike_singular : '%{VOTES} person dislikes %{USERNAME}\'s post',
            title_dislike_plural : '%{VOTES} people dislike %{USERNAME}\'s post',
          
            title_vote_bar : '%{VOTES} people liked %{USERNAME}\'s post %{PERCENT}'
          },
            
            
          // function bound to the onclick handler of the vote buttons
          submit_vote = function() {
            var next = this.nextSibling, // the counter next to the vote button that was clicked
                box = this.parentNode,
                bar = box.getElementsByTagName('DIV'),
                vote = box.getElementsByTagName('A'),
                mode = /eval=plus/.test(this.href) ? 1 : 0,
                i = 0, j = vote.length, pos, neg, percent;
          
            // submit the vote asynchronously
            $.get(this.href, function() {
              next.innerHTML = +next.innerHTML + 1; // add to the vote count
              next.title = next.title.replace(/(\d+)/, function(M, $1) { return +$1 + 1 });
            
              pos = +vote[0].nextSibling.innerHTML;
              neg = vote[1] ? +vote[1].nextSibling.innerHTML : 0;
              percent = pos == 0 ? '0%' : pos == neg ? '50%' : Math.round(pos / (pos + neg) * 100) + '%';
            
              if (bar[0]) {
                bar[0].style.display = '';
                bar[0].firstChild.style.width = percent;
                box.title = box.title.replace(/\d+\/\d+/, pos + '/' + ( pos + neg )).replace(/\(\d+%\)/, '(' + percent + ')');
              }
            });
          
            // revoke voting capabilities on the post once the vote is cast
            for (; i < j; i++) {
              vote[i].href = '#';
              vote[i].className = vote[i].className.replace(/fa_vote/, 'fa_voted');
              vote[i].onclick = function() { return false };
            }
          
            return false;
          },
            
          vote = $('.vote'), i = 0, j = vote.length,
          version = $('.bodylinewidth')[0] ? 0 : document.getElementById('wrap') ? 1 : $('.pun')[0] ? 2 : document.getElementById('ipbwrapper') ? 3 : 'badapple', // version check
        
          // version data so we don't have to redefine these arrays during the loop
          vdata = {
            tag : ['SPAN', 'LI', 'SPAN', 'LI'][version],
            name : ['.name', '.postprofile dt > strong', '.username', '.popmenubutton'][version],
            actions : ['.post-options', '.profile-icons', '.post-options', '.posting-icons'][version],
          },
        
          post, plus, minus, n_pos, n_neg, title_pos, title_neg, li, ul, bar, button, total, percent, span, pseudo, vote_bar; // startup variables for later use in the loop
        
          // prevent execution if the version cannot be determined
          if (version == 'badapple') {
            if (window.console) console.warn('This plugin is not optimized for your forum version. Please contact the support for further assistance.');
            return;
          }
        
          for (; i < j; i++) {
            post = $(vote[i]).parentsUntil('.post').parent()[0];
            bar = $('.vote-bar', vote[i])[0]; // vote bar
            button = $('.vote-button', vote[i]); // plus and minus buttons
            pseudo = $(vdata.name, post).text() || 'MISSING_STRING'; // username of the poster
            ul = $(vdata.actions, post)[0]; // post actions
            li = document.createElement(vdata.tag); // vote system container
            li.className = 'fa_reputation';
          
            if (li.tagName == 'SPAN') li.style.display = 'inline-block';
          
            // calculate votes
            if (bar) {
              total = +bar.title.replace(/.*?\((\d+).*/, '$1');
              percent = +bar.title.replace(/.*?(\d+)%.*/, '$1');
            
              n_pos = Math.round(total * (percent / 100));
              n_neg = total - n_pos;
            } else {
              n_pos = 0;
              n_neg = 0;
            }
          
            // set up negative and positive titles with the correct grammar, votes, and usernames
            title_pos = (n_pos == 1 ? config.title_like_singular : config.title_like_plural).replace(/%\{USERNAME\}/g, pseudo).replace(/%\{VOTES\}/g, n_pos);
            title_neg = (n_neg == 1 ? config.title_dislike_singular : config.title_dislike_plural).replace(/%\{USERNAME\}/g, pseudo).replace(/%\{VOTES\}/g, n_neg);
          
            // define the vote counts
            li.innerHTML = '<span class="fa_count fa_positive" title="' + title_pos + '">' + n_pos + '</span>' + (config.negative_vote ? '&nbsp;<span class="fa_count fa_negative" title="' + title_neg + '">' + n_neg + '</span>' : '');
            span = li.getElementsByTagName('SPAN'); // get the vote count containers for use as insertion points
          
            // create positive vote button
            plus = document.createElement('A');
            plus.href = button[0] ? button[0].firstChild.href : '#';
            plus.onclick = button[0] ? submit_vote : function() { return false };
            plus.className = 'fa_vote' + (button[0] ? '' : 'd') + ' fa_plus';
            plus.innerHTML = config.icon_plus;
            plus.title = (button[0] ? config.title_plus : title_pos).replace(/%\{USERNAME\}/g, pseudo);
          
            span[0] && li.insertBefore(plus, span[0]);
          
            // create negative vote button
            if (config.negative_vote) {
              minus = document.createElement('A');
              minus.href = button[1] ? button[1].firstChild.href : '#';
              minus.onclick = button[1] ? submit_vote : function() { return false };
              minus.className = 'fa_vote' + (button[1] ? '' : 'd') + ' fa_minus';
              minus.innerHTML = config.icon_minus;
              minus.title = (button[1] ? config.title_minus : title_neg).replace(/%\{USERNAME\}/g, pseudo);
            
              span[1] && li.insertBefore(minus, span[1]);
            }
          
            // create vote bar
            if (config.vote_bar) {
              vote_bar = document.createElement('DIV');
              vote_bar.className = 'fa_votebar';
              vote_bar.innerHTML = '<div class="fa_votebar_inner" style="width:' + percent + '%;"></div>';
              vote_bar.style.display = bar ? '' : 'none';
              li.title = config.title_vote_bar.replace(/%\{USERNAME\}/, pseudo).replace(/%\{VOTES\}/, n_pos + '/' + (n_pos + n_neg)).replace(/%\{PERCENT\}/, '(' + percent + '%)');
              li.appendChild(vote_bar);
            }
          
            // finally insert the vote system and remove the default one
            config.position_left ? ul.insertBefore(li, ul.firstChild) : ul.appendChild(li);
            vote[i].parentNode.removeChild(vote[i]);
          }
  
  
 }//end blog exception
        });
Καλησπέρα @Giotis,

Μα εφόσον κατάφερες να κάνεις στα blogs να είναι μόνο τα + και - γιατί δεν τα αντικαθιστάς με τα like/dislike? Αφού τρέχουν μόνο στα blogs. scratch
Luffy

Luffy
Διαχειριστής
Διαχειριστής

Άντρας
Τόπος : Ελλάδα
Δημοσιεύσεις : 2340



Luffy ο/η συγγραφέας σας ευχαριστήσε για την απάντησή σας.

Λύθηκε Απ: Πρόβλημα με Likes σε blog

Δημοσίευση από Giotis Δευ Σεπ 05, 2016 3:36 pm

Luffy έγραψε:
Giotis έγραψε:Καλησπέρα. Έκανα μια αλλαγή στον κώδικα ώστε να μην εμφανίζει τα κουμπιά Like/Dislike στα blogs αλλά τα κλασικά +/-.
Ουσιαστικά έτσι το script εξαιρεί τα blogs και τρέχει μόνο στα forums με την κλασική μορφή.

Παραθέτω τον κώδικα...

Κώδικας:
       $(function() {
         //blog exception
         var myElem = document.getElementById('blog_comments');
         if (myElem == null){

          // General Configuration of the plugin
          var config = {
            position_left : true, // true for left || false for right
            negative_vote : true, // true for negative votes || false for positive only
            vote_bar : true, // display a small bar under the vote buttons
          
            // button config
            icon_plus : '<img src="http://i18.servimg.com/u/f18/18/21/41/30/plus10.png" alt="+"/>',
            icon_minus : '<img src="http://i18.servimg.com/u/f18/18/21/41/30/minus10.png" alt="-"/>',
          
            // language config
            title_plus : 'Like %{USERNAME}\'s post',
            title_minus : 'Dislike %{USERNAME}\'s post',
          
            title_like_singular : '%{VOTES} person likes %{USERNAME}\'s post',
            title_like_plural : '%{VOTES} people like %{USERNAME}\'s post',
          
            title_dislike_singular : '%{VOTES} person dislikes %{USERNAME}\'s post',
            title_dislike_plural : '%{VOTES} people dislike %{USERNAME}\'s post',
          
            title_vote_bar : '%{VOTES} people liked %{USERNAME}\'s post %{PERCENT}'
          },
            
            
          // function bound to the onclick handler of the vote buttons
          submit_vote = function() {
            var next = this.nextSibling, // the counter next to the vote button that was clicked
                box = this.parentNode,
                bar = box.getElementsByTagName('DIV'),
                vote = box.getElementsByTagName('A'),
                mode = /eval=plus/.test(this.href) ? 1 : 0,
                i = 0, j = vote.length, pos, neg, percent;
          
            // submit the vote asynchronously
            $.get(this.href, function() {
              next.innerHTML = +next.innerHTML + 1; // add to the vote count
              next.title = next.title.replace(/(\d+)/, function(M, $1) { return +$1 + 1 });
            
              pos = +vote[0].nextSibling.innerHTML;
              neg = vote[1] ? +vote[1].nextSibling.innerHTML : 0;
              percent = pos == 0 ? '0%' : pos == neg ? '50%' : Math.round(pos / (pos + neg) * 100) + '%';
            
              if (bar[0]) {
                bar[0].style.display = '';
                bar[0].firstChild.style.width = percent;
                box.title = box.title.replace(/\d+\/\d+/, pos + '/' + ( pos + neg )).replace(/\(\d+%\)/, '(' + percent + ')');
              }
            });
          
            // revoke voting capabilities on the post once the vote is cast
            for (; i < j; i++) {
              vote[i].href = '#';
              vote[i].className = vote[i].className.replace(/fa_vote/, 'fa_voted');
              vote[i].onclick = function() { return false };
            }
          
            return false;
          },
            
          vote = $('.vote'), i = 0, j = vote.length,
          version = $('.bodylinewidth')[0] ? 0 : document.getElementById('wrap') ? 1 : $('.pun')[0] ? 2 : document.getElementById('ipbwrapper') ? 3 : 'badapple', // version check
        
          // version data so we don't have to redefine these arrays during the loop
          vdata = {
            tag : ['SPAN', 'LI', 'SPAN', 'LI'][version],
            name : ['.name', '.postprofile dt > strong', '.username', '.popmenubutton'][version],
            actions : ['.post-options', '.profile-icons', '.post-options', '.posting-icons'][version],
          },
        
          post, plus, minus, n_pos, n_neg, title_pos, title_neg, li, ul, bar, button, total, percent, span, pseudo, vote_bar; // startup variables for later use in the loop
        
          // prevent execution if the version cannot be determined
          if (version == 'badapple') {
            if (window.console) console.warn('This plugin is not optimized for your forum version. Please contact the support for further assistance.');
            return;
          }
        
          for (; i < j; i++) {
            post = $(vote[i]).parentsUntil('.post').parent()[0];
            bar = $('.vote-bar', vote[i])[0]; // vote bar
            button = $('.vote-button', vote[i]); // plus and minus buttons
            pseudo = $(vdata.name, post).text() || 'MISSING_STRING'; // username of the poster
            ul = $(vdata.actions, post)[0]; // post actions
            li = document.createElement(vdata.tag); // vote system container
            li.className = 'fa_reputation';
          
            if (li.tagName == 'SPAN') li.style.display = 'inline-block';
          
            // calculate votes
            if (bar) {
              total = +bar.title.replace(/.*?\((\d+).*/, '$1');
              percent = +bar.title.replace(/.*?(\d+)%.*/, '$1');
            
              n_pos = Math.round(total * (percent / 100));
              n_neg = total - n_pos;
            } else {
              n_pos = 0;
              n_neg = 0;
            }
          
            // set up negative and positive titles with the correct grammar, votes, and usernames
            title_pos = (n_pos == 1 ? config.title_like_singular : config.title_like_plural).replace(/%\{USERNAME\}/g, pseudo).replace(/%\{VOTES\}/g, n_pos);
            title_neg = (n_neg == 1 ? config.title_dislike_singular : config.title_dislike_plural).replace(/%\{USERNAME\}/g, pseudo).replace(/%\{VOTES\}/g, n_neg);
          
            // define the vote counts
            li.innerHTML = '<span class="fa_count fa_positive" title="' + title_pos + '">' + n_pos + '</span>' + (config.negative_vote ? '&nbsp;<span class="fa_count fa_negative" title="' + title_neg + '">' + n_neg + '</span>' : '');
            span = li.getElementsByTagName('SPAN'); // get the vote count containers for use as insertion points
          
            // create positive vote button
            plus = document.createElement('A');
            plus.href = button[0] ? button[0].firstChild.href : '#';
            plus.onclick = button[0] ? submit_vote : function() { return false };
            plus.className = 'fa_vote' + (button[0] ? '' : 'd') + ' fa_plus';
            plus.innerHTML = config.icon_plus;
            plus.title = (button[0] ? config.title_plus : title_pos).replace(/%\{USERNAME\}/g, pseudo);
          
            span[0] && li.insertBefore(plus, span[0]);
          
            // create negative vote button
            if (config.negative_vote) {
              minus = document.createElement('A');
              minus.href = button[1] ? button[1].firstChild.href : '#';
              minus.onclick = button[1] ? submit_vote : function() { return false };
              minus.className = 'fa_vote' + (button[1] ? '' : 'd') + ' fa_minus';
              minus.innerHTML = config.icon_minus;
              minus.title = (button[1] ? config.title_minus : title_neg).replace(/%\{USERNAME\}/g, pseudo);
            
              span[1] && li.insertBefore(minus, span[1]);
            }
          
            // create vote bar
            if (config.vote_bar) {
              vote_bar = document.createElement('DIV');
              vote_bar.className = 'fa_votebar';
              vote_bar.innerHTML = '<div class="fa_votebar_inner" style="width:' + percent + '%;"></div>';
              vote_bar.style.display = bar ? '' : 'none';
              li.title = config.title_vote_bar.replace(/%\{USERNAME\}/, pseudo).replace(/%\{VOTES\}/, n_pos + '/' + (n_pos + n_neg)).replace(/%\{PERCENT\}/, '(' + percent + '%)');
              li.appendChild(vote_bar);
            }
          
            // finally insert the vote system and remove the default one
            config.position_left ? ul.insertBefore(li, ul.firstChild) : ul.appendChild(li);
            vote[i].parentNode.removeChild(vote[i]);
          }
  
  
 }//end blog exception
        });
Καλησπέρα @Giotis,

Μα εφόσον κατάφερες να κάνεις στα blogs να είναι μόνο τα + και - γιατί δεν τα αντικαθιστάς με τα like/dislike? Αφού τρέχουν μόνο στα blogs. scratch

Τα εμφανίζει και πάλι όλα μαζί στο πάνω μέρος. Δεν μπόρεσα να το φτιάξω. Κάτι παίζει με την αντικατάσταση των εικονιδίων αλλά δεν το βρίσκω.
Γι' αυτό έβαλα όλον τον κώδικα του script μέσα σε μία if που εξαιρεί τα blogs. Δεν πείραξα τον υπάρχοντα κώδικα.

Οι εντολές που πρόσθεσα ουσιαστικά είναι αυτές:

Κώδικας:
var myElem = document.getElementById('blog_comments');
         if (myElem == null){
               ...
         }
Giotis

Giotis
Νικητής διαγωνισμού
Νικητής διαγωνισμού

Δημοσιεύσεις : 90



Giotis ο/η συγγραφέας σας ευχαριστήσε για την απάντησή σας.

Λύθηκε Απ: Πρόβλημα με Likes σε blog

Δημοσίευση από Van-Helsing Δευ Σεπ 12, 2016 3:24 pm

Καλησπέρα @Giotis,
Απο όσο είδα στο JavaScript θα πρέπει να χρησιμοποιήσεις τη συνάρτηση remove("element_name"); ή την hide("element_name"); ώστε να διαγράφεις ή να αποκρύπτεις το element κάθε φορά που κάποιος μπαίνει στα blogs του φορουμ.
Van-Helsing

Van-Helsing
Διαχειριστής
Διαχειριστής

Άντρας
Ηλικία : 49
Δημοσιεύσεις : 1990



Van-Helsing ο/η συγγραφέας σας ευχαριστήσε για την απάντησή σας.

Λύθηκε Απ: Πρόβλημα με Likes σε blog

Δημοσίευση από Giotis Τετ Σεπ 14, 2016 1:26 am

Van-Helsing έγραψε:Καλησπέρα @Giotis,
Απο όσο είδα στο JavaScript θα πρέπει να χρησιμοποιήσεις τη συνάρτηση remove("element_name"); ή την hide("element_name"); ώστε να διαγράφεις ή να αποκρύπτεις το element κάθε φορά που κάποιος μπαίνει στα blogs του φορουμ.
Ποιο είναι όμως το element που πρέπει να αποκρύψω; Εκεί κολλάω.
Giotis

Giotis
Νικητής διαγωνισμού
Νικητής διαγωνισμού

Δημοσιεύσεις : 90



Giotis ο/η συγγραφέας σας ευχαριστήσε για την απάντησή σας.

Λύθηκε Απ: Πρόβλημα με Likes σε blog

Δημοσίευση από Van-Helsing Παρ Σεπ 16, 2016 2:40 am

Καλημέρα,
Δεν το βλέπω ενεργό το Javascript σου και έτσι το element που δημιουργεί είναι ανενεργό.
Van-Helsing

Van-Helsing
Διαχειριστής
Διαχειριστής

Άντρας
Ηλικία : 49
Δημοσιεύσεις : 1990



Van-Helsing ο/η συγγραφέας σας ευχαριστήσε για την απάντησή σας.

Λύθηκε Απ: Πρόβλημα με Likes σε blog

Δημοσίευση από Giotis Παρ Σεπ 16, 2016 4:32 pm

Εντάξει θα το ξανακοιτάξω αν και τώρα λειτουργεί μια χαρά όπως το βλέπω.
Ευχαριστώ για τη βοήθεια, το θέμα μπορεί να κλειδώσει. Smile
Giotis

Giotis
Νικητής διαγωνισμού
Νικητής διαγωνισμού

Δημοσιεύσεις : 90



Giotis ο/η συγγραφέας σας ευχαριστήσε για την απάντησή σας.

Λύθηκε Απ: Πρόβλημα με Likes σε blog

Δημοσίευση από Nemo Σαβ Σεπ 17, 2016 12:46 pm

Πρόβλημα με Likes σε blog MHDoUixΓια να διευκολύνετε τη διαχείριση των προβλημάτων, αν το δικό σας ζήτημα έχει λυθεί, παρακαλούμε να :


  • επεξεργάζεστε την πρώτη σας δημοσίευση,
  • να επιλέγετε το εικονίδιο ΛΥΘΗΚΕ και να δημοσιεύετε το θέμα


Μπορείτε επίσης να ευχαριστήσετε τα άτομα που σας βοήθησαν πατώντας στο εικονίδιο Πρόβλημα με Likes σε blog UsrblLM. Το θέμα λύθηκε κλειδώθηκε και μεταφέρεται στο Αρχείο.
Nemo

Nemo
Υπεύθυνος Φόρουμ
Υπεύθυνος Φόρουμ

Άντρας
Τόπος : Αθήνα, Ελλάδα
Δημοσιεύσεις : 1206



Nemo ο/η συγγραφέας σας ευχαριστήσε για την απάντησή σας.

Επισκόπηση προηγούμενης Θ.Ενότητας Επισκόπηση επόμενης Θ.Ενότητας Επιστροφή στην κορυφή

- Παρόμοια θέματα

Δικαιώματα σας στην κατηγορία αυτή
Δεν μπορείτε να απαντήσετε στα Θέματα αυτής της Δ.Συζήτησης