Skip to content

Instantly share code, notes, and snippets.

@iainurquhart
Created January 17, 2014 21:18
Show Gist options
  • Save iainurquhart/8481777 to your computer and use it in GitHub Desktop.
Save iainurquhart/8481777 to your computer and use it in GitHub Desktop.
example of image widget using P&T assets, you'll need to update the ACT id for outputting the image thumb, relevant to your install.
<table class="mainTable entry_widget_notop" border="0" cellspacing="0" cellpadding="0" data-index="0">
<tbody>
<tr>
<td style="width: 100px;">
<?php if($options['image_id']):?>
<img src="/?ACT=40&file_id=<?=$options['image_id']?>&size=100x100&hash=1361909881">
<?php endif ?>
<p><a href="#" class="thumbnail_trigger">Add File</a></p>
<div class="filename_holder" style="display:none;">
<?php echo form_hidden($field_name.'[image_id]', $options['image_id']); ?>
</div>
</td>
<td><label>Title</label>
<?php echo form_input($field_name.'[image_title]', $options['image_title']); ?>
</td>
<td style="width: 100px;"><label>Style</label>
<?php echo form_dropdown($field_name.'[image_type]', $options['image_type_options'], $options['image_type']); ?>
</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function(){
$('.thumbnail_trigger').click( function(e) {
e.preventDefault();
var td = $(this).closest("td");
var mySheet = new Assets.Sheet({
// optional settings (these are the default values):
multiSelect: false,
filedirs: 'all', // or array of filedir IDs
kinds: ['image'], // or array of file kinds ("image", "flash", etc)
// onSelect callback (required):
onSelect: function(files) {
console.log(files);
td.find(".filename_holder input").val(files[0].id);
td.find('img').remove();
td.prepend('<img src="/?ACT=40&file_id='+files[0].id+'&size=100x100&hash=1361909881">')
}
});
mySheet.show();
});
});
</script>
@bjornbjorn
Copy link

To get the thumbnail url code like this can be used:

var thumb_url = Assets.siteUrl + '?ACT=' + Assets.actions.view_thumbnail+'&file_id='+file_id+'&size=50x50&hash='+Math.random();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment