Article View: pl.comp.lang.javascript
Article #50227Re: Automatyczne dzielenie tekstu na strony
From: Slawek-L
Date: Wed, 01 Sep 2010 11:15
Date: Wed, 01 Sep 2010 11:15
43 lines
2580 bytes
2580 bytes
W dniu 2010-08-30 09:30, Slawek-L pisze:
> Witam,
Sam sobie odpowiem. :) Może komuś się przyda.
function splitToTabs(fromDiv, tabsDiv, tmpDiv, tabHeight)
{
var tabIndex = 1;
var contentArray = new Array;
var contentIndex =0;
contentArray = jQuery.makeArray( $(fromDiv).contents().clone() );
while ( contentIndex < contentArray.length )
{
$(tmpDiv).append( contentArray[contentIndex] );
contentIndex++;
if ( $(tmpDiv).outerHeight() > tabHeight )
{
contentIndex--;
contentArray[contentIndex] = $(tmpDiv).contents().last();
$("#tabs-"+tabIndex.toString() ).append( $(tmpDiv).contents() );
tabIndex++;
$(tabsDiv).tabs('add', '#tabs-'+tabIndex,tabIndex.toString());
$(tmpDiv).contents().remove();
}
}
if ( $(tmpDiv).contents() != null )
{
$("#tabs-"+tabIndex.toString() ).append( $(tmpDiv).contents() );
}
}
Działa mniej więcej tak: we fromDiv jest treść do podzielenia,
tabsDiv to element w którym będą zakładki, a tmpDiv to
tymczasowy div służący do przerzucania treści.
tabHeight to wysokość zakładki. Jeśli ta wysokość zostanie przekroczona
to zostaje utworzona kolejna zakładka i ciąg dalszy jest wrzucany do
następnych zakładek. tmpDiv musi mieć taką samą szerokość jak docelowa
kolumna tekstu.
Pozdrawiam
Sławek-L
Technical Details
Message-ID:
<4c7e35d7$0$22792$65785112@news.neostrada.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!newsfeed.straub-nv.de!proxad.net!feeder1-2.proxad.net!74.125.46.134.MISMATCH!postnews.google.com!news1.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx02.iad01.newshosting.com!newshosting.com!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!unt-spo-b-01.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mailReferences:
<4c7b5dfa$0$21001$65785112@news.neostrada.pl>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!newsfeed.straub-nv.de!proxad.net!feeder1-2.proxad.net!74.125.46.134.MISMATCH!postnews.google.com!news1.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx02.iad01.newshosting.com!newshosting.com!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!unt-spo-b-01.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail Date: Wed, 01 Sep 2010 13:15:36 +0200 From: Slawek-L <Slawek-L@localhost> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; pl; rv:1.9.2.8) Gecko/20100802 Thunderbird/3.1.2 MIME-Version: 1.0 Newsgroups: pl.comp.lang.javascript Subject: Re: Automatyczne dzielenie tekstu na strony References: <4c7b5dfa$0$21001$65785112@news.neostrada.pl> In-Reply-To: <4c7b5dfa$0$21001$65785112@news.neostrada.pl> Lines: 43 Message-ID: <4c7e35d7$0$22792$65785112@news.neostrada.pl> Organization: Telekomunikacja Polska NNTP-Posting-Host: 95.51.158.58 X-Trace: 1283339735 unt-rea-b-01.news.neostrada.pl 22792 95.51.158.58:51506 X-Complaints-To: abuse@news.neostrada.pl Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit