Changeset 507489
- Timestamp:
- 02/20/2012 01:10:19 AM (14 years ago)
- Location:
- web-fonts/trunk
- Files:
-
- 7 edited
-
lib/template-tags.php (modified) (2 diffs)
-
modules/google-web-fonts/google-web-fonts.php (modified) (8 diffs)
-
modules/google-web-fonts/resources/backend/google-web-fonts.js (modified) (4 diffs)
-
modules/google-web-fonts/views/backend/settings/_inc/fonts/enabled.php (modified) (1 diff)
-
resources/backend/web-fonts.js (modified) (1 diff)
-
views/backend/settings/_inc/selectors-by-font.php (modified) (1 diff)
-
web-fonts.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
web-fonts/trunk/lib/template-tags.php
r492472 r507489 5 5 } 6 6 7 function web_fonts_prepare_font_item($provider_key, $font_id, $font_name, $font_family, $font_preview = 'The Quick Brown Fox Jumped Over The Lazy Dog', $font_selectors = array() ) {7 function web_fonts_prepare_font_item($provider_key, $font_id, $font_name, $font_family, $font_preview = 'The Quick Brown Fox Jumped Over The Lazy Dog', $font_selectors = array(), $additional_styles = array()) { 8 8 return array( 9 9 'family' => $font_family, … … 12 12 'preview' => $font_preview, 13 13 'provider' => $provider_key, 14 'selectors' => (array)$font_selectors 14 'selectors' => (array)$font_selectors, 15 'additional_styles' => (array)$additional_styles 15 16 ); 16 17 } -
web-fonts/trunk/modules/google-web-fonts/google-web-fonts.php
r507482 r507489 147 147 $enabled = ($data['enabled'] == 1); 148 148 $font_data = $data['font_data']; 149 $font_key = sanitize_title_with_dashes($font_data['family_name']); 149 150 150 151 $enabled_fonts = self::get_font_data(); 151 152 152 153 if($enabled) { 153 $enabled_fonts[$font_ data['family_name']] = $font_data;154 } else { 155 unset($enabled_fonts[$font_ data['family_name']]);154 $enabled_fonts[$font_key] = $font_data; 155 } else { 156 unset($enabled_fonts[$font_key]); 156 157 } 157 158 … … 166 167 167 168 public static function add_stylesheet_fonts_and_selectors($data) { 168 $settings = self::get_settings(); 169 170 // $data['selectors'][] = $prepared_selector = web_fonts_prepare_selector_item('fonts-com', $selector_data->SelectorID, $selector_data->SelectorTag, $selector_data->SelectorFallback, 'fonts-com-' . $selector_data->SelectorFontID); 171 172 // $data['fonts'][] = web_fonts_prepare_font_item('fonts-com', $font_data->FontID, $font_data->FontName, $font_data->FontCSSName, $font_data->FontPreviewTextLong, $font_selector_map[$font_data->FontID]); 169 $enabled_fonts = self::get_font_data(); 170 $enabled_selectors = self::get_selector_data(); 171 172 $font_selector_map = array(); 173 174 foreach($enabled_selectors as $enabled_selector_id => $enabled_selector) { 175 $data['selectors'][] = $prepared_selector = web_fonts_prepare_selector_item('google-web-fonts', $enabled_selector_id, $enabled_selector['tag'], $enabled_selector['fallback'], 'google-web-fonts-' . $enabled_selector['font-id']); 176 177 if(!empty($enabled_selector['font-id']) && isset($enabled_fonts[$enabled_selector['font-id']])) { 178 if(!is_array($font_selector_map[$enabled_selector['font-id']])) { 179 $font_selector_map[$enabled_selector['font-id']] = array(); 180 } 181 $font_selector_map[$enabled_selector['font-id']][] = $prepared_selector; 182 } 183 } 184 185 foreach($enabled_fonts as $enabled_font_id => $enabled_font) { 186 $data['fonts'][] = web_fonts_prepare_font_item('google-web-fonts', $enabled_font_id, $enabled_font['family_name'], $enabled_font['family'], 'Quick Brown Fox Jumped Over The Lazy Dog', $font_selector_map[$enabled_font_id], array('font-style' => $enabled_font['style'], 'font-weight' => $enabled_font['weight'])); 187 } 173 188 174 189 return $data; … … 180 195 181 196 public static function enqueue_administrative_resources($hook) { 197 // This is a kludy hack and I hate it, but oh well - have to do it 198 if('toplevel_page_' . Web_Fonts::SETTINGS_PAGE_SLUG === $hook) { 199 self::enqueue_frontend_resources(); 200 } 201 182 202 if(!in_array($hook, self::$admin_page_hooks)) { return; } 183 203 … … 195 215 196 216 public static function enqueue_frontend_resources() { 197 217 $enabled_fonts = self::get_font_data(); 218 219 if(!empty($enabled_fonts)) { 220 $url_parts = array(); 221 foreach($enabled_fonts as $enabled_font) { 222 $url_parts[] = $enabled_font['url_param']; 223 } 224 225 $url_parts = array_filter($url_parts); 226 $url = add_query_arg(array('family' => implode('|', $url_parts)), 'http://fonts.googleapis.com/css'); 227 wp_enqueue_style('google-web-fonts', $url, array(), self::VERSION); 228 } 198 229 } 199 230 200 231 public static function handle_stylesheet_fonts($fonts) { 201 232 $selectors_to_save = array(); 233 234 foreach($fonts as $font) { 235 if('google-web-fonts' == $font->provider && is_array($font->selectors)) { 236 foreach($font->selectors as $selector) { 237 $selectors_to_save['google-web-fonts-' . $selector->tag] = array( 238 'font-id' => $font->id, 239 'fallback' => $selector->fallback, 240 'tag' => $selector->tag, 241 ); 242 } 243 } 244 } 245 246 self::set_selector_data($selectors_to_save); 202 247 203 248 return $fonts; … … 205 250 206 251 public static function handle_stylesheet_selectors($selectors) { 207 252 $selectors_to_save = array(); 253 254 foreach($selectors as $selector) { 255 $font = $selector->font; 256 257 if(is_object($font) && 0 === strpos($font->id, 'google-web-fonts-')) { 258 $selectors_to_save['google-web-fonts-' . $selector->tag] = array( 259 'font-id' => str_replace('google-web-fonts-', '', $font->id), 260 'fallback' => $selector->fallback, 261 'tag' => $selector->tag, 262 ); 263 } 264 } 265 266 self::set_selector_data($selectors_to_save); 208 267 209 268 return $selectors; … … 213 272 214 273 public static function display_styles() { 274 $font_data = self::get_font_data(); 215 275 $selector_data = self::get_selector_data(); 216 276 … … 218 278 echo "\n<!-- Google Web Fonts Style Declarations -->\n"; 219 279 echo '<style type="text/css">'; 220 foreach($selector_data as $selector => $data) { 221 printf('%s{font-family: "%s"%s;}', $selector, esc_attr($data['family']), empty($data['fallback']) ? '' : ',' . esc_attr($data['fallback'])); 280 foreach($selector_data as $selector) { 281 if(isset($font_data[$selector['font-id']])) { 282 $font = $font_data[$selector['font-id']]; 283 284 printf('%s{font-family: "%s"%s; font-style: %s, font-weight: %d}', $selector['tag'], esc_attr($font['family']), empty($selector['fallback']) ? '' : ',' . esc_attr($selector['fallback']), $font['style'], $font['weight']); 285 } 222 286 } 223 287 echo '</style>'; … … 275 339 276 340 if(!is_array($selector_data)) { 277 $selector_data = get_option(self::SELECTOR_DATA_KEY );341 $selector_data = get_option(self::SELECTOR_DATA_KEY, array()); 278 342 wp_cache_set(self::SELECTOR_DATA_KEY, $selector_data, null, time() + CACHE_PERIOD); 279 343 } -
web-fonts/trunk/modules/google-web-fonts/resources/backend/google-web-fonts.js
r507482 r507489 17 17 } 18 18 19 var web_fonts_google_view_model_font = function(family, family_name, is_enabled, style, style_string, weight, weight_string) {19 var web_fonts_google_view_model_font = function(family, family_name, is_enabled, style, style_string, url_param, weight, weight_string) { 20 20 var font = { 21 21 family: ko.observable(family), … … 24 24 style: ko.observable(style), 25 25 style_string: ko.observable(style_string), 26 url_param: ko.observable(url_param), 26 27 weight: ko.observable(weight), 27 28 weight_string: ko.observable(weight_string) … … 77 78 78 79 $.each(data.enabled_fonts, function(index, font) { 79 self.enabled_fonts.push(web_fonts_google_view_model_font(font.family, font.family_name, font.is_enabled, font.style, font.style_string, font. weight, font.weight_string));80 self.enabled_fonts.push(web_fonts_google_view_model_font(font.family, font.family_name, font.is_enabled, font.style, font.style_string, font.url_param, font.weight, font.weight_string)); 80 81 }); 81 82 82 83 $.each(data.fonts, function(index, font) { 83 84 web_fonts_google_create_style_link(font); 84 self.fonts.push(web_fonts_google_view_model_font(font.family, font.family_name, font.is_enabled, font.style, font.style_string, font. weight, font.weight_string));85 self.fonts.push(web_fonts_google_view_model_font(font.family, font.family_name, font.is_enabled, font.style, font.style_string, font.url_param, font.weight, font.weight_string)); 85 86 }); 86 87 … … 99 100 self.enabled_fonts.removeAll(); 100 101 $.each(data.enabled_fonts, function(index, font) { 101 self.enabled_fonts.push(web_fonts_google_view_model_font(font.family, font.family_name, font.is_enabled, font.style, font.style_string, font. weight, font.weight_string));102 self.enabled_fonts.push(web_fonts_google_view_model_font(font.family, font.family_name, font.is_enabled, font.style, font.style_string, font.url_param, font.weight, font.weight_string)); 102 103 }); 103 104 -
web-fonts/trunk/modules/google-web-fonts/views/backend/settings/_inc/fonts/enabled.php
r507471 r507489 2 2 <div id="google-web-fonts-enabled-fonts-list-inner"> 3 3 <h3><?php _e('Enabled Fonts'); ?></h3> 4 5 <ul data-bind="visible: enabled_fonts().length == 0"> 6 <li><?php _e('You do not have any fonts enabled.'); ?></li> 7 </ul> 4 8 5 9 <ul data-bind="foreach: enabled_fonts" id="google-web-fonts-enabled-fonts-list-items"> -
web-fonts/trunk/resources/backend/web-fonts.js
r492472 r507489 8 8 object.provider = font.provider; 9 9 object.selectors = ko.observableArray(font.selectors); 10 11 object.style_properties = { 'font-family': object.family }; 12 for(var style_property in font.additional_styles) { 13 object.style_properties[style_property] = font.additional_styles[style_property]; 14 } 10 15 11 16 // For adding a new selector to the font -
web-fonts/trunk/views/backend/settings/_inc/selectors-by-font.php
r492472 r507489 7 7 <p><em><?php _e('If you just added this font, it may take up to a minute before the preview below appears with the correct font face.'); ?></em></p> 8 8 9 <div data-bind="style: { 'font-family': family }">9 <div data-bind="style: style_properties"> 10 10 <div class="web-fonts-font-details-preview web-fonts-font-details-preview-light" data-bind="text: preview_text"></div> 11 11 -
web-fonts/trunk/web-fonts.php
r507063 r507489 21 21 22 22 //// SLUGS 23 const SETTINGS_PAGE_SLUG = 'web-fonts -settings';23 const SETTINGS_PAGE_SLUG = 'web-fonts'; 24 24 25 25 //// CACHE … … 50 50 public static function add_administrative_interface_items() { 51 51 if(!empty(self::$registered_providers)) { 52 self::$admin_page_hooks[] = $settings = add_menu_page(__('Web Fonts'), __('Web Fonts'), 'manage_options', 'web-fonts', array(__CLASS__, 'display_stylesheet_page'));53 self::$admin_page_hooks[] = $stylesheet = add_submenu_page( 'web-fonts', __('Manage Web Font Stylesheet'), __('Manage Stylesheet'), 'manage_options', 'web-fonts', array(__CLASS__, 'display_stylesheet_page'));52 self::$admin_page_hooks[] = $settings = add_menu_page(__('Web Fonts'), __('Web Fonts'), 'manage_options', self::SETTINGS_PAGE_SLUG, array(__CLASS__, 'display_stylesheet_page')); 53 self::$admin_page_hooks[] = $stylesheet = add_submenu_page(self::SETTINGS_PAGE_SLUG, __('Manage Web Font Stylesheet'), __('Manage Stylesheet'), 'manage_options', 'web-fonts', array(__CLASS__, 'display_stylesheet_page')); 54 54 55 55 add_action("load-{$stylesheet}", array(__CLASS__, 'process_manage_stylesheet')); … … 58 58 $provider_name = call_user_func(array($provider_class_name, 'get_provider_name')); 59 59 60 self::$admin_page_hooks[] = $menu_slug = add_submenu_page( 'web-fonts', sprintf(__('Web Fonts - %s'), $provider_name), $provider_name, 'manage_options', self::get_page_slug_for_provider($provider_class_name), array(__CLASS__, 'display_settings_page'));60 self::$admin_page_hooks[] = $menu_slug = add_submenu_page(self::SETTINGS_PAGE_SLUG, sprintf(__('Web Fonts - %s'), $provider_name), $provider_name, 'manage_options', self::get_page_slug_for_provider($provider_class_name), array(__CLASS__, 'display_settings_page')); 61 61 62 62 call_user_func(array($provider_class_name, 'settings_page_registered'), $menu_slug);
Note: See TracChangeset
for help on using the changeset viewer.