prevent js from being executed multiple times

This commit is contained in:
Send_Nukez 2021-11-28 01:47:32 +01:00
parent 2d30ff934e
commit e18320acb3

View file

@ -4,13 +4,15 @@ import chroma from "chroma-js";
import $ from "jquery"; import $ from "jquery";
import moment from "moment"; import moment from "moment";
// Break if Dribbblish has already been initialized
if ($("html").attr("dribbblish-js-installed") != undefined) throw new Error("Dribbblish has already been initialized");
// Remove not installed message
$("html").attr("dribbblish-js-installed", " ");
import { waitForElement, copyToClipboard, capitalizeFirstLetter, getClosestToNum, randomFromArray, debounce } from "./Util"; import { waitForElement, copyToClipboard, capitalizeFirstLetter, getClosestToNum, randomFromArray, debounce } from "./Util";
import { default as _Dribbblish } from "./Dribbblish"; import { default as _Dribbblish } from "./Dribbblish";
import "./Folders"; import "./Folders";
// Remove not installed message
$("html").attr("dribbblish-js-installed", " ");
// To expose to external scripts // To expose to external scripts
const Dribbblish = new _Dribbblish(); const Dribbblish = new _Dribbblish();
window.Dribbblish = Dribbblish; window.Dribbblish = Dribbblish;
@ -64,7 +66,6 @@ Dribbblish.on("ready", () => {
defaultValue: true, defaultValue: true,
onChange: (val) => $("#main").attr("search-box", val ? "" : null), onChange: (val) => $("#main").attr("search-box", val ? "" : null),
onAppended: () => { onAppended: () => {
if ($("#dribbblish-search-box").length != 0) return;
const input = document.createElement("input"); const input = document.createElement("input");
input.id = "dribbblish-search-box"; input.id = "dribbblish-search-box";
input.type = "search"; input.type = "search";