The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

System of automatic pagination on the images (except functional script on a technicality)

Page 1 of 2 1, 2  Next

View previous topic View next topic Go down

System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Tue Nov 08, 2016 4:53 pm

Technical Details


Forum version : #phpBB2
Position : Founder
Concerned browser(s) : Opera
Who the problem concerns : All members
Forum link : http://altitudetest.forumactif.com

Description of problem

Hello everyone,
I use a js forum that allows paginationsur images and / or text.

The tutorial comes from the French forum : http://forum.forumactif.com/t355762-pagination-dans-un-message?highlight=pagination

History automate the system, I have worked a js that allows to affix the tag page every 6 images.

the script works except on one point: the center tag is not taken into account. This centering can isolate the expanded part of the rest of the message which should not be paged.

Code:
$(function() {
   $('div.postbody').each(function() {
      $(this).find('div').first().find('img:not("[longdesc]")').attr('id', function(img) {
         return 'M14_img_' + img;
      })
   });
   $('img[id^="M14_img"]').unwrap();
});

$(function() {
   $('div.postbody').each(function() {

$(this).find('img[id^="M14_img"]').length;
$(this).find('img[id="M14_img_0"]').before('[center] ');
$(this).find('img[id="M14_img_6"]').before('[page]');
$(this).find('img[id="M14_img_12"]').before('[page]');
$(this).find('img[id="M14_img_18"]').before('[page]');
$(this).find('img[id="M14_img_24"]').before('[page]');
$(this).find('img[id="M14_img_30"]').before('[page]');
$(this).find('img[id^="M14_img"]:last').after('[/center]');


   });
});


Here is a link that allows to realize the concern
http://altitudetest.forumactif.com/t91-essai-post-photos

Would you have a solution to help me solve this little problem ?.

Thank you in advance for your help.

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by Ch@lo Valdez on Wed Nov 09, 2016 3:29 am

send me a test account please
avatar
Ch@lo Valdez
Forumember

Male Posts : 127
Reputation : 42
Language : spanish

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Wed Nov 09, 2016 12:43 pm

Hello Ch@lo Valdez,
here are the identifiers of a test account




Thank for your help Shake

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by Ch@lo Valdez on Thu Nov 10, 2016 12:00 am

i add on your main code this one, and i think is solved or not? @fascicularia
Code:

document.addEventListener('DOMContentLoaded', function () {
    var a, b, c, d, e,f, last, l, postbody = document.getElementsByClassName('postbody');
    for (l = 0; l < postbody.length; l++) {
        a = postbody[l];
        b = a.getElementsByTagName('img');
        last = b[b.length - 1].parentNode.nodeName == 'A' ? b[b.length - 1].parentNode : b[b.length - 1];
        for (c = 0; c < b.length; c++) {
            d = b[c];
            e = a.innerHTML;
            f = d.parentNode.nodeName == 'A' ? d.parentNode : d;
            (!d.hasAttribute('longdesc') && d.src.indexOf('smiles') == -1) && (d.id = 'M14_img_' + c);
            (b.length > 1 && /M14_img_0/.test(d.id)) && (f.insertAdjacentHTML('beforebegin', '[center]'));
            /M14_img_6/.test(d.id) && (f.insertAdjacentHTML('beforebegin', '[page]'));
            /M14_img_12/.test(d.id) && (f.insertAdjacentHTML('beforebegin', '[page]'));
            /M14_img_18/.test(d.id) && (f.insertAdjacentHTML('beforebegin', '[page]'));
            /M14_img_24/.test(d.id) && (f.insertAdjacentHTML('beforebegin', '[page]'));
            /M14_img_30/.test(d.id) && (f.insertAdjacentHTML('beforebegin', '[page]'));
            (b.length > 1 && last.id.indexOf('M14_img_') != -1 )&& (last.insertAdjacentHTML('afterend', '[/center]'));
            e.match(/\[center\]/g) && (a.innerHTML = e.replace(/\[center\]/, '<center>'));
            e.match(/\[\/center\]g/) && (a.innerHTML = e.replace(/\[\/center\]/, '</center>'));
        }
    }
});
avatar
Ch@lo Valdez
Forumember

Male Posts : 127
Reputation : 42
Language : spanish

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Fri Nov 11, 2016 2:02 pm

Hello Ch@lo Valdez,
We are almost there. The modification of the javascript keeps the writings of the top but those of the bottom are always integrated to the pagination.

The current js

Code:
document.addEventListener('DOMContentLoaded', function () {
    var a, b, c, d, e,f, last, l, postbody = document.getElementsByClassName('postbody');
    for (l = 0; l < postbody.length; l++) {
        a = postbody[l];
        b = a.getElementsByTagName('img');
        last = b[b.length - 1].parentNode.nodeName == 'A' ? b[b.length - 1].parentNode : b[b.length - 1];
        for (c = 0; c < b.length; c++) {
         
            d = b[c];
            e = a.innerHTML;
            f = d.parentNode.nodeName == 'A' ? d.parentNode : d;
            (!d.hasAttribute('longdesc') && d.src.indexOf('smiles') == -1) && (d.id = 'M14_img_' + c);
            (b.length > 1 && /M14_img_0/.test(d.id)) && (f.insertAdjacentHTML('beforebegin', '[center]'));
            /M14_img_6/.test(d.id) && (f.insertAdjacentHTML('beforebegin', '[page]'));
            /M14_img_12/.test(d.id) && (f.insertAdjacentHTML('beforebegin', '[page]'));
            /M14_img_18/.test(d.id) && (f.insertAdjacentHTML('beforebegin', '[page]'));
            /M14_img_24/.test(d.id) && (f.insertAdjacentHTML('beforebegin', '[page]'));
            /M14_img_30/.test(d.id) && (f.insertAdjacentHTML('beforebegin', '[page]'));
            (b.length > 1 && last.id.indexOf('M14_img_') != -1 )&& (last.insertAdjacentHTML('afterend', '[/center]'));
            e.match(/\[center\]/g) && (a.innerHTML = e.replace(/\[center\]/, '<center>'));
            e.match(/\[\/center\]g/) && (a.innerHTML = e.replace(/\[\/center\]/, '</center>'));
        }
    }
});
document.addEventListener('DOMContentLoaded', function () {
  var x= "div.postbody";
  if($("#text_editor_textarea").length && $.sceditor) {
    $(function() {
      if(!$("#text_editor_textarea").sceditor("instance")) {
        return
      }
      $('<a class="sceditor-button" unselectable="on" title="Page"><div unselectable="on" style="background:url(http://i.imgur.com/a3RgTJc.gif);opacity:1">Page</div></a>').insertAfter(".sceditor-button-fahide").click(function(e) {
        $("#text_editor_textarea").sceditor("instance").insertText("[page]")
      })
    })
  }
  var c, y, g = function(a) {
    var b;
    a = document.createElement(a);
    b = "getComputedStyle" in window;
    document.body.appendChild(a);
    b = (b ? window.getComputedStyle(a, "") : a.currentStyle).display;
    document.body.removeChild(a);
    return b
  }, t = function(o) {
    if(o.tagName == "CODE") {
      return
    }
    if(!o.hasChildNodes()) {
      return
    }
    var a = 0;
    var p = [0];
    var i;
    for(i = 0;i < o.childNodes.length;i++) {
      c = o.childNodes[i];
      if(c.nodeType == 1) {
        p.push(c);
        t(c)
      }else {
        if(c.nodeType == 3 && c.nodeValue.indexOf("[page]") != -1) {
          while((y = c.nodeValue.indexOf("[page]")) != -1) {
            if(y != 0) {
              p.push(document.createTextNode(c.nodeValue.substr(0, y)))
            }
            p.push(0);
            a++;
            c.nodeValue = c.nodeValue.substr(y + 6)
          }
          p.push(c)
        }else {
          p.push(c)
        }
      }
    }
    if(a == 0) {
      return
    }
    var b = g(o.tagName) == "block";
    for(i = 0;i < p.length;i++) {
      if(p[i] === 0) {
        y = document.createElement(b ? "DIV" : "SPAN");
        y.className = "postpage";
        o.appendChild(y)
      }else {
        y.appendChild(p[i])
      }
    }
    $("> .postpage", o).not(":first").hide();
    y = document.createElement(b ? "DIV" : "SPAN");
    y.className = "postpagination";
    $(y).append('<span class="pp_current">1</span><span>2</span>');
    if(a > 1) {
      $(y).append("<span>... " + (a + 1) + "</span>")
    }
    if(b) {
      $(y).append('<span class="pp_next">Suivant</span><span class="pp_all">Voir tout</span>')
    }else {
      $(y).append('<span class="pp_next"></span>')
    }
    o.appendChild(y);
    $(y).on("click", "span", function() {
      if($(this).hasClass("pp_all")) {
        $(this).parent().parent().children().show();
        $(this).parent().remove();
        return
      }
      var pagin = $(this).parent();
      var num = parseInt($(".pp_next", pagin).prev().text().replace(/ ?\.\.\. ?/, ""));
      var cur = parseInt($(".pp_current", pagin).text().replace(/ ?\.\.\. ?/, ""));
      if($(this).hasClass("pp_next")) {
        cur += 1
      }else {
        cur = parseInt($(this).text().replace(/ ?\.\.\. ?/, ""))
      }
      if(cur < 1) {
        cur = 1
      }else {
        if(cur > num) {
          cur = num
        }
      }
      $(".pp_next", pagin).prevUntil().remove();
      if(cur < num - 1) {
        $(pagin).prepend("<span>... " + num + "</span>")
      }else {
        if(cur == num) {
          $(pagin).prepend('<span class="pp_current">' + num + "</span>")
        }
      }
      if(cur < num) {
        $(".pp_next", pagin).show();
        $(pagin).prepend('<span class="pp_current">' + cur + "</span><span>" + (cur + 1) + "</span>")
      }else {
        $(".pp_next", pagin).hide()
      }
      if(cur > 1) {
        $(pagin).prepend("<span>" + (cur - 1) + "</span>");
        if(cur > 2) {
          $(pagin).prepend("<span>1 ...</span>")
        }
      }
      $(".postpage", $(pagin).parent()).hide();
      $(".postpage", $(pagin).parent()).eq(cur - 1).show()
    })
  };
  $(x).each(function() {
    t(this)
  })
});
In any case, a big thank you for this help.

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by Ch@lo Valdez on Fri Nov 11, 2016 2:07 pm

I don't understand what you mean
avatar
Ch@lo Valdez
Forumember

Male Posts : 127
Reputation : 42
Language : spanish

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Mon Nov 14, 2016 2:28 pm

Hello,
If a text is inserted after the images, it is automatically integrated into the pagination despite the closing of the center tag.

Is it possible to modify the js so that it acts whatever the number of images so that the text that is not paginated is not integrated as part of the pagination?

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Thu Nov 17, 2016 10:25 pm

bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Sat Nov 19, 2016 7:41 pm

bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Mon Nov 21, 2016 5:26 pm

Bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Sat Nov 26, 2016 3:26 pm

bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Tue Nov 29, 2016 12:41 pm

Bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Fri Dec 02, 2016 2:43 pm

bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Mon Dec 12, 2016 5:32 pm

bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Sun Dec 18, 2016 8:28 pm

Bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Mon Dec 26, 2016 1:50 pm

bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Tue Dec 27, 2016 5:22 pm

Bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Mon Jan 02, 2017 2:29 pm

bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Thu Jan 05, 2017 3:23 pm

bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Fri Jan 06, 2017 2:32 pm

bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Sat Jan 07, 2017 3:07 pm

Bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Tue Jan 10, 2017 5:14 pm

bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Sun Jan 15, 2017 5:05 pm

Bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Thu Jan 19, 2017 4:25 pm

bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Fri Jan 20, 2017 8:39 pm

bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Mon Jan 23, 2017 8:08 pm

Bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Fri Jan 27, 2017 3:57 pm

bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Fri Feb 03, 2017 1:09 am

bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Sat Feb 04, 2017 6:20 pm

bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Re: System of automatic pagination on the images (except functional script on a technicality)

Post by fascicularia on Tue Feb 07, 2017 7:23 pm

bump

fascicularia
Forumember

Posts : 171
Reputation : 1
Language : french

Back to top Go down

Page 1 of 2 1, 2  Next

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum