Skip to content

Instantly share code, notes, and snippets.

@KoryNunn
Created December 8, 2015 23:36
Show Gist options
  • Select an option

  • Save KoryNunn/7aeb860098e20b22c49f to your computer and use it in GitHub Desktop.

Select an option

Save KoryNunn/7aeb860098e20b22c49f to your computer and use it in GitHub Desktop.
requirebin sketch
var crel = require('crel');
crel(document.body,
crel(
'select',
crel('option', {value: 'foo1'}, 'foo1'),
crel('option', {value: 'foo2'}, 'foo2'),
crel('option', {value: 'foo3'}, 'foo3')
)
)
require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({crel:[function(require,module,exports){(function(root,factory){if(typeof exports==="object"){module.exports=factory()}else if(typeof define==="function"&&define.amd){define(factory)}else{root.crel=factory()}})(this,function(){var fn="function",obj="object",nodeType="nodeType",textContent="textContent",setAttribute="setAttribute",attrMapString="attrMap",isNodeString="isNode",isElementString="isElement",d=typeof document===obj?document:{},isType=function(a,type){return typeof a===type},isNode=typeof Node===fn?function(object){return object instanceof Node}:function(object){return object&&isType(object,obj)&&nodeType in object&&isType(object.ownerDocument,obj)},isElement=function(object){return crel[isNodeString](object)&&object[nodeType]===1},isArray=function(a){return a instanceof Array},appendChild=function(element,child){if(!crel[isNodeString](child)){child=d.createTextNode(child)}element.appendChild(child)};function crel(){var args=arguments,element=args[0],child,settings=args[1],childIndex=2,argumentsLength=args.length,attributeMap=crel[attrMapString];element=crel[isElementString](element)?element:d.createElement(element);if(argumentsLength===1){return element}if(!isType(settings,obj)||crel[isNodeString](settings)||isArray(settings)){--childIndex;settings=null}if(argumentsLength-childIndex===1&&isType(args[childIndex],"string")&&element[textContent]!==undefined){element[textContent]=args[childIndex]}else{for(;childIndex<argumentsLength;++childIndex){child=args[childIndex];if(child==null){continue}if(isArray(child)){for(var i=0;i<child.length;++i){appendChild(element,child[i])}}else{appendChild(element,child)}}}for(var key in settings){if(!attributeMap[key]){element[setAttribute](key,settings[key])}else{var attr=attributeMap[key];if(typeof attr===fn){attr(element,settings[key])}else{element[setAttribute](attr,settings[key])}}}return element}crel[attrMapString]={};crel[isElementString]=isElement;crel[isNodeString]=isNode;return crel})},{}]},{},[]);var crel=require("crel");crel(document.body,crel("select",crel("option",{value:"foo1"},"foo1"),crel("option",{value:"foo2"},"foo2"),crel("option",{value:"foo3"},"foo3")));
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"crel": "2.1.8"
}
}
<!-- contents of this file will be placed inside the <body> -->
<!-- contents of this file will be placed inside the <head> -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment