Skip to content

Instantly share code, notes, and snippets.

View makeusabrew's full-sized avatar
💭
I may be slow to respond.

Nick Payne makeusabrew

💭
I may be slow to respond.
View GitHub Profile
@makeusabrew
makeusabrew / dialog-hide.js
Created November 7, 2011 13:10
bootbox.js - programatically hide a dialog
var box = bootbox.alert("This dialog will disappear in three seconds.");
setTimeout(function() {
// be careful not to call box.hide() here, which will invoke jQuery's hide method
box.modal('hide');
}, 3000);
@makeusabrew
makeusabrew / label-to-placeholder.js
Created May 22, 2011 18:32
Simple jQuery snippet to convert form labels into inline placeholders
$("form :input").each(function(index, elem) {
var eId = $(elem).attr("id");
var label = null;
if (eId && (label = $(elem).parents("form").find("label[for="+eId+"]")).length == 1) {
$(elem).attr("placeholder", $(label).html());
$(label).remove();
}
});
@makeusabrew
makeusabrew / quick-dirty-ssg.php
Created March 4, 2012 14:38
Quick & dirty SSG function
<?php
// assume $text is our article's full content
$text = preg_replace_callback("@\[gist id=(\d+)\]@s", function($matches) {
// we know that the match at offset 1 will be our target gist ID
$id = $matches[1];
// Go fetch the raw JS from GitHub...
// @todo - you'd want to handle errors here!
$js = file_get_contents("https://gist.github.com/".$id.".js");
// get rid of any superfluous whitespace off either end of the string
@makeusabrew
makeusabrew / dialog-hide-all.js
Created November 7, 2011 13:16
bootbox.js - programatically hide all dialogs
bootbox.alert("Hello");
bootbox.confirm("Can you take it?");
bootbox.alert("Boo!");
setTimeout(function() {
// that's enough of that
bootbox.hideAll();
}, 3000);
@makeusabrew
makeusabrew / usage.js
Last active April 3, 2019 03:17
Potential Bootbox v4.x API and usage examples
/**
* alert
*/
bootbox.alert("Hello world");
bootbox.alert("Hello world", function() {
console.log("dialog dismissed with OK or escape button");
});
bootbox.alert({
@makeusabrew
makeusabrew / modal.html
Created August 24, 2013 09:50
Twitter Bootstrap 3.0.0 - basic dialog box invocation via JavaScript
<!-- set up the modal to start hidden and fade in and out -->
<div id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<!-- dialog body -->
<div class="modal-body">
<button type="button" class="close" data-dismiss="modal">&times;</button>
Hello world!
</div>
<!-- dialog buttons -->
@makeusabrew
makeusabrew / bootbox-setDefaults-v4.js
Last active May 7, 2018 01:05
Bootbox v4.0.0 defaults
bootbox.setDefaults({
/**
* @optional String
* @default: en
* which locale settings to use to translate the three
* standard button labels: OK, CONFIRM, CANCEL
*/
locale: "fr",
/**
@makeusabrew
makeusabrew / bootbox-dialog-v4-all.js
Last active April 18, 2018 18:52
An attempt to demonstrate as many bootbox.dialog options as sanely possible in a single-file gist.
bootbox.dialog({
/**
* @required String|Element
*/
message: "I am a custom dialog",
/**
* @optional String|Element
* adds a header to the dialog and places this text in an h4
*/
@makeusabrew
makeusabrew / base-simplified.tpl
Created January 18, 2012 15:31
Simplified base layout supporting PJAX
{if !$_pjax}
{* everything as normal *}
<html>
<head>
<title>{block name="title"}{/block}</title>
</head>
<body>
<!-- header -->
<!-- nav etc -->
@makeusabrew
makeusabrew / dialog-multiple-buttons.js
Created November 6, 2011 18:19
bootbox.js - dialog with multiple buttons
bootbox.dialog("Plenty of buttons...", [{
"label" : "Success!",
"class" : "success",
"callback": function() {
console.log("great success");
}
}, {
"label" : "Danger!",
"class" : "danger",
"callback": function() {