Committing to debug some JavaScript in Chrome on Dev

This commit is contained in:
Rick Falkvinge
2012-12-03 22:51:43 +00:00
parent 6b74c69523
commit 62afdaa41a
5 changed files with 535 additions and 2 deletions
+2
View File
@@ -10,6 +10,7 @@
<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.js" ></script>
<script language="javascript" type="text/javascript" src="/Scripts/jquery.leanModal.min.js" ></script>
<script language="javascript" type="text/javascript" src="/Scripts/jquery.qtip.js" ></script>
<script language="javascript" type="text/javascript" src="/Scripts/alertify.js" ></script>
<!-- fonts -->
<link href='https://fonts.googleapis.com/css?family=Permanent+Marker' rel='stylesheet' type='text/css' />
@@ -23,6 +24,7 @@
<telerik:RadStyleSheetManager id="RadStyleSheetManager" runat="server" />
<link href="/Style/style-v5.css" rel="stylesheet" type="text/css" />
<link href="/Style/jquery.qtip.css" rel="stylesheet" type="text/css" />
<link href="/Style/alertify.css.css" rel="stylesheet" type="text/css" />
<!-- additional scripts etc from individual pages -->
<asp:ContentPlaceHolder id="PlaceHolderHead" runat="server" />
+19 -2
View File
@@ -5,11 +5,28 @@
<link rel="stylesheet" type="text/css" href="https://hostedscripts.falkvinge.net/easyui/themes/icon.css">␍ <link rel="stylesheet" type="text/css" href="https://hostedscripts.falkvinge.net/easyui/themes/default/tree.css"/>␍ <link rel="stylesheet" type="text/css" href="/Style/v5-easyui-elements.css">␍ <script type="text/javascript">
$(document).ready(function () {
$('#DropBudgets').combotree({
required: true,
animate: true
}); // Is this init call even necessary?
$('input.combo-text').click(function () {
$('span.combo-arrow').click();
});
alertify.success('test');
});
function validateFields() {
var isValid = true;
if ($('#DropBudgets').combotree('tree').tree('getSelected') == null) {
isValid = false;
alertify.error('test');
}
return isValid;
}
</script>␍</asp:Content>
@@ -22,7 +39,7 @@
<asp:TextBox runat="server" ID="TextBank" />&nbsp;<br/>
<asp:TextBox runat="server" ID="TextClearing" />&nbsp;<br/>
<asp:TextBox runat="server" ID="TextAccount" />&nbsp;<br/>
<asp:Button ID="Button1" runat="server" CssClass="buttonAccentColor" Text="Request"/>
<asp:Button ID="ButtonRequest" runat="server" CssClass="buttonAccentColor" OnClientClick="return validateFields();" Text="Request"/>
</div>
<div class="entryLabels">
Amount (SEK)<br/>
+347
View File
@@ -0,0 +1,347 @@
/**
* Alertify
* An unobtrusive customizable JavaScript notification system
*
* @author Fabien Doiron <fabien.doiron@gmail.com>
* @copyright Fabien Doiron 2012
* @license MIT <http://opensource.org/licenses/mit-license.php>
* @link http://www.github.com/fabien-d
* @module Alertify
* @version 0.1.1
*/
/*global define*/
(function (global, undefined) {
"use strict";
var document = global.document,
Alertify;
Alertify = function () {
var $, addListeners, bind, build, close, hide, init, notify, setup, unbind,
dialog, extend, log,
cover, dialogs, delay, element, isopen, keys, labels, logElement, queue;
dialogs = {
buttons : {
holder : "<nav class=\"alertify-buttons\">{{buttons}}</nav>",
ok : "<a href=\"#\" class=\"alertify-button alertify-button-ok\" id=\"aOK\">{{ok}}</a>",
cancel : "<a href=\"#\" class=\"alertify-button alertify-button-cancel\" id=\"aCancel\">{{cancel}}</a>"
},
input : "<input type=\"text\" class=\"alertify-text\" id=\"aText\">",
message : "<p class=\"alertify-message\">{{message}}</p>",
log : "<article class=\"alertify-log{{class}}\">{{message}}</article>"
};
delay = 5000;
keys = { ENTER: 13, ESC: 27 };
labels = { ok: "OK", cancel: "Cancel" };
queue = [];
isopen = false;
/**
* Shorthand for document.getElementById()
*
* @param {String} id A specific element ID
* @return {Object} HTML element
*/
$ = function (id) {
return document.getElementById(id);
};
/**
* Set the proper button click events
*
* @param {Function} fn [Optional] Callback function
*
* @return {undefined}
*/
addListeners = function (fn) {
var btnOK = $("aOK") || undefined,
btnCancel = $("aCancel") || undefined,
input = $("aText") || undefined,
hasOK = (typeof btnOK !== "undefined"),
hasCancel = (typeof btnCancel !== "undefined"),
val = "",
ok, cancel, common, key;
// ok event handler
ok = function (event) {
common(event);
if (typeof input !== "undefined") val = input.value;
if (typeof fn === "function") fn(true, val);
if (typeof event.preventDefault !== "undefined") event.preventDefault();
};
// cancel event handler
cancel = function (event) {
common(event);
if (typeof fn === "function") fn(false);
if (typeof event.preventDefault !== "undefined") event.preventDefault();
};
// common event handler (keyup, ok and cancel)
common = function (event) {
hide();
unbind(document.body, "keyup", key);
};
// keyup handler
key = function (event) {
var keyCode = event.keyCode;
if (keyCode === keys.ENTER && hasOK) ok(event);
else if (keyCode === keys.ESC && hasCancel) cancel(event);
};
// handle OK click
if (hasOK) bind(btnOK, "click", ok);
// handle Cancel click
if (hasCancel) bind(btnCancel, "click", cancel);
// clear focus off activeElement element to ensure
// the ENTER key triggers the correct behaviour
// Firefox has an issue if this isn't done and the current
// focus is an anchor
document.activeElement.blur();
// listen for keys, OK => ENTER, Cancel => ESC
bind(document.body, "keyup", key);
};
/**
* Bind events to elements
*
* @param {Object} el HTML Object
* @param {Event} event Event to attach to element
* @param {Function} fn Callback function
*
* @return {undefined}
*/
bind = function (el, event, fn) {
if (typeof el.addEventListener === "function") {
el.addEventListener(event, fn, false);
} else if (el.attachEvent) {
el.attachEvent("on" + event, fn);
}
};
/**
* Build the proper message box
*
* @param {Object} item Current object in the queue
* @return {String} An HTML string of the message box
*/
build = function (item) {
var html = "",
type = item.type,
message = item.message;
html += "<div class=\"alertify-dialog\">";
html += "<article class=\"alertify-inner\">";
html += dialogs.message.replace("{{message}}", message);
if (type === "prompt") { html += dialogs.input; }
html += dialogs.buttons.holder;
html += "</article>";
html += "</div>";
switch (type) {
case "confirm":
case "prompt":
html = html.replace("{{buttons}}", dialogs.buttons.cancel + dialogs.buttons.ok);
html = html.replace("{{ok}}", labels.ok).replace("{{cancel}}", labels.cancel);
break;
case "alert":
html = html.replace("{{buttons}}", dialogs.buttons.ok);
html = html.replace("{{ok}}", labels.ok);
break;
default:
break;
}
element.className = "alertify alertify-show alertify-" + type;
cover.className = "alertify-cover";
return html;
};
/**
* Close the log messages
*
* @return {undefined}
*/
close = function () {
setTimeout(function () {
var child = logElement.childNodes[logElement.childNodes.length - 1];
if (typeof child !== "undefined") logElement.removeChild(child);
}, delay);
};
/**
* Hide the dialog and rest to defaults
*
* @return {undefined}
*/
hide = function () {
// remove reference from queue
queue.splice(0,1);
// if items remaining in the queue
if (queue.length > 0) setup();
else {
isopen = false;
element.className = "alertify alertify-hide alertify-hidden";
cover.className = "alertify-cover alertify-hidden";
}
};
/**
* Initialize Alertify
* Create the 2 main elements
*
* @return {undefined}
*/
init = function () {
// ensure legacy browsers support html5 tags
document.createElement("nav");
document.createElement("article");
document.createElement("section");
// cover
cover = document.createElement("div");
cover.setAttribute("id", "alertifycover");
cover.className = "alertify-cover alertify-hidden";
document.body.appendChild(cover);
// main element
element = document.createElement("section");
element.setAttribute("id", "alertify");
element.className = "alertify alertify-hidden";
document.body.appendChild(element);
// main element
logElement = document.createElement("section");
logElement.setAttribute("id", "alertifylogs");
logElement.className = "alertify-logs";
document.body.appendChild(logElement);
};
/**
* Add new log message
* If a type is passed, a class name "alertify-log-{type}" will get added.
* This allows for custom look and feel for various types of notifications.
*
* @param {String} message The message passed from the callee
* @param {String} type [Optional] Type of log message
*
* @return {undefined}
*/
notify = function (message, type) {
var log = document.createElement("article");
log.className = "alertify-log" + ((typeof type === "string" && type !== "") ? " alertify-log-" + type : "");
log.innerHTML = message;
// prepend child
logElement.insertBefore(log, logElement.firstChild);
// triggers the CSS animation
setTimeout(function() { log.className = log.className + " alertify-log-show"; }, 50);
close();
};
/**
* Initiate all the required pieces for the dialog box
*
* @return {undefined}
*/
setup = function () {
var item = queue[0];
isopen = true;
element.innerHTML = build(item);
addListeners(item.callback);
// adding focus to prompt input box
// doesn't work without a setTimeout...
if (item.type === "prompt") global.setTimeout(function () { document.getElementById("aText").focus(); }, 0);
};
/**
* Unbind events to elements
*
* @param {Object} el HTML Object
* @param {Event} event Event to detach to element
* @param {Function} fn Callback function
*
* @return {undefined}
*/
unbind = function (el, event, fn) {
if (typeof el.removeEventListener === "function") {
el.removeEventListener(event, fn, false);
} else if (el.detachEvent) {
el.detachEvent("on" + event, fn);
}
};
/**
* Create a dialog box
*
* @param {String} message The message passed from the callee
* @param {String} type Type of dialog to create
* @param {Function} fn [Optional] Callback function
*
* @return {Object}
*/
dialog = function (message, type, fn) {
// error catching
if (typeof message !== "string") throw new Error("message must be a string");
if (typeof type !== "string") throw new Error("type must be a string");
if (typeof fn !== "undefined" && typeof fn !== "function") throw new Error("fn must be a function");
queue.push({ type: type, message: message, callback: fn });
if (!isopen) setup();
return this;
};
/**
* Extend the log method to create custom methods
*
* @param {String} type Custom method name
* @return {Function}
*/
extend = function (type) {
return function (message) { log(message, type); };
};
/**
* Show a new log message box
*
* @param {String} message The message passed from the callee
* @param {String} type [Optional] Optional type of log message
*
* @return {Object}
*/
log = function (message, type) {
notify(message, type);
return this;
};
// Bootstrap
init();
return {
alert : function (message, fn) { dialog(message, "alert", fn); return this; },
confirm : function (message, fn) { dialog(message, "confirm", fn); return this; },
extend : extend,
log : log,
prompt : function (message, fn) { dialog(message, "prompt", fn); return this; },
success : function (message) { log(message, "success"); return this; },
error : function (message) { log(message, "error"); return this; },
delay : delay,
labels : labels
};
};
// AMD and window support
if (typeof define === "function") {
define([], function () { return new Alertify(); });
} else {
if (typeof global.alertify === "undefined") { global.alertify = new Alertify(); }
}
}(this));
+12
View File
@@ -0,0 +1,12 @@
/**
* Alertify
* An unobtrusive customizable JavaScript notification system
*
* @author Fabien Doiron <fabien.doiron@gmail.com>
* @copyright Fabien Doiron 2012
* @license MIT <http://opensource.org/licenses/mit-license.php>
* @link http://www.github.com/fabien-d
* @module Alertify
* @version 0.1.1
*/
(function(e,t){"use strict";var n=e.document,r;r=function(){var r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T;return g={buttons:{holder:'<nav class="alertify-buttons">{{buttons}}</nav>',ok:'<a href="#" class="alertify-button alertify-button-ok" id="aOK">{{ok}}</a>',cancel:'<a href="#" class="alertify-button alertify-button-cancel" id="aCancel">{{cancel}}</a>'},input:'<input type="text" class="alertify-text" id="aText">',message:'<p class="alertify-message">{{message}}</p>',log:'<article class="alertify-log{{class}}">{{message}}</article>'},y=5e3,E={ENTER:13,ESC:27},S={ok:"OK",cancel:"Cancel"},T=[],w=!1,r=function(e){return n.getElementById(e)},i=function(e){var i=r("aOK")||t,o=r("aCancel")||t,u=r("aText")||t,f=typeof i!="undefined",l=typeof o!="undefined",c="",p,d,v,m;p=function(t){v(t),typeof u!="undefined"&&(c=u.value),typeof e=="function"&&e(!0,c),typeof t.preventDefault!="undefined"&&t.preventDefault()},d=function(t){v(t),typeof e=="function"&&e(!1),typeof t.preventDefault!="undefined"&&t.preventDefault()},v=function(e){a(),h(n.body,"keyup",m)},m=function(e){var t=e.keyCode;t===E.ENTER&&f?p(e):t===E.ESC&&l&&d(e)},f&&s(i,"click",p),l&&s(o,"click",d),n.activeElement.blur(),s(n.body,"keyup",m)},s=function(e,t,n){typeof e.addEventListener=="function"?e.addEventListener(t,n,!1):e.attachEvent&&e.attachEvent("on"+t,n)},o=function(e){var t="",n=e.type,r=e.message;t+='<div class="alertify-dialog">',t+='<article class="alertify-inner">',t+=g.message.replace("{{message}}",r),n==="prompt"&&(t+=g.input),t+=g.buttons.holder,t+="</article>",t+="</div>";switch(n){case"confirm":case"prompt":t=t.replace("{{buttons}}",g.buttons.cancel+g.buttons.ok),t=t.replace("{{ok}}",S.ok).replace("{{cancel}}",S.cancel);break;case"alert":t=t.replace("{{buttons}}",g.buttons.ok),t=t.replace("{{ok}}",S.ok);break;default:}return b.className="alertify alertify-show alertify-"+n,m.className="alertify-cover",t},u=function(){setTimeout(function(){var e=x.childNodes[x.childNodes.length-1];typeof e!="undefined"&&x.removeChild(e)},y)},a=function(){T.splice(0,1),T.length>0?c():(w=!1,b.className="alertify alertify-hide alertify-hidden",m.className="alertify-cover alertify-hidden")},f=function(){n.createElement("nav"),n.createElement("article"),n.createElement("section"),m=n.createElement("div"),m.setAttribute("id","alertifycover"),m.className="alertify-cover alertify-hidden",n.body.appendChild(m),b=n.createElement("section"),b.setAttribute("id","alertify"),b.className="alertify alertify-hidden",n.body.appendChild(b),x=n.createElement("section"),x.setAttribute("id","alertifylogs"),x.className="alertify-logs",n.body.appendChild(x)},l=function(e,t){var r=n.createElement("article");r.className="alertify-log"+(typeof t=="string"&&t!==""?" alertify-log-"+t:""),r.innerHTML=e,x.insertBefore(r,x.firstChild),setTimeout(function(){r.className=r.className+" alertify-log-show"},50),u()},c=function(){var t=T[0];w=!0,b.innerHTML=o(t),i(t.callback),t.type==="prompt"&&e.setTimeout(function(){n.getElementById("aText").focus()},0)},h=function(e,t,n){typeof e.removeEventListener=="function"?e.removeEventListener(t,n,!1):e.detachEvent&&e.detachEvent("on"+t,n)},p=function(e,t,n){if(typeof e!="string")throw new Error("message must be a string");if(typeof t!="string")throw new Error("type must be a string");if(typeof n!="undefined"&&typeof n!="function")throw new Error("fn must be a function");return T.push({type:t,message:e,callback:n}),w||c(),this},d=function(e){return function(t){v(t,e)}},v=function(e,t){return l(e,t),this},f(),{alert:function(e,t){return p(e,"alert",t),this},confirm:function(e,t){return p(e,"confirm",t),this},extend:d,log:v,prompt:function(e,t){return p(e,"prompt",t),this},success:function(e){return v(e,"success"),this},error:function(e){return v(e,"error"),this},delay:y,labels:S}},typeof define=="function"?define([],function(){return new r}):typeof e.alertify=="undefined"&&(e.alertify=new r)})(this);
+155
View File
@@ -0,0 +1,155 @@
.alertify-show,
.alertify-log {
-webkit-transition: all 500ms cubic-bezier(0.175, 0.885, 0.320, 1); /* older webkit */
-webkit-transition: all 500ms cubic-bezier(0.175, 0.885, 0.320, 1.275);
-moz-transition: all 500ms cubic-bezier(0.175, 0.885, 0.320, 1.275);
-ms-transition: all 500ms cubic-bezier(0.175, 0.885, 0.320, 1.275);
-o-transition: all 500ms cubic-bezier(0.175, 0.885, 0.320, 1.275);
transition: all 500ms cubic-bezier(0.175, 0.885, 0.320, 1.275); /* easeOutBack */
}
.alertify-hide {
-webkit-transition: all 250ms cubic-bezier(0.600, 0, 0.735, 0.045); /* older webkit */
-webkit-transition: all 250ms cubic-bezier(0.600, -0.280, 0.735, 0.045);
-moz-transition: all 250ms cubic-bezier(0.600, -0.280, 0.735, 0.045);
-ms-transition: all 250ms cubic-bezier(0.600, -0.280, 0.735, 0.045);
-o-transition: all 250ms cubic-bezier(0.600, -0.280, 0.735, 0.045);
transition: all 250ms cubic-bezier(0.600, -0.280, 0.735, 0.045); /* easeInBack */
}
.alertify-cover {
position: fixed; z-index: 99999;
top: 0; right: 0; bottom: 0; left: 0;
}
.alertify {
position: fixed; z-index: 99999;
top: 50px; left: 50%;
width: 550px;
margin-left: -275px;
}
.alertify-hidden {
top: -50px;
visibility: hidden;
}
.alertify-logs {
position: fixed;
z-index: 5000;
bottom: 10px;
right: 10px;
width: 300px;
}
.alertify-log {
display: block;
margin-top: 10px;
position: relative;
right: -300px;
}
.alertify-log-show {
right: 0;
}
.alertify-dialog {
padding: 25px;
}
.alertify-inner {
text-align: center;
}
.alertify-text {
margin-bottom: 15px;
width: 100%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
font-size: 100%;
}
.alertify-buttons {
}
.alertify-button {
display: inline-block;
cursor: pointer;
margin-left: 5px;
}
@media only screen and (max-width: 680px) {
.alertify,
.alertify-logs {
width: 90%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.alertify {
left: 5%;
margin: 0;
}
}
/**
* Default Look and Feel
*/
.alertify,
.alertify-log {
font-family: sans-serif;
}
.alertify {
background: #FFF;
border: 10px solid #333; /* browsers that don't support rgba */
border: 10px solid rgba(0,0,0,.7);
border-radius: 8px;
box-shadow: 0 3px 3px rgba(0,0,0,.3);
-webkit-background-clip: padding; /* Safari 4? Chrome 6? */
-moz-background-clip: padding; /* Firefox 3.6 */
background-clip: padding-box; /* Firefox 4, Safari 5, Opera 10, IE 9 */
}
.alertify-text {
border: 1px solid #CCC;
padding: 10px;
border-radius: 4px;
}
.alertify-button {
border-radius: 4px;
color: #FFF;
font-weight: bold;
padding: 6px 15px;
text-decoration: none;
text-shadow: 1px 1px 0 rgba(0,0,0,.5);
box-shadow: inset 0 1px 0 0 rgba(255,255,255,.5);
background-image: -webkit-linear-gradient(top, rgba(255,255,255,.3), rgba(255,255,255,0));
background-image: -moz-linear-gradient(top, rgba(255,255,255,.3), rgba(255,255,255,0));
background-image: -ms-linear-gradient(top, rgba(255,255,255,.3), rgba(255,255,255,0));
background-image: -o-linear-gradient(top, rgba(255,255,255,.3), rgba(255,255,255,0));
background-image: linear-gradient(top, rgba(255,255,255,.3), rgba(255,255,255,0));
}
.alertify-button:hover,
.alertify-button:focus {
background-image: -webkit-linear-gradient(top, rgba(0,0,0,.1), rgba(0,0,0,0));
background-image: -moz-linear-gradient(top, rgba(0,0,0,.1), rgba(0,0,0,0));
background-image: -ms-linear-gradient(top, rgba(0,0,0,.1), rgba(0,0,0,0));
background-image: -o-linear-gradient(top, rgba(0,0,0,.1), rgba(0,0,0,0));
background-image: linear-gradient(top, rgba(0,0,0,.1), rgba(0,0,0,0));
}
.alertify-button:active {
position: relative;
top: 1px;
}
.alertify-button-cancel {
background-color: #FE1A00;
border: 1px solid #D83526;
}
.alertify-button-ok {
background-color: #5CB811;
border: 1px solid #3b7808;
}
.alertify-log {
background: #1F1F1F;
background: rgba(0,0,0,.9);
padding: 15px;
border-radius: 4px;
color: #FFF;
text-shadow: -1px -1px 0 rgba(0,0,0,.5);
}
.alertify-log-error {
background: #FE1A00;
background: rgba(254,26,0,.9);
}
.alertify-log-success {
background: #5CB811;
background: rgba(92,184,17,.9);
}