Skip to content

Instantly share code, notes, and snippets.

@paulherron
paulherron / slug.js
Created February 4, 2014 10:46
An example of calling the jQuery Slugular plugin (https://github.com/paulherron/jquery_slugular). It uses a fairly broad selector – I just include this in the layout of my CMS and it works for most forms. It works in various different scenarios, e.g. the form having just a `title` field, or alternatively it having just a `name` field. It also ma…
$(document).ready(function() {
$("input[name$='[title]'],input[name$='name]']").slugular();
});
@paulherron
paulherron / image_upload.js
Created September 28, 2012 11:24
XHR multiple image upload
$(document).ready(function() {
var fileInput = $('#ImageImage');
var fileList = $('#file_list');
var form = $('#ImageAdminAddForm');
var fileCount = 0;
// The submit button might have loaded 'disabled' (e.g. if the page was refreshed half-way through an upload) so be sure to remove this.
$('input[type=submit]', form).removeAttr('disabled');
@paulherron
paulherron / readme.markdown
Created January 16, 2012 22:03
Creating a 'Share on Google+' URL with this Dubious Clusterhack

#Creating a 'Share on Google+' URL with this Dubious Clusterhack

Disclaimer: This is a ridiculous set of hacks. I had fun messing about with this and wanted to share it, but I wouldn't recommend using it for anything important. It may stop working at any time.
tl;dr: Google doesn't support sharing arbitrary URLs via a simple share link, but you can work around it by doing a redirect via Google, like so: https://plus.google.com/share?url=http%3A%2F%2Fgoogle.com%2Fsearch%3FbtnI%3D1%26q%3Dshowstudio%26sourceid%3Dnavclient

Most social sites let you share a link by visiting a special URL, for example:

Twitter. http://twitter.com/home?status=http://showstudio.com
Facebook. http://www.facebook.com/sharer.php?u=http://showstudio.com

@paulherron
paulherron / readme.txt
Created June 18, 2011 11:53
jQuery script to populate a specified input with a suggested slug. For example, if I write 'My Title' in a title field, it can populate the slug field with a suggestion of 'my_title'.
Video demo at http://screencast.com/t/WcjpL2lc.
By default it uses a title field ending in [title] or [name] as the source field, and a field ending in [slug] as the destination. This matches the naming conventions for a framework like CakePHP, i.e. <?php echo $form->input('title'); ?> outputs an input with a name of data[Model][title].
You can override the default source and destination fields by setting document.slugField and document.titleField in JavaScript beforehand:
<script>
document.titleField = "input[name$='[heading]']";
document.slugField = "input[name$='[url_safe_heading]']";
</script>