-
-
Save hahalin/00bcb46e566415d5cb4b994fbb7ab737 to your computer and use it in GitHub Desktop.
JS Bin// source http://jsbin.com/secehifome
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> | |
| <script src="https://code.jquery.com/jquery-2.1.4.js"></script> | |
| <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>JS Bin</title> | |
| </head> | |
| <body> | |
| <input type="text" id="eda"></input> | |
| <button id="btn1">btn</button> | |
| <button id="btntest">btntest</button> | |
| <!-- Modal --> | |
| <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> | |
| <div class="modal-dialog" role="document"> | |
| <div class="modal-content"> | |
| <div class="modal-header"> | |
| <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> | |
| <h4 class="modal-title" id="myModalLabel">Modal title</h4> | |
| </div> | |
| <div class="modal-body"> | |
| ... | |
| </div> | |
| <div class="modal-footer"> | |
| <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> | |
| <button type="button" class="btn btn-primary" id="btnyes">Save changes</button> | |
| <button type="button" id="btnNo"> | |
| no</button> | |
| <button type="button" id="name">btnname</button> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <script id="jsbin-javascript"> | |
| function ConfirmYesNo(title, msg) { | |
| var dfd = jQuery.Deferred(); | |
| var $confirm = $('#myModal'); | |
| $confirm.modal('show'); | |
| $('#myModalLabel').html(title); | |
| $('#myModalText').html(msg); | |
| $('#name').off('click').click(function () { | |
| $confirm.modal('hide'); | |
| dfd.resolve("aaa"); | |
| return 1; | |
| }); | |
| $('#btnNo').off('click').click(function () { | |
| $confirm.modal('hide'); | |
| dfd.resolve("bbb"); | |
| return 0; | |
| }); | |
| return dfd.promise(); | |
| } | |
| function ValidationWarning(WarningMsg) { | |
| var a = ConfirmYesNo('title text', ' WarningMsg'); | |
| a.then(function (b) { | |
| console.log(b); | |
| $('#eda').val(b); | |
| //alert(b); | |
| }, | |
| function(c){ | |
| console.log(c); | |
| } | |
| ); | |
| } | |
| $('#btn1').click(function(){ | |
| ValidationWarning(); | |
| }); | |
| $('#btntest').click(function(){ | |
| // Existing object | |
| var obj = { | |
| hello: function( name ) { | |
| alert( "Hello " + name ); | |
| } | |
| }, | |
| // Create a Deferred | |
| defer = $.Deferred(); | |
| // Set object as a promise | |
| var aa=defer.promise(); | |
| // Resolve the deferred | |
| defer.resolve( "John" ); | |
| aa.done(function(a){ | |
| obj.hello(a); | |
| }); | |
| aa.then(function(a){ | |
| console.log(a); | |
| }); | |
| return; | |
| // Use the object as a Promise | |
| obj.done(function( name ) { | |
| obj.hello( name ); // Will alert "Hello John" | |
| }).hello( "Karl" ); // Will alert "Hello Karl" | |
| }); | |
| </script> | |
| <script id="jsbin-source-javascript" type="text/javascript">function ConfirmYesNo(title, msg) { | |
| var dfd = jQuery.Deferred(); | |
| var $confirm = $('#myModal'); | |
| $confirm.modal('show'); | |
| $('#myModalLabel').html(title); | |
| $('#myModalText').html(msg); | |
| $('#name').off('click').click(function () { | |
| $confirm.modal('hide'); | |
| dfd.resolve("aaa"); | |
| return 1; | |
| }); | |
| $('#btnNo').off('click').click(function () { | |
| $confirm.modal('hide'); | |
| dfd.resolve("bbb"); | |
| return 0; | |
| }); | |
| return dfd.promise(); | |
| } | |
| function ValidationWarning(WarningMsg) { | |
| var a = ConfirmYesNo('title text', ' WarningMsg'); | |
| a.then(function (b) { | |
| console.log(b); | |
| $('#eda').val(b); | |
| //alert(b); | |
| }, | |
| function(c){ | |
| console.log(c); | |
| } | |
| ); | |
| } | |
| $('#btn1').click(function(){ | |
| ValidationWarning(); | |
| }); | |
| $('#btntest').click(function(){ | |
| // Existing object | |
| var obj = { | |
| hello: function( name ) { | |
| alert( "Hello " + name ); | |
| } | |
| }, | |
| // Create a Deferred | |
| defer = $.Deferred(); | |
| // Set object as a promise | |
| var aa=defer.promise(); | |
| // Resolve the deferred | |
| defer.resolve( "John" ); | |
| aa.done(function(a){ | |
| obj.hello(a); | |
| }); | |
| aa.then(function(a){ | |
| console.log(a); | |
| }); | |
| return; | |
| // Use the object as a Promise | |
| obj.done(function( name ) { | |
| obj.hello( name ); // Will alert "Hello John" | |
| }).hello( "Karl" ); // Will alert "Hello Karl" | |
| }); | |
| </script></body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function ConfirmYesNo(title, msg) { | |
| var dfd = jQuery.Deferred(); | |
| var $confirm = $('#myModal'); | |
| $confirm.modal('show'); | |
| $('#myModalLabel').html(title); | |
| $('#myModalText').html(msg); | |
| $('#name').off('click').click(function () { | |
| $confirm.modal('hide'); | |
| dfd.resolve("aaa"); | |
| return 1; | |
| }); | |
| $('#btnNo').off('click').click(function () { | |
| $confirm.modal('hide'); | |
| dfd.resolve("bbb"); | |
| return 0; | |
| }); | |
| return dfd.promise(); | |
| } | |
| function ValidationWarning(WarningMsg) { | |
| var a = ConfirmYesNo('title text', ' WarningMsg'); | |
| a.then(function (b) { | |
| console.log(b); | |
| $('#eda').val(b); | |
| //alert(b); | |
| }, | |
| function(c){ | |
| console.log(c); | |
| } | |
| ); | |
| } | |
| $('#btn1').click(function(){ | |
| ValidationWarning(); | |
| }); | |
| $('#btntest').click(function(){ | |
| // Existing object | |
| var obj = { | |
| hello: function( name ) { | |
| alert( "Hello " + name ); | |
| } | |
| }, | |
| // Create a Deferred | |
| defer = $.Deferred(); | |
| // Set object as a promise | |
| var aa=defer.promise(); | |
| // Resolve the deferred | |
| defer.resolve( "John" ); | |
| aa.done(function(a){ | |
| obj.hello(a); | |
| }); | |
| aa.then(function(a){ | |
| console.log(a); | |
| }); | |
| return; | |
| // Use the object as a Promise | |
| obj.done(function( name ) { | |
| obj.hello( name ); // Will alert "Hello John" | |
| }).hello( "Karl" ); // Will alert "Hello Karl" | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment