You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2015/10/08 12:54:01 UTC

svn commit: r1707474 - /sling/trunk/bundles/scripting/sightly/repl/src/main/resources/SLING-INF/etc/clientlibs/repl/script.js

Author: radu
Date: Thu Oct  8 10:54:01 2015
New Revision: 1707474

URL: http://svn.apache.org/viewvc?rev=1707474&view=rev
Log:
SLING-5127 - Implement browser history support for the Sightly REPL tabs

* added history events for the Source, View and Java tabs

Modified:
    sling/trunk/bundles/scripting/sightly/repl/src/main/resources/SLING-INF/etc/clientlibs/repl/script.js

Modified: sling/trunk/bundles/scripting/sightly/repl/src/main/resources/SLING-INF/etc/clientlibs/repl/script.js
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/repl/src/main/resources/SLING-INF/etc/clientlibs/repl/script.js?rev=1707474&r1=1707473&r2=1707474&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/repl/src/main/resources/SLING-INF/etc/clientlibs/repl/script.js (original)
+++ sling/trunk/bundles/scripting/sightly/repl/src/main/resources/SLING-INF/etc/clientlibs/repl/script.js Thu Oct  8 10:54:01 2015
@@ -21,7 +21,8 @@ jQuery(function ($) {
 
     'use strict';
 
-    var currentState = 'source';
+    var hash = window.location.hash;
+    var currentState = hash ? hash.substr(1) : 'source';
 
     // Limits the number of times the function gets called for event handlers
     function debounce(fn, delay) {
@@ -134,19 +135,28 @@ jQuery(function ($) {
         // Setup output tabs
         var allTargets = $('.output-view');
         $('a[data-toggle=tab]').each(function () {
-            var link = $(this);
-            var target = allTargets.filter(link.attr('href'));
-            var state = target.attr('id');
+            var link = $(this),
+                href = link.attr('href'),
+                target = allTargets.filter(href),
+                state = target.attr('id');
 
             link.click(function () {
                 currentState = state;
                 allTargets.addClass('hidden');
                 target.removeClass('hidden');
                 reloadOutput();
+                window.location = href;
             });
         });
+
+        $(window).on('hashchange', function () {
+            hash = window.location.hash;
+            currentState = hash ? hash.substr(1) : 'source';
+            $('a[href=#' + currentState + ']').click();
+        });
     }
 
     init();
+    $('a[href=#' + currentState + ']').click();
 
 });