summaryrefslogtreecommitdiffstats
path: root/jquery-impromptu.js
diff options
context:
space:
mode:
authorTrent Richardson <trentdrichardson@gmail.com>2013-11-08 10:44:50 -0500
committerTrent Richardson <trentdrichardson@gmail.com>2013-11-08 10:44:50 -0500
commit43b172e34d3e71940648334f5ab150e82e8c29a1 (patch)
tree5c8ebb9e79629b31560681a53c6cc05b45efa103 /jquery-impromptu.js
parent534ad07832c93dd93ec87b61b81d87e7b005b01e (diff)
downloadjQuery-Impromptu-43b172e34d3e71940648334f5ab150e82e8c29a1.zip
jQuery-Impromptu-43b172e34d3e71940648334f5ab150e82e8c29a1.tar.gz
jQuery-Impromptu-43b172e34d3e71940648334f5ab150e82e8c29a1.tar.bz2
Add some grunt, jshint cleanup
Diffstat (limited to 'jquery-impromptu.js')
-rw-r--r--jquery-impromptu.js158
1 files changed, 80 insertions, 78 deletions
diff --git a/jquery-impromptu.js b/jquery-impromptu.js
index 45cf98f..4ba5525 100644
--- a/jquery-impromptu.js
+++ b/jquery-impromptu.js
@@ -1,17 +1,10 @@
-/*
- * jQuery Impromptu
- * By: Trent Richardson [http://trentrichardson.com]
- * Version 5.1.0
- * Last Modified: 08/24/2013
- *
- * Copyright 2013 Trent Richardson
- * You may use this project under MIT or GPL licenses.
- * http://trentrichardson.com/Impromptu/GPL-LICENSE.txt
- * http://trentrichardson.com/Impromptu/MIT-LICENSE.txt
- *
- */
-
+/*! jQuery-Impromptu - v5.1.0 - 2013-11-08
+* http://trentrichardson.com/Impromptu
+* Copyright (c) 2013 Trent Richardson; Licensed MIT */
+/*! jQuery-Impromptu - v5.1.0* http://trentrichardson.com/Impromptu
+* Copyright (c) 2013 Trent Richardson; Licensed MIT */
(function($) {
+ "use strict";
/**
* setDefaults - Sets the default options
@@ -21,7 +14,7 @@
*/
$.prompt = function(message, options) {
// only for backwards compat, to be removed in future version
- if(options !== undefined && options.classes != undefined && typeof options.classes === 'string'){
+ if(options !== undefined && options.classes !== undefined && typeof options.classes === 'string'){
options = { box: options.classes };
}
@@ -58,17 +51,17 @@
$.prompt.jqif = $.prompt.jqib.children('.'+ opts.prefix +'fade');
//if a string was passed, convert to a single state
- if(message.constructor == String){
+ if(message.constructor === String){
message = {
state0: {
title: opts.title,
html: message,
- buttons: opts.buttons,
- position: opts.position,
- focus: opts.focus,
- submit: opts.submit
- }
- };
+ buttons: opts.buttons,
+ position: opts.position,
+ focus: opts.focus,
+ submit: opts.submit
+ }
+ };
}
//build the states
@@ -78,8 +71,9 @@
v = $.extend({},$.prompt.defaults.state,{name:k},message[k]);
$.prompt.addState(v.name, v);
- if($.prompt.currentStateName === '')
+ if($.prompt.currentStateName === ''){
$.prompt.currentStateName = v.name;
+ }
}
// Go ahead and transition to the first state. It won't be visible just yet though until we show the prompt
@@ -96,9 +90,9 @@
forminputs = {};
// if for some reason we couldn't get the value
- if(clicked == undefined){
+ if(clicked === undefined){
for(var i in stateobj.buttons){
- if(stateobj.buttons[i].title == $t.text() || stateobj.buttons[i].title == $t.html()){
+ if(stateobj.buttons[i].title === $t.text() || stateobj.buttons[i].title === $t.html()){
clicked = stateobj.buttons[i].value;
}
}
@@ -108,7 +102,7 @@
$.each($.prompt.jqi.children('form').serializeArray(),function(i,obj){
if (forminputs[obj.name] === undefined) {
forminputs[obj.name] = obj.value;
- } else if (typeof forminputs[obj.name] == Array || typeof forminputs[obj.name] == 'object') {
+ } else if (typeof forminputs[obj.name] === Array || typeof forminputs[obj.name] === 'object') {
forminputs[obj.name].push(obj.value);
} else {
forminputs[obj.name] = [forminputs[obj.name],obj.value];
@@ -155,23 +149,25 @@
var key = (window.event) ? event.keyCode : e.keyCode;
//escape key closes
- if(key==27) {
+ if(key===27) {
fadeClicked();
}
//constrain tabs, tabs should iterate through the state and not leave
- if (key == 9){
+ if (key === 9){
var $inputels = $('input,select,textarea,button',$.prompt.getCurrentState());
- var fwd = !e.shiftKey && e.target == $inputels[$inputels.length-1];
- var back = e.shiftKey && e.target == $inputels[0];
+ var fwd = !e.shiftKey && e.target === $inputels[$inputels.length-1];
+ var back = e.shiftKey && e.target === $inputels[0];
if (fwd || back) {
setTimeout(function(){
- if (!$inputels)
+ if (!$inputels){
return;
+ }
var el = $inputels[back===true ? $inputels.length-1 : 0];
- if (el)
- el.focus();
+ if (el){
+ el.focus();
+ }
},10);
return false;
}
@@ -222,20 +218,20 @@
buttons: {
Ok: true
},
- loaded: function(e){},
- submit: function(e,v,m,f){},
- close: function(e,v,m,f){},
- statechanging: function(e, from, to){},
- statechanged: function(e, to){},
+ loaded: function(e){},
+ submit: function(e,v,m,f){},
+ close: function(e,v,m,f){},
+ statechanging: function(e, from, to){},
+ statechanged: function(e, to){},
opacity: 0.6,
- zIndex: 999,
- overlayspeed: 'slow',
- promptspeed: 'fast',
- show: 'fadeIn',
- focus: 0,
- defaultButton: 0,
- useiframe: false,
- top: '15%',
+ zIndex: 999,
+ overlayspeed: 'slow',
+ promptspeed: 'fast',
+ show: 'fadeIn',
+ focus: 0,
+ defaultButton: 0,
+ useiframe: false,
+ top: '15%',
position: {
container: null,
x: null,
@@ -243,29 +239,29 @@
arrow: null,
width: null
},
- persistent: true,
- timeout: 0,
- states: {},
- state: {
- name: null,
- title: '',
+ persistent: true,
+ timeout: 0,
+ states: {},
+ state: {
+ name: null,
+ title: '',
html: '',
- buttons: {
- Ok: true
- },
- focus: 0,
- defaultButton: 0,
- position: {
- container: null,
- x: null,
- y: null,
- arrow: null,
- width: null
- },
- submit: function(e,v,m,f){
- return true;
- }
- }
+ buttons: {
+ Ok: true
+ },
+ focus: 0,
+ defaultButton: 0,
+ position: {
+ container: null,
+ x: null,
+ y: null,
+ arrow: null,
+ width: null
+ },
+ submit: function(e,v,m,f){
+ return true;
+ }
+ }
};
/**
@@ -316,8 +312,9 @@
(windowHeight*(parseInt($.prompt.options.top,10)/100)) : parseInt($.prompt.options.top,10));
// when resizing the window turn off animation
- if(e !== undefined && e.data.animate === false)
+ if(e !== undefined && e.data.animate === false){
$.fx.off = true;
+ }
$.prompt.jqib.css({
position: "absolute",
@@ -380,8 +377,9 @@
}
// restore fx settings
- if(e !== undefined && e.data.animate === false)
+ if(e !== undefined && e.data.animate === false){
$.fx.off = restoreFx;
+ }
};
/**
@@ -429,10 +427,12 @@
stateobj = $.extend({},$.prompt.defaults.state, {name:statename}, stateobj);
- if(stateobj.position.arrow !== null)
+ if(stateobj.position.arrow !== null){
arrow = '<div class="'+ opts.prefix + 'arrow '+ opts.prefix + 'arrow'+ stateobj.position.arrow +'"></div>';
- if(stateobj.title && stateobj.title !== '')
- title = '<div class="lead '+ opts.prefix + 'title '+ opts.classes.title +'">'+ stateobj.title +'</div>';
+ }
+ if(stateobj.title && stateobj.title !== ''){
+ title = '<div class="lead '+ opts.prefix + 'title '+ opts.classes.title +'">'+ stateobj.title +'</div>';
+ }
state += '<div id="'+ opts.prefix +'state_'+ statename +'" class="'+ opts.prefix + 'state" data-jqi-name="'+ statename +'" style="display:none;">'+
arrow + title +
'<div class="'+ opts.prefix +'message '+ opts.classes.message +'">' + stateobj.html +'</div>'+
@@ -442,7 +442,7 @@
v = stateobj.buttons[k],
defbtn = stateobj.focus === i || stateobj.defaultButton === i ? ($.prompt.currentPrefix + 'defaultbutton ' + opts.classes.defaultButton) : '';
- if(typeof v == 'object'){
+ if(typeof v === 'object'){
state += '<button class="'+ opts.classes.button +' '+ defbtn;
if(typeof v.classes !== "undefined"){
@@ -590,11 +590,11 @@
$t.find('.'+ $.prompt.currentPrefix +'arrow').show(jqiopts.promptspeed);
- if (typeof callback == 'function'){
+ if (typeof callback === 'function'){
$.prompt.jqib.on('impromptu:statechanged', callback);
}
$.prompt.jqib.trigger('impromptu:statechanged', [state]);
- if (typeof callback == 'function'){
+ if (typeof callback === 'function'){
$.prompt.jqib.off('impromptu:statechanged', callback);
}
});
@@ -646,7 +646,7 @@
}
$.prompt.jqib.remove();
- $(window).off('resize',$.prompt.position);
+ $(window).off('resize',$.prompt.position);
});
};
@@ -655,10 +655,12 @@
* This will grab the html within the prompt as the prompt message
*/
$.fn.prompt = function(options){
- if(options == undefined)
+ if(options === undefined){
options = {};
- if(options.withDataAndEvents == undefined)
+ }
+ if(options.withDataAndEvents === undefined){
options.withDataAndEvents = false;
+ }
$.prompt($(this).clone(options.withDataAndEvents).html(),options);
};