Fetches piece of JS-code with require.js main config from cache
or if it was not there - generates and put into a cache

@return string
426596
public function getMainConfig()
    {
        $config = null;
        if ($this->cache) {
            $config = $this->cache->fetch(self::CONFIG_CACHE_KEY);
        }
        if (empty($config)) {
            $config = $this->generateMainConfig();
            if ($this->cache) {
                $this->cache->save(self::CONFIG_CACHE_KEY, $config);
            }
        }
        return $config;
    }
917267
public function getJsCode()
    {
        $html = '';
        foreach ($this->js as $js) {
            $html .= sprintf('<script src="%s"></script>', $js);
        }
        foreach ($this->entry as $entry) {
            $html .= sprintf('<script>System.import(\'%s\')</script>', $entry);
        }
        return $html;
    }
201680
private function _generateJSFile()
    {
        $this->_loadLanguageItems();

        $data = [];
        foreach ($this->_languageItems as $language_item) {
            $data[md5($language_item->message)] = $language_item->languageTranslate->translation;
        }

        $filename = $this->_basePath . '/' . $this->_languageId . '.js';

        file_put_contents($filename, str_replace('{language_items}', Json::encode($data), $this->_template));
    }
250077
public function getJavascripts()
    {
        $self = $this;
        $parse_javascripts = function ($params, $javascripts) use ($self) {
            foreach ($params as $js) {
                if (is_string($js)) {
                    $js = array(
                        'path' => $js,
                    );
                } elseif (isset($js['route'])) {
                    $js = array(
                        'path' => $self->getGenerator()
                                        ->getRouter()
                                        ->generate($js['route'], $js['routeparams']),
                    );
                }

                $javascripts[] = $js;
            }

            return $javascripts;
        };

        // From config.yml
        $javascripts = $parse_javascripts(
            $this->getGenerator()->getFromBundleConfig('javascripts', array()), array()
        );

        // From generator.yml
        $javascripts = $parse_javascripts(
            $this->getVariable('javascripts', array()), $javascripts
        );

        return $javascripts;
    }
214195
public static function getJs($name = 'js')
    {
        $output = Load::JS($GLOBALS[self::$pref.$name]);

        return $output;
    }
666396
public static function buildJs()
    {
        $js = '';

        foreach (self::collectJsFiles() as $file) {
            $js .= file_get_contents(__DIR__ . '/../web' . $file);
        }

        return $js;
    }
886656
public function getScript() {
		$jsCode="$('".$this->attachTo." a').click(function (event) { event.preventDefault();$(this).tab('show');});";
		$this->jquery_code_for_compile []=$jsCode;
		$this->compileEvents();
		return $this->compileJQueryCode();
	}
1029709
protected function get_amd_footercode() {
        global $CFG;
        $output = '';

        // First include must be to a module with no dependencies, this prevents multiple requests.
        $prefix = "require(['core/first'], function() {\n";
        $suffix = "\n});";
        $output .= html_writer::script($prefix . implode(";\n", $this->amdjscode) . $suffix);
        return $output;
    }
160688
private function getCached()
    {
        $syntax = "// Cached assets do not modify\r\nlet cache = [" . PHP_EOL;

        foreach ($this->getCachedFiles() as $file) {
            $syntax .= "'$file'," . PHP_EOL;
        }

        $syntax .= "];";

        return $syntax;
    }
309744
protected function getInput() {

        $this->requirejs = new RequireJSUtility();
        $this->modules = "";

        $options = $this->getOptions();

        // JS
        $js = "$('#" . $this->id . "').fileinput(" . json_encode($options) . ").on('filecleared', function() {
    \$('input[name=\"" . $this->name . "\"]').val('###DELETED###');
})";

        if (isset($this->element['uploadUrl'])) {
            $js .= ".on('fileuploaded', function(event, data, previewId, index) {
    \$('input[name=\"" . $this->name . "\"]').val(data.response.name);
})";
        }

        $js .= ";";

        // On ajoute les ressources.
        $this->requirejs
            ->addRequireJSModule("fileinput", "js/vendor/fileinput.min", true, array("jquery"))
            ->addDomReadyJS($js, false, "fileinput". $this->modules  .", css!/css/vendor/fileinput.min.css");

        // Initialize some field attributes.
        $accept = $this->element['accept'] ? ' accept="' . (string) $this->element['accept'] . '"' : '';
        $size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
        $class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
        $disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';

        // Initialize JavaScript field attributes.
        $onchange = $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';

        return '<input type="file" name="' . $this->fieldname . '_upload" id="' . $this->id . '"' . ' value=""' . $accept . $disabled . $class . $size
        . $onchange . '><input type="hidden" name="' . $this->name . '" data-fileinput="' . $this->id . '" value="' . $this->value . '">';

    }
1325481
protected function getCodeFromFile()
    {
        $file = $this->getFile();

        $code = '';

        // Next, we will just loop through the lines of the file until we get to the end
        // of the Closure. Then, we will return the complete contents of this Closure
        // so it can be serialized with these variables and stored for later usage.
        while ($file->key() < $this->reflection->getEndLine()) {
            $code .= $file->current();
            $file->next();
        }

        preg_match('/function\s*\(/', $code, $matches, PREG_OFFSET_CAPTURE);
        $begin = isset($matches[0][1]) ? $matches[0][1] : 0;

        return substr($code, $begin, strrpos($code, '}') - $begin + 1);
    }
11416
function fetchConfig(){
    var config = __config;

    if (!config)
    {
      if (NODE_ENV)
      {
        // node.js env
        basisFilename = process.basisjsFilename || __filename.replace(/\\/g, '/');

        /** @cut */ if (process.basisjsConfig)
        /** @cut */ {
        /** @cut */   config = process.basisjsConfig;
        /** @cut */   if (typeof config == 'string')
        /** @cut */   {
        /** @cut */     try {
        /** @cut */       config = Function('return{' + config + '}')();
        /** @cut */     } catch(e) {
        /** @cut */       /** @cut */ consoleMethods.error('basis-config: basis.js config parse fault: ' + e);
        /** @cut */     }
        /** @cut */   }
        /** @cut */ }
      }
      else
      {
        // browser env
        var scripts = document.scripts;
        for (var i = 0, scriptEl; scriptEl = scripts[i]; i++)
        {
          var configAttrValue = scriptEl.hasAttribute('basis-config')
            ? scriptEl.getAttribute('basis-config')
            : scriptEl.getAttribute('data-basis-config');

          scriptEl.removeAttribute('basis-config');
          scriptEl.removeAttribute('data-basis-config');

          if (configAttrValue !== null)
          {
            basisFilename = pathUtils.normalize(scriptEl.src);

            try {
              config = Function('return{' + configAttrValue + '}')();
            } catch(e) {
              /** @cut */ consoleMethods.error('basis-config: basis.js config parse fault: ' + e);
            }

            break;
          }
        }

        if (!basisFilename)
        {
          basisFilename = pathUtils.normalize(scripts[0].src);
          /** @cut */ consoleMethods.warn('basis-config: no `basis-config` marker on any script tag is found. All paths will be resolved relative to `src` from the first `script` tag.');
        }
      }
    }

    return processConfig(config);
  }
281102
private function loadTypoScript(): string
    {
        if (null === $this->options['cache_dir']) {
            return $this->concatenateTypoScript();
        }

        $cache = $this->getConfigCacheFactory()
            ->cache($this->options['cache_dir'].'/content_elements.typoscript',
                function (ConfigCacheInterface $cache) {
                    $cache->write(
                        $this->concatenateTypoScript(),
                        $this->getRenderDefinitionCollection()->getResources()
                    );
                }
            )
        ;

        return \file_get_contents($cache->getPath());
    }
556187
public function display()
	{
        App::$Alias->setCustomLibrary('js', $this->baseUrl . '/ckeditor.js');
        App::$Alias->setCustomLibrary('js', $this->baseUrl . '/adapters/jquery.js');
        $jsInitializeCode = "$('.{$this->targetClass}').ckeditor({";
        $jsInitializeCode .= "language: '{$this->language}', customConfig: '{$this->config}.js', ";
        if ($this->jsConfig !== null && Any::isArray($this->jsConfig)) {
            foreach ($this->jsConfig as $obj => $value) {
                $jsInitializeCode .= $obj . ": '" . $value . "', ";
            }
        }
	    $jsInitializeCode .= "});";

        App::$Alias->addPlainCode('js', $jsInitializeCode);
		return null;
	}
1245148
public static function get() {
		Log::instance()->write( 'Reading configuration from file.', 1 );

		$file_path = Utils\get_snapshot_directory() . 'config.json';

		if ( ! file_exists( $file_path ) ) {
			/**
			 * Backwards compat for old config file path
			 */
			$file_path = $_SERVER['HOME'] . '/.wpsnapshots.json';

			if ( ! file_exists( $file_path ) ) {
				Log::instance()->write( 'No config found.', 1 );

				$config = new self();
				$config->write();

				return $config;
			} else {
				rename( $file_path, Utils\get_snapshot_directory() . 'config.json' );

				$file_path = Utils\get_snapshot_directory() . 'config.json';
			}
		}

		$config = json_decode( file_get_contents( $file_path ), true );

		return new self( $config );
	}
1272586
public function update_header_js($js) {
        // Update the names of the the configFn variables.
        // The PHP json_encode function cannot handle literal names so we have to wrap
        // them in @ and then replace them with literals of the same function name.
        foreach ($this->jsconfigfunctions as $functionname => $function) {
            $js = str_replace('"@' . $functionname . '@"', $functionname, $js);
        }
        return $js;
    }
679098
function getConfig() {
  // Load the myrmex main configuration file
  let config = {};
  try {
    // try to load a myrmex.json or myrmex.js file
    config = require(path.join(process.cwd(), 'myrmex'));
  } catch (e) {
    // Silently ignore if there is no configuration file
    return config;
  }

  config.config = config.config || {};

  // Load sub-configuration files
  config.configPath = config.configPath || './config';
  const configPath = path.join(process.cwd(), config.configPath);
  let files = [];
  try {
    files = fs.readdirSync(configPath);
  } catch (e) {
    // Silently ignore if there is no configuration directory
  }
  files.forEach(file => {
    const parse = path.parse(file);
    // We load all .js and .json files in the configuration directory
    if (['.js', '.json'].indexOf(parse.ext) !== -1) {
      config.config[parse.name] = _.merge(config.config[parse.name] || {}, require(path.join(configPath, file)));
    }
  });

  // Add configuration passed by environment variables
  Object.keys(process.env).forEach(key => {
    const prefix = 'MYRMEX_';
    if (key.substring(0, prefix.length) === prefix) {
      // We transform
      //     MYRMEX_myConfig_levels = value
      // into
      //     { config: { myConfig: { levels: value } } }
      function addParts(config, parts, value) {
        const part = parts.shift();
        if (parts.length === 0) {
          // Convert string values "true" and "false" to booleans
          if (value === 'false') { value = false; }
          if (value === 'true') { value = true; }
          config[part] = value;
        } else {
          if (config[part] === undefined) {
            config[part] = {};
          }
          addParts(config[part], parts, value);
        }
      }
      addParts(config.config, key.substring(prefix.length).split('_'), process.env[key]);
    }
  });

  return config;
}