File size: 116,136 Bytes
105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 b5c09f4 105f246 4002961 105f246 b5c09f4 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 b5c09f4 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 b5c09f4 105f246 4002961 105f246 4002961 105f246 4002961 105f246 628fef6 105f246 b5c09f4 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 b5c09f4 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 628fef6 105f246 4002961 628fef6 4002961 105f246 4002961 628fef6 105f246 4002961 105f246 4002961 b5c09f4 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 b5c09f4 105f246 4002961 b5c09f4 4002961 105f246 4002961 105f246 4002961 628fef6 4002961 105f246 4002961 b5c09f4 4002961 b5c09f4 4002961 b5c09f4 4002961 b5c09f4 4002961 b5c09f4 105f246 4002961 105f246 b5c09f4 4002961 b5c09f4 105f246 b5c09f4 4002961 628fef6 b5c09f4 105f246 628fef6 b5c09f4 4002961 60ca6d2 105f246 4002961 60ca6d2 105f246 b5c09f4 105f246 b5c09f4 105f246 4002961 b5c09f4 4002961 b5c09f4 105f246 b5c09f4 4002961 b5c09f4 105f246 60ca6d2 4002961 60ca6d2 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 4002961 105f246 60ca6d2 4002961 105f246 60ca6d2 105f246 60ca6d2 105f246 60ca6d2 105f246 b5c09f4 105f246 b5c09f4 105f246 4002961 105f246 60ca6d2 105f246 b5c09f4 105f246 4002961 105f246 60ca6d2 4002961 105f246 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Advanced Component Builder (WordPress Safe)</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&family=Open+Sans:wght@400;700&family=Lato:wght@400;700&family=Montserrat:wght@400;700&family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.0/FileSaver.min.js"></script>
<style>
:root {
--primary-color: #3b82f6;
--primary-hover-color: #2563eb;
--secondary-color: #10b981;
--secondary-hover-color: #059669;
--text-color: #374151;
--heading-color: #111827;
--font-family: 'Inter', sans-serif;
}
body {
font-family: var(--font-family);
color: var(--text-color);
background-color: var(--background-color);
}
h1, h2, h3, h4, h5, h6 {
color: var(--heading-color);
}
/* Custom scrollbar for webkit browsers */
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
}
::-webkit-scrollbar-thumb {
background: #888;
border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
background: #555;
}
.onley-preview-iframe {
width: 100%;
height: 100%;
border: 0;
transition: all 0.3s ease-in-out;
}
#preview-container.onley-preview-desktop .onley-preview-iframe { width: 100%; }
#preview-container.onley-preview-tablet .onley-preview-iframe { width: 768px; margin: 0 auto; }
#preview-container.onley-preview-mobile .onley-preview-iframe { width: 375px; margin: 0 auto; }
.onley-toast {
visibility: hidden;
min-width: 250px;
background-color: #333;
color: #fff;
text-align: center;
border-radius: 8px;
padding: 16px;
position: fixed;
z-index: 100;
left: 50%;
bottom: 30px;
transform: translateX(-50%);
opacity: 0;
transition: opacity 0.3s, visibility 0.3s;
}
.onley-toast.onley-show {
visibility: visible;
opacity: 1;
}
/* New Professional Controls UI Styles */
#onley-controls-layout {
display: flex;
height: 100%;
}
#onley-controls-nav {
width: 180px;
flex-shrink: 0;
background-color: #f8fafc;
border-right: 1px solid #e5e7eb;
padding: 0.5rem;
overflow-y: auto;
}
.onley-control-nav-button {
display: flex;
align-items: center;
width: 100%;
padding: 0.75rem;
border-radius: 0.375rem;
font-weight: 500;
color: var(--text-color);
transition: background-color 0.2s, color 0.2s;
text-align: left;
}
.onley-control-nav-button:hover {
background-color: #e5e7eb;
}
.onley-control-nav-button.onley-active {
background-color: var(--primary-color);
color: white;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}
.onley-control-nav-button i {
margin-right: 0.75rem;
width: 20px;
text-align: center;
}
#onley-controls-panels {
flex-grow: 1;
padding: 1.5rem;
overflow-y: auto;
}
.onley-control-panel {
display: none;
}
.onley-control-panel.onley-active {
display: block;
}
.onley-control-panel h3 {
font-size: 1.25rem;
font-weight: 600;
margin-bottom: 1.5rem;
border-bottom: 1px solid #e5e7eb;
padding-bottom: 0.75rem;
}
.onley-nested-builder {
margin-left: 1rem;
padding-left: 1rem;
border-left: 2px solid #e5e7eb;
margin-top: 1rem;
padding-top: 1rem;
}
.onley-item-toolbar {
display: flex;
justify-content: flex-end;
gap: 0.25rem;
margin-bottom: 0.5rem;
}
.onley-layout-item {
cursor: move;
}
.onley-code-modal-pre {
background-color: #2d3748;
color: #e2e8f0;
padding: 1rem;
border-radius: 0.375rem;
max-height: 200px;
overflow-y: auto;
position: relative;
}
/* Feature: Hide/Show Sidebar */
#controls-sidebar {
flex-shrink: 0;
}
#main-container.onley-sidebar-collapsed #controls-sidebar {
width: 0;
padding: 0;
overflow: hidden;
}
#main-container.onley-sidebar-collapsed #preview-main {
width: 100%;
}
input[type="color"] {
-webkit-appearance: none;
border: none;
width: 100%;
height: 32px;
padding: 0;
border-radius: 0.25rem;
cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper {
padding: 0;
}
input[type="color"]::-webkit-color-swatch {
border: 1px solid #ccc;
border-radius: 0.25rem;
}
.onley-sub-items-container {
margin-left: 1rem;
padding-left: 1rem;
border-left: 2px solid #e5e7eb;
}
</style>
</head>
<body class="text-gray-800">
<div id="app" class="flex flex-col h-screen">
<header class="bg-white shadow-md p-4 flex justify-between items-center z-20">
<div class="flex items-center space-x-3">
<h1 class="text-xl font-bold text-gray-700">Component Builder</h1>
<button id="toggle-sidebar-btn" class="p-2 rounded-md hover:bg-gray-200 text-gray-600" title="Hide Controls">
<i class="fas fa-chevron-left"></i>
</button>
</div>
<div class="flex items-center space-x-4">
<button id="import-btn" class="flex items-center space-x-2 bg-blue-600 text-white font-bold py-2 px-4 rounded-md hover:bg-blue-700 transition">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
<path d="M10 2a1 1 0 00-1 1v5.586l-1.293-1.293a1 1 0 00-1.414 1.414l3 3a1 1 0 001.414 0l3-3a1 1 0 00-1.414-1.414L11 8.586V3a1 1 0 00-1-1z"></path>
<path d="M4 14a1 1 0 011 1v1a1 1 0 001 1h8a1 1 0 001-1v-1a1 1 0 112 0v1a3 3 0 01-3 3H6a3 3 0 01-3-3v-1a1 1 0 011-1z"></path>
</svg>
<span>Import</span>
</button>
<input type="file" id="import-file-input" class="hidden" accept=".html">
<div id="export-menu-container" class="relative">
<button id="export-menu-btn" class="flex items-center space-x-2 bg-green-600 text-white font-bold py-2 px-4 rounded-md hover:bg-green-700 transition">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M3 17a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM6.293 6.707a1 1 0 010-1.414l3-3a1 1 0 011.414 0l3 3a1 1 0 01-1.414 1.414L11 5.414V13a1 1 0 11-2 0V5.414L7.707 6.707a1 1 0 01-1.414 0z" clip-rule="evenodd"></path></svg>
<span>Export Page</span>
</button>
<div id="export-dropdown" class="hidden absolute right-0 mt-2 w-64 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 z-30">
<div class="py-1" role="menu" aria-orientation="vertical" aria-labelledby="export-menu-btn">
<a href="#" id="copy-combined-code" class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-3 text-gray-500" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"></path></svg>
<span>Copy Combined Code</span>
</a>
<a href="#" id="copy-html" class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-3 text-gray-500" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path d="M5 5a2 2 0 012-2h10a2 2 0 012 2v1h-14V5zM3 8h18v10a2 2 0 01-2 2H5a2 2 0 01-2-2V8z"></path></svg>
<span>Copy Embeddable HTML</span>
</a>
<a href="#" id="copy-css" class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-3 text-gray-500" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21a4 4 0 01-4-4V5a2 2 0 012-2h4a2 2 0 012 2v12a4 4 0 01-4 4zm0 0h12a2 2 0 002-2v-4a2 2 0 00-2-2h-2.343M11 7.343l1.657-1.657a2 2 0 012.828 0l2.829 2.829a2 2 0 010 2.828l-8.486 8.485M7 17h.01"></path></svg>
<span>Copy Page CSS</span>
</a>
<a href="#" id="copy-js" class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-3 text-gray-500" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M10 2a1 1 0 011 1v1h1a1 1 0 010 2h-1v1a1 1 0 01-2 0V6H8a1 1 0 010-2h1V3a1 1 0 011-1zM5 5a3 3 0 013-3h4a3 3 0 013 3v1h-1V5a2 2 0 00-2-2H8a2 2 0 00-2 2v1H5V5zm2 5a1 1 0 011-1h4a1 1 0 110 2H8a1 1 0 01-1-1zm-1 4a1 1 0 100 2h8a1 1 0 100-2H6z" clip-rule="evenodd" /></svg>
<span>Copy Page JS</span>
</a>
<div class="border-t border-gray-100"></div>
<a href="#" id="download-zip-btn" class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-3 text-gray-500" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M4 2a2 2 0 00-2 2v12a2 2 0 002 2h12a2 2 0 002-2V4a2 2 0 00-2-2H4zm1 3a1 1 0 000 2h10a1 1 0 100-2H5zM5 13a1 1 0 100 2h10a1 1 0 100-2H5z" clip-rule="evenodd"></path></svg>
<span>Download Page .zip</span>
</a>
</div>
</div>
</div>
<div class="flex items-center space-x-2">
<span class="text-sm font-medium text-gray-500">Preview:</span>
<button id="desktop-btn" class="p-2 rounded-md bg-blue-500 text-white shadow" title="Desktop View">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M10 2a2 2 0 00-2 2v1H6a2 2 0 00-2 2v7a2 2 0 002 2h8a2 2 0 002-2V7a2 2 0 00-2-2h-2V4a2 2 0 00-2-2zm-1 3V4a1 1 0 112 0v1h-2zM6 7v7h8V7H6z" clip-rule="evenodd"></path></svg>
</button>
<button id="tablet-btn" class="p-2 rounded-md bg-gray-200 text-gray-700" title="Tablet View">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M4 2a2 2 0 00-2 2v12a2 2 0 002 2h12a2 2 0 002-2V4a2 2 0 00-2-2H4zm1 2a1 1 0 00-1 1v10a1 1 0 001 1h10a1 1 0 001-1V5a1 1 0 00-1-1H5z" clip-rule="evenodd"></path></svg>
</button>
<button id="mobile-btn" class="p-2 rounded-md bg-gray-200 text-gray-700" title="Mobile View">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"><path d="M5 2a2 2 0 00-2 2v12a2 2 0 002 2h6a2 2 0 002-2V4a2 2 0 00-2-2H5z"></path></svg>
</button>
</div>
</div>
</header>
<div class="flex flex-1 overflow-hidden" id="main-container">
<aside id="controls-sidebar" class="w-1/3 bg-white shadow-lg overflow-hidden transition-all duration-300 ease-in-out">
<div id="onley-controls-layout">
<nav id="onley-controls-nav" class="space-y-2">
<button class="onley-control-nav-button" data-target="#panel-global-settings"><i class="fas fa-cog"></i>Global</button>
<button class="onley-control-nav-button" data-target="#panel-layout"><i class="fas fa-layer-group"></i>Layout</button>
<button class="onley-control-nav-button" data-target="#panel-topbar"><i class="fas fa-window-minimize fa-rotate-180"></i>Top Bar</button>
<button class="onley-control-nav-button" data-target="#panel-lms-header"><i class="fas fa-graduation-cap"></i>LMS Header</button>
<button class="onley-control-nav-button" data-target="#panel-lms-sidebar"><i class="fas fa-columns"></i>LMS Sidebar</button>
<button class="onley-control-nav-button" data-target="#panel-custom-html"><i class="fas fa-code"></i>Custom HTML</button>
</nav>
<div id="onley-controls-panels">
<div id="panel-global-settings" class="onley-control-panel">
<h3>⚙️ Global Settings</h3>
<div class="space-y-4">
<div class="space-y-2 border-b pb-4">
<label class="font-medium text-sm">Color Palette</label>
<div class="grid grid-cols-2 gap-2 text-xs">
<div>
<label for="global-color-primary">Primary</label>
<input type="color" id="global-color-primary" class="w-full p-0 h-8 border-none rounded-md">
</div>
<div>
<label for="global-color-secondary">Secondary</label>
<input type="color" id="global-color-secondary" class="w-full p-0 h-8 border-none rounded-md">
</div>
<div>
<label for="global-color-text">Text</label>
<input type="color" id="global-color-text" class="w-full p-0 h-8 border-none rounded-md">
</div>
<div>
<label for="global-color-heading">Heading</label>
<input type="color" id="global-color-heading" class="w-full p-0 h-8 border-none rounded-md">
</div>
</div>
</div>
<div class="space-y-2 border-b pb-4">
<label class="font-medium text-sm">Typography</label>
<div>
<label for="global-font-family" class="text-xs">Font Family</label>
<select id="global-font-family" class="w-full p-1 border rounded-md text-sm">
<option value="'Inter', sans-serif">Inter</option>
<option value="'Roboto', sans-serif">Roboto</option>
<option value="'Open Sans', sans-serif">Open Sans</option>
<option value="'Lato', sans-serif">Lato</option>
<option value="'Montserrat', sans-serif">Montserrat</option>
<option value="'Poppins', sans-serif">Poppins</option>
</select>
</div>
</div>
<button id="apply-global-settings" class="w-full bg-blue-600 text-white font-bold py-2 px-4 rounded-md hover:bg-blue-700 transition">Apply Global Styles</button>
</div>
</div>
<div id="panel-layout" class="onley-control-panel">
<h3>↕️ Component Layout</h3>
<p class="text-xs text-gray-500 mb-4">Drag and drop to change the vertical order of the components on your page.</p>
<div id="layout-builder-container" class="space-y-2"></div>
</div>
<div id="panel-topbar" class="onley-control-panel">
<h3>📢 Top Bar Settings</h3>
<div class="space-y-4">
<div class="flex justify-between items-center mb-6">
<h3 class="mb-0 pb-0 border-b-0"></h3>
<button class="get-component-code-btn text-sm bg-indigo-500 text-white py-1 px-3 rounded-md hover:bg-indigo-600" data-component-key="topBar">
<i class="fas fa-code mr-1"></i> Get Code
</button>
</div>
<div class="flex items-center space-x-2 border-b pb-4">
<input type="checkbox" id="topbar-toggle" class="h-4 w-4 rounded">
<label for="topbar-toggle">Enable Top Bar</label>
</div>
<div id="topbar-main-controls" class="space-y-4">
<div>
<label for="topbar-text" class="text-xs">Text (Can include HTML for advanced styling)</label>
<textarea id="topbar-text" rows="4" class="w-full p-1 border rounded-md text-sm"></textarea>
</div>
<div>
<label for="topbar-url" class="text-xs">Fallback Link URL (used if text is not HTML)</label>
<input type="text" id="topbar-url" class="w-full p-1 border rounded-md text-sm" placeholder="#">
</div>
<div id="topbar-style-controls" class="space-y-4 pt-4 border-t">
<div class="grid grid-cols-2 gap-2 text-xs">
<div>
<label for="topbar-bg-color-start">BG Gradient Start</label>
<input type="color" id="topbar-bg-color-start">
</div>
<div>
<label for="topbar-bg-color-end">BG Gradient End</label>
<input type="color" id="topbar-bg-color-end">
</div>
</div>
<div>
<label for="topbar-text-color" class="text-xs">Text Color</label>
<input type="color" id="topbar-text-color">
</div>
<div>
<label for="topbar-font-size" class="text-xs">Font Size (<span id="topbar-font-size-val"></span>px)</label>
<input type="range" id="topbar-font-size" min="10" max="24" class="w-full">
</div>
<div>
<label for="topbar-padding" class="text-xs">Padding (<span id="topbar-padding-val"></span>px)</label>
<input type="range" id="topbar-padding" min="4" max="20" class="w-full">
</div>
</div>
</div>
</div>
</div>
<div id="panel-lms-header" class="onley-control-panel">
<div class="flex justify-between items-center mb-6">
<h3 class="mb-0 pb-0 border-b-0">📚 Learning App Header</h3>
<button class="get-component-code-btn text-sm bg-indigo-500 text-white py-1 px-3 rounded-md hover:bg-indigo-600" data-component-key="lmsHeader">
<i class="fas fa-code mr-1"></i> Get Code
</button>
</div>
<div class="space-y-4">
<div class="space-y-2 border-b pb-4">
<div class="flex items-center space-x-2">
<input type="checkbox" id="lms-header-sticky-toggle" class="h-4 w-4 rounded">
<label for="lms-header-sticky-toggle" class="font-medium text-sm">Enable Sticky Header</label>
</div>
</div>
<div class="space-y-2 border-b pb-4">
<div class="flex items-center space-x-2">
<input type="checkbox" id="lms-primary-bar-toggle" class="h-4 w-4 rounded" checked>
<label for="lms-primary-bar-toggle" class="font-medium text-sm">Enable Top App Bar</label>
</div>
<div class="space-y-2 border-t pt-4 mt-4 pl-4">
<label class="font-medium text-xs">Brand Settings</label>
<div>
<label for="lms-brand-type" class="text-xs">Brand Type</label>
<select id="lms-brand-type" class="w-full p-1 border rounded-md text-sm">
<option value="text">Text</option>
<option value="image">Image Logo</option>
</select>
</div>
<div id="lms-brand-text-control">
<label for="lms-brand-text" class="text-xs">Brand Text</label>
<input type="text" id="lms-brand-text" class="w-full p-1 border rounded-md text-sm">
</div>
<div id="lms-brand-image-controls" class="hidden space-y-2">
<div>
<label for="lms-brand-image-url" class="text-xs">Logo Image URL</label>
<input type="text" id="lms-brand-image-url" class="w-full p-1 border rounded-md text-sm">
</div>
<div>
<label for="lms-brand-image-height" class="text-xs">Logo Height (px)</label>
<input type="range" id="lms-brand-image-height" min="20" max="80" value="30" class="w-full">
</div>
</div>
</div>
<div class="pl-4 space-y-2 pt-4 border-t mt-4">
<label class="font-medium text-xs">Elements</label>
<div class="flex items-center space-x-2"><input type="checkbox" id="lms-el-hamburger" class="h-4 w-4 rounded" checked><label for="lms-el-hamburger" class="text-sm">Hamburger Menu ☰</label></div>
<div class="flex items-center space-x-2"><input type="checkbox" id="lms-el-search" class="h-4 w-4 rounded" checked><label for="lms-el-search" class="text-sm">Search 🔍</label></div>
<div class="flex items-center space-x-2"><input type="checkbox" id="lms-el-notifications" class="h-4 w-4 rounded" checked><label for="lms-el-notifications" class="text-sm">Notification Bell 🔔</label></div>
<div class="pl-6"><label for="lms-notification-count" class="text-xs">Badge Count</label><input type="number" id="lms-notification-count" class="w-20 p-1 border rounded-md text-sm" value="2"></div>
<div class="flex items-center space-x-2"><input type="checkbox" id="lms-el-avatar" class="h-4 w-4 rounded" checked><label for="lms-el-avatar" class="text-sm">User Avatar 👤</label></div>
<div id="lms-avatar-url-control" class="pl-6 space-y-1"><label for="lms-avatar-url" class="text-xs">URL</label><input type="text" id="lms-avatar-url" class="w-full p-1 border rounded-md text-sm" placeholder="#"></div>
<label class="font-medium text-xs pt-2 block">Bonus Icons</label>
<div class="flex items-center space-x-2"><input type="checkbox" id="lms-el-refresh" class="h-4 w-4 rounded"><label for="lms-el-refresh" class="text-sm">Refresh Icon 🔁</label></div>
<div class="flex items-center space-x-2"><input type="checkbox" id="lms-el-theme" class="h-4 w-4 rounded" checked><label for="lms-el-theme" class="text-sm">Theme Toggle (Header) 🌙</label></div>
<div class="flex items-center space-x-2"><input type="checkbox" id="lms-el-calendar" class="h-4 w-4 rounded"><label for="lms-el-calendar" class="text-sm">Calendar Icon 📅</label></div>
<div class="flex items-center space-x-2"><input type="checkbox" id="lms-el-share" class="h-4 w-4 rounded"><label for="lms-el-share" class="text-sm">Share Icon 📤</label></div>
</div>
<div id="lms-custom-icons-builder" class="pl-4 space-y-2 pt-4 border-t mt-4">
<label class="font-medium text-xs">Custom Icons</label>
<div id="lms-custom-icons-container" class="space-y-2"></div>
<button id="add-lms-custom-icon-btn" class="text-sm bg-blue-500 text-white py-1 px-3 rounded-md hover:bg-blue-600">+ Add Custom Icon</button>
</div>
</div>
<div class="space-y-2 border-b pb-4">
<div class="flex items-center space-x-2">
<input type="checkbox" id="lms-page-title-toggle" class="h-4 w-4 rounded" checked>
<label for="lms-page-title-toggle" class="font-medium text-sm">Enable Page Title Area</label>
</div>
<div class="pl-4 space-y-2">
<div><label for="lms-page-title-text" class="text-xs">Page Title Text</label><input type="text" id="lms-page-title-text" class="w-full p-1 border rounded-md text-sm" value="Mock Test Series"></div>
<div class="flex items-center space-x-2"><input type="checkbox" id="lms-page-title-back" class="h-4 w-4 rounded" checked><label for="lms-page-title-back" class="text-sm">Show Back Button ←</label></div>
</div>
</div>
<div id="lms-tabs-builder" class="space-y-3">
<div class="flex items-center space-x-2">
<input type="checkbox" id="lms-tabs-toggle" class="h-4 w-4 rounded" checked>
<label for="lms-tabs-toggle" class="font-medium text-sm">Enable Secondary Header Tabs</label>
</div>
<div id="lms-tabs-container" class="space-y-2"></div>
<button id="add-lms-tab-btn" class="text-sm bg-blue-500 text-white py-1 px-3 rounded-md hover:bg-blue-600">+ Add Tab</button>
</div>
</div>
</div>
<div id="panel-lms-sidebar" class="onley-control-panel">
<div class="flex justify-between items-center mb-6">
<h3 class="mb-0 pb-0 border-b-0">📚 Learning App Sidebar</h3>
<button class="get-component-code-btn text-sm bg-indigo-500 text-white py-1 px-3 rounded-md hover:bg-indigo-600" data-component-key="sidebar">
<i class="fas fa-code mr-1"></i> Get Code
</button>
</div>
<div class="space-y-4">
<div class="flex items-center space-x-2 border-b pb-4">
<input type="checkbox" id="sidebar-enable-toggle" class="h-4 w-4 rounded" checked>
<label for="sidebar-enable-toggle" class="font-medium text-sm">Enable Sidebar</label>
</div>
<div id="sidebar-controls-container" class="space-y-4">
<div class="space-y-2 border-b pb-4">
<label class="font-medium text-sm">Branding Area</label>
<div class="flex items-center space-x-2"><input type="checkbox" id="sidebar-brand-logo-toggle" class="h-4 w-4 rounded"><label for="sidebar-brand-logo-toggle" class="text-sm">Show Logo</label></div>
<div class="flex items-center space-x-2"><input type="checkbox" id="sidebar-brand-sitename-toggle" class="h-4 w-4 rounded"><label for="sidebar-brand-sitename-toggle" class="text-sm">Show Sitename/Tagline</label></div>
<div><label class="text-xs">Sitename</label><input type="text" id="sidebar-brand-sitename" class="w-full p-1 border rounded-md text-sm"></div>
<div><label class="text-xs">Tagline</label><input type="text" id="sidebar-brand-tagline" class="w-full p-1 border rounded-md text-sm"></div>
</div>
<div id="sidebar-primary-nav-builder" class="space-y-3 border-b pb-4"></div>
<div id="sidebar-categories-builder" class="space-y-3 border-b pb-4"></div>
<div id="sidebar-user-section-builder" class="space-y-3 border-b pb-4"></div>
<div id="sidebar-shortcuts-builder" class="space-y-3 border-b pb-4"></div>
<div class="space-y-2 border-b pb-4 pl-4">
<label class="font-medium text-sm">Special Toggles</label>
<div class="flex items-center space-x-2">
<input type="checkbox" id="sidebar-theme-toggle-cb" class="h-4 w-4 rounded">
<label for="sidebar-theme-toggle-cb" class="text-sm">Add Dark/Light Mode Toggle</label>
</div>
</div>
<div id="sidebar-footer-builder" class="space-y-3 border-b pb-4"></div>
</div>
</div>
</div>
<div id="panel-custom-html" class="onley-control-panel">
<div class="flex justify-between items-center mb-6">
<h3 class="mb-0 pb-0 border-b-0"> </> Custom HTML</h3>
<button class="get-component-code-btn text-sm bg-indigo-500 text-white py-1 px-3 rounded-md hover:bg-indigo-600" data-component-key="customHtml">
<i class="fas fa-code mr-1"></i> Get Code
</button>
</div>
<div class="space-y-4">
<div class="flex items-center space-x-2 border-b pb-4">
<input type="checkbox" id="custom-html-toggle" class="h-4 w-4 rounded">
<label for="custom-html-toggle" class="font-medium">Enable Custom HTML Section</label>
</div>
<div id="custom-html-builder">
<label for="custom-html-content" class="text-sm font-medium">HTML Content</label>
<p class="text-xs text-gray-500 mb-2">Paste any valid HTML. Be cautious, as invalid code can break the page layout.</p>
<textarea id="custom-html-content" rows="10" class="w-full p-2 border rounded-md font-mono text-sm"></textarea>
</div>
</div>
</div>
</div>
</div>
</aside>
<main id="preview-main" class="w-2/3 bg-gray-200 p-4 flex flex-col items-center justify-center overflow-hidden transition-all duration-300 ease-in-out">
<div id="preview-container" class="bg-white shadow-lg rounded-lg w-full h-full overflow-hidden">
<iframe id="preview-iframe" class="onley-preview-iframe"></iframe>
</div>
</main>
</div>
</div>
<div id="toast-notification" class="onley-toast"></div>
<div id="code-modal" class="hidden fixed inset-0 bg-gray-600 bg-opacity-75 overflow-y-auto h-full w-full z-50">
<div class="relative top-10 mx-auto p-5 border w-11/12 md:w-2/3 shadow-lg rounded-md bg-white">
<div class="flex justify-between items-center border-b pb-3">
<h3 id="code-modal-title" class="text-lg leading-6 font-medium text-gray-900">Component Code</h3>
<button id="close-code-modal-btn" class="text-gray-400 hover:text-gray-600">×</button>
</div>
<div class="mt-4 space-y-4">
<div>
<label class="font-semibold text-gray-700">HTML</label>
<pre id="code-modal-html" class="onley-code-modal-pre"><code></code></pre>
</div>
<div>
<label class="font-semibold text-gray-700">CSS</label>
<pre id="code-modal-css" class="onley-code-modal-pre"><code></code></pre>
</div>
<div>
<label class="font-semibold text-gray-700">JavaScript</label>
<pre id="code-modal-js" class="onley-code-modal-pre"><code></code></pre>
</div>
</div>
<div class="items-center px-4 py-3 mt-4 text-right bg-gray-50 -mx-5 -mb-5 rounded-b-md">
<button id="download-component-zip-btn" class="px-4 py-2 bg-green-600 text-white text-base font-medium rounded-md shadow-sm hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-300">
Download .zip
</button>
<button id="close-code-modal-btn-2" class="px-4 py-2 bg-gray-200 text-gray-800 text-base font-medium rounded-md shadow-sm hover:bg-gray-300 focus:outline-none focus:ring-2 focus:ring-gray-300 ml-2">
Close
</button>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
// State object to hold all configurations
const config = {
globalSettings: {
colors: {
primary: '#3b82f6',
secondary: '#10b981',
text: '#374151',
heading: '#111827',
},
typography: {
fontFamily: "'Inter', sans-serif",
}
},
componentOrder: [
'topBar',
'lmsHeader',
'customHtml',
],
customHtml: {
enabled: false,
content: '<h2>Custom HTML Content</h2><p>This is a placeholder for your own HTML code.</p>'
},
learningAppHeader: {
sticky: false,
primaryBar: {
enabled: true,
brand: {
type: 'image',
text: 'LearnX',
imageUrl: 'https://examups.com/wp-content/uploads/2024/08/examups.com-2.png',
height: 30,
},
elements: {
hamburger: true,
search: true,
notifications: { enabled: true, url: '#' },
avatar: { enabled: true, url: '#' },
refresh: false,
themeToggle: true,
calendar: false,
share: false,
customIcons: [
{ name: 'Cart', icon: 'fas fa-shopping-cart', url: '#', enabled: true },
{ name: 'Dashboard', icon: 'fas fa-th-large', url: '#', enabled: true },
]
},
notificationCount: 2
},
pageTitle: {
enabled: true,
text: 'Mock Test Series',
showBackButton: true,
},
tabs: {
enabled: true,
items: [
{ text: 'All', url: '#', active: true },
{ text: 'Courses', url: '#', active: false },
{ text: 'Mock Tests', url: '#', active: false },
]
}
},
sidebar: {
enabled: true,
branding: {
showLogo: true,
showSitename: true,
sitename: 'ExamUPS',
tagline: 'Your Learning Partner'
},
primaryNav: {
enabled: true,
title: 'Primary Navigation',
links: [
{ icon: 'fas fa-tachometer-alt', text: 'Dashboard', url: '#', enabled: true },
{ icon: 'fas fa-book', text: 'My Courses', url: '#', enabled: true },
{ icon: 'fas fa-file-alt', text: 'Mock Test Series', url: '#', enabled: true },
]
},
categories: {
enabled: true,
title: 'Course & Test Categories',
links: [ { icon: 'fas fa-leaf', text: 'Agriculture', url: '#', enabled: true }, ]
},
userSection: { enabled: true, title: 'User Account', links: [ { icon: 'fas fa-user-circle', text: 'Profile', url: '#', enabled: true }, ] },
shortcuts: { enabled: true, title: 'Shortcuts & CTA', links: [ { icon: 'fas fa-bell', text: 'Notifications', url: '#', badge: '3', enabled: true }, { icon: 'fas fa-moon', text: 'Theme Toggle', url: '#', enabled: true, isThemeToggle: true } ] },
footer: { enabled: true, title: 'Support', links: [ { icon: 'fas fa-headset', text: 'Contact / Support', url: '#', enabled: true }, ] }
},
topBar: {
enabled: true,
text: '<i class="fas fa-gift onley-offer-icon"></i> Special Announcement! Save 25% on all test series! <a href="#" class="onley-cta-button">Claim Offer</a>',
url: '#', // Fallback URL
styles: {
bgColorStart: '#004d40',
bgColorEnd: '#009688',
textColor: '#ffffff',
fontSize: '14',
padding: '10'
}
}
};
const componentNames = {
customHtml: 'Custom HTML',
lmsHeader: 'LMS Header',
sidebar: 'LMS Sidebar',
topBar: 'Top Bar',
};
// UI Element References
const ui = {
previewIframe: document.getElementById('preview-iframe'),
mainContainer: document.getElementById('main-container'),
toggleSidebarBtn: document.getElementById('toggle-sidebar-btn'),
controls: {
nav: document.getElementById('onley-controls-nav'),
panels: document.getElementById('onley-controls-panels'),
},
globalSettings: {
primaryColor: document.getElementById('global-color-primary'),
secondaryColor: document.getElementById('global-color-secondary'),
textColor: document.getElementById('global-color-text'),
headingColor: document.getElementById('global-color-heading'),
fontFamily: document.getElementById('global-font-family'),
applyBtn: document.getElementById('apply-global-settings'),
},
layout: {
container: document.getElementById('layout-builder-container'),
panel: document.getElementById('panel-layout')
},
customHtml: {
toggle: document.getElementById('custom-html-toggle'),
content: document.getElementById('custom-html-content'),
},
learningAppHeader: {
stickyToggle: document.getElementById('lms-header-sticky-toggle'),
primaryBarToggle: document.getElementById('lms-primary-bar-toggle'),
brand: { type: document.getElementById('lms-brand-type'), text: document.getElementById('lms-brand-text'), textControl: document.getElementById('lms-brand-text-control'), imageUrl: document.getElementById('lms-brand-image-url'), imageHeight: document.getElementById('lms-brand-image-height'), imageControls: document.getElementById('lms-brand-image-controls'), },
elHamburger: document.getElementById('lms-el-hamburger'),
elSearch: document.getElementById('lms-el-search'),
elNotifications: document.getElementById('lms-el-notifications'),
notificationCount: document.getElementById('lms-notification-count'),
elAvatar: document.getElementById('lms-el-avatar'),
lmsAvatarUrl: document.getElementById('lms-avatar-url'),
lmsAvatarUrlControl: document.getElementById('lms-avatar-url-control'),
elRefresh: document.getElementById('lms-el-refresh'),
elTheme: document.getElementById('lms-el-theme'),
elCalendar: document.getElementById('lms-el-calendar'),
elShare: document.getElementById('lms-el-share'),
pageTitleToggle: document.getElementById('lms-page-title-toggle'),
pageTitleText: document.getElementById('lms-page-title-text'),
pageTitleBack: document.getElementById('lms-page-title-back'),
tabs: { toggle: document.getElementById('lms-tabs-toggle'), builder: document.getElementById('lms-tabs-builder'), container: document.getElementById('lms-tabs-container'), },
customIcons: { builder: document.getElementById('lms-custom-icons-builder'), container: document.getElementById('lms-custom-icons-container') }
},
sidebar: {
enableToggle: document.getElementById('sidebar-enable-toggle'),
controlsContainer: document.getElementById('sidebar-controls-container'),
brand: { logoToggle: document.getElementById('sidebar-brand-logo-toggle'), sitenameToggle: document.getElementById('sidebar-brand-sitename-toggle'), sitename: document.getElementById('sidebar-brand-sitename'), tagline: document.getElementById('sidebar-brand-tagline'), },
primaryNavBuilder: document.getElementById('sidebar-primary-nav-builder'),
categoriesBuilder: document.getElementById('sidebar-categories-builder'),
userSectionBuilder: document.getElementById('sidebar-user-section-builder'),
shortcutsBuilder: document.getElementById('sidebar-shortcuts-builder'),
themeToggleCheckbox: document.getElementById('sidebar-theme-toggle-cb'),
footerBuilder: document.getElementById('sidebar-footer-builder'),
},
topBar: {
toggle: document.getElementById('topbar-toggle'),
text: document.getElementById('topbar-text'),
url: document.getElementById('topbar-url'),
mainControls: document.getElementById('topbar-main-controls'),
bgColorStart: document.getElementById('topbar-bg-color-start'),
bgColorEnd: document.getElementById('topbar-bg-color-end'),
textColor: document.getElementById('topbar-text-color'),
fontSize: document.getElementById('topbar-font-size'),
padding: document.getElementById('topbar-padding'),
fontSizeVal: document.getElementById('topbar-font-size-val'),
paddingVal: document.getElementById('topbar-padding-val'),
},
buttons: {
desktop: document.getElementById('desktop-btn'),
tablet: document.getElementById('tablet-btn'),
mobile: document.getElementById('mobile-btn'),
import: document.getElementById('import-btn'),
importFile: document.getElementById('import-file-input'),
},
exportMenu: {
container: document.getElementById('export-menu-container'),
button: document.getElementById('export-menu-btn'),
dropdown: document.getElementById('export-dropdown'),
copyCombined: document.getElementById('copy-combined-code'),
copyHtml: document.getElementById('copy-html'),
copyCss: document.getElementById('copy-css'),
copyJs: document.getElementById('copy-js'),
downloadZip: document.getElementById('download-zip-btn'),
},
codeModal: {
modal: document.getElementById('code-modal'),
title: document.getElementById('code-modal-title'),
htmlContainer: document.getElementById('code-modal-html'),
cssContainer: document.getElementById('code-modal-css'),
jsContainer: document.getElementById('code-modal-js'),
htmlCode: document.querySelector('#code-modal-html code'),
cssCode: document.querySelector('#code-modal-css code'),
jsCode: document.querySelector('#code-modal-js code'),
downloadBtn: document.getElementById('download-component-zip-btn'),
closeBtns: [document.getElementById('close-code-modal-btn'), document.getElementById('close-code-modal-btn-2')],
},
previewContainer: document.getElementById('preview-container'),
};
// --- Event Listeners ---
function setupEventListeners() {
ui.controls.nav.addEventListener('click', (e) => {
const button = e.target.closest('.onley-control-nav-button');
if (!button) return;
const targetPanelId = button.dataset.target;
ui.controls.nav.querySelectorAll('.onley-control-nav-button').forEach(btn => btn.classList.remove('onley-active'));
button.classList.add('onley-active');
ui.controls.panels.querySelectorAll('.onley-control-panel').forEach(panel => {
panel.classList.toggle('onley-active', `#${panel.id}` === targetPanelId);
});
});
// Global Settings Listeners
ui.globalSettings.primaryColor.addEventListener('input', e => { config.globalSettings.colors.primary = e.target.value; renderAll(); });
ui.globalSettings.secondaryColor.addEventListener('input', e => { config.globalSettings.colors.secondary = e.target.value; renderAll(); });
ui.globalSettings.textColor.addEventListener('input', e => { config.globalSettings.colors.text = e.target.value; renderAll(); });
ui.globalSettings.headingColor.addEventListener('input', e => { config.globalSettings.colors.heading = e.target.value; renderAll(); });
ui.globalSettings.fontFamily.addEventListener('change', e => { config.globalSettings.typography.fontFamily = e.target.value; renderAll(); });
ui.globalSettings.applyBtn.addEventListener('click', () => {
renderAll();
showToast('Global styles applied!');
});
// Layout Controls
ui.layout.panel.addEventListener('click', handleLayoutControlsClick);
setupDragAndDrop();
// Component Listeners
ui.customHtml.toggle.addEventListener('change', e => { config.customHtml.enabled = e.target.checked; renderAll(); });
ui.customHtml.content.addEventListener('input', e => { config.customHtml.content = e.target.value; renderAll(); });
// LMS Header Listeners
const lmsUI = ui.learningAppHeader;
const lmsConfig = config.learningAppHeader;
lmsUI.stickyToggle.addEventListener('change', e => { lmsConfig.sticky = e.target.checked; renderAll(); });
lmsUI.primaryBarToggle.addEventListener('change', e => { lmsConfig.primaryBar.enabled = e.target.checked; renderAll(); });
lmsUI.brand.type.addEventListener('change', e => { lmsConfig.primaryBar.brand.type = e.target.value; toggleLmsBrandControls(); renderAll(); });
lmsUI.brand.text.addEventListener('input', e => { lmsConfig.primaryBar.brand.text = e.target.value; renderAll(); });
lmsUI.brand.imageUrl.addEventListener('input', e => { lmsConfig.primaryBar.brand.imageUrl = e.target.value; renderAll(); });
lmsUI.brand.imageHeight.addEventListener('input', e => { lmsConfig.primaryBar.brand.height = e.target.value; renderAll(); });
lmsUI.elHamburger.addEventListener('change', e => { lmsConfig.primaryBar.elements.hamburger = e.target.checked; renderAll(); });
lmsUI.elSearch.addEventListener('change', e => { lmsConfig.primaryBar.elements.search = e.target.checked; renderAll(); });
lmsUI.elNotifications.addEventListener('change', e => { lmsConfig.primaryBar.elements.notifications.enabled = e.target.checked; renderAll(); });
lmsUI.notificationCount.addEventListener('input', e => { lmsConfig.primaryBar.notificationCount = e.target.value; renderAll(); });
lmsUI.elAvatar.addEventListener('change', e => { const isChecked = e.target.checked; lmsConfig.primaryBar.elements.avatar.enabled = isChecked; lmsUI.lmsAvatarUrlControl.style.display = isChecked ? 'block' : 'none'; renderAll(); });
lmsUI.lmsAvatarUrl.addEventListener('input', e => { lmsConfig.primaryBar.elements.avatar.url = e.target.value; renderAll(); });
lmsUI.elRefresh.addEventListener('change', e => { lmsConfig.primaryBar.elements.refresh = e.target.checked; renderAll(); });
lmsUI.elTheme.addEventListener('change', e => { lmsConfig.primaryBar.elements.themeToggle = e.target.checked; renderAll(); });
lmsUI.elCalendar.addEventListener('change', e => { lmsConfig.primaryBar.elements.calendar = e.target.checked; renderAll(); });
lmsUI.elShare.addEventListener('change', e => { lmsConfig.primaryBar.elements.share = e.target.checked; renderAll(); });
lmsUI.pageTitleToggle.addEventListener('change', e => { lmsConfig.pageTitle.enabled = e.target.checked; renderAll(); });
lmsUI.pageTitleText.addEventListener('input', e => { lmsConfig.pageTitle.text = e.target.value; renderAll(); });
lmsUI.pageTitleBack.addEventListener('change', e => { lmsConfig.pageTitle.showBackButton = e.target.checked; renderAll(); });
lmsUI.tabs.toggle.addEventListener('change', e => { lmsConfig.tabs.enabled = e.target.checked; renderAll(); });
lmsUI.tabs.builder.addEventListener('click', handleLmsTabsClick);
lmsUI.tabs.builder.addEventListener('input', handleLmsTabsChange);
lmsUI.customIcons.builder.addEventListener('click', handleLmsCustomIconsClick);
lmsUI.customIcons.builder.addEventListener('input', handleLmsCustomIconsChange);
// Sidebar Listeners
const sidebarUI = ui.sidebar;
const sidebarConfig = config.sidebar;
sidebarUI.enableToggle.addEventListener('change', e => { sidebarConfig.enabled = e.target.checked; sidebarUI.controlsContainer.style.display = e.target.checked ? 'block' : 'none'; renderAll(); });
sidebarUI.brand.logoToggle.addEventListener('change', e => { sidebarConfig.branding.showLogo = e.target.checked; renderAll(); });
sidebarUI.brand.sitenameToggle.addEventListener('change', e => { sidebarConfig.branding.showSitename = e.target.checked; renderAll(); });
sidebarUI.brand.sitename.addEventListener('input', e => { sidebarConfig.branding.sitename = e.target.value; renderAll(); });
sidebarUI.brand.tagline.addEventListener('input', e => { sidebarConfig.branding.tagline = e.target.value; renderAll(); });
sidebarUI.themeToggleCheckbox.addEventListener('change', handleThemeToggleCheckboxChange);
// Top Bar Listeners
const topBarUI = ui.topBar;
topBarUI.toggle.addEventListener('change', (e) => {
config.topBar.enabled = e.target.checked;
topBarUI.mainControls.style.display = e.target.checked ? 'block' : 'none';
renderAll();
});
topBarUI.text.addEventListener('input', (e) => { config.topBar.text = e.target.value; renderAll(); });
topBarUI.url.addEventListener('input', (e) => { config.topBar.url = e.target.value; renderAll(); });
topBarUI.bgColorStart.addEventListener('input', (e) => { config.topBar.styles.bgColorStart = e.target.value; renderAll(); });
topBarUI.bgColorEnd.addEventListener('input', (e) => { config.topBar.styles.bgColorEnd = e.target.value; renderAll(); });
topBarUI.textColor.addEventListener('input', (e) => { config.topBar.styles.textColor = e.target.value; renderAll(); });
topBarUI.fontSize.addEventListener('input', (e) => { config.topBar.styles.fontSize = e.target.value; topBarUI.fontSizeVal.textContent = e.target.value; renderAll(); });
topBarUI.padding.addEventListener('input', (e) => { config.topBar.styles.padding = e.target.value; topBarUI.paddingVal.textContent = e.target.value; renderAll(); });
// Preview & Export
ui.buttons.desktop.addEventListener('click', () => setPreviewMode('desktop'));
ui.buttons.tablet.addEventListener('click', () => setPreviewMode('tablet'));
ui.buttons.mobile.addEventListener('click', () => setPreviewMode('mobile'));
ui.exportMenu.button.addEventListener('click', (e) => { e.stopPropagation(); ui.exportMenu.dropdown.classList.toggle('hidden'); });
window.addEventListener('click', (e) => { if (!ui.exportMenu.container.contains(e.target)) { ui.exportMenu.dropdown.classList.add('hidden'); } });
const copyAction = (e, dataGetter, message) => {
e.preventDefault();
navigator.clipboard.writeText(dataGetter()).then(() => showToast(message));
ui.exportMenu.dropdown.classList.add('hidden');
};
ui.exportMenu.copyCombined.addEventListener('click', (e) => copyAction(e, getCombinedCode, 'Combined code copied!'));
ui.exportMenu.copyHtml.addEventListener('click', (e) => copyAction(e, getEmbeddableHtml, 'Embeddable HTML copied!'));
ui.exportMenu.copyCss.addEventListener('click', (e) => copyAction(e, getFullCSS, 'All CSS copied!'));
ui.exportMenu.copyJs.addEventListener('click', (e) => copyAction(e, getFullJS, 'All JS copied!'));
ui.exportMenu.downloadZip.addEventListener('click', (e) => { e.preventDefault(); generatePageZip(); ui.exportMenu.dropdown.classList.add('hidden'); });
// Import
ui.buttons.import.addEventListener('click', () => ui.buttons.importFile.click());
ui.buttons.importFile.addEventListener('change', handleFileImport);
// Code Modal Listeners
ui.controls.panels.addEventListener('click', handleGetCodeClick);
ui.codeModal.closeBtns.forEach(btn => btn.addEventListener('click', () => ui.codeModal.modal.classList.add('hidden')));
ui.codeModal.modal.addEventListener('click', (e) => {
if (e.target.id === 'code-modal-html' || e.target.id === 'code-modal-css' || e.target.id === 'code-modal-js') {
const code = e.target.querySelector('code').innerText;
navigator.clipboard.writeText(code).then(() => showToast('Copied to clipboard!'));
}
});
// Sidebar Toggle Listener
ui.toggleSidebarBtn.addEventListener('click', () => {
ui.mainContainer.classList.toggle('onley-sidebar-collapsed');
const isCollapsed = ui.mainContainer.classList.contains('onley-sidebar-collapsed');
const icon = ui.toggleSidebarBtn.querySelector('i');
icon.classList.toggle('fa-chevron-left', !isCollapsed);
icon.classList.toggle('fa-chevron-right', isCollapsed);
ui.toggleSidebarBtn.title = isCollapsed ? 'Show Controls' : 'Hide Controls';
});
}
// --- LAYOUT CONTROLS ---
function renderLayoutControls() {
const draggableComponents = config.componentOrder.filter(key => key !== 'sidebar' && key !== 'mobileFooter');
ui.layout.container.innerHTML = draggableComponents.map((key, index) => {
const total = draggableComponents.length;
return `
<div class="onley-layout-item p-3 border rounded-md bg-white flex items-center justify-between" draggable="true" data-key="${key}">
<span class="font-medium text-sm"><i class="fas fa-grip-vertical mr-3 text-gray-400"></i> ${componentNames[key]}</span>
<div class="onley-item-toolbar mb-0">
<button class="reorder-layout-up-btn text-xs bg-gray-200 text-gray-700 p-1 rounded-md hover:bg-gray-300" data-index="${index}" ${index === 0 ? 'disabled' : ''}><i class="fas fa-arrow-up fa-fw"></i></button>
<button class="reorder-layout-down-btn text-xs bg-gray-200 text-gray-700 p-1 rounded-md hover:bg-gray-300" data-index="${index}" ${index === total - 1 ? 'disabled' : ''}><i class="fas fa-arrow-down fa-fw"></i></button>
</div>
</div>`;
}).join('');
}
function handleLayoutControlsClick(e) {
const button = e.target.closest('button');
if (!button) return;
let draggableComponents = config.componentOrder.filter(key => key !== 'sidebar' && key !== 'mobileFooter');
const index = parseInt(button.dataset.index, 10);
let changed = false;
if (button.classList.contains('reorder-layout-up-btn') && index > 0) {
[draggableComponents[index], draggableComponents[index - 1]] = [draggableComponents[index - 1], draggableComponents[index]];
changed = true;
} else if (button.classList.contains('reorder-layout-down-btn') && index < draggableComponents.length - 1) {
[draggableComponents[index], draggableComponents[index + 1]] = [draggableComponents[index + 1], draggableComponents[index]];
changed = true;
}
if(changed) {
config.componentOrder = ['sidebar', ...draggableComponents, 'mobileFooter'].filter((v, i, a) => a.indexOf(v) === i);
renderLayoutControls();
renderAll();
}
}
function setupDragAndDrop() {
let draggedItem = null;
ui.layout.container.addEventListener('dragstart', e => {
if (!e.target.classList.contains('onley-layout-item')) return;
draggedItem = e.target;
setTimeout(() => { e.target.style.display = 'none'; }, 0);
});
ui.layout.container.addEventListener('dragend', e => {
if (!draggedItem) return;
setTimeout(() => { draggedItem.style.display = 'flex'; draggedItem = null; }, 0);
});
ui.layout.container.addEventListener('dragover', e => {
e.preventDefault();
const afterElement = getDragAfterElement(ui.layout.container, e.clientY);
if (afterElement == null) {
ui.layout.container.appendChild(draggedItem);
} else {
ui.layout.container.insertBefore(draggedItem, afterElement);
}
});
ui.layout.container.addEventListener('drop', e => {
e.preventDefault();
if (!draggedItem) return;
const newDraggableOrder = [...ui.layout.container.querySelectorAll('.onley-layout-item')].map(item => item.dataset.key);
config.componentOrder = ['sidebar', ...newDraggableOrder, 'mobileFooter'].filter((v, i, a) => a.indexOf(v) === i);
renderLayoutControls();
renderAll();
});
}
function getDragAfterElement(container, y) {
const draggableElements = [...container.querySelectorAll('.onley-layout-item:not(.dragging)')];
return draggableElements.reduce((closest, child) => {
const box = child.getBoundingClientRect();
const offset = y - box.top - box.height / 2;
if (offset < 0 && offset > closest.offset) {
return { offset: offset, element: child };
} else {
return closest;
}
}, { offset: Number.NEGATIVE_INFINITY }).element;
}
// --- DYNAMIC ITEM BUILDER LOGIC ---
function createSidebarLinkBuilder(sectionKey, sectionTitle, builderUI, configSection) {
function renderControls() {
let linksHtml = configSection.links.map((link, index) => {
const hasBadge = 'badge' in link;
const badgeInput = hasBadge ? `<input type="text" data-prop="badge" value="${link.badge || ''}" placeholder="Badge" class="p-1 border rounded-md text-sm w-16">` : '';
return `<div class="flex items-center gap-1 p-2 border rounded bg-white" data-index="${index}">
<div class="flex-grow grid grid-cols-2 gap-1">
<input type="text" data-prop="icon" value="${link.icon}" placeholder="Icon Class" class="w-full p-1 border rounded-md text-sm">
<input type="text" data-prop="text" value="${link.text}" placeholder="Link Text" class="w-full p-1 border rounded-md text-sm">
<input type="text" data-prop="url" value="${link.url}" placeholder="URL" class="w-full p-1 border rounded-md text-sm col-span-2">
</div>
<div class="flex flex-col items-center gap-1 px-2">
${badgeInput}
<input type="checkbox" data-prop="enabled" class="h-4 w-4 rounded" ${link.enabled ? 'checked' : ''}>
</div>
<button class="remove-link-btn self-start text-xs bg-red-400 text-white py-1 px-2 rounded-md">-</button>
</div>`;
}).join('');
builderUI.innerHTML = `<div class="flex items-center space-x-2">
<input type="checkbox" id="enable-${sectionKey}" class="h-4 w-4 rounded" ${configSection.enabled ? 'checked' : ''}>
<label for="enable-${sectionKey}" class="font-medium text-sm">${sectionTitle}</label>
</div>
<div class="space-y-2 pl-4 links-container">${linksHtml}</div>
<button id="add-${sectionKey}-btn" class="text-sm bg-blue-500 text-white py-1 px-3 rounded-md hover:bg-blue-600 mt-2 ml-4">+ Add Link</button>`;
}
function handleClick(e) {
let changed = false;
if (e.target.id === `add-${sectionKey}-btn`) {
const newLink = { icon: 'fas fa-link', text: 'New Link', url: '#', enabled: true };
if (configSection.links.length > 0 && 'badge' in configSection.links[0]) newLink.badge = '';
configSection.links.push(newLink);
changed = true;
} else if (e.target.classList.contains('remove-link-btn')) {
configSection.links.splice(parseInt(e.target.closest('[data-index]').dataset.index, 10), 1);
changed = true;
}
if (changed) { renderControls(); renderAll(); }
}
function handleChange(e) {
if (e.target.id === `enable-${sectionKey}`) {
configSection.enabled = e.target.checked;
} else {
const index = e.target.closest('[data-index]').dataset.index;
const property = e.target.dataset.prop;
const value = e.target.type === 'checkbox' ? e.target.checked : e.target.value;
configSection.links[index][property] = value;
}
renderAll();
}
builderUI.addEventListener('click', handleClick);
builderUI.addEventListener('input', handleChange);
builderUI.addEventListener('change', handleChange);
renderControls();
}
function handleThemeToggleCheckboxChange(e) {
const shortcuts = config.sidebar.shortcuts;
const themeToggleLink = { icon: 'fas fa-moon', text: 'Theme Toggle', url: '#', enabled: true, isThemeToggle: true };
shortcuts.links = shortcuts.links.filter(link => !link.isThemeToggle);
if (e.target.checked) {
shortcuts.links.push(themeToggleLink);
}
createSidebarLinkBuilder('shortcuts', 'Shortcuts & CTA', ui.sidebar.shortcutsBuilder, config.sidebar.shortcuts);
renderAll();
}
function renderLmsTabsControls() {
ui.learningAppHeader.tabs.container.innerHTML = config.learningAppHeader.tabs.items.map((tab, index) => `
<div class="flex items-center gap-1 p-2 border rounded bg-white">
<div class="flex-grow space-y-1">
<input type="text" data-index="${index}" data-prop="text" value="${tab.text}" placeholder="Tab Label" class="w-full p-1 border rounded-md text-sm">
<input type="text" data-index="${index}" data-prop="url" value="${tab.url}" placeholder="URL" class="w-full p-1 border rounded-md text-sm">
</div>
<div class="flex flex-col items-center"><label class="text-xs">Active</label><input type="radio" name="lms-tab-active" data-index="${index}" data-prop="active" class="h-4 w-4" ${tab.active ? 'checked' : ''}></div>
<button class="remove-lms-tab-btn self-start text-xs bg-red-400 text-white py-1 px-2 rounded-md" data-index="${index}">-</button>
</div>`).join('');
}
function handleLmsTabsClick(e) {
let changed = false;
if (e.target.id === 'add-lms-tab-btn') {
config.learningAppHeader.tabs.items.push({ text: 'New Tab', url: '#', active: false }); changed = true;
} else if (e.target.classList.contains('remove-lms-tab-btn')) {
const index = parseInt(e.target.dataset.index, 10);
if (config.learningAppHeader.tabs.items[index].active && config.learningAppHeader.tabs.items.length > 1) config.learningAppHeader.tabs.items[0].active = true;
config.learningAppHeader.tabs.items.splice(index, 1); changed = true;
}
if(changed) { renderLmsTabsControls(); renderAll(); }
}
function handleLmsTabsChange(e) {
const { index, prop } = e.target.dataset;
if (prop === 'active') {
config.learningAppHeader.tabs.items.forEach((tab, i) => tab.active = (i === parseInt(index, 10)));
renderLmsTabsControls();
} else { config.learningAppHeader.tabs.items[index][prop] = e.target.value; }
renderAll();
}
function renderLmsCustomIconsControls() {
ui.learningAppHeader.customIcons.container.innerHTML = config.learningAppHeader.primaryBar.elements.customIcons.map((icon, index) => `
<div class="flex items-center gap-2 p-2 border rounded bg-white">
<div class="flex-grow space-y-1">
<input type="text" data-index="${index}" data-prop="name" value="${icon.name}" placeholder="Icon Name" class="w-full p-1 border rounded-md text-sm">
<div class="grid grid-cols-2 gap-2">
<input type="text" data-index="${index}" data-prop="icon" value="${icon.icon}" placeholder="Font Awesome Class" class="w-full p-1 border rounded-md text-sm">
<input type="text" data-index="${index}" data-prop="url" value="${icon.url}" placeholder="URL" class="w-full p-1 border rounded-md text-sm">
</div>
</div>
<div class="flex flex-col items-center px-2"><label class="text-xs">On</label><input type="checkbox" data-index="${index}" data-prop="enabled" class="h-4 w-4 rounded" ${icon.enabled ? 'checked' : ''}></div>
<button class="remove-lms-custom-icon-btn self-start text-xs bg-red-400 text-white py-1 px-2 rounded-md" data-index="${index}">-</button>
</div>`).join('');
}
function handleLmsCustomIconsClick(e) {
let changed = false;
if (e.target.id === 'add-lms-custom-icon-btn') {
config.learningAppHeader.primaryBar.elements.customIcons.push({ name: 'New Icon', icon: 'fas fa-star', url: '#', enabled: true }); changed = true;
} else if (e.target.classList.contains('remove-lms-custom-icon-btn')) {
config.learningAppHeader.primaryBar.elements.customIcons.splice(parseInt(e.target.dataset.index, 10), 1); changed = true;
}
if (changed) { renderLmsCustomIconsControls(); renderAll(); }
}
function handleLmsCustomIconsChange(e) {
const { index, prop } = e.target.dataset; if (index === undefined || prop === undefined) return;
const value = e.target.type === 'checkbox' ? e.target.checked : e.target.value;
config.learningAppHeader.primaryBar.elements.customIcons[index][prop] = value;
renderAll();
}
function toggleLmsBrandControls() {
const isImage = config.learningAppHeader.primaryBar.brand.type === 'image';
ui.learningAppHeader.brand.textControl.classList.toggle('hidden', isImage);
ui.learningAppHeader.brand.imageControls.classList.toggle('hidden', !isImage);
}
// --- HTML Generation Logic ---
const componentGenerators = {
customHtml: () => config.customHtml.enabled ? `<div class="onley-custom-html-section">${config.customHtml.content}</div>` : '',
topBar: () => {
if (!config.topBar.enabled) return '';
const s = config.topBar.styles;
const content = config.topBar.text.includes('<a') ? config.topBar.text : `<a href="${config.topBar.url}">${config.topBar.text}</a>`;
return `<div id="site-topbar" class="onley-site-topbar" style="--bg-start: ${s.bgColorStart}; --bg-end: ${s.bgColorEnd}; --text-color: ${s.textColor}; --font-size: ${s.fontSize}px; --padding: ${s.padding}px;"><div class="onley-container">${content}</div></div>`;
},
lmsHeader: () => {
const c = config.learningAppHeader; if (!c.primaryBar.enabled && !c.pageTitle.enabled && !c.tabs.enabled) return '';
let primaryBar = '';
const { elements, brand, notificationCount } = c.primaryBar;
const searchOverlay = elements.search ? `
<div id="lms-search-overlay" class="onley-lms-search-overlay">
<button id="lms-search-close-btn" class="onley-lms-search-close-btn">×</button>
<div class="onley-lms-search-content">
<h2 class="onley-search-title">What are you looking for?</h2>
<form id="lms-search-form" class="onley-lms-search-form" action="https://examups.com/" method="get" target="_self">
<input type="search" name="s" id="lms-search-input" placeholder="Search..." required>
<button type="submit"><i class="fas fa-search"></i></button>
</form>
<div class="onley-search-suggestions">
<span>Popular:</span>
<a href="https://examups.com/?s=UPSC" target="_self">UPSC</a>
<a href="https://examups.com/?s=BPSC" target="_self">BPSC</a>
<a href="https://examups.com/?s=Test+Series" target="_self">Test Series</a>
</div>
</div>
</div>` : '';
const notificationSidebar = elements.notifications.enabled ? `
<div class="onley-notification-sidebar-overlay"></div>
<aside class="onley-notification-sidebar">
<div class="onley-notification-sidebar-header">
<h3>Notifications</h3>
<button id="close-notification-sidebar-btn">×</button>
</div>
<div class="onley-notification-sidebar-content">
<iframe src="https://examups.com/notification/" title="Notifications"></iframe>
</div>
</aside>
` : '';
if(c.primaryBar.enabled) {
const brandHtml = (brand.type === 'image' && brand.imageUrl) ? `<img src="${brand.imageUrl}" alt="Brand Logo" class="onley-lms-logo" style="height: ${brand.height}px;">` : `<span class="onley-app-name">${brand.text}</span>`;
const badge = (notificationCount > 0) ? `<span class="onley-badge">${notificationCount}</span>` : '';
const customIcons = elements.customIcons.filter(i => i.enabled).map(i => `<a href="${i.url}" class="onley-icon-btn onley-lms-custom-icon" title="${i.name}"><i class="${i.icon}"></i></a>`).join('');
const inlineSearchForm = elements.search ? `
<div class="onley-lms-inline-search">
<form action="https://examups.com/" method="get" target="_self">
<input type="search" name="s" placeholder="Search courses & tests...">
<button type="submit"><i class="fas fa-search"></i></button>
</form>
</div>` : '';
primaryBar = `<div class="onley-lms-primary-bar">
<div class="onley-lms-brand">${elements.hamburger ? '<button class="onley-hamburger-menu" id="lms-sidebar-toggle">☰</button>' : ''}${brandHtml}</div>
${inlineSearchForm}
<div class="onley-lms-icon-group">
${elements.search ? '<button class="onley-icon-btn" id="lms-search-btn"><i class="fas fa-search"></i></button>' : ''}
${elements.notifications.enabled ? `<button id="lms-notification-btn" class="onley-icon-btn onley-notification-bell">${badge}<i class="fas fa-bell"></i></button>` : ''}
${elements.avatar.enabled ? `<a href="${elements.avatar.url}" class="onley-icon-btn onley-user-avatar"><i class="fas fa-user"></i></a>` : ''}
${elements.refresh ? '<button class="onley-icon-btn onley-lms-bonus-icon"><i class="fas fa-sync-alt"></i></button>' : ''}
${elements.themeToggle ? '<button class="onley-icon-btn" id="header-theme-toggle"><i class="fas fa-moon"></i></button>' : ''}
${elements.calendar ? '<button class="onley-icon-btn onley-lms-bonus-icon"><i class="fas fa-calendar-alt"></i></button>' : ''}
${elements.share ? '<button class="onley-icon-btn onley-lms-bonus-icon"><i class="fas fa-share-alt"></i></button>' : ''}
${customIcons}
</div>
</div>`;
}
const title = c.pageTitle.enabled ? `<div class="onley-lms-page-title">${c.pageTitle.showBackButton ? '<button class="onley-back-btn">←</button>' : ''}<h2>${c.pageTitle.text}</h2></div>` : '';
const tabs = c.tabs.enabled ? `<nav class="onley-lms-tabs-nav">${c.tabs.items.map(t => `<a href="${t.url}" class="onley-lms-tab-item ${t.active ? 'onley-active' : ''}">${t.text}</a>`).join('')}</nav>` : '';
return `<header class="onley-learning-app-header-container ${c.sticky ? 'onley-sticky-header' : ''}">${primaryBar}${title}${tabs}${searchOverlay}</header>${notificationSidebar}`;
},
sidebar: () => {
if (!config.sidebar.enabled) return '';
const s = config.sidebar;
const brandHtml = `<div class="onley-lms-sidebar-brand">${s.branding.showLogo ? `<img src="${config.learningAppHeader.primaryBar.brand.imageUrl}" alt="Logo" class="onley-lms-sidebar-logo">` : ''}${s.branding.showSitename ? `<div class="onley-lms-sidebar-sitename"><strong>${s.branding.sitename}</strong><small>${s.branding.tagline}</small></div>` : ''}</div>`;
const createLinkSection = (sec) => {
if (!sec.enabled) return '';
const links = sec.links.filter(l => l.enabled).map(l => {
const badge = l.badge ? `<span class="onley-sidebar-badge">${l.badge}</span>` : '';
const themeToggleId = l.isThemeToggle ? 'id="sidebar-theme-toggle"' : '';
return `<li><a href="${l.url}" ${themeToggleId}><i class="${l.icon}"></i><span>${l.text}</span>${badge}</a></li>`;
}).join('');
return `<nav class="onley-lms-sidebar-nav"><ul>${links}</ul></nav>`;
};
const catSection = () => {
if (!s.categories.enabled) return '';
const links = s.categories.links.filter(l => l.enabled).map(l => `<li><a href="${l.url}"><i class="${l.icon}"></i><span>${l.text}</span></a></li>`).join('');
return `<div class="onley-lms-sidebar-nav-accordion"><button class="onley-accordion-trigger"><div><i class="fas fa-folder"></i><span>${s.categories.title}</span></div><i class="fas fa-chevron-down onley-arrow"></i></button><div class="onley-accordion-panel"><nav class="onley-lms-sidebar-nav"><ul>${links}</ul></nav></div></div>`;
};
return `<div class="onley-lms-sidebar-overlay"></div><aside class="onley-lms-sidebar">${brandHtml}<div class="onley-lms-sidebar-content">${createLinkSection(s.primaryNav)}${catSection()}${createLinkSection(s.userSection)}${createLinkSection(s.shortcuts)}</div><div class="onley-lms-sidebar-footer">${createLinkSection(s.footer)}</div></aside>`;
},
};
function getAllHtml() {
const allComponents = {
sidebar: componentGenerators.sidebar(),
main: ''
};
const mainComponents = config.componentOrder
.filter(key => key !== 'sidebar' && key !== 'mobileFooter')
.map(key => componentGenerators[key] ? componentGenerators[key]() : '')
.filter(Boolean)
.join('\n\n');
allComponents.main = mainComponents;
return allComponents;
}
function getEmbeddableHtml() {
const { sidebar, main } = getAllHtml();
const sidebarHtml = sidebar ? sidebar + '\n' : '';
return `${sidebarHtml}<div class="onley-main-content-pusher">\n${main}\n</div>`;
}
function generateComponentCSS(targetKey = null) {
const { colors, typography } = config.globalSettings;
const css = {};
css.global = `
:root {
--sidebar-width: 260px;
--primary-color: ${colors.primary};
--secondary-color: ${colors.secondary};
--text-color: ${colors.text};
--heading-color: ${colors.heading};
--font-family: ${typography.fontFamily};
}
body { font-family: var(--font-family); color: var(--text-color); margin: 0; background-color: #f0f2f5; transition: background-color 0.3s, color 0.3s; }
h1,h2,h3,h4,h5,h6 { color: var(--heading-color); }
.onley-container { max-width: 1280px; margin: 0 auto; width: 90%; } a { color: var(--primary-color); text-decoration: none; }
.onley-main-content-pusher { transition: margin-left 0.3s ease-in-out; }
@keyframes onley-gift-bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes onley-button-pulse { 0% { box-shadow: 0 0 0 0 rgba(255, 152, 0, 0.7); } 70% { box-shadow: 0 0 0 10px rgba(255, 152, 0, 0); } 100% { box-shadow: 0 0 0 0 rgba(255, 152, 0, 0); } }
/* --- Dark Mode Styles --- */
body.onley-dark-mode { background-color: #1f2937; color: #d1d5db; }
body.onley-dark-mode h1, body.onley-dark-mode h2, body.onley-dark-mode h3, body.onley-dark-mode h4 { color: #f9fafb; }
body.onley-dark-mode .onley-lms-sidebar,
body.onley-dark-mode .onley-learning-app-header-container,
body.onley-dark-mode .onley-lms-page-title,
body.onley-dark-mode .onley-lms-tabs-nav,
body.onley-dark-mode .onley-site-footer { background-color: #111827; border-color: #374151; }
body.onley-dark-mode .onley-lms-sidebar-nav ul li a, body.onley-dark-mode .onley-icon-btn, body.onley-dark-mode .onley-back-btn { color: #f9fafb; }
body.onley-dark-mode .onley-lms-sidebar-nav ul li a:hover, body.onley-dark-mode .onley-icon-btn:hover { background-color: #374151; }
body.onley-dark-mode .onley-site-footer { color: #9ca3af; }
body.onley-dark-mode .onley-footer-widget a { color: #9ca3af; } body.onley-dark-mode .onley-footer-widget a:hover { color: #fff; }
body.onley-dark-mode .onley-widget-title { color: #fff; }
body.onley-dark-mode .onley-lms-inline-search form { background-color: #374151; border-color: #4b5563; }
body.onley-dark-mode .onley-lms-inline-search input { color: #d1d5db; }
`;
if(config.customHtml.enabled) css.customHtml = `.onley-custom-html-section { padding: 2rem 0; }`;
css.topBar = config.topBar.enabled ? `.onley-site-topbar { background: linear-gradient(90deg, var(--bg-start), var(--bg-end)); color: var(--text-color); font-size: var(--font-size); padding: var(--padding) 0; font-weight: 500; } .onley-site-topbar .onley-container { display: flex; align-items: center; justify-content: center; gap: 15px; flex-wrap: wrap; } .onley-site-topbar a { color: inherit; text-decoration: none; } .onley-offer-icon { margin-right: 12px; font-size: 1.2em; animation: onley-gift-bounce 1.5s ease-in-out infinite; } .onley-cta-button { margin-left: 20px; background-color: #ff9800; color: #fff; padding: 0.5em 1.2em; border-radius: 50px; font-weight: 700; animation: onley-button-pulse 2s infinite; } @media (max-width: 768px) { .onley-site-topbar .onley-container { flex-direction: column; gap: 8px; text-align: center; } .onley-cta-button { margin-left: 0; } }` : '';
css.lmsHeader = `
.onley-learning-app-header-container { background-color: #fff; box-shadow: 0 1px 2px rgba(0,0,0,0.05); z-index: 100; position: relative; transition: background-color 0.3s; }
.onley-learning-app-header-container.onley-sticky-header { position: sticky; top: 0; z-index: 1010; }
.onley-lms-primary-bar { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 1rem; height: 60px; border-bottom: 1px solid #e5e7eb; }
.onley-lms-brand { display: flex; align-items: center; gap: 1rem; }
.onley-hamburger-menu { background: none; border: none; font-size: 1.5rem; cursor: pointer; display: block; }
.onley-lms-logo { height: 30px; }
.onley-app-name { font-weight: 700; font-size: 1.25rem; }
.onley-lms-icon-group { display: flex; align-items: center; gap: 0.25rem; }
.onley-icon-btn { display: inline-flex; align-items: center; justify-content: center; background: none; border: none; color: #4b5563; font-size: 1.2rem; cursor: pointer; position: relative; width: 40px; height: 40px; border-radius: 50%; transition: background-color 0.2s, color 0.2s; }
.onley-icon-btn:hover { background-color: #f3f4f6; color: var(--primary-color); }
.onley-notification-bell .onley-badge { position: absolute; top: 5px; right: 5px; background-color: #ef4444; color: #fff; font-size: 0.65rem; width: 18px; height: 18px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 500; }
.onley-lms-page-title { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 1rem; background-color: #fafafa; border-bottom: 1px solid #e5e7eb; transition: background-color 0.3s; }
.onley-back-btn { background: none; border: 1px solid #d1d5db; border-radius: 50%; width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.onley-lms-page-title h2 { font-size: 1.125rem; font-weight: 600; margin: 0; }
.onley-lms-tabs-nav { display: flex; overflow-x: auto; padding: 0 1rem; border-bottom: 1px solid #e5e7eb; background: #fff; transition: background-color 0.3s;}
.onley-lms-tab-item { padding: 0.75rem 1rem; font-size: 0.9rem; color: #6b7280; white-space: nowrap; border-bottom: 2px solid transparent; transition: all 0.2s; }
.onley-lms-tab-item.onley-active, .onley-lms-tab-item:hover { color: var(--primary-color); font-weight: 600; border-bottom-color: var(--primary-color); }
.onley-lms-search-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(243, 244, 246, 0.8); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); z-index: 2000; display: flex; align-items: center; justify-content: center; opacity: 0; visibility: hidden; transition: opacity 0.3s ease-in-out; }
body.onley-search-active .onley-lms-search-overlay { opacity: 1; visibility: visible; }
.onley-lms-search-content { text-align: center; }
.onley-lms-search-close-btn { position: absolute; top: 20px; right: 30px; font-size: 3rem; color: #374151; background: none; border: none; cursor: pointer; }
.onley-search-title { font-size: 2rem; color: #111827; margin-bottom: 1.5rem; font-weight: 600; }
.onley-lms-search-form { display: flex; align-items: center; width: 90%; max-width: 550px; margin: 0 auto; background-color: #ffffff; border-radius: 999px; padding: 0.5rem 0.75rem 0.5rem 1.5rem; box-shadow: 0 10px 25px rgba(0,0,0,0.1), 0 5px 10px rgba(0,0,0,0.05); border: 1px solid rgba(0,0,0,0.05); }
.onley-lms-search-form input { flex-grow: 1; border: none; font-size: 1rem; outline: none; background-color: transparent; color: #333; }
.onley-lms-search-form input::placeholder { color: #9ca3af; }
.onley-lms-search-form button { background-color: transparent; color: #6b7280; border: none; padding: 0.5rem; font-size: 1.2rem; cursor: pointer; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: background-color 0.2s ease; }
.onley-lms-search-form button:hover { background-color: #f3f4f6; }
.onley-search-suggestions { margin-top: 1.5rem; color: #4b5563; }
.onley-search-suggestions span { margin-right: 10px; }
.onley-search-suggestions a { display: inline-block; color: #374151; text-decoration: none; border: 1px solid #d1d5db; padding: 5px 12px; border-radius: 20px; margin: 0 5px; transition: all 0.3s ease; font-size: 0.9rem; }
.onley-search-suggestions a:hover { background-color: #374151; color: #fff; border-color: #374151; }
.onley-lms-inline-search { flex-grow: 1; margin: 0 1rem; max-width: 600px; display: none; }
.onley-lms-inline-search form { display: flex; align-items: center; background-color: #f3f4f6; border-radius: 8px; padding: 0 0.5rem; border: 1px solid #e5e7eb; transition: background-color 0.3s, border-color 0.3s; }
.onley-lms-inline-search input { flex-grow: 1; border: none; outline: none; background-color: transparent; padding: 0.6rem 0.5rem; font-size: 0.9rem; transition: color 0.3s; }
.onley-lms-inline-search button { background: none; border: none; cursor: pointer; color: #6b7280; padding: 0.5rem; }
.onley-notification-sidebar { position: fixed; top: 0; right: 0; height: 100vh; width: 380px; max-width: 90%; background-color: #fff; z-index: 2010; display: flex; flex-direction: column; box-shadow: -2px 0 8px rgba(0,0,0,0.1); transform: translateX(100%); transition: transform 0.3s ease-in-out; }
body.onley-notification-sidebar-open .onley-notification-sidebar { transform: translateX(0); }
.onley-notification-sidebar-overlay { position: fixed; inset: 0; background-color: rgba(0,0,0,0.4); z-index: 2009; opacity: 0; visibility: hidden; transition: opacity 0.3s, visibility 0.3s; }
body.onley-notification-sidebar-open .onley-notification-sidebar-overlay { opacity: 1; visibility: visible; }
.onley-notification-sidebar-header { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 1rem; border-bottom: 1px solid #e5e7eb; flex-shrink: 0; }
.onley-notification-sidebar-header h3 { margin: 0; font-size: 1.1rem; font-weight: 600; }
#close-notification-sidebar-btn { background: none; border: none; font-size: 1.8rem; line-height: 1; cursor: pointer; color: #6b7280; }
.onley-notification-sidebar-content { flex-grow: 1; overflow-y: auto; }
.onley-notification-sidebar-content iframe { width: 100%; height: 100%; border: none; }
body.onley-dark-mode .onley-notification-sidebar { background-color: #111827; border-left: 1px solid #374151; }
body.onley-dark-mode .onley-notification-sidebar-header { border-bottom-color: #374151; }
body.onley-dark-mode #close-notification-sidebar-btn { color: #d1d5db; }
@media (max-width: 768px) { .onley-lms-bonus-icon, .onley-lms-custom-icon { display: none; } .onley-lms-brand .onley-app-name { display: none; } }
@media (min-width: 769px) { .onley-lms-inline-search { display: block; } #lms-search-btn { display: none; } }
`;
css.sidebar = config.sidebar.enabled ? `
.onley-lms-sidebar {
position: fixed; top: 0; left: 0; height: 100vh; width: var(--sidebar-width);
background-color: #fff; z-index: 2000; display: flex; flex-direction: column;
border-right: 1px solid #e5e7eb;
transform: translateX(-100%);
transition: transform 0.3s ease-in-out, background-color 0.3s;
}
body.onley-sidebar-open .onley-lms-sidebar {
transform: translateX(0);
}
.onley-lms-sidebar-overlay {
position: fixed; inset: 0; background-color: rgba(0,0,0,0.5); z-index: 1999;
opacity: 0; visibility: hidden; transition: opacity 0.3s, visibility 0.3s;
}
body.onley-sidebar-open .onley-lms-sidebar-overlay {
opacity: 1; visibility: visible;
}
.onley-lms-sidebar-brand { display: flex; align-items: center; padding: 1rem; height: 60px; border-bottom: 1px solid #e5e7eb; flex-shrink: 0; }
.onley-lms-sidebar-logo { height: 40px; object-fit: contain; }
.onley-lms-sidebar-sitename { margin-left: 0.75rem; line-height: 1.2; } .onley-lms-sidebar-sitename strong { font-weight: 600; } .onley-lms-sidebar-sitename small { font-size: 0.8rem; color: #6b7280; }
.onley-lms-sidebar-content { flex-grow: 1; overflow-y: auto; padding: 0.5rem; }
.onley-lms-sidebar-nav, .onley-lms-sidebar-nav-accordion { border-bottom: 1px solid #e5e7eb; padding: 0.5rem 0; margin-bottom: 0.5rem; }
.onley-lms-sidebar-nav:last-child, .onley-lms-sidebar-nav-accordion:last-child { border: none; }
.onley-lms-sidebar-nav ul { list-style: none; padding: 0; margin: 0; }
.onley-lms-sidebar-nav ul li a { display: flex; align-items: center; gap: 0.85rem; padding: 0.65rem; border-radius: 6px; font-weight: 500; color: #374151; overflow: hidden; white-space: nowrap; }
.onley-lms-sidebar-nav ul li a:hover { background-color: #f3f4f6; }
.onley-lms-sidebar-nav ul li a i { width: 20px; text-align: center; color: #9ca3af; flex-shrink: 0; }
.onley-lms-sidebar-nav ul li a span, .onley-accordion-trigger div span { transition: opacity 0.2s; }
.onley-sidebar-badge { margin-left: auto; background-color: var(--primary-color); color: white; font-size: 0.7rem; padding: 2px 6px; border-radius: 10px; }
.onley-accordion-trigger { display: flex; justify-content: space-between; align-items: center; width: 100%; background: none; border: none; cursor: pointer; padding: 0.65rem; font-weight: 500; color: #374151; }
.onley-accordion-trigger div { display: flex; align-items: center; gap: 0.85rem; overflow: hidden; }
.onley-accordion-trigger i { width: 20px; text-align: center; color: #9ca3af; } .onley-accordion-trigger .onley-arrow { transition: transform 0.3s ease; }
.onley-accordion-trigger.onley-active .onley-arrow { transform: rotate(180deg); }
.onley-accordion-panel { max-height: 0; overflow: hidden; transition: max-height 0.3s ease-out; }
.onley-accordion-panel .onley-lms-sidebar-nav { border: none; padding: 0; margin: 0; }
.onley-accordion-panel .onley-lms-sidebar-nav ul { padding-left: 1.5rem; }
.onley-lms-sidebar-footer { padding: 0.5rem; border-top: 1px solid #e5e7eb; flex-shrink: 0; }
` : '';
if (targetKey) { return { global: css.global, component: css[targetKey] || '', js: '' }; }
return css;
}
function getFullCSS() {
const cssObject = generateComponentCSS();
return [cssObject.global, cssObject.sidebar, cssObject.topBar, cssObject.lmsHeader, cssObject.customHtml].filter(Boolean).join('\n\n');
}
function generateComponentJavaScript(targetKey = null) {
const js = {};
const fullInteractiveScript = `
const body = document.body;
// Theme Toggling
const toggleTheme = () => {
body.classList.toggle('onley-dark-mode');
const icon = document.querySelector('#sidebar-theme-toggle i') || document.querySelector('#header-theme-toggle i');
if (icon) {
icon.classList.toggle('fa-moon');
icon.classList.toggle('fa-sun');
}
};
document.getElementById('header-theme-toggle')?.addEventListener('click', toggleTheme);
document.getElementById('sidebar-theme-toggle')?.addEventListener('click', (e) => {
e.preventDefault();
toggleTheme();
});
// Sidebar Toggling Logic
const lmsSidebarToggle = document.getElementById('lms-sidebar-toggle');
const lmsSidebarOverlay = document.querySelector('.onley-lms-sidebar-overlay');
if (lmsSidebarToggle && lmsSidebarOverlay) {
const handleSidebarToggle = () => body.classList.toggle('onley-sidebar-open');
const closeSidebar = () => body.classList.remove('onley-sidebar-open');
lmsSidebarToggle.addEventListener('click', handleSidebarToggle);
lmsSidebarOverlay.addEventListener('click', closeSidebar);
}
// Notification Sidebar Logic
const notificationBtn = document.getElementById('lms-notification-btn');
const notificationOverlay = document.querySelector('.onley-notification-sidebar-overlay');
const closeNotificationBtn = document.getElementById('close-notification-sidebar-btn');
if (notificationBtn && notificationOverlay && closeNotificationBtn) {
const openNotificationSidebar = (e) => {
e.preventDefault();
body.classList.add('onley-notification-sidebar-open');
};
const closeNotificationSidebar = () => {
body.classList.remove('onley-notification-sidebar-open');
};
notificationBtn.addEventListener('click', openNotificationSidebar);
closeNotificationBtn.addEventListener('click', closeNotificationSidebar);
notificationOverlay.addEventListener('click', closeNotificationSidebar);
}
// Accordion Logic
document.querySelectorAll('.onley-lms-sidebar-nav-accordion .onley-accordion-trigger').forEach(trigger => {
trigger.addEventListener('click', (e) => {
e.preventDefault();
const panel = trigger.nextElementSibling;
trigger.classList.toggle('onley-active');
if (panel.style.maxHeight) {
panel.style.maxHeight = null;
} else {
panel.style.maxHeight = panel.scrollHeight + 'px';
}
});
});
// Search Overlay Logic
const searchBtn = document.getElementById('lms-search-btn');
const searchOverlay = document.getElementById('lms-search-overlay');
const searchCloseBtn = document.getElementById('lms-search-close-btn');
const searchInput = document.getElementById('lms-search-input');
if (searchBtn && searchOverlay && searchCloseBtn) {
const openSearch = (e) => {
e.preventDefault();
body.classList.add('onley-search-active');
setTimeout(() => searchInput.focus(), 50);
};
const closeSearch = () => body.classList.remove('onley-search-active');
searchBtn.addEventListener('click', openSearch);
searchCloseBtn.addEventListener('click', closeSearch);
searchOverlay.addEventListener('click', (e) => {
if (e.target === searchOverlay) closeSearch();
});
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && body.classList.contains('onley-search-active')) {
closeSearch();
}
});
}
`;
// Bundle all interactive JS under one key since they are interdependent.
js.interactive = fullInteractiveScript;
if (targetKey) { return js[targetKey] || ''; }
return js;
}
function getFullJS() {
return generateComponentJavaScript().interactive || '';
}
function getCombinedCode() {
const css = getFullCSS();
let js = getFullJS();
if (js.trim()) js = `document.addEventListener('DOMContentLoaded', () => { \n${js.trim()} \n});`;
const configScript = `<script id="app-config" type="application/json">${JSON.stringify(config, null, 2)}<\/script>`;
const embeddableHtml = getEmbeddableHtml();
return `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Exported Page</title><script src="https://cdn.tailwindcss.com"><\/script><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"><link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Roboto:wght@400;500;700&family=Open+Sans:wght@400;700&family=Lato:wght@400;700&family=Montserrat:wght@400;700&family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet"><style>${css}</style></head><body class="bg-gray-100">${embeddableHtml}${configScript}${js ? `<script>${js}<\/script>` : ''}</body></html>`;
}
// --- Rendering ---
function renderAll() {
const fullJs = getFullJS();
const embeddableHtml = getEmbeddableHtml();
const previewContent = `<!DOCTYPE html><html><head><title>Preview</title>
<script src="https://cdn.tailwindcss.com"><\/script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Roboto:wght@400;500;700&family=Open+Sans:wght@400;700&family=Lato:wght@400;700&family=Montserrat:wght@400;700&family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>${getFullCSS()}</style></head><body>
${embeddableHtml}
<div style="min-height: 400px; padding: 40px; text-align: center; color: #6b7280; font-family: 'Inter', sans-serif;">Main Content Area</div>
<script> ${fullJs ? `document.addEventListener('DOMContentLoaded', () => { \n${fullJs} \n});` : ''} <\/script></body></html>`;
ui.previewIframe.srcdoc = previewContent;
}
// --- Utility Functions ---
function setPreviewMode(mode) {
ui.previewContainer.classList.remove('bg-white', 'shadow-lg', 'rounded-lg', 'w-full', 'h-full', 'overflow-hidden', 'transition-all', 'duration-300', 'onley-preview-desktop', 'onley-preview-tablet', 'onley-preview-mobile');
ui.previewContainer.className = `bg-white shadow-lg rounded-lg w-full h-full overflow-hidden transition-all duration-300 onley-preview-${mode}`;
['desktop', 'tablet', 'mobile'].forEach(m => {
const btn = ui.buttons[m];
btn.classList.toggle('bg-blue-500', m === mode); btn.classList.toggle('text-white', m === mode);
btn.classList.toggle('bg-gray-200', m !== mode); btn.classList.toggle('text-gray-700', m !== mode);
});
}
function showToast(message) {
const toast = document.getElementById('toast-notification');
toast.textContent = message;
toast.classList.add('onley-show');
setTimeout(() => { toast.classList.remove('onley-show'); }, 3000);
}
function generatePageZip() {
const zip = new JSZip();
const embeddableHtml = getEmbeddableHtml();
const css = getFullCSS();
const js = getFullJS();
const configScript = `<script id="app-config" type="application/json">${JSON.stringify(config, null, 2)}<\/script>`;
const html = `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Exported Page</title><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"><link rel="stylesheet" href="style.css"></head><body>${embeddableHtml}${configScript}<script src="script.js"><\/script></body></html>`;
zip.file("index.html", html);
zip.file("style.css", css);
if (js.trim()) zip.file("script.js", `document.addEventListener('DOMContentLoaded', () => { \n${js} \n});`);
zip.generateAsync({type:"blob"}).then(content => { saveAs(content, "exported-page.zip"); showToast("ZIP file generated!"); });
}
function handleFileImport(event) {
const file = event.target.files[0];
if (!file) {
return;
}
const reader = new FileReader();
reader.onload = function(e) {
const fileContent = e.target.result;
try {
const parser = new DOMParser();
const doc = parser.parseFromString(fileContent, 'text/html');
const configScript = doc.getElementById('app-config');
if (!configScript) {
showToast('Error: No configuration data found in this file.');
return;
}
const importedConfig = JSON.parse(configScript.textContent);
if (!importedConfig || typeof importedConfig !== 'object' || !importedConfig.componentOrder || !importedConfig.globalSettings) {
showToast('Error: Invalid or corrupted configuration file.');
return;
}
Object.keys(config).forEach(key => delete config[key]);
Object.assign(config, importedConfig);
showToast('Configuration imported successfully!');
init();
} catch (error) {
console.error("Import failed:", error);
showToast(`Import failed: ${error.message}`);
} finally {
event.target.value = null;
}
};
reader.readAsText(file);
}
function handleGetCodeClick(e) {
const button = e.target.closest('.get-component-code-btn');
if (!button) return;
const key = button.dataset.componentKey; if (!key) return;
const html = componentGenerators[key] ? componentGenerators[key]() : 'N/A';
const { global, component: css } = generateComponentCSS(key);
const js = getFullJS();
ui.codeModal.title.textContent = `${componentNames[key]} Component Code`;
ui.codeModal.htmlCode.textContent = html;
ui.codeModal.cssCode.textContent = (global + '\n\n' + css).trim();
ui.codeModal.jsCode.textContent = js.trim() ? `document.addEventListener('DOMContentLoaded', () => { \n${js}\n });` : '// No JS for this component';
[ui.codeModal.htmlContainer, ui.codeModal.cssContainer, ui.codeModal.jsContainer].forEach(el => {
const codeContent = el.querySelector('code').textContent;
el.style.display = (codeContent && !codeContent.startsWith('//') && codeContent !== 'N/A') ? 'block' : 'none';
});
ui.codeModal.downloadBtn.onclick = () => generateComponentZip(key);
ui.codeModal.modal.classList.remove('hidden');
}
function generateComponentZip(key) {
const zip = new JSZip();
const { global, component: css } = generateComponentCSS(key);
const js = getFullJS();
const htmlBody = componentGenerators[key] ? componentGenerators[key]() : '';
const html = `<!DOCTYPE html><html><head><title>${componentNames[key]}</title><link rel="stylesheet" href="style.css"></head><body>${htmlBody}${js.trim() ? '<script src="script.js"><\/script>' : ''}</body></html>`;
zip.file("index.html", html);
zip.file("style.css", (global + '\n\n' + css).trim());
if (js.trim()) zip.file("script.js", `document.addEventListener('DOMContentLoaded', () => { \n${js} \n});`);
zip.generateAsync({type:"blob"}).then(content => { saveAs(content, `${key}-component.zip`); showToast("Component ZIP generated!"); });
}
// Initial Load
function init() {
// Init Global Settings
ui.globalSettings.primaryColor.value = config.globalSettings.colors.primary;
ui.globalSettings.secondaryColor.value = config.globalSettings.colors.secondary;
ui.globalSettings.textColor.value = config.globalSettings.colors.text;
ui.globalSettings.headingColor.value = config.globalSettings.colors.heading;
ui.globalSettings.fontFamily.value = config.globalSettings.typography.fontFamily;
ui.customHtml.toggle.checked = config.customHtml.enabled;
ui.customHtml.content.value = config.customHtml.content;
const lmsUI = ui.learningAppHeader; const lmsConfig = config.learningAppHeader;
lmsUI.stickyToggle.checked = lmsConfig.sticky;
lmsUI.primaryBarToggle.checked = lmsConfig.primaryBar.enabled;
lmsUI.brand.type.value = lmsConfig.primaryBar.brand.type;
lmsUI.brand.text.value = lmsConfig.primaryBar.brand.text;
lmsUI.brand.imageUrl.value = lmsConfig.primaryBar.brand.imageUrl;
lmsUI.brand.imageHeight.value = lmsConfig.primaryBar.brand.height;
lmsUI.notificationCount.value = lmsConfig.primaryBar.notificationCount;
lmsUI.pageTitleToggle.checked = lmsConfig.pageTitle.enabled;
lmsUI.pageTitleText.value = lmsConfig.pageTitle.text;
lmsUI.tabs.toggle.checked = lmsConfig.tabs.enabled;
ui.sidebar.enableToggle.checked = config.sidebar.enabled;
ui.sidebar.brand.sitename.value = config.sidebar.branding.sitename;
ui.sidebar.brand.tagline.value = config.sidebar.branding.tagline;
const topBarUI = ui.topBar;
topBarUI.toggle.checked = config.topBar.enabled;
topBarUI.text.value = config.topBar.text;
topBarUI.url.value = config.topBar.url;
topBarUI.bgColorStart.value = config.topBar.styles.bgColorStart;
topBarUI.bgColorEnd.value = config.topBar.styles.bgColorEnd;
topBarUI.textColor.value = config.topBar.styles.textColor;
topBarUI.fontSize.value = config.topBar.styles.fontSize;
topBarUI.padding.value = config.topBar.styles.padding;
topBarUI.fontSizeVal.textContent = config.topBar.styles.fontSize;
topBarUI.paddingVal.textContent = config.topBar.styles.padding;
topBarUI.mainControls.style.display = config.topBar.enabled ? 'block' : 'none';
if (!document.body.classList.contains('initialized')) {
setupEventListeners();
document.body.classList.add('initialized');
}
const hasThemeToggle = config.sidebar.shortcuts.links.some(link => link.isThemeToggle);
ui.sidebar.themeToggleCheckbox.checked = hasThemeToggle;
toggleLmsBrandControls();
createSidebarLinkBuilder('primary-nav', 'Primary Navigation', ui.sidebar.primaryNavBuilder, config.sidebar.primaryNav);
createSidebarLinkBuilder('categories', 'Course Categories', ui.sidebar.categoriesBuilder, config.sidebar.categories);
createSidebarLinkBuilder('user-section', 'User Section', ui.sidebar.userSectionBuilder, config.sidebar.userSection);
createSidebarLinkBuilder('shortcuts', 'Shortcuts & CTA', ui.sidebar.shortcutsBuilder, config.sidebar.shortcuts);
createSidebarLinkBuilder('footer', 'Sidebar Footer', ui.sidebar.footerBuilder, config.sidebar.footer);
renderLmsTabsControls();
renderLmsCustomIconsControls();
renderLayoutControls();
setPreviewMode('desktop');
renderAll();
if(!document.querySelector('.onley-control-nav-button.onley-active')){
ui.controls.nav.querySelector('.onley-control-nav-button').click();
}
}
init();
});
</script>
</body>
</html> |