WordPress.org

Plugin Directory

Changeset 541378


Ignore:
Timestamp:
05/08/12 12:58:07 (2 years ago)
Author:
chriswallace
Message:

Fixed font weight and character set saving and loading.
Updated pro plugin to use new TYPECASE_FILE constant.
Added support for symlinking to plugin.
Convert jQuery .on() to .live() for jQuery 1.6 support.

Location:
typecase/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • typecase/trunk/README.txt

    r537962 r541378  
    55Requires at least: 3.1 
    66Tested up to: 3.3.2 
    7 Stable tag: 0.3.4 
     7Stable tag: 0.3.7 
    88License: GPLv2 
    99 
     
    5656== Changelog == 
    5757 
     58= 0.3.7 = 
     59* Fixed font weight and character set loading 
     60* Added support for jQuery 1.6.1 by switching on() to live() 
     61* Added ability to symlink to Typecase without breaking the plugin 
     62* Added new class_exists() wrapper to determine if Typecase & Typecase Pro are both installed 
     63 
    5864= 0.3.4 = 
    5965* Fixed bug where fonts would eventually be hidden in Firefox on Windows. 
  • typecase/trunk/scripts/main.js

    r537453 r541378  
    6565  $( document ).ready( function(){ 
    6666 
    67     $( "#your-collection .font-list" ).on( "click", "a.delete", $( this ), removeFont ); 
    68     $( "#available-fonts" ).on( "click", "a.add", $( this ), addFont ); 
    69     $( "#available-fonts" ).on( "dblclick", ".font", $( this ), addFont ); 
    70    
    71     $( "#selectors" ).on( "click", "a.delete", $( this ), removeSelector ); 
    72     $( "#selectors" ).on( "submit", "#new-selector-form", $( this ), addSelector ); 
    73    
    74     $( "#selectors" ).on( "keyup", "#new-selector", $( this ), adjustSelectorBox ); 
    75     $( "#variants-form" ).on( "click", "input[type='checkbox']", $( this ), toggleVariant ); 
    76     $( "#subsets-form" ).on( "click", "input[type='checkbox']", $( this ), toggleSubset ); 
    77  
    78     $( ".sidebar" ).on( "click", "#save-fonts", $( this ), saveFonts ); 
    79  
    80     $( "#search" ).on( "keyup", "#search-input", $( this ), searchFonts ); 
    81    
    82     $( "#your-collection" ).on( "click", ".font", $( this ), activateFont ); 
     67    $( "#your-collection .font-list a.delete" ).live( "click", $( this ), removeFont ); 
     68    $( "#available-fonts a.add" ).live( "click", $( this ), addFont ); 
     69    $( "#available-fonts .font" ).live( "dblclick", $( this ), addFont ); 
     70   
     71    $( "#selectors a.delete" ).live( "click", $( this ), removeSelector ); 
     72    $( "#selectors #new-selector-form" ).live( "submit", $( this ), addSelector ); 
     73   
     74    $( "#selectors #new-selector" ).live( "keyup", $( this ), adjustSelectorBox ); 
     75    $( "#variants-form input[type='checkbox']" ).live( "click", $( this ), toggleVariant ); 
     76    $( "#subsets-form input[type='checkbox']" ).live( "click", $( this ), toggleSubset ); 
     77 
     78    $( ".sidebar #save-fonts" ).live( "click", $( this ), saveFonts ); 
     79 
     80    $( "#search #search-input" ).live( "keyup", $( this ), searchFonts ); 
     81   
     82    $( "#your-collection .font" ).live( "click", $( this ), activateFont ); 
    8383   
    8484    function addFont( e ) { $( e.target ).trigger( "addFont" );saveFonts();e.preventDefault(); } 
     
    137137    }); 
    138138     
    139     $("#firsttimer").find('#kill').on('click',function(e){ 
     139    $("#firsttimer").find('#kill').live('click',function(e){ 
    140140      e.preventDefault(); 
    141141      $.getJSON(ajaxurl,{ action : 'clear_firsttimer', _nonce : typecase.nonce },function(data){ 
     
    265265   
    266266      $(_this).closest("#variants-form").find("input[type='checkbox']").each(function(){ 
    267         variants += "|" + $(this).closest("label").find(".variant-name").text() + "-"; 
     267        variants += "|" + $(this).closest("label").find(".variant-name").text() + "&"; 
    268268        if ($(this).is(":checked")) variants += "1"; 
    269269        else variants += "0"; 
     
    280280   
    281281      $(_this).closest("#subsets-form").find("input[type='checkbox']").each(function(){ 
    282         subsets += "|" + $(this).closest("label").find(".subset-name").text() + "-"; 
     282        subsets += "|" + $(this).closest("label").find(".subset-name").text() + "&"; 
    283283        if ($(this).is(":checked")) subsets += "1"; 
    284284        else subsets += "0"; 
     
    312312 
    313313            $.each(Typecase.masterFontList.items[i].variants,function(){ 
    314               variants += "|" + this + "-1"; 
     314              variants += "|" + this + "&1"; 
    315315            }); 
    316316 
    317317            $.each(Typecase.masterFontList.items[i].subsets,function(){ 
    318               subsets += "|" + this + "-1"; 
     318              subsets += "|" + this + "&1"; 
    319319            }); 
    320320   
     
    394394          if (this.length !== 0) { 
    395395            var checkedMarkup = ""; 
    396             if (this.indexOf("-1") >= 0) checkedMarkup = "checked='checked'"; 
     396            if (this.indexOf("&1") >= 0) checkedMarkup = "checked='checked'"; 
    397397            variantMarkup += "<label for='variant-" + i + "'><input type='checkbox' " + checkedMarkup + " name='variant' id='variant-" + i + "'/><span class='variant-name'>"+this.slice(0,-2)+"</span></label>"; 
    398398            i++; 
     
    403403          if (this.length !== 0) { 
    404404            var checkedMarkup = ""; 
    405             if (this.indexOf("-1") >= 0) checkedMarkup = "checked='checked'"; 
     405            if (this.indexOf("&1") >= 0) checkedMarkup = "checked='checked'"; 
    406406            subsetsMarkup += "<label for='subset-" + i + "'><input type='checkbox' " + checkedMarkup + " name='subset' id='subset-" + i + "'/><span class='subset-name'>"+this.slice(0,-2)+"</span></label>"; 
    407407            i++; 
     
    490490        if( !$( "body" ).hasClass( "wf-"+family_class+"-n4-active" ) ){ 
    491491          $.each(this[1],function(){ 
    492             variants += "|" + this + "-1"; 
     492            variants += "|" + this + "&1"; 
    493493          }); 
    494494          $.each(this[2],function(){ 
    495             subsets += "|" + this + "-1"; 
     495            subsets += "|" + this + "&1"; 
    496496          }); 
    497497          $( '#available-fonts .font-list#loaded-fonts' ).append( "<div class='font "+family_class+"' data-selectors='|."+family_class+"' data-variants='"+variants+"' data-subsets='"+subsets+"' data-name='"+this[0]+"'><div class='font-meta'><ul class='font-actions'><li><a class='edit'><span></span></a></li><li><a class='preview'><span></span></a></li><li><a class='add'><span></span></a></li></ul><!--/.font-actions--><div class='font-name'>"+this[0]+"</div><div class='active-arrow'></div><!--/.active-arrow--></div><!--/.font-meta--><style type='text/css'> .font-sample span."+family_class+" { font-family: '"+this[0]+"'; } \n .wf-"+family_class+"-n4-loading .font-sample span."+family_class+" { background-image:url('"+typecase.loading_gif+"'); text-indent: -9000; display:block; overflow:hidden; background-repeat: no-repeat; background-position: center left; color: #f9f9f9; padding-left:23px; } \n .wf-"+family_class+"-n4-loading .font-sample span."+family_class+":before{ content:'loading'; color: #aaa; font-size:12px; font-family: Helvetica, Arial, Tahoma, sans-serif; text-transform:uppercase; } </style><div class='font-sample'><span class='font-item "+family_class+"'>"+Typecase.previewText+"</span></div><div class='clear'></div></div><!--/.font-->" ); 
     
    605605    }); 
    606606   
    607     $( "#more-fonts" ).on("click", function( e ){ 
     607    $( "#more-fonts" ).live("click", function( e ){ 
    608608      $(this).trigger('moreFontsLoading'); 
    609609      loadFonts(); 
  • typecase/trunk/typecase.php

    r537453 r541378  
    44Plugin URI: http://upthemes.com 
    55Description: A plugin that makes it dead simple to add custom webfonts to your website. 
    6 Version: 0.3.4 
     6Version: 0.3.7 
    77Author: UpThemes 
    88Author URI: http://upthemes.com 
     
    1313if ( !defined( 'ABSPATH' ) ) 
    1414    return; 
     15 
     16$typecase_file = __FILE__; 
     17 
     18if (isset($plugin)) { 
     19    $typecase_file = $plugin; 
     20} 
     21else if (isset($mu_plugin)) { 
     22    $typecase_file = $mu_plugin; 
     23} 
     24else if (isset($network_plugin)) { 
     25    $typecase_file = $network_plugin; 
     26} 
     27 
     28define('TYPECASE_FILE', $typecase_file); 
     29define('TYPECASE_PATH', WP_PLUGIN_DIR.'/'.basename(dirname($typecase_file))); 
    1530 
    1631/** 
     
    5974     */ 
    6075    public function __construct() { 
    61         register_activation_hook( __FILE__, array(&$this, 'activate' ) ); 
    62         register_deactivation_hook( __FILE__, array(&$this, 'deactivate' ) ); 
     76        register_activation_hook( TYPECASE_FILE, array(&$this, 'activate' ) ); 
     77        register_deactivation_hook( TYPECASE_FILE, array(&$this, 'deactivate' ) ); 
    6378 
    6479        add_action('init',array(&$this,'localization_setup')); 
     
    204219     */ 
    205220    public function localization_setup() { 
    206         load_plugin_textdomain( 'typecase', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 
     221        load_plugin_textdomain( 'typecase', false, dirname( plugin_basename( TYPECASE_FILE ) ) . '/languages/' ); 
    207222    } 
    208223 
     
    224239     */ 
    225240    public function load_menu() { 
    226         $hook = add_menu_page( $this->name, $this->name, 'manage_options', 'typecase', array(&$this, 'ui' ), plugins_url( 'images/ico_typecase.png', __FILE__ ) ); 
     241        $hook = add_menu_page( $this->name, $this->name, 'manage_options', 'typecase', array(&$this, 'ui' ), plugins_url( 'images/ico_typecase.png', TYPECASE_FILE ) ); 
    227242        add_action( 'admin_print_styles-' . $hook, array($this,'admin_styles')); 
    228243    } 
     
    247262 
    248263        wp_enqueue_script('json2'); 
    249         wp_enqueue_script('selectivizr', plugins_url( 'scripts/selectivizr-min.js', __FILE__ ), array('json2'), date( 'Ymd' ) ); 
     264        wp_enqueue_script('selectivizr', plugins_url( 'scripts/selectivizr-min.js', TYPECASE_FILE ), array('json2'), date( 'Ymd' ) ); 
    250265        wp_enqueue_script('google-api', 'https://www.google.com/jsapi', array('selectivizr'), date( 'Ymd' ) ); 
    251         wp_enqueue_script('typecase', plugins_url( 'scripts/main.js', __FILE__ ), array('jquery','google-api'), date( 'Ymd' ) ); 
    252         wp_enqueue_style('typecase', plugins_url( 'styles/main.css', __FILE__ ), false, date( 'Ymd' ) ); 
    253         wp_enqueue_style('journal-font', plugins_url( 'fonts/journal/journal.css', __FILE__ ), false, date( 'Ymd' ) ); 
    254  
    255         wp_localize_script( 'typecase', 'typecase', array( 'nonce' => wp_create_nonce($this->nonce_key), 'loading_gif' => plugins_url( 'images/loading.gif', __FILE__ ) ) ); 
     266        wp_enqueue_script('typecase', plugins_url( 'scripts/main.js', TYPECASE_FILE ), array('jquery','google-api'), date( 'Ymd' ) ); 
     267        wp_enqueue_style('typecase', plugins_url( 'styles/main.css', TYPECASE_FILE ), false, date( 'Ymd' ) ); 
     268        wp_enqueue_style('journal-font', plugins_url( 'fonts/journal/journal.css', TYPECASE_FILE ), false, date( 'Ymd' ) ); 
     269 
     270        wp_localize_script( 'typecase', 'typecase', array( 'nonce' => wp_create_nonce($this->nonce_key), 'loading_gif' => plugins_url( 'images/loading.gif', TYPECASE_FILE ) ) ); 
    256271    } 
    257272 
     
    425440            $import_url = ''; 
    426441            $font_styles = ''; 
    427             $font_weights = ''; 
    428442 
    429443            foreach($fonts as $font){ 
     
    433447                $selectors = substr( $font[1], 1); 
    434448                $weights = substr( $font[2], 1); 
    435  
    436                 $weights = explode("|",$weights); 
    437  
    438                 foreach( $weights as $i => $weight ){ 
    439                     $pos = strpos($weight, '-'); 
    440                     $weight = mb_substr($weight,0,$pos); 
    441                     if($i>0) 
    442                         $font_weights .= ","; 
    443                     else 
    444                         $font_weights .= ":"; 
    445                     $font_weights .= $weight; 
    446                 } 
     449                $charsets = substr( $font[3], 1); 
    447450 
    448451                if( $import_url != '' ) 
    449452                    $import_url .= '|'; 
    450453 
    451                 $import_url .= str_replace(" ","+",$family).$font_weights; 
     454                $import_url .= str_replace(" ","+",$family).$this->stringify_font_part($weights).$this->stringify_font_part($charsets); 
    452455 
    453456                $selectors = explode("|",$selectors); 
     
    465468            $import_fonts = "@import url($apiUrl$import_url);\n"; 
    466469 
    467             echo "\n\n<!--====== Typecase Font Declarations ======-->"; 
    468             echo "\n<style type=\"text/css\">\n"; 
    469             echo $import_fonts; 
    470             echo $font_styles; 
    471             echo "</style>\n"; 
    472             echo "<!--==-- End Typecase Font Declarations --==-->\n\n"; 
     470echo "\n<style type=\"text/css\">\n"; 
     471echo $import_fonts; 
     472echo $font_styles; 
     473echo "</style>\n"; 
     474echo "<!--==-- End Typecase Font Declarations --==-->\n\n"; 
    473475 
    474476        } 
     477    } 
     478     
     479    protected function stringify_font_part($parts){ 
     480 
     481        $parts = explode("|",$parts); 
     482        $string = ''; 
     483 
     484        foreach( $parts as $i => $part ){ 
     485 
     486            if( $i == 0 ){ 
     487                $count = 0; 
     488            } 
     489             
     490            // split font weight into pairs                  
     491            $part = explode('&',$part); 
     492 
     493            // assign 
     494            $part_id = $part[0]; 
     495            $part_status = $part[1]; 
     496 
     497            if( $part_status ){ 
     498                $count++; 
     499 
     500                if( $count == 1 ){ 
     501                    $string .= ":".$part_id; 
     502                } else { 
     503                    $string .= ",".$part_id; 
     504                } 
     505 
     506            } 
     507 
     508        } 
     509 
     510        return $string; 
     511 
    475512    } 
    476513 
     
    500537 * 
    501538 */ 
    502 if( file_exists( dirname(__FILE__) . '/pro.php' ) ){ 
    503     include_once(dirname(__FILE__) . '/pro.php'); 
     539if( file_exists( dirname(TYPECASE_FILE) . '/pro.php' ) ){ 
     540    include_once(dirname(TYPECASE_FILE) . '/pro.php'); 
    504541}else{ 
    505542    $typecase = Typecase::init(); 
Note: See TracChangeset for help on using the changeset viewer.