Javaika
Javaika Technologies:

Lightweight platform for web developers.

Skip the bloat, build on clean infrastructure.

Modular decentralised web frameworks.

JT - "Just Works"

User Guide - Web Interface

13. Switch

This guide demonstrates how to display a switch, embedded within the window frame container. Resizing the window frame also resizes the switch proportionately; clicking the switch logs the event to the console.


                
               <!DOCTYPE html> <!-- Copyright (c) 2026 by Javaika Technologies -->

               <html lang = "en-AU"> <!-- Set the primary language to en-AU -->
    
                  <head>

                     <title>Switch</title> <!-- Set the page title -->
                     
                     <meta name = "robots" content = "noindex, follow">
  
                  </head>


                  <body>

                     <!-- Include the framework script tag -->
    
                     <script type = "module" src = "https://www.javaika.com/frame/web-interface@main/api.js"></script>
    
    
                     <!-- Run the demo as an ES Module -->

                     <script type = "module">
      
                        // Initialize a shorter prefix for referencing.

                        const jwi = window.javaika.webInterface;
                     
                        let switchControl; // Declare switch control.
            
            
                        // Initialize the developer token endpoint.
            
                        jwi.init({
            
                           tokenEndpoint: "https://www.javaika.com/pscript/jwt-access.php"
            
                        });
            
            
                        // Authenticate before using the framework.
            
                        jwi.requestToken({
              
                           framework: "web_interface" // Specify the framework for token issuance.
              
                        });
                     
                     
                        // Authenticate callback handler.
                     
                        function onAuthenticate(event)
                        {
                           jwi.refreshToken(); // Refresh the authentication token.
              
                           console.log('[Web Interface] Authentication received callback:', event);
                        }
                     
                     
                        // Window frame resized callback handler.
                     
                        function onWindowFrameResized(event)
                        {
                           jwi.scaleInterfaceControls(event.detail.scaleFactor);
                        }
                     
                     
                        // Switch initialized callback handler.
                     
                        function onSwitchInitialized(event)
                        {
                           switchControl.setSizeFactor(2.5); // Increase initial size.
                        
                           switchControl.setEvent('click', onClick); // Bind click event.
                        
                        
                           console.log('[Web Interface] Switch initialized callback:', event);
                        }
                     
                     
                        // Click callback handler.
                     
                        function onClick(event)
                        {
                           const active = switchControl.isActive();
                        
                        
                           console.log('[Web Interface] Click callback:', event);
                        
                           console.log('[Web Interface] Switch active:', active);
                        }
                     
                     
                        // Initialized callback handler.
                     
                        function onInitialized(event)
                        {
                           // Define the controls for the interface.
            
                           let windowFrame = new jwi.WindowFrame();
                        
                           switchControl = new jwi.Switch();
                        
                        
                           // Add initial styles for the switch.
                        
                           switchControl.addStyle('left', '40%');
                        
                           switchControl.addStyle('top', '45%');
                        
                        
                           // Add switch component to the window frame.
                        
                           windowFrame.addSwitchElement(switchControl);
                        
                        
                           // Enable manual resizing of the container window.
                        
                           jwi.setContainerManuallyResizable(true);
                        
                           jwi.setMaintainAspectRatio(true);
                        
                        
                           // Set handle offsets from the container window.
                        
                           jwi.setContainerOffsetHeight(50);
                        
                           jwi.setContainerOffsetWidth(50);
                        
                        
                           // Render interface to the browser window.
            
                           jwi.renderInterface(windowFrame);
                        
                        
                           console.log('[Web Interface] Framework initialized callback:', event);
                        }
                     
                     
                        // Callback event after authenticate.
            
                        document.addEventListener
                        (
                           'javaika.webInterface.authenticate', onAuthenticate
                        );
                     
                     
                        // Callback event after initialized.
            
                        document.addEventListener
                        (
                           'javaika.webInterface.initialized', onInitialized
                        );
                     
                     
                        // Callback event after switch initialized.
            
                        document.addEventListener
                        (
                           'javaika.webInterface.switchInitialized', onSwitchInitialized
                        );
                     
                     
                        // Callback event after window frame resize.
            
                        document.addEventListener
                        (
                           'javaika.webInterface.windowFrameResized', onWindowFrameResized
                        );
    
                     </script>

                  </body>
  
               </html>

            

                
               /* Standard class styles */

               .javaika-switch 
               {
                 transition: background-color 0.3s;
              
                 background-color: #F3F3F3;
                 border-radius: 15px;
              
                 box-sizing: border-box;
                 align-items: center;
              
                 position: absolute;
                 cursor: pointer;
              
                 border: 1px solid;
                 border-color: #AAA;
              
                 height: 30px;
                 width: 50px;
              
                 display: none;
               }
            
               .javaika-switch-knob
               {
                 background: linear-gradient(to bottom, #F0F0F0, #D0D0D0);
                
                 box-shadow: 0 0 0 1px #AAA inset;
              
                 transition: transform 0.3s;
              
                 transform: translateX(25%);
              
                 border-radius: 50%;
                  
                 position: absolute;
                 cursor: pointer;
            
                 height: 20px;
                 width: 20px;
               }
            
            
               /* Adjoined class styles */
            
               .javaika-switch.disabled
               {
                 pointer-events: none;
                 cursor: not-allowed;
              
                 opacity: 0.5;
               }
            
               .javaika-switch.on
               {
                 background-color: white;
               }
            
               .javaika-switch.on .javaika-switch-knob
               {
                 transform: translateX(calc(125% - 2px));
               }
            
            
               /* Pseudo class styles */
            
               .javaika-switch:focus
               {
                 outline: none;
               }
            
               .javaika-switch:focus-visible
               {
                 outline: 2px solid #809DFF;
              
                 outline-offset: 3px;
               }
            
               .javaika-switch-knob:hover
               {
                 background: linear-gradient(to bottom, #FAFAFA, #E0E0E0);
               }

            
View Demo   Download Demo

Next capability: Demonstrate how to incorporate a Date Picker.