Changeset 1163686
- Timestamp:
- 05/19/2015 10:10:46 PM (11 years ago)
- Location:
- getty-images/trunk
- Files:
-
- 7 edited
-
getty-images.css (modified) (1 diff)
-
getty-images.php (modified) (4 diffs)
-
getty-templates.php (modified) (2 diffs)
-
js/getty-filters.js (modified) (1 diff)
-
js/getty-images.js (modified) (1 diff)
-
js/getty-models.js (modified) (4 diffs)
-
js/getty-views.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
getty-images/trunk/getty-images.css
r1085627 r1163686 645 645 width: 40px; 646 646 } 647 .getty-embed-attachment-details { 648 border-bottom: 1px solid #ddd; 649 padding-bottom: 11px; 650 } 647 651 648 652 /* Top-level search form */ -
getty-images/trunk/getty-images.php
r1091863 r1163686 73 73 // Register shorcodes 74 74 add_action( 'init', array( $this, 'action_init' ) ); 75 // Handle shortcode alignment 76 add_filter( 'embed_oembed_html', array( $this, 'align_embed' ), 10, 4 ); 77 // Add styles for alignment 78 add_action( 'wp_head', array( $this, 'frontend_style' ) ); 75 79 } 76 80 … … 81 85 wp_oembed_add_provider( 'http://gty.im/*', 'http://embed.gettyimages.com/oembed' ); 82 86 } 87 88 /** 89 * Filter embed shortcode html 90 * @param string $html html generated from embed shortcode 91 * @param string $url original oembed URL 92 * @param array $attr shortcode attributes 93 * @param integer $post_ID post id 94 * @return string modified or original html 95 */ 96 function align_embed( $html, $url, $attr, $post_ID ) { 97 // check that this is a getty embed 98 if ( strpos( $url, 'http://gty.im/' ) === 0 ) { 99 if ( isset( $attr['align'] ) && in_array( $attr['align'], array( 'left', 'center', 'right' ) ) ) { 100 // container div must be displayed as block, rather than inline-block for center align 101 if ( $attr['align'] == 'center' ) { 102 $html = preg_replace( '/^(<div[^>]*)inline-block/', '$1block', $html ); 103 } 104 return str_replace( 'class="', 'class="' . esc_attr( 'align' . $attr['align'] ) . ' ', $html ); 105 } 106 } 107 return $html; 108 } 109 110 /** 111 * Print some frontend styles for getty embeds that are aligned 112 */ 113 function frontend_style() { 114 ?> 115 <style> 116 .getty.alignleft { 117 margin-right: 5px; 118 } 119 .getty.alignright { 120 margin-left: 5px; 121 } 122 </style> 123 <?php 124 } 83 125 84 126 // Convenience methods for adding 'message' data to standard … … 163 205 'nonce' => wp_create_nonce( 'getty-images' ), 164 206 'sizes' => $this->get_possible_image_sizes(), 207 'embedSizes' => array( 208 'scale50' => array( 'scale' => 0.50, 'label' => __( 'Scaled 50%', 'getty-images' ) ), 209 'scale75' => array( 'scale' => 0.75, 'label' => __( 'Scaled 75%', 'getty-images' ) ), 210 ), 165 211 'isWPcom' => $isWPcom, 166 212 'text' => array( … … 226 272 'bestMatch' => __( "Best Match", 'getty-images' ), 227 273 'newest' => __( "Newest", 'getty-images' ), 274 275 'alignments' => array( 276 'none' => __( 'None', 'getty-images' ), 277 'left' => __( 'Left', 'getty-images' ), 278 'center' => __( 'Center', 'getty-images' ), 279 'right' => __( 'Right', 'getty-images' ), 280 ), 228 281 ) 229 282 ) -
getty-images/trunk/getty-templates.php
r1091863 r1163686 303 303 </dd> 304 304 <# } 305 // Specific for non logged in users (i.e. embedable images) 306 if ( !gettyImages.isWPcom && !gettyImages.user.get('loggedIn') ) { #> 307 <dt class="getty-image-caption"><?php esc_html_e( "Caption: ", 'getty-images' ); ?></dt> 308 <dd class="getty-image-caption"><p class="description">{{ data.Caption }}</p></dd> 309 310 <dt class="getty-image-alt"><?php esc_html_e( "Alt Text: ", 'getty-images' ); ?></dt> 311 <dd class="getty-image-alt"><p class="description">{{ data.Title }}</p></dd> 312 <# 313 } 305 314 } #> 306 315 </dl> … … 358 367 359 368 <script type="text/html" id="tmpl-getty-display-settings"> 360 <# if(gettyImages.isWPcom || gettyImages.user.get('loggedIn')) { #>361 369 <h3><?php esc_html_e( "Display Options", 'getty-images' ); ?></h3> 362 370 363 <div class="setting align"> 364 <span><?php esc_html_e('Align'); ?></span> 365 <select data-setting="align" data-user-setting="getty_align"> 366 <# selected = data.model.align == 'none' ? 'selected="selected"' : '' #> 367 <option value="none" {{ selected }}> 368 <?php esc_html_e('None'); ?> 369 </option> 370 <# selected = data.model.align == 'left' ? 'selected="selected"' : '' #> 371 <option value="left" {{ selected }}> 372 <?php esc_html_e('Left'); ?> 373 </option> 374 <# selected = data.model.align == 'center' ? 'selected="selected"' : '' #> 375 <option value="center" {{ selected }}> 376 <?php esc_html_e('Center'); ?> 377 </option> 378 <# selected = data.model.align == 'right' ? 'selected="selected"' : '' #> 379 <option value="right" {{ selected }}> 380 <?php esc_html_e('Right'); ?> 381 </option> 382 </select> 383 </div> 384 385 <label class="setting"> 386 <span><?php esc_html_e('Size'); ?></span> 387 <select class="size" name="size" data-setting="size" data-user-setting="getty_imgsize"> 388 <# _.each(data.model.sizes, function(size, value) { 389 var selected = data.model.size == size ? 'selected="selected"' : ''; 390 #> 391 <option value="{{ value }}" {{{ selected }}}>{{ size.label }} – {{ parseInt(size.width) }} × {{ parseInt(size.height) }}</option> 392 <# }); #> 393 </select> 394 </label> 395 396 <label class="setting alt-text"> 397 <span><?php esc_html_e('Alt Text'); ?></span> 398 <input type="text" data-setting="alt" value="{{ data.model.alt }}" data-user-setting="getty_alt" /> 399 </label> 400 401 <label class="setting caption"> 402 <span><?php esc_html_e('Caption'); ?></span> 403 <textarea data-setting="caption">{{ data.model.caption }}</textarea> 404 </label> 405 <# } else { #> 406 <dl class="getty-image-details-list"> 407 <dt class="getty-image-caption"><?php esc_html_e( "Caption: ", 'getty-images' ); ?></dt> 408 <dd class="getty-image-caption"><p class="description">{{ data.model.caption }}</p></dd> 409 410 <dt class="getty-image-alt"><?php esc_html_e( "Alt Text: ", 'getty-images' ); ?></dt> 411 <dd class="getty-image-alt"><p class="description">{{ data.model.alt }}</p></dd> 412 </dl> 413 <# } #> 371 <div class="attachment-info"> 372 <div class="setting align"> 373 <span><?php esc_html_e( 'Align' ); ?></span> 374 <select data-setting="align" data-user-setting="getty_align"> 375 <# _(gettyImages.text.alignments).each(function(text,value){ #> 376 <option value="{{ value }}" {{ ( data.model.align === value ) ? 'selected="selected"' : '' }}> 377 {{ text }} 378 </option> 379 <# }); #> 380 </select> 381 </div> 382 383 <label class="setting"> 384 <span><?php esc_html_e('Size'); ?></span> 385 <# if (data.model.downloadingSizes) { #> 386 <em><?php esc_html_e( 'Downloading sizes...', 'getty-images' ); ?></em> 387 <# } else { #> 388 <select class="size" name="size" data-setting="size" data-user-setting="getty_imgsize"> 389 <# _.each(data.model.sizes, function(size, value) { 390 var selected = data.model.size == size ? 'selected="selected"' : ''; 391 #> 392 <option value="{{ value }}" {{{ selected }}}>{{ size.label }} – {{ parseInt(size.width) }} × {{ parseInt(size.height) }}</option> 393 <# }); #> 394 </select> 395 <# } #> 396 </label> 397 398 <# if(gettyImages.isWPcom || gettyImages.user.get('loggedIn')) { #> 399 <label class="setting alt-text"> 400 <span><?php esc_html_e('Alt Text'); ?></span> 401 <input type="text" data-setting="alt" value="{{ data.model.alt }}" data-user-setting="getty_alt" /> 402 </label> 403 404 <label class="setting caption"> 405 <span><?php esc_html_e('Caption'); ?></span> 406 <textarea data-setting="caption">{{ data.model.caption }}</textarea> 407 </label> 408 <# } #> 409 </div><!--// .attachment-info --> 414 410 </script> 415 411 -
getty-images/trunk/js/getty-filters.js
r923152 r1163686 62 62 this.model.on('change', this.select, this); 63 63 64 if(!getty.user.settings.get(this.prop)) 65 getty.user.settings.set(this.prop, this.value); 64 if(typeof getty.user.settings.get(this.prop)==='undefined') { 65 getty.user.settings.set(this.prop, this.value); 66 } 66 67 67 68 this.model.set(this.prop, getty.user.settings.get(this.prop)); -
getty-images/trunk/js/getty-images.js
r1091863 r1163686 240 240 } 241 241 242 // Get display options from user 243 var display = this.display(image) 244 , align = display.get('align') || 'none' 245 , sizeSlug = display.get('size') || 'full' 246 , sizes = display.get('sizes') 247 , size = sizes[sizeSlug] 248 ; 249 242 250 if(this.get('mode') == 'embed') { 243 251 //Build the Embed code and insert it 244 252 embed_code = 'http://gty.im/' + image.get('ImageId'); 245 253 254 var attrs = {}; 255 if ( align != 'none' ) { 256 attrs.align = align; 257 } 258 259 if ( sizeSlug != 'full' ) { 260 attrs.width = size.width; 261 attrs.height = size.height; 262 } 263 264 if ( _.keys(attrs).length ) { 265 embed_code = wp.shortcode.string({ 266 tag: 'embed', 267 content: embed_code, 268 attrs: attrs, 269 }); 270 } 271 246 272 wp.media.editor.insert("\n" + embed_code + "\n"); 247 273 } else { 248 274 249 // Get display options from user250 var display = this.display(image);251 252 var align = display.get('align') || 'none';253 275 var alt = display.get('alt'); 254 276 var caption = display.get('caption'); 255 256 var sizeSlug = display.get('size');257 var sizes = display.get('sizes');258 var size = sizes[sizeSlug];259 277 260 278 if(!size) { -
getty-images/trunk/js/getty-models.js
r1091863 r1163686 1067 1067 }, this); 1068 1068 this.wpAttachment = this.attachment.get('attachment'); 1069 this.set('caption', this.attachment.get('Caption'));1070 this.set('alt', this.attachment.get('Title'));1071 1069 this.set('sizes', _.clone(getty.sizes)); 1070 //set defaults for embeds 1071 if ( !gettyImages.isWPcom && !gettyImages.user.get('loggedIn') ) { 1072 this.set({ 1073 align: 'none', 1074 size: 'full', 1075 }); 1076 } 1072 1077 this.fetch(); 1073 1078 }, … … 1097 1102 1098 1103 $(this.image).on('load', this.loadImage()); 1104 this.set('downloadingSizes',true); 1099 1105 this.image.src = url; 1100 1106 } … … 1111 1117 1112 1118 // Constrain image to image sizes 1113 _.each(gettyImages.sizes, function(size, slug) { 1114 var cr = size.width / size.height; 1115 var s = { label: size.label }; 1116 1117 s.url = this.src; 1118 1119 if(ar > cr) { 1120 // Constrain to width 1121 s.width = parseInt(size.width); 1122 s.height = parseInt(size.width / ar); 1123 } 1124 else { 1125 // Constrain to height (or square!) 1126 s.width = parseInt(ar * size.height); 1127 s.height = parseInt(size.height); 1128 } 1129 1130 sizes[slug] = s; 1131 }, this); 1119 if ( gettyImages.isWPcom || gettyImages.user.get('loggedIn') ) { 1120 _.each(gettyImages.sizes, function(size, slug) { 1121 var cr = size.width / size.height; 1122 var s = { label: size.label }; 1123 1124 s.url = this.src; 1125 1126 if(ar > cr) { 1127 // Constrain to width 1128 s.width = parseInt(size.width); 1129 s.height = parseInt(size.width / ar); 1130 } 1131 else { 1132 // Constrain to height (or square!) 1133 s.width = parseInt(ar * size.height); 1134 s.height = parseInt(size.height); 1135 } 1136 1137 sizes[slug] = s; 1138 }, this); 1139 } else { 1140 _.each(gettyImages.embedSizes, function(size, slug) { 1141 sizes[slug] = { 1142 label: size.label, 1143 width: parseInt(size.scale * this.width), 1144 height: parseInt(size.scale * this.height), 1145 }; 1146 }, this); 1147 } 1132 1148 1133 1149 sizes.full = { … … 1138 1154 } 1139 1155 1156 self.unset('downloadingSizes'); 1140 1157 self.set('sizes', sizes); 1141 1158 } -
getty-images/trunk/js/getty-views.js
r1091863 r1163686 289 289 var displayOptions = { 290 290 model: this.model.display(attachment), 291 priority: 200, 291 // for non-logged in users, put the display options higher 292 priority: (!gettyImages.isWPcom && !gettyImages.user.get('loggedIn')) ? 50 : 200, 292 293 userSettings: true 293 294 };
Note: See TracChangeset
for help on using the changeset viewer.