Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 13

Discussione: javascript commenti

  1. #1
    Utente di HTML.it
    Registrato dal
    Sep 2011
    Messaggi
    67

    javascript commenti

    ciao ragazzi, c' è qualche santo tra di voi che può aiutarmi?
    Avrei il bisogno che il box dei commenti in blogger non appaia in automatico come per il replybox delle risposte che basta cliccare sul link "rispondi" e il box si apre e nlla stesso tempo il box normale "posta un commento" si riduce a link.
    Qualcuno sà aiutarmi a modificare il codice facendo sì che il box commenti non venga visualizzato in automatico ma appaia solo il link che poi cliccato fà comparire il box.
    Infiniti ringraziamenti a chi volesse aiutarmi.
    Posto il codice:
    codice:
    <script type='text/javascript'>
        (function() {
          var items = <data:post.commentJso/>;
          var msgs = <data:post.commentMsgs/>;
          var config = <data:post.commentConfig/>;
    
    // <![CDATA[
          var cursor = null;
          if (items && items.length > 0) {
            cursor = parseInt(items[items.length - 1].timestamp) + 1;
          }
    
          var bodyFromEntry = function(entry) {
            if (entry.gd$extendedProperty) {
              for (var k in entry.gd$extendedProperty) {
                if (entry.gd$extendedProperty[k].name == 'blogger.contentRemoved') {
                  return '<span class="deleted-comment">' + entry.content.$t + '</span>';
                }
              }
            }
            return entry.content.$t;
          }
    
          var parse = function(data) {
            cursor = null;
            var comments = [];
            if (data && data.feed && data.feed.entry) {
              for (var i = 0, entry; entry = data.feed.entry[i]; i++) {
                var comment = {};
                // comment ID, parsed out of the original id format
                var id = /blog-(\d+).post-(\d+)/.exec(entry.id.$t);
                comment.id = id ? id[2] : null;
                comment.body = bodyFromEntry(entry);
                comment.timestamp = Date.parse(entry.published.$t) + '';
                if (entry.author && entry.author.constructor === Array) {
                  var auth = entry.author[0];
                  if (auth) {
                    comment.author = {
                      name: (auth.name ? auth.name.$t : undefined),
                      profileUrl: (auth.uri ? auth.uri.$t : undefined),
                      avatarUrl: (auth.gd$image ? auth.gd$image.src : undefined)
                    };
                  }
                }
                if (entry.link) {
                  if (entry.link[2]) {
                    comment.link = comment.permalink = entry.link[2].href;
                  }
                  if (entry.link[3]) {
                    var pid = /.*comments\/default\/(\d+)\?.*/.exec(entry.link[3].href);
                    if (pid && pid[1]) {
                      comment.parentId = pid[1];
                    }
                  }
                }
                comment.deleteclass = 'item-control blog-admin';
                if (entry.gd$extendedProperty) {
                  for (var k in entry.gd$extendedProperty) {
                    if (entry.gd$extendedProperty[k].name == 'blogger.itemClass') {
                      comment.deleteclass += ' ' + entry.gd$extendedProperty[k].value;
                    } else if (entry.gd$extendedProperty[k].name == 'blogger.displayTime') {
                      comment.displayTime = entry.gd$extendedProperty[k].value;
                    }
                  }
                }
                comments.push(comment);
              }
            }
            return comments;
          };
    
          var paginator = function(callback) {
            if (hasMore()) {
              var url = config.feed + '?alt=json&v=2&orderby=published&reverse=false&max-results=50';
              if (cursor) {
                url += '&published-min=' + new Date(cursor).toISOString();
              }
              window.bloggercomments = function(data) {
                var parsed = parse(data);
                cursor = parsed.length < 50 ? null
                    : parseInt(parsed[parsed.length - 1].timestamp) + 1
                callback(parsed);
                window.bloggercomments = null;
              }
              url += '&callback=bloggercomments';
              var script = document.createElement('script');
              script.type = 'text/javascript';
              script.src = url;
              document.getElementsByTagName('head')[0].appendChild(script);
            }
          };
          var hasMore = function() {
            return !!cursor;
          };
          var getMeta = function(key, comment) {
            if ('iswriter' == key) {
              var matches = !!comment.author
                  && comment.author.name == config.authorName
                  && comment.author.profileUrl == config.authorUrl;
              return matches ? 'true' : '';
            } else if ('deletelink' == key) {
              return config.baseUri + '/delete-comment.g?blogID='
                   + config.blogId + '&postID=' + comment.id;
            } else if ('deleteclass' == key) {
              return comment.deleteclass;
            }
            return '';
          };
    
          var replybox = null;
          var replyUrlParts = null;
          var replyParent = undefined;
    
          var onReply = function(commentId, domId) {
            if (replybox == null) {
              // lazily cache replybox, and adjust to suit this style:
              replybox = document.getElementById('comment-editor');
              if (replybox != null) {
                replybox.height = '250px';
                replybox.style.display = 'block';
                replyUrlParts = replybox.src.split('#');
              }
            }
            if (replybox && (commentId !== replyParent)) {
              document.getElementById(domId).insertBefore(replybox, null);
              replybox.src = replyUrlParts[0]
                  + (commentId ? '&parentID=' + commentId : '')
                  + '#' + replyUrlParts[1];
              replyParent = commentId;
            }
          };
    
          var hash = (window.location.hash || '#').substring(1);
          var startThread, targetComment;
          if (/^comment-form_/.test(hash)) {
            startThread = hash.substring('comment-form_'.length);
          } else if (/^c[0-9]+$/.test(hash)) {
            targetComment = hash.substring(1);
          }
    
          // Configure commenting API:
          var configJso = {
            'maxDepth': config.maxThreadDepth
          };
          var provider = {
            'id': config.postId,
            'data': items,
            'loadNext': paginator,
            'hasMore': hasMore,
            'getMeta': getMeta,
            'onReply': onReply,
            'rendered': true,
            'initComment': targetComment,
            'initReplyThread': startThread,
            'config': configJso,
            'messages': msgs
          };
    
          var render = function() {
            if (window.goog && window.goog.comments) {
              var holder = document.getElementById('comment-holder');
              window.goog.comments.render(holder, provider);
            }
          };
    
          // render now, or queue to render when library loads:
          if (window.goog && window.goog.comments) {
            render();
          } else {
            window.goog = window.goog || {};
            window.goog.comments = window.goog.comments || {};
            window.goog.comments.loadQueue = window.goog.comments.loadQueue || [];
            window.goog.comments.loadQueue.push(render);
          }
        })();
    // ]]>
      </script>

  2. #2
    Posta il link alla pagina, oltre al js servono i CSS.

    Ciao

  3. #3
    Utente di HTML.it
    Registrato dal
    Sep 2011
    Messaggi
    67
    ho anche cercato di modificare i css ma con nessun risultato.
    Comunque le modifiche le sto prvando in un blog di prova http://giochieducativionline.blogspot.com/ , i css della sezione commenti dovrebbero essere gli stessi per tutti i template.

  4. #4
    Se non ho capito male, bisognerebbe fare:

    #comments {background: #ffeee4;margin-left:15px; margin-rigth: 0px;}
    diventa:
    #comments {background: #ffeee4;margin-left:15px; margin-rigth: 0px;display: none;}

    poi nel''HTML
    <div class='comments' id='comments'>
    diventa:
    codice:
    Commenti>
    <div class='comments' id='comments'>
    Ciao

    P.S.:nell'href del link per aprire "java-script" va scritto senza trattino.

  5. #5
    Utente di HTML.it
    Registrato dal
    Sep 2011
    Messaggi
    67
    luca, aggiungendo display: none; a #comments scompare tutta la sezione commenti compresi i commenti.

    Il link quindi chiude e apre tutta la sezione e comunque se qualcuno volesse una cosa del genere posso dire che funziona basta inserire il link in un altra posizione facendo sì che appaia nel post, sopra <div class='comments' id='comments'> almeno nel mio template non compare.

    Io volevo invece fare questo, ma solo per il box dove si inserisce il commento ovviamente compreso i pulsanti pubblica, anteprima, ecc.. i commenti vorrei che possano essere visibili quando si carica la pagina.

    Avevo già provato una cosa simile aggiungendo display: none; e un link ma ho solo realizzato una cosa simile a quello che mi hai suggerito. Non riesco a farlo solo per il box ecco perchè pensavo bisognasse modificare il javascript.

    come fare per ottenerlo solo per il box commenti?

    luca gazie comuque

  6. #6
    Quindi vuoi nascondere solo il form per l'aggiunta di un commento?

  7. #7
    Utente di HTML.it
    Registrato dal
    Sep 2011
    Messaggi
    67
    esatto, come per la risposte che c' è solo il link che cliccato fà apparire il form.

  8. #8
    CSS:
    #comment-editor{display:none;}
    HTML:
    codice:
    Lascia un commento
    <iframe id='comment-editor'............
    Ciao

  9. #9
    Utente di HTML.it
    Registrato dal
    Sep 2011
    Messaggi
    67
    ok, il link apre e chiude il form quindi funziona ma #comment-editor{display:none;} invece no, se inserisco altri elementi come altezza o altro la parte contenente tutto il form si modifica ma display:none; non funziona, al caricamento della pagina è sempre "aperto"

    Se chiudo il form con il link e clicco sul link rispondi, invece di apparire il form appare il link Aggiugi commento.

  10. #10
    Prova ad eliminare il rigo rosso:

    codice:
    var onReply = function(commentId, domId) {
            if (replybox == null) {
              // lazily cache replybox, and adjust to suit this style:
              replybox = document.getElementById('comment-editor');
              if (replybox != null) {
                replybox.height = '250px';
                replybox.style.display = 'block'; 
                replyUrlParts = replybox.src.split('#');
              }
            }
            if (replybox && (commentId !== replyParent)) {
              document.getElementById(domId).insertBefore(replybox, null);
              replybox.src = replyUrlParts[0]
                  + (commentId ? '&parentID=' + commentId : '')
                  + '#' + replyUrlParts[1];
              replyParent = commentId;
            }
          };

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.