You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

jquery-impromptu.js 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. /*! jQuery-Impromptu - v5.1.1
  2. * http://trentrichardson.com/Impromptu
  3. * Copyright (c) 2013 Trent Richardson; Licensed MIT */
  4. (function($) {
  5. "use strict";
  6. /**
  7. * setDefaults - Sets the default options
  8. * @param message String/Object - String of html or Object of states
  9. * @param options Object - Options to set the prompt
  10. * @return jQuery - container with overlay and prompt
  11. */
  12. $.prompt = function(message, options) {
  13. // only for backwards compat, to be removed in future version
  14. if(options !== undefined && options.classes !== undefined && typeof options.classes === 'string'){
  15. options = { box: options.classes };
  16. }
  17. $.prompt.options = $.extend({},$.prompt.defaults,options);
  18. $.prompt.currentPrefix = $.prompt.options.prefix;
  19. // Be sure any previous timeouts are destroyed
  20. if($.prompt.timeout){
  21. clearTimeout($.prompt.timeout);
  22. }
  23. $.prompt.timeout = false;
  24. var opts = $.prompt.options,
  25. $body = $(document.body),
  26. $window = $(window);
  27. //build the box and fade
  28. var msgbox = '<div class="'+ $.prompt.options.prefix +'box '+ opts.classes.box +'">';
  29. if(opts.useiframe && ($('object, applet').length > 0)) {
  30. msgbox += '<iframe src="javascript:false;" style="display:block;position:absolute;z-index:-1;" class="'+ opts.prefix +'fade '+ opts.classes.fade +'"></iframe>';
  31. } else {
  32. msgbox +='<div class="'+ opts.prefix +'fade '+ opts.classes.fade +'"></div>';
  33. }
  34. msgbox += '<div class="'+ opts.prefix +' '+ opts.classes.prompt +'">'+
  35. '<form action="javascript:false;" onsubmit="return false;" class="'+ opts.prefix +'form">'+
  36. '<div class="'+ opts.prefix +'close '+ opts.classes.close +'">'+ opts.closeText +'</div>'+
  37. '<div class="'+ opts.prefix +'states"></div>'+
  38. '</form>'+
  39. '</div>'+
  40. '</div>';
  41. $.prompt.jqib = $(msgbox).appendTo($body);
  42. $.prompt.jqi = $.prompt.jqib.children('.'+ opts.prefix);//.data('jqi',opts);
  43. $.prompt.jqif = $.prompt.jqib.children('.'+ opts.prefix +'fade');
  44. //if a string was passed, convert to a single state
  45. if(message.constructor === String){
  46. message = {
  47. state0: {
  48. title: opts.title,
  49. html: message,
  50. buttons: opts.buttons,
  51. position: opts.position,
  52. focus: opts.focus,
  53. submit: opts.submit
  54. }
  55. };
  56. }
  57. //build the states
  58. $.prompt.options.states = {};
  59. var k,v;
  60. for(k in message){
  61. v = $.extend({},$.prompt.defaults.state,{name:k},message[k]);
  62. $.prompt.addState(v.name, v);
  63. if($.prompt.currentStateName === ''){
  64. $.prompt.currentStateName = v.name;
  65. }
  66. }
  67. // Go ahead and transition to the first state. It won't be visible just yet though until we show the prompt
  68. var $firstState = $.prompt.jqi.find('.'+ opts.prefix +'states .'+ opts.prefix +'state').eq(0);
  69. $.prompt.goToState($firstState.data('jqi-name'));
  70. //Events
  71. $.prompt.jqi.on('click', '.'+ opts.prefix +'buttons button', function(e){
  72. var $t = $(this),
  73. $state = $t.parents('.'+ opts.prefix +'state'),
  74. stateobj = $.prompt.options.states[$state.data('jqi-name')],
  75. msg = $state.children('.'+ opts.prefix +'message'),
  76. clicked = stateobj.buttons[$t.text()] || stateobj.buttons[$t.html()],
  77. forminputs = {};
  78. // if for some reason we couldn't get the value
  79. if(clicked === undefined){
  80. for(var i in stateobj.buttons){
  81. if(stateobj.buttons[i].title === $t.text() || stateobj.buttons[i].title === $t.html()){
  82. clicked = stateobj.buttons[i].value;
  83. }
  84. }
  85. }
  86. //collect all form element values from all states.
  87. $.each($.prompt.jqi.children('form').serializeArray(),function(i,obj){
  88. if (forminputs[obj.name] === undefined) {
  89. forminputs[obj.name] = obj.value;
  90. } else if (typeof forminputs[obj.name] === Array || typeof forminputs[obj.name] === 'object') {
  91. forminputs[obj.name].push(obj.value);
  92. } else {
  93. forminputs[obj.name] = [forminputs[obj.name],obj.value];
  94. }
  95. });
  96. // trigger an event
  97. var promptsubmite = new $.Event('impromptu:submit');
  98. promptsubmite.stateName = stateobj.name;
  99. promptsubmite.state = $state;
  100. $state.trigger(promptsubmite, [clicked, msg, forminputs]);
  101. if(!promptsubmite.isDefaultPrevented()){
  102. $.prompt.close(true, clicked,msg,forminputs);
  103. }
  104. });
  105. // if the fade is clicked blink the prompt
  106. var fadeClicked = function(){
  107. if(opts.persistent){
  108. var offset = (opts.top.toString().indexOf('%') >= 0? ($window.height()*(parseInt(opts.top,10)/100)) : parseInt(opts.top,10)),
  109. top = parseInt($.prompt.jqi.css('top').replace('px',''),10) - offset;
  110. //$window.scrollTop(top);
  111. $('html,body').animate({ scrollTop: top }, 'fast', function(){
  112. var i = 0;
  113. $.prompt.jqib.addClass(opts.prefix +'warning');
  114. var intervalid = setInterval(function(){
  115. $.prompt.jqib.toggleClass(opts.prefix +'warning');
  116. if(i++ > 1){
  117. clearInterval(intervalid);
  118. $.prompt.jqib.removeClass(opts.prefix +'warning');
  119. }
  120. }, 100);
  121. });
  122. }
  123. else {
  124. $.prompt.close(true);
  125. }
  126. };
  127. // listen for esc or tab keys
  128. var keyPressEventHandler = function(e){
  129. var key = (window.event) ? event.keyCode : e.keyCode;
  130. //escape key closes
  131. if(key===27) {
  132. fadeClicked();
  133. }
  134. //constrain tabs, tabs should iterate through the state and not leave
  135. if (key === 9){
  136. var $inputels = $('input,select,textarea,button',$.prompt.getCurrentState());
  137. var fwd = !e.shiftKey && e.target === $inputels[$inputels.length-1];
  138. var back = e.shiftKey && e.target === $inputels[0];
  139. if (fwd || back) {
  140. setTimeout(function(){
  141. if (!$inputels){
  142. return;
  143. }
  144. var el = $inputels[back===true ? $inputels.length-1 : 0];
  145. if (el){
  146. el.focus();
  147. }
  148. },10);
  149. return false;
  150. }
  151. }
  152. };
  153. $.prompt.position();
  154. $.prompt.style();
  155. $.prompt.jqif.click(fadeClicked);
  156. $window.resize({animate:false}, $.prompt.position);
  157. $.prompt.jqi.find('.'+ opts.prefix +'close').click($.prompt.close);
  158. $.prompt.jqib.on("keydown",keyPressEventHandler)
  159. .on('impromptu:loaded', opts.loaded)
  160. .on('impromptu:close', opts.close)
  161. .on('impromptu:statechanging', opts.statechanging)
  162. .on('impromptu:statechanged', opts.statechanged);
  163. // Show it
  164. $.prompt.jqif[opts.show](opts.overlayspeed);
  165. $.prompt.jqi[opts.show](opts.promptspeed, function(){
  166. $.prompt.jqib.trigger('impromptu:loaded');
  167. });
  168. // Timeout
  169. if(opts.timeout > 0){
  170. $.prompt.timeout = setTimeout(function(){ $.prompt.close(true); },opts.timeout);
  171. }
  172. return $.prompt.jqib;
  173. };
  174. $.prompt.defaults = {
  175. prefix:'jqi',
  176. classes: {
  177. box: '',
  178. fade: '',
  179. prompt: '',
  180. close: '',
  181. title: '',
  182. message: '',
  183. buttons: '',
  184. button: '',
  185. defaultButton: ''
  186. },
  187. title: '',
  188. closeText: '&times;',
  189. buttons: {
  190. Ok: true
  191. },
  192. loaded: function(e){},
  193. submit: function(e,v,m,f){},
  194. close: function(e,v,m,f){},
  195. statechanging: function(e, from, to){},
  196. statechanged: function(e, to){},
  197. opacity: 0.6,
  198. zIndex: 999,
  199. overlayspeed: 'slow',
  200. promptspeed: 'fast',
  201. show: 'fadeIn',
  202. focus: 0,
  203. defaultButton: 0,
  204. useiframe: false,
  205. top: '15%',
  206. position: {
  207. container: null,
  208. x: null,
  209. y: null,
  210. arrow: null,
  211. width: null
  212. },
  213. persistent: true,
  214. timeout: 0,
  215. states: {},
  216. state: {
  217. name: null,
  218. title: '',
  219. html: '',
  220. buttons: {
  221. Ok: true
  222. },
  223. focus: 0,
  224. defaultButton: 0,
  225. position: {
  226. container: null,
  227. x: null,
  228. y: null,
  229. arrow: null,
  230. width: null
  231. },
  232. submit: function(e,v,m,f){
  233. return true;
  234. }
  235. }
  236. };
  237. /**
  238. * currentPrefix String - At any time this show be the prefix
  239. * of the current prompt ex: "jqi"
  240. */
  241. $.prompt.currentPrefix = $.prompt.defaults.prefix;
  242. /**
  243. * currentStateName String - At any time this is the current state
  244. * of the current prompt ex: "state0"
  245. */
  246. $.prompt.currentStateName = "";
  247. /**
  248. * setDefaults - Sets the default options
  249. * @param o Object - Options to set as defaults
  250. * @return void
  251. */
  252. $.prompt.setDefaults = function(o) {
  253. $.prompt.defaults = $.extend({}, $.prompt.defaults, o);
  254. };
  255. /**
  256. * setStateDefaults - Sets the default options for a state
  257. * @param o Object - Options to set as defaults
  258. * @return void
  259. */
  260. $.prompt.setStateDefaults = function(o) {
  261. $.prompt.defaults.state = $.extend({}, $.prompt.defaults.state, o);
  262. };
  263. /**
  264. * position - Repositions the prompt (Used internally)
  265. * @return void
  266. */
  267. $.prompt.position = function(e){
  268. var restoreFx = $.fx.off,
  269. $state = $.prompt.getCurrentState(),
  270. stateObj = $.prompt.options.states[$state.data('jqi-name')],
  271. pos = stateObj? stateObj.position : undefined,
  272. $window = $(window),
  273. bodyHeight = document.body.scrollHeight, //$(document.body).outerHeight(true),
  274. windowHeight = $(window).height(),
  275. documentHeight = $(document).height(),
  276. height = bodyHeight > windowHeight ? bodyHeight : windowHeight,
  277. top = parseInt($window.scrollTop(),10) + ($.prompt.options.top.toString().indexOf('%') >= 0?
  278. (windowHeight*(parseInt($.prompt.options.top,10)/100)) : parseInt($.prompt.options.top,10));
  279. // when resizing the window turn off animation
  280. if(e !== undefined && e.data.animate === false){
  281. $.fx.off = true;
  282. }
  283. $.prompt.jqib.css({
  284. position: "absolute",
  285. height: height,
  286. width: "100%",
  287. top: 0,
  288. left: 0,
  289. right: 0,
  290. bottom: 0
  291. });
  292. $.prompt.jqif.css({
  293. position: "fixed",
  294. height: height,
  295. width: "100%",
  296. top: 0,
  297. left: 0,
  298. right: 0,
  299. bottom: 0
  300. });
  301. // tour positioning
  302. if(pos && pos.container){
  303. var offset = $(pos.container).offset();
  304. if($.isPlainObject(offset) && offset.top !== undefined){
  305. $.prompt.jqi.css({
  306. position: "absolute"
  307. });
  308. $.prompt.jqi.animate({
  309. top: offset.top + pos.y,
  310. left: offset.left + pos.x,
  311. marginLeft: 0,
  312. width: (pos.width !== undefined)? pos.width : null
  313. });
  314. top = (offset.top + pos.y) - ($.prompt.options.top.toString().indexOf('%') >= 0? (windowHeight*(parseInt($.prompt.options.top,10)/100)) : parseInt($.prompt.options.top,10));
  315. $('html,body').animate({ scrollTop: top }, 'slow', 'swing', function(){});
  316. }
  317. }
  318. // custom state width animation
  319. else if(pos && pos.width){
  320. $.prompt.jqi.css({
  321. position: "absolute",
  322. left: '50%'
  323. });
  324. $.prompt.jqi.animate({
  325. top: pos.y || top,
  326. left: pos.x || '50%',
  327. marginLeft: ((pos.width/2)*-1),
  328. width: pos.width
  329. });
  330. }
  331. // standard prompt positioning
  332. else{
  333. $.prompt.jqi.css({
  334. position: "absolute",
  335. top: top,
  336. left: '50%',//$window.width()/2,
  337. marginLeft: (($.prompt.jqi.outerWidth(false)/2)*-1)
  338. });
  339. }
  340. // restore fx settings
  341. if(e !== undefined && e.data.animate === false){
  342. $.fx.off = restoreFx;
  343. }
  344. };
  345. /**
  346. * style - Restyles the prompt (Used internally)
  347. * @return void
  348. */
  349. $.prompt.style = function(){
  350. $.prompt.jqif.css({
  351. zIndex: $.prompt.options.zIndex,
  352. display: "none",
  353. opacity: $.prompt.options.opacity
  354. });
  355. $.prompt.jqi.css({
  356. zIndex: $.prompt.options.zIndex+1,
  357. display: "none"
  358. });
  359. $.prompt.jqib.css({
  360. zIndex: $.prompt.options.zIndex
  361. });
  362. };
  363. /**
  364. * get - Get the prompt
  365. * @return jQuery - the prompt
  366. */
  367. $.prompt.get = function(state) {
  368. return $('.'+ $.prompt.currentPrefix);
  369. };
  370. /**
  371. * addState - Injects a state into the prompt
  372. * @param statename String - Name of the state
  373. * @param stateobj Object - options for the state
  374. * @param afterState String - selector of the state to insert after
  375. * @return jQuery - the newly created state
  376. */
  377. $.prompt.addState = function(statename, stateobj, afterState) {
  378. var state = "",
  379. $state = null,
  380. arrow = "",
  381. title = "",
  382. opts = $.prompt.options,
  383. $jqistates = $('.'+ $.prompt.currentPrefix +'states'),
  384. defbtn,k,v,i=0;
  385. stateobj = $.extend({},$.prompt.defaults.state, {name:statename}, stateobj);
  386. if(stateobj.position.arrow !== null){
  387. arrow = '<div class="'+ opts.prefix + 'arrow '+ opts.prefix + 'arrow'+ stateobj.position.arrow +'"></div>';
  388. }
  389. if(stateobj.title && stateobj.title !== ''){
  390. title = '<div class="lead '+ opts.prefix + 'title '+ opts.classes.title +'">'+ stateobj.title +'</div>';
  391. }
  392. state += '<div id="'+ opts.prefix +'state_'+ statename +'" class="'+ opts.prefix + 'state" data-jqi-name="'+ statename +'" style="display:none;">'+
  393. arrow + title +
  394. '<div class="'+ opts.prefix +'message '+ opts.classes.message +'">' + stateobj.html +'</div>'+
  395. '<div class="'+ opts.prefix +'buttons '+ opts.classes.buttons +'"'+ ($.isEmptyObject(stateobj.buttons)? 'style="display:none;"':'') +'>';
  396. for(k in stateobj.buttons){
  397. v = stateobj.buttons[k],
  398. defbtn = stateobj.focus === i || (isNaN(stateobj.focus) && stateobj.defaultButton === i) ? ($.prompt.currentPrefix + 'defaultbutton ' + opts.classes.defaultButton) : '';
  399. if(typeof v === 'object'){
  400. state += '<button class="'+ opts.classes.button +' '+ defbtn;
  401. if(typeof v.classes !== "undefined"){
  402. state += ' '+ ($.isArray(v.classes)? v.classes.join(' ') : v.classes) + ' ';
  403. }
  404. state += '" name="' + opts.prefix + '_' + statename + '_button' + v.title.replace(/[^a-z0-9]+/gi,'') + '" id="' + opts.prefix + '_' + statename + '_button' + v.title.replace(/[^a-z0-9]+/gi,'') + '" value="' + v.value + '">' + v.title + '</button>';
  405. } else {
  406. state += '<button class="'+ opts.classes.button +' '+ defbtn +'" name="' + opts.prefix + '_' + statename + '_button' + k + '" id="' + opts.prefix + '_' + statename + '_button' + k + '" value="' + v + '">' + k + '</button>';
  407. }
  408. i++;
  409. }
  410. state += '</div></div>';
  411. $state = $(state);
  412. $state.on('impromptu:submit', stateobj.submit);
  413. if(afterState !== undefined){
  414. $jqistates.find('#'+ $.prompt.currentPrefix +'state_'+ afterState).after($state);
  415. }
  416. else{
  417. $jqistates.append($state);
  418. }
  419. $.prompt.options.states[statename] = stateobj;
  420. return $state;
  421. };
  422. /**
  423. * removeState - Removes a state from the promt
  424. * @param state String - Name of the state
  425. * @return Boolean - returns true on success, false on failure
  426. */
  427. $.prompt.removeState = function(state) {
  428. var $state = $.prompt.getState(state),
  429. rm = function(){ $state.remove(); };
  430. if($state.length === 0){
  431. return false;
  432. }
  433. // transition away from it before deleting
  434. if($state.is(':visible')){
  435. if($state.next().length > 0){
  436. $.prompt.nextState(rm);
  437. }
  438. else{
  439. $.prompt.prevState(rm);
  440. }
  441. }
  442. else{
  443. $state.slideUp('slow', rm);
  444. }
  445. return true;
  446. };
  447. /**
  448. * getState - Get the state by its name
  449. * @param state String - Name of the state
  450. * @return jQuery - the state
  451. */
  452. $.prompt.getState = function(state) {
  453. return $('#'+ $.prompt.currentPrefix +'state_'+ state);
  454. };
  455. $.prompt.getStateContent = function(state) {
  456. return $.prompt.getState(state);
  457. };
  458. /**
  459. * getCurrentState - Get the current visible state
  460. * @return jQuery - the current visible state
  461. */
  462. $.prompt.getCurrentState = function() {
  463. return $.prompt.getState($.prompt.getCurrentStateName());
  464. };
  465. /**
  466. * getCurrentStateName - Get the name of the current visible state
  467. * @return String - the current visible state's name
  468. */
  469. $.prompt.getCurrentStateName = function() {
  470. return $.prompt.currentStateName;
  471. };
  472. /**
  473. * goToState - Goto the specified state
  474. * @param state String - name of the state to transition to
  475. * @param subState Boolean - true to be a sub state within the currently open state
  476. * @param callback Function - called when the transition is complete
  477. * @return jQuery - the newly active state
  478. */
  479. $.prompt.goToState = function(state, subState, callback) {
  480. var $jqi = $.prompt.get(),
  481. jqiopts = $.prompt.options,
  482. $state = $.prompt.getState(state),
  483. stateobj = jqiopts.states[$state.data('jqi-name')],
  484. promptstatechanginge = new $.Event('impromptu:statechanging');
  485. // subState can be ommitted
  486. if(typeof subState === 'function'){
  487. callback = subState;
  488. subState = false;
  489. }
  490. $.prompt.jqib.trigger(promptstatechanginge, [$.prompt.getCurrentStateName(), state]);
  491. if(!promptstatechanginge.isDefaultPrevented() && $state.length > 0){
  492. $.prompt.jqi.find('.'+ $.prompt.currentPrefix +'parentstate').removeClass($.prompt.currentPrefix +'parentstate');
  493. if(subState){ // hide any open substates
  494. // get rid of any substates
  495. $.prompt.jqi.find('.'+ $.prompt.currentPrefix +'substate').not($state)
  496. .slideUp(jqiopts.promptspeed)
  497. .removeClass('.'+ $.prompt.currentPrefix +'substate')
  498. .find('.'+ $.prompt.currentPrefix +'arrow').hide();
  499. // add parent state class so it can be visible, but blocked
  500. $.prompt.jqi.find('.'+ $.prompt.currentPrefix +'state:visible').addClass($.prompt.currentPrefix +'parentstate');
  501. // add substate class so we know it will be smaller
  502. $state.addClass($.prompt.currentPrefix +'substate');
  503. }
  504. else{ // hide any open states
  505. $.prompt.jqi.find('.'+ $.prompt.currentPrefix +'state').not($state)
  506. .slideUp(jqiopts.promptspeed)
  507. .find('.'+ $.prompt.currentPrefix +'arrow').hide();
  508. }
  509. $.prompt.currentStateName = stateobj.name;
  510. $state.slideDown(jqiopts.promptspeed,function(){
  511. var $t = $(this);
  512. // if focus is a selector, find it, else its button index
  513. if(typeof(stateobj.focus) === 'string'){
  514. $t.find(stateobj.focus).eq(0).focus();
  515. }
  516. else{
  517. $t.find('.'+ $.prompt.currentPrefix +'defaultbutton').focus();
  518. }
  519. $t.find('.'+ $.prompt.currentPrefix +'arrow').show(jqiopts.promptspeed);
  520. if (typeof callback === 'function'){
  521. $.prompt.jqib.on('impromptu:statechanged', callback);
  522. }
  523. $.prompt.jqib.trigger('impromptu:statechanged', [state]);
  524. if (typeof callback === 'function'){
  525. $.prompt.jqib.off('impromptu:statechanged', callback);
  526. }
  527. });
  528. if(!subState){
  529. $.prompt.position();
  530. }
  531. }
  532. return $state;
  533. };
  534. /**
  535. * nextState - Transition to the next state
  536. * @param callback Function - called when the transition is complete
  537. * @return jQuery - the newly active state
  538. */
  539. $.prompt.nextState = function(callback) {
  540. var $next = $('#'+ $.prompt.currentPrefix +'state_'+ $.prompt.getCurrentStateName()).next();
  541. return $.prompt.goToState( $next.attr('id').replace($.prompt.currentPrefix +'state_',''), callback );
  542. };
  543. /**
  544. * prevState - Transition to the previous state
  545. * @param callback Function - called when the transition is complete
  546. * @return jQuery - the newly active state
  547. */
  548. $.prompt.prevState = function(callback) {
  549. var $prev = $('#'+ $.prompt.currentPrefix +'state_'+ $.prompt.getCurrentStateName()).prev();
  550. $.prompt.goToState( $prev.attr('id').replace($.prompt.currentPrefix +'state_',''), callback );
  551. };
  552. /**
  553. * close - Closes the prompt
  554. * @param callback Function - called when the transition is complete
  555. * @param clicked String - value of the button clicked (only used internally)
  556. * @param msg jQuery - The state message body (only used internally)
  557. * @param forvals Object - key/value pairs of all form field names and values (only used internally)
  558. * @return jQuery - the newly active state
  559. */
  560. $.prompt.close = function(callCallback, clicked, msg, formvals){
  561. if($.prompt.timeout){
  562. clearTimeout($.prompt.timeout);
  563. $.prompt.timeout = false;
  564. }
  565. $.prompt.jqib.fadeOut('fast',function(){
  566. if(callCallback) {
  567. $.prompt.jqib.trigger('impromptu:close', [clicked,msg,formvals]);
  568. }
  569. $.prompt.jqib.remove();
  570. $(window).off('resize',$.prompt.position);
  571. });
  572. };
  573. /**
  574. * Enable using $('.selector').prompt({});
  575. * This will grab the html within the prompt as the prompt message
  576. */
  577. $.fn.prompt = function(options){
  578. if(options === undefined){
  579. options = {};
  580. }
  581. if(options.withDataAndEvents === undefined){
  582. options.withDataAndEvents = false;
  583. }
  584. $.prompt($(this).clone(options.withDataAndEvents).html(),options);
  585. };
  586. })(jQuery);