| 1 | <html lang="en"> |
| 2 | <head> |
| 3 | <style> |
| 4 | div { |
| 5 | transition: all 1000ms ease-in; |
| 6 | } |
| 7 | |
| 8 | .indicator { |
| 9 | opacity: 0; |
| 10 | } |
| 11 | |
| 12 | .hx-show-indicator .indicator { |
| 13 | opacity: 100%; |
| 14 | } |
| 15 | |
| 16 | </style> |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> |
| 22 | |
| 23 | </head> |
| 24 | <body style="padding:20px;font-family: sans-serif"> |
| 25 | <script src="../../node_modules/sinon/pkg/sinon.js"></script> |
| 26 | <script src="../../src/htmx.js"></script> |
| 27 | <script src="../util/util.js"></script> |
| 28 | <script src="../util/scratch_server.js"></script> |
| 29 | |
| 30 | <script> |
| 31 | |
| 32 | // this.server.respondWith("GET", "/test2", "Clicked!"); |
| 33 | // |
| 34 | // make('<div hx-get="/test">dd</div>') |
| 35 | |
| 36 | // htmx.logAll(); |
| 37 | |
| 38 | // var i = 1; |
| 39 | // this.server.respondWith("GET", "/test", function(xhr){ |
| 40 | // xhr.respond(201, {}, "" + i++); |
| 41 | // }); |
| 42 | // |
| 43 | // make('<div hx-get="/test" hx-trigger="load, every 5s">Init</div>'); |
| 44 | |
| 45 | let xhr; |
| 46 | |
| 47 | htmx.on('htmx:beforeSend', function(evt) { |
| 48 | xhr = evt.detail.xhr; |
| 49 | }); |
| 50 | |
| 51 | |
| 52 | </script> |
| 53 | |
| 54 | |
| 55 | |
| 56 | <h2>Server Options</h2> |
| 57 | <button onclick="server.respond()">Server Respond</button> |
| 58 | <br/> |
| 59 | Autorespond: <input id="autorespond" type="checkbox" onclick="toggleAutoRespond()"> |
| 60 | <br/> |
| 61 | <br/> |
| 62 | <em>Work Area</em> |
| 63 | <hr/> |
| 64 | |
| 65 | <form id="whatever"> |
| 66 | </form> |
| 67 | |
| 68 | <input form="whatever"> |
| 69 | |
| 70 | <div id="work-area" hx-history-elt> |
| 71 | <a id="a1" hx-boost="true" href="#" target="">Asdf</a> |
| 72 | </div> |
| 73 | |
| 74 | <button onclick="console.log(this, event)">Log It...</button> |
| 75 | |
| 76 | <button hx-get="/whatever"> |
| 77 | |
| 78 | </button> |
| 79 | |
| 80 | <script> |
| 81 | let requestCount = 0; |
| 82 | this.server.respondWith("GET", "/demo", function(xhr){ |
| 83 | let randomStr = (Math.random() + 1).toString(36).substring(7); |
| 84 | xhr.respond(200, {}, "Request #" + requestCount++ + " : " + randomStr) |
| 85 | }); |
| 86 | </script> |
| 87 | |
| 88 | <button hx-get="/demo" |
| 89 | hx-target="next h1" |
| 90 | hx-swap="innerHTML transition:true">Issue Request</button> |
| 91 | <h1 id="h1">--</h1> |
| 92 | |
| 93 | |
| 94 | <style> |
| 95 | @keyframes fade-in { |
| 96 | from { opacity: 0; } |
| 97 | } |
| 98 | |
| 99 | @keyframes fade-out { |
| 100 | to { opacity: 0; } |
| 101 | } |
| 102 | |
| 103 | @keyframes slide-from-right { |
| 104 | from { transform: translateX(90px); } |
| 105 | } |
| 106 | |
| 107 | @keyframes slide-to-left { |
| 108 | to { transform: translateX(-90px); } |
| 109 | } |
| 110 | |
| 111 | .slide-it { |
| 112 | view-transition-name: slide-it; |
| 113 | } |
| 114 | |
| 115 | ::view-transition-old(slide-it) { |
| 116 | animation: 180ms cubic-bezier(0.4, 0, 1, 1) both fade-out, |
| 117 | 600ms cubic-bezier(0.4, 0, 0.2, 1) both slide-to-left; |
| 118 | } |
| 119 | ::view-transition-new(slide-it) { |
| 120 | animation: 420ms cubic-bezier(0, 0, 0.2, 1) 90ms both fade-in, |
| 121 | 600ms cubic-bezier(0.4, 0, 0.2, 1) both slide-from-right; |
| 122 | } |
| 123 | </style> |
| 124 | |
| 125 | |
| 126 | <div class="slide-it"> |
| 127 | <h1>Initial Content</h1> |
| 128 | <button hx-get="/new-content" hx-swap="innerHTML transition:true" hx-target="closest div"> |
| 129 | Swap It! |
| 130 | </button> |
| 131 | </div> |
| 132 | |
| 133 | <script> |
| 134 | var originalContent = htmx.find(".slide-it").innerHTML; |
| 135 | |
| 136 | this.server.respondWith("GET", "/new-content", function(xhr){ |
| 137 | xhr.respond(200, {}, "<h1>Initial Content</h1> <button hx-get='/original-content' hx-swap='innerHTML transition:true' hx-target='closest div'>Restore It! </button>") |
| 138 | }); |
| 139 | |
| 140 | this.server.respondWith("GET", "/original-content", function(xhr){ |
| 141 | xhr.respond(200, {}, originalContent) |
| 142 | }); |
| 143 | </script> |
| 144 | |
| 145 | |
| 146 | </body> |
| 147 | </html> |