Plugin Directory

Changeset 802789


Ignore:
Timestamp:
11/11/2013 10:40:49 PM (12 years ago)
Author:
ajferg
Message:

1.7.2 + 1.7.3 updates

Location:
tailored-tools
Files:
68 added
5 edited

Legend:

Unmodified
Added
Removed
  • tailored-tools/trunk/js/loader.js

    r726509 r802789  
    112112/**
    113113 *  Launch jQuery UI Tabs for .ui_tabs sections
     114 *  Revised to handle different HTML format, to handle <h2 id="something">
    114115 */
    115116var tab_counter = 0;
     
    119120    $('.ui_tabs').each(function(i, tabset) {
    120121        var ul = $( document.createElement('ul') );
    121         //var ul = $('ul');
    122122        $(tabset).find('.tab_panel').each(function() {
    123123            tab_counter++;
    124             label = $(this).find('h2:first').text();
     124            tab_id = 'tab-'+tab_counter;
     125            label = $(this).prev('h2').text();
     126            hid = $(this).prev('h2').attr('id');
     127            if (typeof hid !== 'undefined' && hid !== false) {
     128                tab_id = hid;
     129            }
     130            $(this).prev('h2').prependTo( $(this) ).removeAttr('id');
    125131            if (label == '')    label = 'TAB_TITLE_MISSING';
    126             $(ul).append('<li><a href="#tab-' + tab_counter + '"><span>' + label + '</span></a></li>');
    127             $(this).attr( 'id', 'tab-'+tab_counter );
     132            $(ul).append('<li><a href="#' + tab_id + '"><span>' + label + '</span></a></li>');
     133            $(this).attr( 'id', tab_id );
     134            // Now set up triggers for <a href="#something"> matching our tab_ids
     135            var $this = $(this);
     136            $("a[href$='#"+tab_id+"']").click(function(e) {
     137                hash = $(this).attr('href').substr($(this).attr('href').indexOf('#')+1);
     138                $('.ui-tabs a[href=#'+hash+']').click();
     139                $('html,body').animate({ scrollTop:$('.ui-tabs a[href=#'+tab_id+']').offset().top-30 },500);
     140                e.preventDefault;
     141                return false;
     142            });
    128143        });
    129144        $(ul).prependTo( $(tabset) );
     145//      alert( $(tabset).html() );
    130146        $(tabset).tabs();
     147       
    131148    });
     149//  alert('done');
     150    $('.ui-tabs').tabs('load', 2);
    132151});
    133152
     153
  • tailored-tools/trunk/lib/class.forms.php

    r795003 r802789  
    121121        $insertID = wp_insert_post(array(
    122122            'post_title'    => '',
    123             'post_content'  => serialize($data),
     123            'post_content'  => json_encode($data),
    124124            'post_status'   => 'private',
    125125            'post_type'     => $this->log_type,
     
    904904     *  Helper to fix the "Error at offset" issue
    905905     */
    906     function __unserialize($sObject) {
    907         $__ret =preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'", $sObject );
    908         return unserialize($__ret);
     906    function __unserialize($data) {
     907        // First attempt json_decode
     908        $decoded = json_decode($data);
     909        if ($decoded)   return (array) $decoded;
     910        // If not, go ahead with unseralize
     911        $data = preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'", $data );
     912        return unserialize($data);
    909913    }
    910914   
  • tailored-tools/trunk/readme.txt

    r798391 r802789  
    44Requires at least:  3.0
    55Tested up to:       3.7
    6 Stable tag:         1.7.1
     6Stable tag:         1.7.3
    77
    88Contains some helper classes to help you build custom forms.
     
    5454
    5555== Changelog ==
     56
     57= 1.7.3 =
     58* Update how the [tabs] shortcode is parsed & handled to allow for <h2 class="something"> attributes
     59* Update the related JS to handle new format, and to allow for <a href="#something"> triggers
     60
     61= 1.7.2 =
     62* Now using json_encode() instead of serialize() when saving arrays to database
     63* Maintaining backwards compat so that old logged records still readable
     64
    5665= 1.7.1 =
    5766* Fix a stylesheet problem with jquery-chosen
  • tailored-tools/trunk/shortcodes.php

    r752666 r802789  
    4242     *  Shortcode:  [tabs] for jQuery UI Tabs
    4343     *  Javascript does the heavy lifting
     44     *  Revised this to use DOMDocument instead of str_replace, to allow for <h2 id="something">
    4445     */
    4546    function shortcode_ui_tabs($atts=false, $content=null) {
     
    4849        if (substr($content, -3, 3)=='<p>') $content = substr($content, 0, -3);
    4950        $content = trim($content);
    50         // Apply a wrapper for each panel
    51         $content = str_replace('<h2>', '</div><div class="tab_panel"><h2>', $content);
    52         // Fix start and end <div> panels to avoid broken HTML
    53         if (substr($content, 0, 6)=='</div>')   $content = substr($content, 6);
    54         $content .= '</div>'."\n";
    55         // Using do_shortcode() to apply shortcodes inside the tabs
    56         $content = '<div class="ui_tabs">'."\n".do_shortcode($content)."\n".'</div>'."\n";
    57         // Add JS
     51       
     52        $dom = new DOMDocument();
     53        $dom->loadHTML( $content );
     54        // Loop H2 and wrap
     55        $nodes = $dom->getElementsByTagName('h2');
     56        foreach ($nodes as $i => $h) {
     57            $div = $dom->createElement('div');
     58            $div->setAttribute('class', 'tab_panel');
     59            while ($h->nextSibling && $h->nextSibling->localName != 'h2') {
     60                $div->appendChild( $h->nextSibling );
     61            }
     62            if ($h->nextSibling) {
     63                $h->parentNode->insertBefore($div, $h->nextSibling);
     64            } else {
     65                $h->parentNode->appendChild($div);
     66            }
     67        }
     68        // Now go through and remove empty tags
     69        $xp = new DOMXPath($dom);
     70        foreach($xp->query('//*[not(node() or self::br) or normalize-space() = ""]') as $node) {
     71            $node->parentNode->removeChild($node);
     72        }
     73       
     74        $output = preg_replace('~<(?:!DOCTYPE|/?(?:html|body))[^>]*>\s*~i', '', $dom->saveHTML());
     75        $output = '<div class="ui_tabs">'."\n".do_shortcode($output)."\n".'</div>'."\n";
     76        // Fix some strange HTML
     77        $output = str_replace('<p><form', '<form', $output);
     78        $output = str_replace('</form></p>', '</form>', $output);
     79        $output = str_replace("</form>\n</p>", '</form>', $output);
     80       
    5881        wp_enqueue_script('jquery-ui-tabs');
    59         // Return
    60         return $content;
     82        return $output;
    6183    }
    6284   
  • tailored-tools/trunk/tools.php

    r798391 r802789  
    33Plugin Name:    Tailored Tools
    44Description:    Adds some functionality to WordPress that you'll need.  (Version 1.5+ has different style rules. Do not upgrade without checking these.)
    5 Version:        1.7.1
     5Version:        1.7.3
    66Author:         Tailored Web Services
    77Author URI:     http://www.tailored.com.au
Note: See TracChangeset for help on using the changeset viewer.