Intro
jQuery docPlugin is a set of helpers to create dynamically parts of a document and add effects to it.
The plugin works under HTML5+Bootstrap+jQuery.
Install
Put jquery.documentPlugin.js
in you js directory and docPlugin.css
in your ccs directory.
Use
Look at the logic, this is a document template inside the html body:
<div id=document">
<div><!--Chapter-->
<h2>Section title</h2>
<p>paragraph</p>
<p>paragraph</p>
<p>paragraph</p>
<h3>Sub-section</h3>
<p>paragraph</p>
<p>paragraph</p>
<p>paragraph</p>
</div>
<div><!--Chapter-->
<h2>Section title</h2>
<p>paragraph</p>
<p>paragraph</p>
<p>paragraph</p>
<h3>Sub-section</h3>
<p>paragraph</p>
<p>paragraph</p>
<p>paragraph</p>
</div>
<div><!--Chapter-->
<h2>Section title</h2>
<p>paragraph</p>
<p>paragraph</p>
<p>paragraph</p>
<h3>Sub-section</h3>
<p>paragraph</p>
<p>paragraph</p>
<p>paragraph</p>
</div>
</div>
Just add the id="document"
attribute to the text to parse.
Call the plugin you need.
There are several plugins:
- docPlugin
- tocfy
- tabfy
- footnotes
- prettyPre
- scroller
- fullpage
- sortlist
Each plugin/helper is indipendent.
$.fn.docPlugin
$.fn.docPlugin
provides for actions on the full area marked as #document
Trigger
Call the plugin on the element to parse
$("#document").docPlugin();
Options
You can configure some options
//activate fullpage on every .chapter
chapterfullpage: true, //true|false
//show chapter buttons
chapterbuttons: "top,prev,next", //false|"top,prev,next"
//prettify <pre> elements in document
prettify:true, //true|false
//activate scroller in document
scroller:true,
//set globally the scroller delta with an integer
scrollerdelta:50,
//sort each list with class .sorted
sortlist:true,
$.fn.tocfy - creates a toc
This function grabs h1/2/3/4/5 elements from a page area and creates a table of contents.
Trigger
Just call the plugin like this: $.fn.tocfy()
if you want to use the same id of docPlugin and apply the toc to the whole document.
Or call it in this way: $('#document').tocfy();
to apply on a selected element.
Options
deepness:'123456', //a string of numbers from 1 to 6 defines how deep is your menu
tocside: right, //choose :right|left|top
tocbehavior: scroll //choose:scroll|scrollFixed|fixed|offcanvas
offcanvasBtn: '#main' //if set offcanvas toc prepend here the butto for the sliding
tocliststyle: "ul square" //options: ol (decimal numbered list),ul square|circle|disc (unordered list)
data-*
This function accepts options also by data-*
attribute:
<div id="document" data-tocside="right" data-tocbehavior="scrollFixed">
...
</div>
$.fn.tabfy - show a section as tabs
If you have a page or a section like this:
<div id="sectionUniqueId">
<p class="tabitem">Title 1</p>
<div>Content</div>
<p class="tabitem">Title 2</p>
<div>Content 2</div>
<p class="tabitem">Title 3</p>
<div>Content 3</div>
...
</div>
The tabfy plugin can create a tabbed section.
Trigger
Add a unique id to the section and call the plugin $("#sectionUniqueId").tabfy()
Options:
Or by jquery trigger:
selector: the class for the items you want to tab
tabnav: tab|pill : according to bootstrap spec you can choose tab or pill
tabfade: true|false : add a fading effect to tabs
data-*
You can pass options by data-*
attribute.
<div id="uniqueId" data-tabnav="pill" data-tabfade="false">
...
</div>
Example
Lorem
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras vestibulum quis nibh vitae viverra. Donec sit amet aliquam ligula, non suscipit erat. Morbi cursus sit amet erat a cursus. Praesent dui nibh, eleifend nec vulputate vel, auctor sed quam. Aenean massa magna, fermentum et sagittis at, fringilla at sapien. Mauris bibendum lectus nibh, at consectetur nulla viverra eu. Quisque aliquet neque vitae convallis placerat. Etiam et commodo sapien, vel consectetur felis. Sed iaculis rutrum pulvinar. Interdum et malesuada fames ac ante ipsum primis in faucibus. In interdum eget tortor sit amet mattis. Curabitur non eros ligula. Duis nibh mauris, tincidunt sed commodo ac, lobortis sit amet orci. Maecenas rhoncus neque nec vestibulum tincidunt. Morbi ex neque, luctus sit amet nibh sed, ornare imperdiet nisl. Praesent venenatis gravida mollis. Duis nec maximus sem, non efficitur velit. Fusce dictum dolor cursus, vehicula neque sed, venenatis augue. Donec non turpis pharetra, aliquam ante et, volutpat sapien. Sed ornare, erat et faucibus dictum, libero urna sagittis ex, eget consequat felis tellus id risus. Aliquam et posuere tortor. Nullam convallis cursus porttitor. Aliquam auctor eget tortor sit amet auctor.
Ipsum
Sed iaculis rutrum pulvinar. Interdum et malesuada fames ac ante ipsum primis in faucibus. In interdum eget tortor sit amet mattis. Curabitur non eros ligula. Duis nibh mauris, tincidunt sed commodo ac, lobortis sit amet orci. Maecenas rhoncus neque nec vestibulum tincidunt. Morbi ex neque, luctus sit amet nibh sed, ornare imperdiet nisl. Praesent venenatis gravida mollis. Duis nec maximus sem, non efficitur velit. Fusce dictum dolor cursus, vehicula neque sed, venenatis augue. Donec non turpis pharetra, aliquam ante et, volutpat sapien. Sed ornare, erat et faucibus dictum, libero urna sagittis ex, eget consequat felis tellus id risus. Aliquam et posuere tortor. Nullam convallis cursus porttitor. Aliquam auctor eget tortor sit amet auctor.
Dolor
Interdum et malesuada fames ac ante ipsum primis in faucibus. In interdum eget tortor sit amet mattis. Curabitur non eros ligula. Duis nibh mauris, tincidunt sed commodo ac, lobortis sit amet orci. Maecenas rhoncus neque nec vestibulum tincidunt. Morbi ex neque, luctus sit amet nibh sed, ornare imperdiet nisl. Praesent venenatis gravida mollis. Duis nec maximus sem, non efficitur velit. Fusce dictum dolor cursus, vehicula neque sed, venenatis augue. Donec non turpis pharetra, aliquam ante et, volutpat sapien. Sed ornare, erat et faucibus dictum, libero urna sagittis ex, eget consequat felis tellus id risus. Aliquam et posuere tortor. Nullam convallis cursus porttitor. Aliquam auctor eget tortor sit amet auctor.
Consectetur
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras vestibulum quis nibh vitae viverra. Donec sit amet aliquam ligula, non suscipit erat. Morbi cursus sit amet erat a cursus. Praesent dui nibh, eleifend nec vulputate vel, auctor sed quam. Aenean massa magna, fermentum et sagittis at, fringilla at sapien. Mauris bibendum lectus nibh, at consectetur nulla viverra eu. Quisque aliquet neque vitae convallis placerat. Etiam et commodo sapien, vel consectetur felis. Sed iaculis rutrum pulvinar. Interdum et malesuada fames ac ante ipsum primis in faucibus. In interdum eget tortor sit amet mattis. Curabitur non eros ligula. Duis nibh mauris, tincidunt sed commodo ac, lobortis sit amet orci. Maecenas rhoncus neque nec vestibulum tincidunt. Morbi ex neque, luctus sit amet nibh sed, ornare imperdiet nisl. Praesent venenatis gravida mollis. Duis nec maximus sem, non efficitur velit. Fusce dictum dolor cursus, vehicula neque sed, venenatis augue. Donec non turpis pharetra, aliquam ante et, volutpat sapien. Sed ornare, erat et faucibus dictum, libero urna sagittis ex, eget consequat felis tellus id risus. Aliquam et posuere tortor. Nullam convallis cursus porttitor. Aliquam auctor eget tortor sit amet auctor.
Pulvinar
Sed iaculis rutrum pulvinar. Interdum et malesuada fames ac ante ipsum primis in faucibus. In interdum eget tortor sit amet mattis. Curabitur non eros ligula. Duis nibh mauris, tincidunt sed commodo ac, lobortis sit amet orci. Maecenas rhoncus neque nec vestibulum tincidunt. Morbi ex neque, luctus sit amet nibh sed, ornare imperdiet nisl. Praesent venenatis gravida mollis. Duis nec maximus sem, non efficitur velit. Fusce dictum dolor cursus, vehicula neque sed, venenatis augue. Donec non turpis pharetra, aliquam ante et, volutpat sapien. Sed ornare, erat et faucibus dictum, libero urna sagittis ex, eget consequat felis tellus id risus. Aliquam et posuere tortor. Nullam convallis cursus porttitor. Aliquam auctor eget tortor sit amet auctor.
Interdum
Interdum et malesuada fames ac ante ipsum primis in faucibus. In interdum eget tortor sit amet mattis. Curabitur non eros ligula. Duis nibh mauris, tincidunt sed commodo ac, lobortis sit amet orci. Maecenas rhoncus neque nec vestibulum tincidunt. Morbi ex neque, luctus sit amet nibh sed, ornare imperdiet nisl. Praesent venenatis gravida mollis. Duis nec maximus sem, non efficitur velit. Fusce dictum dolor cursus, vehicula neque sed, venenatis augue. Donec non turpis pharetra, aliquam ante et, volutpat sapien. Sed ornare, erat et faucibus dictum, libero urna sagittis ex, eget consequat felis tellus id risus. Aliquam et posuere tortor. Nullam convallis cursus porttitor. Aliquam auctor eget tortor sit amet auctor.
$.fn.prettyPre - pretty code boxes
With $.fn.prtettyPre
you can prettify code blocks.
Trigger
Just set prettify:true
in docPlugin options to prettify all the #document
, or load the plugin alone: $.fn.prettyPre()
The plugin ha effects only on pre
elements.
The pretty-pre CSS provides also for a class .expand
to extend the pre box with long code strings.
$.fn.fullpage - stretch a section
This plug-in extends an element to the full size of the page
Trigger
Set in docPlugin options chapterfullpage: true
to set full page for all your document main sections (chapters).
Or hook the plugin to an element:
$('.jumbotron').fullpage();
Or add the .fullpage
class to the element(s) to stretch and load the plugin alone:
$.fn.fullpage()
Options
//delta is an integer to
//subtract from the windows height
//useful if you have a navbar
delta: 50