diff --git a/css/custom.css b/css/custom.css index 97ef28f..c1ece71 100644 --- a/css/custom.css +++ b/css/custom.css @@ -23,4 +23,20 @@ height: 25px; width: auto; vertical-align: middle; +} + +/* row 214: untouched slider = grey handle + transparent selection; touched = + sliderhandlecolor (the .slider-handle rule in custom_header.twig). + The slider-is-untouched class is synced onto li.slider-item by + scripts/custom.js from the answer input's value — core's own + slider-untouched class on the .slider element is unreliable when + "slider_default_set" is on. Specificity (0,3,0) beats the .slider-handle + rule (0,1,0) from custom_header.twig regardless of style-block order. */ +.slider-item.slider-is-untouched .slider-handle { + background-color: grey; +} + +.slider-item.slider-is-untouched .slider-selection { + background: transparent; + box-shadow: none; } \ No newline at end of file diff --git a/scripts/custom.js b/scripts/custom.js index 5c9694c..9ced8af 100644 --- a/scripts/custom.js +++ b/scripts/custom.js @@ -65,4 +65,31 @@ $(document).on('ready pjax:scriptcomplete',function(){ // namespaced so re-running on pjax:scriptcomplete never stacks duplicate handlers $(window).off('resize.stickyheader').on('resize.stickyheader', fixBodyPaddingSticky); fixBodyPaddingSticky(); + + /** + * THEME ADDITION: untouched vs touched slider (grey handle when untouched, + * sliderhandlecolor when touched — styled in css/custom.css). + * Core toggles slider-untouched/slider-touched on the .slider element, but + * that class is NOT a reliable state signal (with "slider_default_set" an + * untouched slider keeps slider-touched). The reliable signal is the real + * answer input inside .slider-container (#answer, the .ls-js-hidden + * one — NOT the #answerslid bootstrap-slider element): it is empty + * until the slider is used. Sync a theme class slider-is-untouched onto + * the li.slider-item row; core fires change+keyup on that input on every + * slider action (slideStart/slideStop/reset via triggerChanges). + */ + var syncSliderItems = function () { + $('.slider-item').each(function () { + var item = $(this); + var container = item.find('.slider-container').first(); + var rootId = (container.attr('id') || '').replace(/slid-container$/, ''); + var root = rootId ? $('#' + rootId) : $(); + if (!root.length) { return; } + item.toggleClass('slider-is-untouched', String(root.val()) === ''); + }); + }; + syncSliderItems(); + // namespaced + rebound so re-running on pjax:scriptcomplete never stacks duplicates + $(document).off('change.sliderstate keyup.sliderstate input.sliderstate'); + $(document).on('change.sliderstate keyup.sliderstate input.sliderstate', '.slider-container input', syncSliderItems); });