Commits

Daniel Herzog committed 0cd7c1f

Encanced add-remove-runtime test a bit

  • Participants
  • Parent commits bb8ba77

Comments (0)

Files changed (1)

File tests/add-remove-runtime/index.html

 	</style>
 </head>
 <body>
-  <input type="text" name="iframesrc" value="http://google.no" id="iframesrc">
-  <a href="#" class="add">Add iframe</a>
+  <form>
+    <input type="text" name="iframesrc" value="http://google.no" id="iframesrc"> 
+    <input type="submit" value="Add"></input>
+  </form>
   <div class="log"></div>
   <script src="http://jquery.com/src/jquery-latest.js"></script>
   <script>
     $(function(){
       
-      var add_iframe = function(url, force)
+      var add_iframe = function(evt_or_url)
       {
-        if (url || force)
+        var url = $("#iframesrc").val();
+        if (evt_or_url.preventDefault)
+        {
+          evt_or_url.preventDefault();
+        }
+        else if (typeof evt_or_url === "string")
+        {
+          url = evt_or_url;
+        }
+        if (url)
         {
           var container = $("<div>")
             .addClass("container")
           $("<iframe>")
             .attr("src", url)
             .appendTo(container);
+
+          // In case the last iframe was added via ?open=, set the url in the input field
+          if ($("#iframesrc").val() !== url)
+          {
+            $("#iframesrc").val(url);
+          }
         }
       }
 
-      $(".add").click(
+      // $(".add").click(add_iframe);
+      $("form").submit(
         function(evt)
         {
           add_iframe($("#iframesrc").val(), true);
           evt.preventDefault();
         }
-      );      
-      location.search.replace("?open=","").split(",").forEach(add_iframe);
+      );
+      var open_via_query = location.search.replace("?open=","").split(",")
+      if (open_via_query.length)
+      {
+        open_via_query.forEach(add_iframe);
+      }
     })
   </script>
 </body>