@description Appends given javascript source to DOM head.
@param {String} src - url src for javascript to append
968508
function asyncLoadJs(src) {
  if (!isBrowser()) {
    _logger2.default.error({
      description: 'Document does not exsist to load assets into.',
      func: 'asyncLoadJs', obj: 'dom'
    });
    throw new Error('Document object is required to load assets.');
  }
  var js = window.document.createElement('script');
  js.src = src;
  js.type = 'text/javascript';
  window.document.getElementsByTagName('head')[0].appendChild(js);
  _logger2.default.log({
    description: 'JS was loaded into document.', element: js,
    func: 'asyncLoadJs', obj: 'dom'
  });
  return new Promise(function (resolve) {
    window.setTimeout(resolve, 200);
  });
}
162691
function combine( dest, src ) {
	var destChildren = dest.children;

	function find( collection, name ) {
		return _.where( collection, {
			name: name
		} )[ 0 ];
	}

	/**
	 * Append a tag to the destination or destination's <body> element if found
	 * @param {Object} elem Element to append
	 */
	function appendTag( elem ) {
		var parent;
		// no parent or parent is a root = we're at the top level -> try to add to body
		if ( !elem.parent || elem.parent.type === 'root' ) {
			parent = find( destChildren, 'html' );

			if ( parent ) {
				parent = find( parent.children, 'body' );
			}

			if ( parent ) {
				utils.appendChild( parent, elem );
			} else {
				// append the element to the destination
				utils.append( destChildren[ destChildren.length - 1 ], elem );
			}
			// append the element to the destination
		} else {
			utils.append( destChildren[ destChildren.length - 1 ], elem );
		}
	}

	/**
	 * Merge element with equivalent found in destination
	 * @param {Object}   elem     Source element
	 * @param {Function} callback Callback called when equivalent found
	 */
	function merge( elem, callback ) {
		var old = find( destChildren, elem.name ),
			nl;

		// merge with old element
		if ( old ) {
			if ( typeof callback == 'function' ) {
				return callback( old );
			}

			_.merge( old.attribs, elem.attribs );

			if ( elem.children ) {
				combine( old, elem );
			}
			// append new element
		} else {
			if ( dest.children ) {
				utils.appendChild( dest, elem );
			} else {
				utils.prepend( destChildren[ 0 ], elem );
				// fix for domutils issue
				elem.parent = destChildren[ 0 ].parent;
				destChildren.unshift( elem );
				destChildren.splice( destChildren.indexOf( elem ) + 1, 0, nl );
			}
		}
	}

	/**
	 * Merge doctype directives
	 * @param {Object} elem New doctype directive
	 */
	function mergeDoctype( elem ) {
		merge( elem, function( old ) {
			utils.replaceElement( old, elem );
			destChildren[ destChildren.indexOf( old ) ] = elem;
		} );
	}

	/**
	 * Merge <head> and <body> tags that are directly in the source
	 * @param {Object} elem New head/body element
	 */
	function mergeHeadBody( elem ) {
		var old = find( destChildren, elem.name ),
			html;

		if ( old ) {
			merge( elem );
		} else {
			html = find( destChildren, 'html' );
			combine( html.children, elem );
		}
	}

	/**
	 * Merge <title> tags
	 * @param {Object} elem New title tag
	 */
	function mergeTitle( elem ) {
		merge( elem, function( old ) {
			var text = elem.children[ 0 ];

			utils.replaceElement( old.children[ 0 ], text );
			old.children[ 0 ] = text;
		} );
	}

	/**
	 * Merge <meta> tags
	 * @param  {Object} elem New meta tag
	 * @return {Boolean} True if merged
	 */
	function mergeMeta( elem ) {
		var attr = elem.attribs,
			old = _.where( destChildren, {
				name: 'meta'
			} ),
			merged = false;

		[ 'charset', 'name', 'http-equiv' ].forEach( function( meta ) {
			if ( !attr[ meta ] ) {
				return;
			}

			old.forEach( function( el ) {
				var idx;

				if ( ( el.attribs[ meta ] === attr[ meta ] ) ||
					( meta === 'charset' && el.attribs[ meta ] ) ) {
					idx = destChildren.indexOf( el );
					utils.replaceElement( el, elem );
					destChildren[ idx ] = elem;
					merged = true;
				}
			} );
		} );

		return merged;
	}

	// iterate over all source elements
	src.children.forEach( function( elem ) {
		var name = elem.name;

		// ignore plain text and comments ?
		if ( elem.type === 'text' || elem.type === 'comment' ) {
			return appendTag( elem );
		}

		if ( name === '!doctype' ) {
			mergeDoctype( elem );
		} else if ( name === 'html' ) {
			merge( elem );
		} else if ( name === 'head' || name === 'body' ) {
			mergeHeadBody( elem );
		} else if ( name === 'title' ) {
			mergeTitle( elem );
		} else if ( name === 'meta' && mergeMeta( elem ) ) {
			return;
		} else {
			appendTag( elem );
		}
	} );

	return dest;
}
739084
function compile( src ) {
    var watch  = arguments.length <= 1 || arguments[1] === void 0 ? true : arguments[1];
    var parent = arguments.length <= 2 || arguments[2] === void 0 ? null : arguments[2];

    var script = new SourceScript( src, parent );

    if( watch ) {
        script.watch();
    }

    return script;
}
76546
public static void writeHtmlImagePreloadJavaScript(String url, Appendable out) throws IOException {
		out.append("<script type='text/javascript'>\n"
				+ "  var img=new Image();\n"
				+ "  img.src=\"");
		// Escape for javascript
		StringBuilder javascript = new StringBuilder(url.length());
		encodeTextInJavaScript(url, javascript);
		// Encode for XML attribute
		encodeJavaScriptInXhtmlAttribute(javascript, out);
		out.append("\";\n"
				+ "</script>");
	}
307230
public JsCodeBuilder append(JsDoc jsDoc) {
    jsDoc.collectRequires(requireCollector);
    return appendLine(jsDoc.toString());
  }
935498
public function addScript ($src, $prepend = false)
		{
			if ($prepend) {
				array_unshift($this->scriptUrls, $src);
			} else {
				$this->scriptUrls[] = $src;
			}

			$html = '<script type="text/javascript" src="' . $this->sanitize($src) . '"></script>';

			$this->addHeader($html, $prepend);
		}
279670
protected void appendDirectEditOpenerScript(StringBuffer html) {

        html.append("<script type=\"text/javascript\">\n");
        html.append("function doOnload() {\n");

        // the window's name must be the same as in:
        // system/workplace/resources/commons/explorer.js
        html.append("window.name='preview';");
        html.append("window.location.replace('");
        html.append(link(m_directEditPath));
        html.append("');");

        html.append("}\n");
        html.append("</script>\n");
    }
675471
function addSourceToNode(
  node: TreeDirectory,
  url: ParsedURL,
  source: Source
): Source | TreeNode[] {
  const isFile = !isPathDirectory(url.path);

  if (node.type == "source") {
    throw new Error(`Unexpected type "source" at: ${node.name}`);
  }

  // if we have a file, and the subtree has no elements, overwrite the
  // subtree contents with the source
  if (isFile) {
    // $FlowIgnore
    node.type = "source";
    return source;
  }

  const { filename } = url;
  const { found: childFound, index: childIndex } = findNodeInContents(
    node,
    createTreeNodeMatcher(filename, false, null)
  );

  // if we are readding an existing file in the node, overwrite the existing
  // file and return the node's contents
  if (childFound) {
    const existingNode = node.contents[childIndex];
    if (existingNode.type === "source") {
      existingNode.contents = source;
    }

    return node.contents;
  }

  // if this is a new file, add the new file;
  const newNode = createSourceNode(filename, source.url, source);
  const contents = node.contents.slice(0);
  contents.splice(childIndex, 0, newNode);
  return contents;
}
818118
public void setSourcePath(Path src) {
        if (sourcePath == null) {
            sourcePath = src;
        } else {
            sourcePath.append(src);
        }
    }
1257679
public static HtmlTree SCRIPT(String src) {
        HtmlTree htmltree = HtmlTree.SCRIPT();
        htmltree.addAttr(HtmlAttr.SRC, nullCheck(src));
        return htmltree;
    }
38635
function appendJSValue(token) {
		builder.add('(')
		if (options.compileDebug) {
			builder.add(`${compile._getDebugMarker(token)},`)
		}
		builder.addToken(token)
		builder.add(')')
	}
1009450
function(src) {
    var cache;

    try {
      cache = fs.existsSync(src) ? file.readJSON(src) : undefined;
    } catch (e) {
      debug(e);
    }

    // Progressively upgrade `cache`, which is one of:
    // empty
    // {}
    // { file: size [,...] }
    // { "": { tips: { label: SHA1, ... } }, label: { file: size, ... }, ... }
    // { "": { version: 0.4, tips: { label: SHA1, ... } },
    //   label: { file: { "": size, compressor: size, ... }, ... }, ... }
    if (typeof cache !== "object") {
      cache = undefined;
    }
    if (!cache || !cache[""]) {
      // If promoting cache to dictionary, assume that data are for last run
      cache = _.zipObject(["", lastrun], [{ version: 0, tips: {} }, cache]);
    }
    if (!cache[""].version) {
      cache[""].version = 0.4;
      _.forEach(cache, function(sizes, label) {
        if (!label || !sizes) {
          return;
        }

        // If promoting sizes to dictionary, assume that compressed size data are indicated by suffixes
        Object.keys(sizes)
          .sort()
          .forEach(function(file) {
            var parts = file.split("."),
              prefix = parts.shift();

            // Append compressed size data to a matching prefix
            while (parts.length) {
              if (typeof sizes[prefix] === "object") {
                sizes[prefix][parts.join(".")] = sizes[file];
                delete sizes[file];
                return;
              }
              prefix += "." + parts.shift();
            }

            // Store uncompressed size data
            sizes[file] = { "": sizes[file] };
          });
      });
    }

    return cache;
  }
1190338
public function addAsyncJsUrl(string $src, bool $prepend = false) {
		$this->htmlProperties->add(self::HEAD_SCRIPT_KEY, 'type:javascript:src:' . $src,
				new HtmlElement('script', array(/*'type' => 'text/javascript'*/),
						"\r\n" . '//<![CDATA[' . "\r\n" . '(function() {var b=document.createElement("script");b.type="text/javascript";b.async=true;b.src="' .
						addslashes($src) . '";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(b,a)})();' . "\r\n" . '//]]>' . "\r\n"),
				$prepend);
		
		return $this;
	}
968374
def add_JSsource(self, new_src):
        """"""
        if isinstance(new_src, list):
            for h in new_src:
                self.JSsource.append(h)
        elif isinstance(new_src, basestring):
            self.JSsource.append(new_src)
        else:
            raise OptionTypeError("Option: %s Not Allowed For Series Type: %s" % type(new_src))
1337189
public JsStatement append(CharSequence javascriptCode)
	{
		JsStatement statement = new JsStatement();
		statements.add(statement);
		return statement.append(javascriptCode);
	}
169128
function appendStyle(code) {
        var dom = document.createElement('style');
        dom.innerHTML = code;
        head.appendChild(dom);
    }
420161
function extend(dest, src, merge) {
    for(var key in src) {
      if(dest[key] !== undefined && merge) {
        continue;
      }
      dest[key] = src[key];
    }
    return dest;
  }