Skip to content

Instantly share code, notes, and snippets.

@kaosat-dev
Forked from serapath/codepen.md
Created December 2, 2017 15:12
Show Gist options
  • Select an option

  • Save kaosat-dev/799f3ee233fd943a7e80dfd3222842d4 to your computer and use it in GitHub Desktop.

Select an option

Save kaosat-dev/799f3ee233fd943a7e80dfd3222842d4 to your computer and use it in GitHub Desktop.

Revisions

  1. @serapath serapath revised this gist Nov 21, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions codepen.md
    Original file line number Diff line number Diff line change
    @@ -9,3 +9,5 @@ https://cdn.rawgit.com/serapath/e2b55cab315e60fbbffea7b43acd8749/raw/a2709905ca0

    3. Press **`Save & Close`** and start using the `require(...)` in your JavaScript code on codepen


    (For more detailed help, check: https://github.com/wizardamigos/app/blob/master/curriculum/newLessons/codepen.md)
  2. @serapath serapath revised this gist Nov 21, 2017. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions codepen.md
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,11 @@
    # use `require` in a codepen

    Click on the little icon `Open JS Settings` on the JavaScript editor pane and add the following link under **Add External Javascript**
    1. click on the little icon **`Open JS Settings`** on the JavaScript editor pane
    2. Then add the following link under **`Add External Javascript`**

    ```
    https://cdn.rawgit.com/serapath/e2b55cab315e60fbbffea7b43acd8749/raw/a2709905ca06830f78d6069b97cda1f18eb9ef4c/require.js
    ```

    then press `Save & Close` and start using the **`require`** function in you JavaScript on codepen
    3. Press **`Save & Close`** and start using the `require(...)` in your JavaScript code on codepen

  3. @serapath serapath revised this gist Jul 2, 2017. 2 changed files with 1 addition and 7 deletions.
    6 changes: 0 additions & 6 deletions bookmarklet.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +0,0 @@
    # `require` Bookmarklet

    Just make a new bookmark and edit it's **url** to:
    ```js
    javascript:!function(){window.require=function(e){function r(r,n){var o=document.createElement("script"),a=JSON.parse(n)[r];return o.text=a.bundle,document.head.appendChild(o),document.head.removeChild(o),a.exports=window.require(r),window.require=t,e[r]=a}function t(t,n){var o=e[t];if(o)return n&&console.error('using cached version "'+o["package"].version+'" of "'+t+'"'),o.exports;n=n||"latest";var a=t+"@"+n+":"+location.host,i=localStorage[a];if("latest"===n&&i){var o=JSON.parse(i)[t],s=o.timestamp,c=+new Date,l=(c-s)/36e5;if(!(l>24))return r(t,i).exports;i=o=null}if(!i){var d=new XMLHttpRequest;d.open("POST","https://wzrd.in/multi",!1);var p={dependencies:{}};p.dependencies[t]=n,d.send(JSON.stringify(p)),i=d.responseText,o=JSON.parse(i)[t],o.timestamp=+new Date;var u={};u[t]=o,i=JSON.stringify(u),localStorage[a]=i,"latest"===n&&(n=o["package"].version,a=t+"@"+n+":"+location.host,localStorage[a]=i),console.log('caching version "'+n+'" of "'+t+'" for one day')}return r(t,i).exports}return t.cache=e,t}({})}();
    ```
    2 changes: 1 addition & 1 deletion codepen.md
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    Click on the little icon `Open JS Settings` on the JavaScript editor pane and add the following link under **Add External Javascript**

    ```
    https://cdn.rawgit.com/serapath/e2b55cab315e60fbbffea7b43acd8749/raw/fc0d32703dc77cfa51405f198fa0eaea3e5a7bbb/require.js
    https://cdn.rawgit.com/serapath/e2b55cab315e60fbbffea7b43acd8749/raw/a2709905ca06830f78d6069b97cda1f18eb9ef4c/require.js
    ```

    then press `Save & Close` and start using the **`require`** function in you JavaScript on codepen
  4. @serapath serapath revised this gist Jul 2, 2017. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion require.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    window.require = (function (modules) {
    var URL = 'https://wizardamigos-browserify-cdn.herokuapp.com/multi'
    function init (name, _module) {
    var se = document.createElement('script')
    var module = JSON.parse(_module)[name]
    @@ -28,7 +29,7 @@ window.require = (function (modules) {
    }
    if (!_module) {
    var xhr = new XMLHttpRequest()
    xhr.open('POST', 'https://wzrd.in/multi', false)
    xhr.open('POST', URL, false)
    var data = { dependencies: { } }
    data.dependencies[name] = version
    xhr.send(JSON.stringify(data))
  5. @serapath serapath revised this gist Mar 23, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bookmarklet.md
    Original file line number Diff line number Diff line change
    @@ -2,5 +2,5 @@

    Just make a new bookmark and edit it's **url** to:
    ```js
    javascript:!function(){window.require=function(e){function t(t,n){var o=document.createElement("script"),a=JSON.parse(n)[t];return o.text=a.bundle,document.head.appendChild(o),document.head.removeChild(o),a.exports=window.require(t),window.require=r,e[t]=a}function r(r,n){var o=e[r];if(o)return n&&console.error('using cached version "'+o["package"].version+'"'),o.exports;n=n||"latest";var a=r+"@"+n+":"+location.host,i=localStorage[a];if("latest"===n&&i){var o=JSON.parse(i)[r],s=o.timestamp,c=+new Date,l=(c-s)/36e5;if(!(l>24))return t(r,i).exports;i=o=null}if(!i){var d=new XMLHttpRequest;d.open("POST","https://wzrd.in/multi",!1);var p={dependencies:{}};p.dependencies[r]=n,d.send(JSON.stringify(p)),i=d.responseText,o=JSON.parse(i)[r],o.timestamp=+new Date;var u={};u[r]=o,i=JSON.stringify(u),localStorage[a]=i,"latest"===n&&(n=o["package"].version,a=r+"@"+n+":"+location.host,localStorage[a]=i),console.log('caching version "'+n+'" for one day')}return t(r,i).exports}return r.cache=e,r}({})}();
    javascript:!function(){window.require=function(e){function r(r,n){var o=document.createElement("script"),a=JSON.parse(n)[r];return o.text=a.bundle,document.head.appendChild(o),document.head.removeChild(o),a.exports=window.require(r),window.require=t,e[r]=a}function t(t,n){var o=e[t];if(o)return n&&console.error('using cached version "'+o["package"].version+'" of "'+t+'"'),o.exports;n=n||"latest";var a=t+"@"+n+":"+location.host,i=localStorage[a];if("latest"===n&&i){var o=JSON.parse(i)[t],s=o.timestamp,c=+new Date,l=(c-s)/36e5;if(!(l>24))return r(t,i).exports;i=o=null}if(!i){var d=new XMLHttpRequest;d.open("POST","https://wzrd.in/multi",!1);var p={dependencies:{}};p.dependencies[t]=n,d.send(JSON.stringify(p)),i=d.responseText,o=JSON.parse(i)[t],o.timestamp=+new Date;var u={};u[t]=o,i=JSON.stringify(u),localStorage[a]=i,"latest"===n&&(n=o["package"].version,a=t+"@"+n+":"+location.host,localStorage[a]=i),console.log('caching version "'+n+'" of "'+t+'" for one day')}return r(t,i).exports}return t.cache=e,t}({})}();
    ```
  6. @serapath serapath revised this gist Mar 23, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions require.js
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ window.require = (function (modules) {
    function require (name, version) {
    var module = modules[name]
    if (module) {
    if (version) console.error('using cached version "' + module.package.version + '"')
    if (version) console.error('using cached version "' + module.package.version + '" of "' + name + '"')
    return module.exports
    }
    version = version || 'latest'
    @@ -44,7 +44,7 @@ window.require = (function (modules) {
    modulename = name + '@' + version + ':' + location.host
    localStorage[modulename] = _module
    }
    console.log('caching version "' + version + '" for one day')
    console.log('caching version "' + version + '" of "' + name + '" for one day')
    }
    return init(name, _module).exports
    }
  7. @serapath serapath revised this gist Mar 19, 2017. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions codepen.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    # use `require` in a codepen

    Click on the little icon `Open JS Settings` on the JavaScript editor pane and add the following link under **Add External Javascript**

    ```
    https://cdn.rawgit.com/serapath/e2b55cab315e60fbbffea7b43acd8749/raw/fc0d32703dc77cfa51405f198fa0eaea3e5a7bbb/require.js
    ```

    then press `Save & Close` and start using the **`require`** function in you JavaScript on codepen
  8. @serapath serapath revised this gist Mar 13, 2017. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions bookmarklet.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    # `require` Bookmarklet

    Just make a new bookmark and edit it's **url** to:
    ```js
    javascript:!function(){window.require=function(e){function t(t,n){var o=document.createElement("script"),a=JSON.parse(n)[t];return o.text=a.bundle,document.head.appendChild(o),document.head.removeChild(o),a.exports=window.require(t),window.require=r,e[t]=a}function r(r,n){var o=e[r];if(o)return n&&console.error('using cached version "'+o["package"].version+'"'),o.exports;n=n||"latest";var a=r+"@"+n+":"+location.host,i=localStorage[a];if("latest"===n&&i){var o=JSON.parse(i)[r],s=o.timestamp,c=+new Date,l=(c-s)/36e5;if(!(l>24))return t(r,i).exports;i=o=null}if(!i){var d=new XMLHttpRequest;d.open("POST","https://wzrd.in/multi",!1);var p={dependencies:{}};p.dependencies[r]=n,d.send(JSON.stringify(p)),i=d.responseText,o=JSON.parse(i)[r],o.timestamp=+new Date;var u={};u[r]=o,i=JSON.stringify(u),localStorage[a]=i,"latest"===n&&(n=o["package"].version,a=r+"@"+n+":"+location.host,localStorage[a]=i),console.log('caching version "'+n+'" for one day')}return t(r,i).exports}return r.cache=e,r}({})}();
    ```
  9. @serapath serapath created this gist Mar 13, 2017.
    53 changes: 53 additions & 0 deletions require.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    window.require = (function (modules) {
    function init (name, _module) {
    var se = document.createElement('script')
    var module = JSON.parse(_module)[name]
    se.text = module.bundle
    document.head.appendChild(se)
    document.head.removeChild(se)
    module.exports = window.require(name)
    window.require = require
    return modules[name] = module
    }
    function require (name, version) {
    var module = modules[name]
    if (module) {
    if (version) console.error('using cached version "' + module.package.version + '"')
    return module.exports
    }
    version = version || 'latest'
    var modulename = name + '@' + version + ':' + location.host
    var _module = localStorage[modulename]
    if (version === 'latest' && _module) {
    var module = JSON.parse(_module)[name]
    var oldstamp = module.timestamp
    var newstamp = +new Date()
    var age = (newstamp - oldstamp) / (1000*3600)
    if (age > 24) _module = module = null
    else return init(name, _module).exports
    }
    if (!_module) {
    var xhr = new XMLHttpRequest()
    xhr.open('POST', 'https://wzrd.in/multi', false)
    var data = { dependencies: { } }
    data.dependencies[name] = version
    xhr.send(JSON.stringify(data))
    _module = xhr.responseText
    module = JSON.parse(_module)[name]
    module.timestamp = +new Date()
    var m = {}
    m[name] = module
    _module = JSON.stringify(m)
    localStorage[modulename] = _module
    if (version === 'latest') {
    version = module.package.version
    modulename = name + '@' + version + ':' + location.host
    localStorage[modulename] = _module
    }
    console.log('caching version "' + version + '" for one day')
    }
    return init(name, _module).exports
    }
    require.cache = modules
    return require
    })({})