protected function getInlineJavaScript()
    {
        static $shown = false;

        if (!$shown) {
            $javascript = $this->getInlineJavaScriptTranslations();
            $shown = true;
        } else {
            $javascript = '';
        }

        $javascript .= sprintf(
            "var %s = new %s(\n" . "%s, %s, %s, %s, %s, %s);\n",
            $this->id,
            $this->getJavaScriptClass(),
            SwatString::quoteJavaScriptString($this->id),
            SwatString::quoteJavaScriptString($this->preview_image),
            intval($this->preview_width),
            intval($this->preview_height),
            $this->show_title ? 'true' : 'false',
            SwatString::quoteJavaScriptString($this->preview_title)
        );

        if ($this->container_width !== null) {
            $javascript .= sprintf(
                "%s.width = %s;",
                $this->id,
                (int) $this->container_width
            );
        }

        if ($this->container_height !== null) {
            $javascript .= sprintf(
                "%s.height = %s;",
                $this->id,
                (int) $this->container_height
            );
        }

        return $javascript;
    }