SC CODE: Function InitializePrivate() Uint64
10 IF init() == 0 THEN GOTO 30
20 RETURN 1
30 STORE("nameHdr", "router-utils.js")
31 STORE("descrHdr", "Navigation helpers and utilities")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "explorer.tela")
34 STORE("docType", "TELA-JS-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "861faead6b38d8e6ef8cd78b4f960c5029d933a69f9b4bb122f820e8e8f213f")
37 STORE("fileCheckS", "1074dda6189672198b83c88c49c42ba287e0913fc2c94f7e25aa545f0e4c4abc")
100 RETURN 0
End Function
Function init() Uint64
10 IF EXISTS("owner") == 0 THEN GOTO 30
20 RETURN 1
30 STORE("owner", address())
50 STORE("docVersion", "1.0.0")
60 STORE("hash", HEX(TXID()))
70 STORE("likes", 0)
80 STORE("dislikes", 0)
100 RETURN 0
End Function
Function address() String
10 DIM s as String
20 LET s = SIGNER()
30 IF IS_ADDRESS_VALID(s) THEN GOTO 50
40 RETURN "anon"
50 RETURN ADDRESS_STRING(s)
End Function
Function Rate(r Uint64) Uint64
10 DIM addr as String
15 LET addr = address()
16 IF r < 100 && EXISTS(addr) == 0 && addr != "anon" THEN GOTO 30
20 RETURN 1
30 STORE(addr, ""+r+"_"+BLOCK_HEIGHT())
40 IF r < 50 THEN GOTO 70
50 STORE("likes", LOAD("likes")+1)
60 RETURN 0
70 STORE("dislikes", LOAD("dislikes")+1)
100 RETURN 0
End Function
/*
// TELA Explorer - Router Utilities (< 18KB)
// Navigation helpers and global functions
// Update active navigation button
function updateActiveNav(page) {
var buttons = document.querySelectorAll('.nav-btn');
// Remove active classes from all buttons and reset styles
buttons.forEach(function(button) {
button.classList.remove('active');
button.style.removeProperty('background');
button.style.removeProperty('color');
button.style.removeProperty('border-color');
});
// Handle home page special case - no button to highlight since logo handles this
if (page === 'loadHome' || page === 'home') {
return;
}
// Create a mapping of page names to data-page attributes
const pageMapping = {
'blocks': 'blocks',
'loadBlocksIncremental': 'blocks',
'transactions': 'transactions',
'pool': 'pool',
'smartcontracts': 'contracts',
'network': 'network'
};
const dataPage = pageMapping[page];
if (!dataPage) return;
// Find and activate the correct button
var activeButton = document.querySelector(`.nav-btn[data-page="${dataPage}"]`);
if (activeButton) {
activeButton.classList.add('active');
activeButton.style.setProperty('background', 'rgba(185,89,182,0.15)', 'important');
activeButton.style.setProperty('color', 'white', 'important');
activeButton.style.setProperty('border-color', '#b959b6', 'important');
window.currentActivePage = page;
}
}
// Navigate to specific block
function navigateToBlock(height) {
window.location.hash = 'block/' + height;
}
// Common loading and error templates
function getLoadingHtml(message) {
return '<div class="loading-progress">' + (message || 'Loading...') + '<div class="progress-bar"></div></div>';
}
function getErrorHtml(title, message) {
return '<div class="enhanced-card"><h3>' + (title || 'Error') + '</h3>' +
(message ? '<p>' + message + '</p>' : '') + '</div>';
}
function getConnectionErrorHtml() {
return '<div class="enhanced-card"><h3>TELA connection required</h3></div>';
}
// Navigation state helpers
function setRouteAndUpdateNav(route, param) {
if (window.setCurrentRoute) window.setCurrentRoute(route);
window.location.hash = route + (param ? '/' + param : '');
updateActiveNav(route);
}
// Immediate active state setter for instant visual feedback
function setActiveNavImmediate(clickedButton, page) {
var buttons = document.querySelectorAll('.nav-btn');
buttons.forEach(function(button) {
button.classList.remove('active');
button.style.removeProperty('background');
button.style.removeProperty('color');
button.style.removeProperty('border-color');
});
const pageMapping = {
'blocks': 'blocks',
'loadBlocksIncremental': 'blocks',
'transactions': 'transactions',
'pool': 'pool',
'smartcontracts': 'contracts',
'network': 'network'
};
const dataPage = pageMapping[page];
if (!dataPage) return;
var targetButton = clickedButton || document.querySelector(`.nav-btn[data-page="${dataPage}"]`);
if (targetButton) {
targetButton.classList.add('active');
targetButton.style.setProperty('background', 'rgba(185,89,182,0.15)', 'important');
targetButton.style.setProperty('color', 'white', 'important');
targetButton.style.setProperty('border-color', '#b959b6', 'important');
window.currentActivePage = page;
}
}
// Export functions directly to global scope
window.updateActiveNav = updateActiveNav;
window.navigateToBlock = navigateToBlock;
window.setActiveNavImmediate = setActiveNavImmediate;
window.navigateToPage = navigateToPage;
// Active state functionality integrated into router
// Export router utilities
window.routerUtils = {
updateActiveNav: updateActiveNav,
navigateToBlock: navigateToBlock,
getLoadingHtml: getLoadingHtml,
getErrorHtml: getErrorHtml,
getConnectionErrorHtml: getConnectionErrorHtml,
setRouteAndUpdateNav: setRouteAndUpdateNav,
setActiveNavImmediate: setActiveNavImmediate,
restoreActiveState: restoreActiveState
};
// Export restore function globally
window.restoreActiveState = restoreActiveState;
// Global router functions (keep for compatibility)
window.handleRoute = function() {
if (window.router) window.router.hr();
};
window.loadBlocks = function() {
if (window.router) window.router.lbs();
};
window.loadTransactions = function() {
if (window.router) window.router.lts();
};
window.loadNetwork = function() {
if (window.router) window.router.ln();
};
window.navigateToBlock = function(height) {
if (window.router) window.router.navigateToBlock(height);
};
window.loadBlocksIncremental = function() {
if (window.router) window.router.loadBlocksIncremental();
};
// Function to restore active state after page loads
function restoreActiveState() {
const hash = window.location.hash.slice(1);
const route = hash.split('/')[0] || 'home';
if (route && route !== 'home' && route !== '' && window.currentActivePage !== route) {
updateActiveNav(route);
}
}
// Removed conflicting definition - using direct export above
*/ |
SC Arguments: [Name:SC_ACTION Type:uint64 Value:'1' Name:SC_CODE Type:string Value:'Function InitializePrivate() Uint64
10 IF init() == 0 THEN GOTO 30
20 RETURN 1
30 STORE("nameHdr", "router-utils.js")
31 STORE("descrHdr", "Navigation helpers and utilities")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "explorer.tela")
34 STORE("docType", "TELA-JS-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "861faead6b38d8e6ef8cd78b4f960c5029d933a69f9b4bb122f820e8e8f213f")
37 STORE("fileCheckS", "1074dda6189672198b83c88c49c42ba287e0913fc2c94f7e25aa545f0e4c4abc")
100 RETURN 0
End Function
Function init() Uint64
10 IF EXISTS("owner") == 0 THEN GOTO 30
20 RETURN 1
30 STORE("owner", address())
50 STORE("docVersion", "1.0.0")
60 STORE("hash", HEX(TXID()))
70 STORE("likes", 0)
80 STORE("dislikes", 0)
100 RETURN 0
End Function
Function address() String
10 DIM s as String
20 LET s = SIGNER()
30 IF IS_ADDRESS_VALID(s) THEN GOTO 50
40 RETURN "anon"
50 RETURN ADDRESS_STRING(s)
End Function
Function Rate(r Uint64) Uint64
10 DIM addr as String
15 LET addr = address()
16 IF r < 100 && EXISTS(addr) == 0 && addr != "anon" THEN GOTO 30
20 RETURN 1
30 STORE(addr, ""+r+"_"+BLOCK_HEIGHT())
40 IF r < 50 THEN GOTO 70
50 STORE("likes", LOAD("likes")+1)
60 RETURN 0
70 STORE("dislikes", LOAD("dislikes")+1)
100 RETURN 0
End Function
/*
// TELA Explorer - Router Utilities (< 18KB)
// Navigation helpers and global functions
// Update active navigation button
function updateActiveNav(page) {
var buttons = document.querySelectorAll('.nav-btn');
// Remove active classes from all buttons and reset styles
buttons.forEach(function(button) {
button.classList.remove('active');
button.style.removeProperty('background');
button.style.removeProperty('color');
button.style.removeProperty('border-color');
});
// Handle home page special case - no button to highlight since logo handles this
if (page === 'loadHome' || page === 'home') {
return;
}
// Create a mapping of page names to data-page attributes
const pageMapping = {
'blocks': 'blocks',
'loadBlocksIncremental': 'blocks',
'transactions': 'transactions',
'pool': 'pool',
'smartcontracts': 'contracts',
'network': 'network'
};
const dataPage = pageMapping[page];
if (!dataPage) return;
// Find and activate the correct button
var activeButton = document.querySelector(`.nav-btn[data-page="${dataPage}"]`);
if (activeButton) {
activeButton.classList.add('active');
activeButton.style.setProperty('background', 'rgba(185,89,182,0.15)', 'important');
activeButton.style.setProperty('color', 'white', 'important');
activeButton.style.setProperty('border-color', '#b959b6', 'important');
window.currentActivePage = page;
}
}
// Navigate to specific block
function navigateToBlock(height) {
window.location.hash = 'block/' + height;
}
// Common loading and error templates
function getLoadingHtml(message) {
return '<div class="loading-progress">' + (message || 'Loading...') + '<div class="progress-bar"></div></div>';
}
function getErrorHtml(title, message) {
return '<div class="enhanced-card"><h3>' + (title || 'Error') + '</h3>' +
(message ? '<p>' + message + '</p>' : '') + '</div>';
}
function getConnectionErrorHtml() {
return '<div class="enhanced-card"><h3>TELA connection required</h3></div>';
}
// Navigation state helpers
function setRouteAndUpdateNav(route, param) {
if (window.setCurrentRoute) window.setCurrentRoute(route);
window.location.hash = route + (param ? '/' + param : '');
updateActiveNav(route);
}
// Immediate active state setter for instant visual feedback
function setActiveNavImmediate(clickedButton, page) {
var buttons = document.querySelectorAll('.nav-btn');
buttons.forEach(function(button) {
button.classList.remove('active');
button.style.removeProperty('background');
button.style.removeProperty('color');
button.style.removeProperty('border-color');
});
const pageMapping = {
'blocks': 'blocks',
'loadBlocksIncremental': 'blocks',
'transactions': 'transactions',
'pool': 'pool',
'smartcontracts': 'contracts',
'network': 'network'
};
const dataPage = pageMapping[page];
if (!dataPage) return;
var targetButton = clickedButton || document.querySelector(`.nav-btn[data-page="${dataPage}"]`);
if (targetButton) {
targetButton.classList.add('active');
targetButton.style.setProperty('background', 'rgba(185,89,182,0.15)', 'important');
targetButton.style.setProperty('color', 'white', 'important');
targetButton.style.setProperty('border-color', '#b959b6', 'important');
window.currentActivePage = page;
}
}
// Export functions directly to global scope
window.updateActiveNav = updateActiveNav;
window.navigateToBlock = navigateToBlock;
window.setActiveNavImmediate = setActiveNavImmediate;
window.navigateToPage = navigateToPage;
// Active state functionality integrated into router
// Export router utilities
window.routerUtils = {
updateActiveNav: updateActiveNav,
navigateToBlock: navigateToBlock,
getLoadingHtml: getLoadingHtml,
getErrorHtml: getErrorHtml,
getConnectionErrorHtml: getConnectionErrorHtml,
setRouteAndUpdateNav: setRouteAndUpdateNav,
setActiveNavImmediate: setActiveNavImmediate,
restoreActiveState: restoreActiveState
};
// Export restore function globally
window.restoreActiveState = restoreActiveState;
// Global router functions (keep for compatibility)
window.handleRoute = function() {
if (window.router) window.router.hr();
};
window.loadBlocks = function() {
if (window.router) window.router.lbs();
};
window.loadTransactions = function() {
if (window.router) window.router.lts();
};
window.loadNetwork = function() {
if (window.router) window.router.ln();
};
window.navigateToBlock = function(height) {
if (window.router) window.router.navigateToBlock(height);
};
window.loadBlocksIncremental = function() {
if (window.router) window.router.loadBlocksIncremental();
};
// Function to restore active state after page loads
function restoreActiveState() {
const hash = window.location.hash.slice(1);
const route = hash.split('/')[0] || 'home';
if (route && route !== 'home' && route !== '' && window.currentActivePage !== route) {
updateActiveNav(route);
}
}
// Removed conflicting definition - using direct export above
*/'] |