Skip to content

Commit

Permalink
Added fittext script for the hero region title.
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Mar 26, 2013
1 parent 8980418 commit b0c9a76
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
43 changes: 43 additions & 0 deletions assets/js/vendor/jquery.fittext.js
@@ -0,0 +1,43 @@
/*global jQuery */
/*!
* FitText.js 1.1
*
* Copyright 2011, Dave Rupert http://daverupert.com
* Released under the WTFPL license
* http://sam.zoy.org/wtfpl/
*
* Date: Thu May 05 14:23:00 2011 -0600
*/

(function( $ ){

$.fn.fitText = function( kompressor, options ) {

// Setup options
var compressor = kompressor || 1,
settings = $.extend({
'minFontSize' : Number.NEGATIVE_INFINITY,
'maxFontSize' : Number.POSITIVE_INFINITY
}, options);

return this.each(function(){

// Store the object
var $this = $(this);

// Resizer() resizes items based on the object width divided by the compressor * 10
var resizer = function () {
$this.css('font-size', Math.max(Math.min($this.width() / (compressor*10), parseFloat(settings.maxFontSize)), parseFloat(settings.minFontSize)));
};

// Call once to set.
resizer();

// Call on resize. Opera debounces their resize by default.
$(window).on('resize', resizer);

});

};

})( jQuery );
25 changes: 24 additions & 1 deletion lib/customizer/hero/functions.php
Expand Up @@ -22,6 +22,7 @@ function shoestrap_hero_customizer( $wp_customize ){
$settings[] = array( 'slug' => 'shoestrap_hero_background_color', 'default' => '#333333' );
$settings[] = array( 'slug' => 'shoestrap_hero_textcolor', 'default' => '#ffffff' );
$settings[] = array( 'slug' => 'shoestrap_hero_visibility', 'default' => 'front' );
$settings[] = array( 'slug' => 'shoestrap_hero_title_fittext', 'default' => '' );

foreach( $settings as $setting ){
$wp_customize->add_setting( $setting['slug'], array( 'default' => $setting['default'], 'type' => 'theme_mod', 'capability' => 'edit_theme_options' ) );
Expand All @@ -47,6 +48,10 @@ function shoestrap_hero_customizer( $wp_customize ){
$text_controls[] = array( 'setting' => 'shoestrap_hero_cta_text', 'label' => 'Call To Action Button Text', 'section' => 'shoestrap_hero', 'priority' => 3 );
$text_controls[] = array( 'setting' => 'shoestrap_hero_cta_link', 'label' => 'Call To Action Button Link', 'section' => 'shoestrap_hero', 'priority' => 4 );

//Checkbox Controls
$checkbox_controls = array();
$checkbox_controls[] = array( 'setting' => 'shoestrap_hero_title_fittext', 'label' => 'Use FitText for the Title', 'section' => 'shoestrap_hero', 'priority' => 2 );

foreach( $color_controls as $control ){
$wp_customize->add_control( new WP_Customize_Color_Control(
$wp_customize,
Expand Down Expand Up @@ -94,6 +99,16 @@ function shoestrap_hero_customizer( $wp_customize ){
));
}

foreach ( $checkbox_controls as $control ) {
$wp_customize->add_control( $control['setting'], array(
'label' => __( $control['label'], 'shoestrap' ),
'section' => $control['section'],
'settings' => $control['setting'],
'type' => 'checkbox',
'priority' => $control['priority'],
));
}

// Content of the Hero Region
$wp_customize->add_control( new Shoestrap_Customize_Textarea_Control( $wp_customize, 'shoestrap_hero_content', array(
'label' => 'Content',
Expand Down Expand Up @@ -149,4 +164,12 @@ function shoestrap_hero_content() {
</div>
<?php }
}
add_action( 'shoestrap_hero', 'shoestrap_hero_content' );
add_action( 'shoestrap_hero', 'shoestrap_hero_content' );

function shoestrap_hero_title_fittext_script() {
if ( get_theme_mod( 'shoestrap_hero_title_fittext' ) == 1 ) {
echo '<style>.hero-title { width: 100%; } </style>';
echo '<script>$(".hero-title").fitText();</script>';
}
}
add_action('wp_footer', 'shoestrap_hero_title_fittext_script', 100);
9 changes: 9 additions & 0 deletions lib/scripts.php
Expand Up @@ -21,6 +21,7 @@ function shoestrap_scripts() {
$no_radius = get_theme_mod( 'shoestrap_general_no_radius' );
$no_gradients = get_theme_mod( 'shoestrap_general_no_gradients' );
$override_js_version = get_option( 'shoestrap_override_js_version' );
$hero_title_fittext = get_theme_mod( 'shoestrap_hero_title_fittext' );

if ( $header_scripts == 1 )
$h_f = false;
Expand Down Expand Up @@ -64,12 +65,20 @@ function shoestrap_scripts() {
wp_enqueue_script('comment-reply');
}
}

if ( $hero_title_fittext == 1 ) {
wp_register_script('shoestrap_fittext', get_template_directory_uri() . '/assets/js/vendor/jquery.fittext.js', false, null, $h_f);
}

wp_register_script('modernizr', get_template_directory_uri() . '/assets/js/vendor/modernizr-2.6.2.min.js', false, null, $h_f);
wp_register_script('shoestrap_main', get_template_directory_uri() . '/assets/js/main.js', false, null, $h_f);
wp_enqueue_script('jquery');
wp_enqueue_script('modernizr');
wp_enqueue_script('shoestrap_main');

if ( $hero_title_fittext == 1 ) {
wp_enqueue_script('shoestrap_fittext');
}
}
add_action('wp_enqueue_scripts', 'shoestrap_scripts', 100);

Expand Down

0 comments on commit b0c9a76

Please sign in to comment.