Skip to content

Commit

Permalink
Update demo.html
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Offen committed Aug 12, 2015
1 parent 2db0c2d commit c233b7c
Showing 1 changed file with 41 additions and 14 deletions.
55 changes: 41 additions & 14 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ <h3 class="panel-title">Make Your Own Toast</h3>
<form id="preptoast" role="form" class="form-inline">
<div class="form-group">
<label class="sr-only" for="toastPriority">Toast Priority</label>
<select class="form-control" id="toastPriority">
<select class="form-control" id="toastPriority" placeholder="Priority">
<option>&lt;use default&gt;</option>
<option value="success">success</option>
<option value="info">info</option>
<option value="warning">warning</option>
Expand Down Expand Up @@ -78,6 +79,7 @@ <h3 class="panel-title">Make Your Own Toast</h3>
<script src="./jquery.toaster.js"></script>
<script>
var interval;
var codetmpl = "<code>%codeobj%</code><br><code>%codestr%</code>";

$(document).ready(function ()
{
Expand All @@ -88,9 +90,6 @@ <h3 class="panel-title">Make Your Own Toast</h3>
$('#preptoast').on('submit', maketoast);

start();

$.toaster("Hello World", "My Title", "danger");

});

function start ()
Expand Down Expand Up @@ -128,18 +127,46 @@ <h3 class="panel-title">Make Your Own Toast</h3>
{
evt.preventDefault();

var priority = $('#toastPriority').val();
var title = $('#toastTitle').val() || 'Notice';
var message = $('#toastMessage').val() || 'Your message here';
var options =
{
priority : $('#toastPriority').val() || null,
title : $('#toastTitle').val() || null,
message : $('#toastMessage').val() || 'A message is required'
};

var code =
[
"$.toaster({ priority : '" + priority + "', title : '" + title + "', message : '" + message + "'});",
"$.toaster('" + message + "', '" + title + "', '" + priority + "');"
].join("</code><br><code>");
if (options.priority === '<use default>')
{
options.priority = null;
}

$('#toastCode').html("<code>" + code + "</code>");
$.toaster({ priority : priority, title : title, message : message });
var codeobj = [];
var codestr = [];

var labels = ['message', 'title', 'priority'];
for (var i = 0, l = labels.length; i < l; i += 1)
{
if (options[labels[i]] !== null)
{
codeobj.push([labels[i], "'" + options[labels[i]] + "'"].join(' : '));
}

codestr.push((options[labels[i]] !== null) ? "'" + options[labels[i]] + "'" : 'null');
}

if (codestr[2] === 'null')
{
codestr.pop();
if (codestr[1] === 'null')
{
codestr.pop();
}
}

codeobj = "$.toaster({ " + codeobj.join(", ") + " });"
codestr = "$.toaster(" + codestr.join(", ") + ");"

$('#toastCode').html(codetmpl.replace('%codeobj%', codeobj).replace('%codestr%', codestr));
$.toaster(options);
}
</script>
</body>
Expand Down

0 comments on commit c233b7c

Please sign in to comment.