function smd_pagicle($atts, $thing='') { // Plugin options extract(lAtts(array( 'container' => '#content', 'splitat' => '', 'splitwraptag' => 'h2', 'header' => 'h1', 'footer' => '', 'delete' => 'SMD_AUTO', 'wraptag' => 'div', 'wrapid' => 'smd_pag_', 'wrapclass' => 'smd_pag', 'outerwraptag' => 'div', 'outerwrapid' => 'smd_pagicle', 'focus' => 'body:400', 'animate' => 'opacity:show', 'addnavto' => '#smd_pagnav', 'navclass' => 'smd_pages', 'navactive' => 'smd_currpage', 'navdisabled' => 'smd_disabled', 'navdisplay' => 'f p # n l', ), $atts)); // Sanitize the options so we can guarantee that jQuery at least has _something_ to swing off // This part simply reaffirms the defaults above if ($splitwraptag && $splitat == "") { $splitat = ".*"; } $wraptag = ($wraptag) ? $wraptag : 'div'; $wrapid = ($wrapid) ? $wrapid : 'smd_pag_'; $wrapclass = ($wrapclass) ? $wrapclass : 'smd_pag'; $animate = ($animate) ? $animate : 'opacity:show'; $addnavto = ($addnavto) ? $addnavto : '#smd_pagnav'; $navclass = ($navclass) ? $navclass : 'smd_pages'; $navactive = ($navactive) ? $navactive : 'smd_currpage'; $navdisabled = ($navdisabled) ? $navdisabled : 'smd_disabled'; // Remove spaces between items in addnavto and make a comma-separated list $addnavto = implode(",", do_list($addnavto)); // Optional items $theclass = ($navclass) ? ' class="'.$navclass.'"' : ' class="smd_pages"'; $theactive = ($navclass && $navactive) ? ' class="'.$navclass.' '.$navactive.'"' : (($navactive) ? ' class="'.$navactive.'"' : ''); $owrap_beg = ($outerwraptag) ? '<'.$outerwraptag.(($outerwrapid) ? ' id="'.$outerwrapid.'"' : '').'>' : ''; $owrap_end = ($outerwraptag) ? '' : ''; $swrap_beg = ($splitwraptag) ? '<'.$splitwraptag.'>' : ''; $swrap_end = ($splitwraptag) ? '' : ''; // Nicify default if ($delete == "SMD_AUTO") { $delete = ($splitwraptag) ? 0 : 1; } // split the navdisplay into its characters for making a js array $navitems = implode(",", doArray(preg_split('//', $navdisplay, -1, PREG_SPLIT_NO_EMPTY), 'doQuote')); // Handle the focus element $jfocus = ''; if ($focus) { $focusItems = do_list($focus, ':'); $jfocus = (isset($focusItems[0])) ? $focusItems[0] : 'body'; $jfocustime = (isset($focusItems[1])) ? $focusItems[1] : '400'; if ($jfocus) { $jfocus = 'var pos = jQuery("' .$jfocus. '").offset();'; $jfocus .= 'jQuery("html").animate({ scrollTop: pos.top + "px" }, { duration: ' .(($jfocustime) ? $jfocustime : 400).' });'; } } // Handle the animation element $janimate = do_list($animate); $elem = array(); foreach ($janimate as $animopt) { if (trim($animopt) == '') continue; list($jobj, $jval) = do_list($animopt, ":"); $elem[] = doArray($jobj, 'doQuote'). ':'. doArray($jval, 'doQuote'); } $janimate = ($elem) ? "{" . implode(",", $elem) . "}" : ''; // Since the regex 'captures' the delimiter, the matches alternate between // a block of content (evens) and the delimiter itself (odds) $out = << var smd_pag_num = 1; var smd_pag_max = 1; function smd_pagicle() { var paged = ''; var nav = ''; var header = ''; var footer = ''; var idx = 0; var ctr = 1; var navitems = [{$navitems}]; if ('{$header}' != '') { header = jQuery("{$header}"); } if ('{$footer}' != '') { footer = jQuery("{$footer}"); } var reg = new RegExp("({$swrap_beg}{$splitat}{$swrap_end})"); jQuery("{$container}").each(function(content) { smd_pageparts = jQuery(this).html().split(reg); var capture = ''; $(smd_pageparts).each(function(part) { if (idx%2 == 1 && {$delete}==0) { // For odd parts that are not to be removed capture = this; } if (idx%2 == 0) { paged += '<{$wraptag} id="{$wrapid}' +ctr+ '" class="{$wrapclass}">' + capture + this + ''; ctr++; } idx++; }); }); smd_pag_max = ctr-1; paged = '{$owrap_beg}' +paged+ '{$owrap_end}'; jQuery("{$container}").replaceWith(paged); if (header) { jQuery(".{$wrapclass}:gt(0)").prepend(header); } if (footer) { jQuery(".{$wrapclass}:lt("+(smd_pag_max-1)+")").append(footer); } // Now add the paging options jQuery.each(navitems, function() { switch(this.toString()) { case 'f': nav += '«'; break; case 'l': nav += '»'; break; case 'p': nav += '<'; break; case 'n': nav += '>'; break; case '#': for (jdx = 1; jdx < ctr; jdx++) { nav += ' ' +jdx+ ''; } break; default: nav += ' '; break; } }); jQuery("{$addnavto}").each(function() { jQuery(this).append(nav); }); } // Display a particualr page function smd_pag_show(dir) { re = /(\+|\-)?(\d+)/; matches = re.exec(dir); if (matches[1] == "+" && smd_pag_num < smd_pag_max) { smd_pag_num++; } if (matches[1] == "-" && smd_pag_num > 1) { smd_pag_num--; } if (matches[1] == null) { smd_pag_num = matches[2]; } // Show the page thispage = "#{$wrapid}"+smd_pag_num; jQuery(".{$wrapclass}").hide(); if ("{$janimate}" != "") { jQuery(thispage).animate({$janimate}); } if (smd_pag_num==1) { jQuery("#smd_fst").addClass("{$navdisabled}"); jQuery("#smd_prv").addClass("{$navdisabled}"); } else { jQuery("#smd_fst").removeClass("{$navdisabled}"); jQuery("#smd_prv").removeClass("{$navdisabled}"); } if (smd_pag_num==smd_pag_max) { jQuery("#smd_lst").addClass("{$navdisabled}"); jQuery("#smd_nxt").addClass("{$navdisabled}"); } else { jQuery("#smd_lst").removeClass("{$navdisabled}"); jQuery("#smd_nxt").removeClass("{$navdisabled}"); } // Set the current class jQuery("a.{$navclass}").each(function() { jQuery(this).removeClass("{$navactive}"); if (jQuery(this).text() == smd_pag_num) { jQuery(this).addClass("{$navactive}"); } }); // And scroll to the top {$jfocus} return false; } jQuery(function() { smd_pagicle(); smd_pag_show(1) }); EOJS; return $out; }