(function() { window.spawn = window.spawn || function(gen) { function continuer(verb, arg) { var result; try { result = generator[verb](arg); } catch (err) { return Promise.reject(err); } if (result.done) { return result.value; } else { return Promise.resolve(result.value).then(onFulfilled, onRejected); } } var generator = gen(); var onFulfilled = continuer.bind(continuer, 'next'); var onRejected = continuer.bind(continuer, 'throw'); return onFulfilled(); }; window.showModalDialog2 = function(url) { if ($("#dialogModal").length) { $("#dialog-body").attr("src", url); $("#dialogModal").show(); return; } else if (window.parent) { if ($("#dialogModal", window.parent.document).length) { $("#dialog-body", window.parent.document).attr("src", url); $("#dialogModal", window.parent.document).show(); return; } } var dialog = document.body.appendChild(document.createElement('div')); dialog.setAttribute('id', 'dialogModal'); //dialog.setAttribute('style', opt.replace(/dialog/gi, '')); dialog.setAttribute('style', "width: 100%; height:100%; min-height: 100%; position:fixed; top:0px; left:0px; background-color:white;"); dialog.innerHTML = ''; /* document.getElementById('dialog-body').contentWindow.dialogArguments = arg; document.getElementById('dialog-close').addEventListener('click', function(e) { e.preventDefault(); dialog.close(); }); */ }; window.showModalDialog__ = function(url, arg, opt) { url = url || ''; //URL of a dialog arg = arg || null; //arguments to a dialog opt = opt || 'dialogWidth:300px;dialogHeight:200px'; //options: dialogTop;dialogLeft;dialogWidth;dialogHeight or CSS styles var caller = showModalDialog.caller.toString(); var dialog = document.body.appendChild(document.createElement('dialog')); dialog.setAttribute('id', 'dialogModal'); dialog.setAttribute('style', opt.replace(/dialog/gi, '')); dialog.innerHTML = '×'; document.getElementById('dialog-body').contentWindow.dialogArguments = arg; document.getElementById('dialog-close').addEventListener('click', function(e) { e.preventDefault(); dialog.close(); }); //dialog.showModal(); //if using yield if(caller.indexOf('yield') >= 0) { return new Promise(function(resolve, reject) { dialog.addEventListener('close', function() { var returnValue = document.getElementById('dialog-body').contentWindow.returnValue; document.body.removeChild(dialog); resolve(returnValue); }); }); } //if using eval var isNext = false; var nextStmts = caller.split('\n').filter(function(stmt) { if(isNext || stmt.indexOf('showModalDialog(') >= 0) return isNext = true; return false; }); dialog.addEventListener('close', function() { var returnValue = document.getElementById('dialog-body').contentWindow.returnValue; document.body.removeChild(dialog); nextStmts[0] = nextStmts[0].replace(/(window\.)?showModalDialog\(.*\)/g, JSON.stringify(returnValue)); eval('{\n' + nextStmts.join('\n')); }); // throw 'Execution stopped until showModalDialog is closed'; }; })(); $.fn.focusNextInputField = function() { return this.each(function() { var fields = $(this).parents('form:eq(0),body').find('button,input,textarea,select'); var index = fields.index( this ); if ( index > -1 && ( index + 1 ) < fields.length ) { fields.eq( index + 1 ).focus(); } return false; }); }; $("body").ready( function() { $('input').keydown(function(e) { if ( e.which == 13 ) { e.preventDefault(); $(this).focusNextInputField(); } }); });