From 0c63328413ec08a4367685c9a3c5ee6bafb10240 Mon Sep 17 00:00:00 2001 From: Jay Shah Date: Sun, 5 Mar 2017 23:03:51 +0530 Subject: [PATCH] repaired add-ins toggle --- editor.js | 85 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 68 insertions(+), 17 deletions(-) diff --git a/editor.js b/editor.js index e5a246a..f5f290c 100644 --- a/editor.js +++ b/editor.js @@ -236,46 +236,74 @@ function addScript () { let jsSpan = jsMenu.querySelectorAll('span') var ScrFlags = [0, 0, 0, 0] jsButtons[0].addEventListener('click', function (e) { - toggleStatus(0, jsSpan) + var aniStr = "" if (ScrFlags[0] === 0) { - var bootjsStr = "" - scripts += bootjsStr + scripts += aniStr ScrFlags[0] = 1 console.log('Anime added!') + toggleStatus(0, jsSpan) + } + else + { + scripts = scripts.replace(aniStr,'') + ScrFlags[0] = 0 + console.log('Anime removed!') + toggleStatus(0, jsSpan) } }) jsButtons[1].addEventListener('click', function (e) { - toggleStatus(1, jsSpan) - toggleStatus(2, jsSpan) + var jQStr = "" if (ScrFlags[2] === 0) { - var jQStr = "" + if (ScrFlags[1] === 0) { scripts += bootjsStr ScrFlags[1] = 1 console.log('Bootstrap added!') + toggleStatus(1, jsSpan) + } + else + { + scripts = scripts.replace(bootjsStr,'') + ScrFlags[1] = 0 + console.log('Bootstrap removed!') + toggleStatus(1, jsSpan) } }) jsButtons[2].addEventListener('click', function (e) { - toggleStatus(2, jsSpan) + var jQStr = "" if (ScrFlags[2] === 0) { - var jQStr = "" scripts += jQStr ScrFlags[2] = 1 console.log('jQuery added!') + toggleStatus(2, jsSpan) + } + else if(ScrFlags[1] !== 1) + { + scripts = scripts.replace(jQStr,'') + ScrFlags[2] = 0 + console.log('jQuery removed!') + toggleStatus(2, jsSpan) } }) jsButtons[3].addEventListener('click', function (e) { - toggleStatus(3, jsSpan) + var js3Str = "" if (ScrFlags[3] === 0) { - var js3Str = "" scripts += js3Str ScrFlags[3] = 1 console.log('Three.js added!') + toggleStatus(3, jsSpan) + } + else + { + scripts = scripts.replace(js3Str,'') + ScrFlags[3] = 0 + console.log('Three.js removed!') + toggleStatus(3, jsSpan) } }) }; @@ -286,30 +314,53 @@ function addStyle () { let cssSpan = cssMenu.querySelectorAll('span') var StyFlags = [0, 0, 0] cssButtons[0].addEventListener('click', function (e) { - toggleStatus(0, cssSpan) + var aniStr = "" if (StyFlags[0] === 0) { var aniStr = "" styles += aniStr StyFlags[0] = 1 console.log('Animate added!') + toggleStatus(0, cssSpan) + } + else + { + styles = styles.replace(aniStr,'') + StyFlags[0] = 0 + console.log('Animate removed!') + toggleStatus(0, cssSpan) } }) cssButtons[1].addEventListener('click', function (e) { - toggleStatus(1, cssSpan) + var bootStr = "" + if (StyFlags[1] === 0) { - var bootStr = "" styles += bootStr StyFlags[1] = 1 console.log('Bootstrap added!') + toggleStatus(1, cssSpan) + } + else + { + styles = styles.replace(bootStr,'') + StyFlags[1] = 0 + console.log('Bootstrap removed!') + toggleStatus(1, cssSpan) } }) cssButtons[2].addEventListener('click', function (e) { - toggleStatus(2, cssSpan) + var faStr = "" if (StyFlags[2] === 0) { - var faStr = "" styles += faStr StyFlags[2] = 1 console.log('Font Awesome added!') + toggleStatus(2, cssSpan) + } + else + { + styles = styles.replace(faStr,''); + StyFlags[2] = 0 + console.log('Font Awesome removed!') + toggleStatus(2, cssSpan) } }) };