No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
/** | /* IFRAME COMMUNICATION */ | ||
(function() { | (function() { | ||
'use strict'; | 'use strict'; | ||
| Line 33: | Line 32: | ||
console.log('Click detected and reported:', elementInfo); | console.log('Click detected and reported:', elementInfo); | ||
}); | }); | ||
| Line 42: | Line 38: | ||
} | } | ||
})(); | })(); | ||
/* SIDEBAR CUSTOMIZATION */ | |||
$(document).ready(function() { | $(document).ready(function() { | ||
| Line 88: | Line 83: | ||
container.animate({ | container.animate({ | ||
scrollTop: twoPosition - 240 | scrollTop: twoPosition - 240 | ||
}, 300); // 300ms | }, 300); // 300ms | ||
}); | }); | ||
Revision as of 18:51, 20 March 2025
/* IFRAME COMMUNICATION */
(function() {
'use strict';
// Only run if we're in an iframe
if (window.parent !== window) {
// Wait for the page to load
$(function() {
// Configuration
var PARENT_ORIGIN = 'http://localhost:3001';
var CLICKABLE_ELEMENTS = [
'a' // Category links
];
// Add click handlers to the specified elements
$(CLICKABLE_ELEMENTS.join(', ')).on('click', function(e) {
// Get element information
var elementInfo = {
type: 'elementClicked',
elementId: this.id || 'unnamed-element',
elementTag: this.tagName.toLowerCase(),
elementClass: this.className,
elementText: $(this).text().trim(),
timestamp: Date.now()
};
// Send message to parent React app
window.parent.postMessage(elementInfo, PARENT_ORIGIN);
console.log('Click detected and reported:', elementInfo);
});
console.log('Click detection initialized for iframe communication');
});
}
})();
/* SIDEBAR CUSTOMIZATION */
$(document).ready(function() {
// Get element's position relative to the viewport
function getElementTopPosition(selector) {
var element = $(selector);
if (element.length) {
var elementPosition = element.offset().top;
var scrollTop = $(window).scrollTop();
var positionInViewport = elementPosition - scrollTop;
// Store the position for later use
var storedPosition = elementPosition;
console.log('Element position stored:', storedPosition);
return storedPosition;
}
return 0;
}
// Store positions when page loads
var onePosition = getElementTopPosition('.sidebar-heading.one');
var twoPosition = getElementTopPosition('.sidebar-heading.two');
var threePosition = getElementTopPosition('.sidebar-heading.three');
// Select elements with the scroll-trigger class
$('.sidebar-heading.one').click(function() {
// Find the scrollable container
var container = $('#topbar');
// Scroll to the top of the container (position 0)
container.animate({
scrollTop: onePosition - 202
}, 300); // 300ms animation duration
});
$('.sidebar-heading.two').click(function() {
// Find the scrollable container
var container = $('#topbar');
// Scroll to the top of the container (position 0)
container.animate({
scrollTop: twoPosition - 240
}, 300); // 300ms
});
// Select elements with the scroll-trigger class
$('.sidebar-heading.three').click(function() {
// Find the scrollable container
var container = $('#topbar');
// Scroll to the top of the container (position 0)
container.animate({
scrollTop: threePosition - 275
}, 300); // 300ms animation duration
});
});
