├── index.php ├── README.md ├── style.css ├── liff-starter.js ├── catatan-config.js └── index.html /index.php: -------------------------------------------------------------------------------- 1 | { 52 | // start to use LIFF's api 53 | initializeApp(); 54 | }) 55 | .catch((err) => { 56 | document.getElementById("liffAppContent").classList.add('hidden'); 57 | document.getElementById("liffInitErrorMessage").classList.remove('hidden'); 58 | }); 59 | } 60 | 61 | /** 62 | * Initialize the app by calling functions handling individual app components 63 | */ 64 | function initializeApp() { 65 | displayLiffData(); 66 | displayIsInClientInfo(); 67 | registerButtonHandlers(); 68 | 69 | // check if the user is logged in/out, and disable inappropriate button 70 | if (liff.isLoggedIn()) { 71 | document.getElementById('liffLoginButton').disabled = true; 72 | } else { 73 | document.getElementById('liffLogoutButton').disabled = true; 74 | } 75 | } 76 | 77 | /** 78 | * Display data generated by invoking LIFF methods 79 | */ 80 | function displayLiffData() { 81 | document.getElementById('isInClient').textContent = liff.isInClient(); 82 | document.getElementById('isLoggedIn').textContent = liff.isLoggedIn(); 83 | } 84 | 85 | /** 86 | * Toggle the login/logout buttons based on the isInClient status, and display a message accordingly 87 | */ 88 | function displayIsInClientInfo() { 89 | if (liff.isInClient()) { 90 | document.getElementById('liffLoginButton').classList.toggle('hidden'); 91 | document.getElementById('liffLogoutButton').classList.toggle('hidden'); 92 | document.getElementById('isInClientMessage').textContent = 'You are opening the app in the in-app browser of LINE.'; 93 | } else { 94 | document.getElementById('isInClientMessage').textContent = 'You are opening the app in an external browser.'; 95 | } 96 | } 97 | 98 | function registerButtonHandlers() { 99 | // openWindow call 100 | document.getElementById('openWindowButton').addEventListener('click', function() { 101 | liff.openWindow({ 102 | url: 'https://catatanliffv2.herokuapp.com/', // Isi dengan Endpoint URL aplikasi web Anda 103 | external: true 104 | }); 105 | }); 106 | 107 | // closeWindow call 108 | document.getElementById('closeWindowButton').addEventListener('click', function() { 109 | if (!liff.isInClient()) { 110 | sendAlertIfNotInClient(); 111 | } else { 112 | liff.closeWindow(); 113 | } 114 | }); 115 | 116 | // login call, only when external browser is used 117 | document.getElementById('liffLoginButton').addEventListener('click', function() { 118 | if (!liff.isLoggedIn()) { 119 | liff.login(); 120 | } 121 | }); 122 | 123 | // logout call only when external browse 124 | document.getElementById('liffLogoutButton').addEventListener('click', function() { 125 | if (liff.isLoggedIn()) { 126 | liff.logout(); 127 | window.location.reload(); 128 | } 129 | }); 130 | 131 | // sendMessages call 132 | document.getElementById('sendMessageButton').addEventListener('click', function() { 133 | if (!liff.isInClient()) { 134 | sendAlertIfNotInClient(); 135 | } else { 136 | liff.sendMessages([{ 137 | 'type': 'text', 138 | 'text': "Anda telah menggunakan fitur Send Message!" 139 | }]).then(function() { 140 | window.alert('Ini adalah pesan dari fitur Send Message'); 141 | }).catch(function(error) { 142 | window.alert('Error sending message: ' + error); 143 | }); 144 | } 145 | }); 146 | } 147 | 148 | /** 149 | * Alert the user if LIFF is opened in an external browser and unavailable buttons are tapped 150 | */ 151 | function sendAlertIfNotInClient() { 152 | alert('This button is unavailable as LIFF is currently being opened in an external browser.'); 153 | } 154 | 155 | /** 156 | * Toggle specified element 157 | * @param {string} elementId The ID of the selected element 158 | */ 159 | function toggleElement(elementId) { 160 | const elem = document.getElementById(elementId); 161 | if (elem.offsetWidth > 0 && elem.offsetHeight > 0) { 162 | elem.style.display = 'none'; 163 | } else { 164 | elem.style.display = 'block'; 165 | } 166 | } -------------------------------------------------------------------------------- /catatan-config.js: -------------------------------------------------------------------------------- 1 | function loadCatatan() { 2 | if (localStorage.list_data && localStorage.id_data) { 3 | list_data = JSON.parse(localStorage.getItem('list_data')); 4 | var data_app = ""; 5 | if (list_data.length > 0) { 6 | data_app = '
| ID | ' + 9 | 'Nama | ' + 10 | 'Tanggal | ' + 11 | 'Agenda | ' + 12 | 'Hapus Agenda | ' + 13 | 'Lihat Agenda | ' + 14 | 'Edit Agenda | ' + 15 | ' '; 16 | 17 | for (i in list_data) { 18 | data_app += '
|---|---|---|---|---|---|---|
| ' + list_data[i].id_data + ' | ' + 21 | '' + list_data[i].nama + ' | ' + 22 | '' + list_data[i].tanggal + ' | ' + 23 | '' + list_data[i].agenda + ' | ' + 24 | 'Hapus | ' + 25 | 'Lihat | ' + 26 | 'Edit | '; 27 | data_app += '
| isInClient : | 129 |130 | |
|---|---|
| isLoggedIn : | 133 |134 | |
Available LIFF methods vary depending on the browser you use to open the LIFF app.
146 |Please refer to the API reference 148 | page for more information.
149 |You have not assigned any value for LIFF ID.
155 |If you are running the app using Node.js, please set the LIFF ID as an environment variable in your 156 | Heroku account follwing the below steps:
157 |
158 |
159 | - Go to `Dashboard` in your Heroku account.
160 | - Click on the app you just created.
161 | - Click on `Settings` and toggle `Reveal Config Vars`.
162 | - Set `MY_LIFF_ID` as the key and the LIFF ID as the value.
163 | - Your app should be up and running. Enter the URL of your app in a web browser.
164 |
165 |
166 | If you are using any other platform, please add your LIFF ID in the index.html file.
For more information about how to add your LIFF ID, see Initializing the LIFF 169 | app.
170 |Something went wrong with LIFF initialization.
174 |LIFF initialization can fail if a user clicks "Cancel" on the "Grant permission" screen, or if an error occurs in the process of liff.init().
175 |
Unable to receive the LIFF ID as an environment variable.
179 |