├── test ├── fixtures │ └── index.js └── unit.js ├── .jshintrc ├── .codeclimate.yml ├── .gitignore ├── docs ├── fonts │ ├── OpenSans-Bold-webfont.eot │ ├── OpenSans-Bold-webfont.woff │ ├── OpenSans-Italic-webfont.eot │ ├── OpenSans-Italic-webfont.woff │ ├── OpenSans-Light-webfont.eot │ ├── OpenSans-Light-webfont.woff │ ├── OpenSans-Regular-webfont.eot │ ├── OpenSans-Regular-webfont.woff │ ├── OpenSans-BoldItalic-webfont.eot │ ├── OpenSans-BoldItalic-webfont.woff │ ├── OpenSans-LightItalic-webfont.eot │ └── OpenSans-LightItalic-webfont.woff ├── scripts │ ├── linenumber.js │ └── prettify │ │ └── lang-css.js ├── styles │ ├── prettify-jsdoc.css │ ├── prettify-tomorrow.css │ └── jsdoc-default.css ├── cache.js.html ├── Fragments_Separator.html ├── experiments.js.html ├── Experiments.html ├── prismic.js.html ├── Fragments_Text.html ├── Fragments_SliceZone.html ├── index.html ├── Fragments_Num.html ├── Fragments_Color.html ├── Fragments_Select.html ├── Fragments_Date.html ├── Fragments_Timestamp.html ├── Fragments_Embed.html ├── Ref.html ├── Fragments_SimpleSlice.html ├── Fragments_CompositeSlice.html ├── Fragments_Group.html ├── Fragments_GeoPoint.html └── Fragments_WebLink.html ├── .travis.yml ├── scripts └── browser.js ├── lib ├── utils │ └── date.js ├── browser.js ├── cache.js ├── cookies.js ├── experiments.js ├── quickRoutes.js ├── prismic.js ├── requests.js └── lru.js ├── bower.json ├── .eslintrc.json ├── browsertests └── browser.html ├── package.json ├── examples └── browser │ └── index.html └── README.md /test/fixtures/index.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "sub": true, 3 | "expr": true, 4 | "loopfunc": true 5 | } 6 | -------------------------------------------------------------------------------- /.codeclimate.yml: -------------------------------------------------------------------------------- 1 | engines: 2 | eslint: 3 | enabled: true 4 | 5 | ratings: 6 | paths: 7 | - "**.js" 8 | 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | coverage/ 2 | node_modules 3 | build 4 | local-build 5 | .idea 6 | .grunt 7 | .tern-port 8 | npm-debug.log 9 | -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Bold-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/javascript-kit/HEAD/docs/fonts/OpenSans-Bold-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Bold-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/javascript-kit/HEAD/docs/fonts/OpenSans-Bold-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Italic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/javascript-kit/HEAD/docs/fonts/OpenSans-Italic-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Italic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/javascript-kit/HEAD/docs/fonts/OpenSans-Italic-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Light-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/javascript-kit/HEAD/docs/fonts/OpenSans-Light-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Light-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/javascript-kit/HEAD/docs/fonts/OpenSans-Light-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Regular-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/javascript-kit/HEAD/docs/fonts/OpenSans-Regular-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Regular-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/javascript-kit/HEAD/docs/fonts/OpenSans-Regular-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-BoldItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/javascript-kit/HEAD/docs/fonts/OpenSans-BoldItalic-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-BoldItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/javascript-kit/HEAD/docs/fonts/OpenSans-BoldItalic-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-LightItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/javascript-kit/HEAD/docs/fonts/OpenSans-LightItalic-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-LightItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/javascript-kit/HEAD/docs/fonts/OpenSans-LightItalic-webfont.woff -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | sudo: false 3 | node_js: 4 | - '4' 5 | - '5' 6 | - '6' 7 | - '7' 8 | +script: 9 | npm run lint 10 | after_script: 11 | - codeclimate < coverage/lcov.info 12 | addons: 13 | code_climate: 14 | repo_token: 25760a4ae3dea7404d3a3ef79951e0b6bf8808fcdb7f63bc1533610a9d8f936d -------------------------------------------------------------------------------- /scripts/browser.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /*eslint-env es6 */ 4 | 5 | var fs = require("fs"); 6 | var browserify = require("browserify"); 7 | 8 | browserify("./lib/browser.js") 9 | .transform("babelify", {presets: ["es2015"]}) 10 | .bundle() 11 | .pipe(fs.createWriteStream("dist/prismic.io.js")); 12 | -------------------------------------------------------------------------------- /lib/utils/date.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parse: function (strDate) { 3 | if (strDate) { 4 | var correctIso8601Date = (strDate.length == 24) ? strDate.substring(0, 22) + ':' + strDate.substring(22, 24) : strDate; 5 | return new Date(correctIso8601Date); 6 | } 7 | else { 8 | return null; 9 | } 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "prismic.io", 3 | "description": "JavaScript development kit for prismic.io", 4 | "main": "lib/prismic.js", 5 | "license": "Apache-2.0", 6 | "keywords": [ 7 | "prismic", 8 | "prismic.io", 9 | "cms", 10 | "content", 11 | "api" 12 | ], 13 | "homepage": "https://github.com/prismicio/javascript-kit", 14 | "ignore": [ 15 | "**/.*", 16 | "node_modules", 17 | "bower_components", 18 | "test", 19 | "tests" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "indent": [2, 2, 4 | {"VariableDeclarator": { "var": 2, "let": 2, "const": 3}} 5 | ], 6 | "linebreak-style": [2, "unix"], 7 | "semi": [2, "always"], 8 | "consistent-return": 2, 9 | "block-scoped-var": 2, 10 | "no-alert": 2, 11 | "no-console": 0, 12 | "array-bracket-spacing": [2, "never"], 13 | "block-spacing": [2, "always"] 14 | }, 15 | "env": { 16 | "node": true, 17 | "browser": true 18 | }, 19 | "globals": { 20 | "Promise": true 21 | }, 22 | "extends": "eslint:recommended" 23 | } 24 | -------------------------------------------------------------------------------- /lib/browser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // IE below 12 doesn't support promises 4 | require('es6-promise').polyfill(); 5 | 6 | // Polyfill for inheritance 7 | if (typeof Object.create != 'function') { 8 | Object.create = (function() { 9 | var Object = function() {}; 10 | return function (prototype) { 11 | if (arguments.length > 1) { 12 | throw Error('Second argument not supported'); 13 | } 14 | if (typeof prototype != 'object') { 15 | throw TypeError('Argument must be an object'); 16 | } 17 | Object.prototype = prototype; 18 | var result = {}; 19 | Object.prototype = null; 20 | return result; 21 | }; 22 | })(); 23 | } 24 | 25 | window.Prismic = require('./prismic'); 26 | -------------------------------------------------------------------------------- /browsertests/browser.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Prismic.io Javascript kit Test Suite 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /docs/scripts/linenumber.js: -------------------------------------------------------------------------------- 1 | /*global document */ 2 | (function() { 3 | var source = document.getElementsByClassName('prettyprint source linenums'); 4 | var i = 0; 5 | var lineNumber = 0; 6 | var lineId; 7 | var lines; 8 | var totalLines; 9 | var anchorHash; 10 | 11 | if (source && source[0]) { 12 | anchorHash = document.location.hash.substring(1); 13 | lines = source[0].getElementsByTagName('li'); 14 | totalLines = lines.length; 15 | 16 | for (; i < totalLines; i++) { 17 | lineNumber++; 18 | lineId = 'line' + lineNumber; 19 | lines[i].id = lineId; 20 | if (lineId === anchorHash) { 21 | lines[i].className += ' selected'; 22 | } 23 | } 24 | } 25 | })(); 26 | -------------------------------------------------------------------------------- /docs/scripts/prettify/lang-css.js: -------------------------------------------------------------------------------- 1 | PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n "]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com", 2 | /^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); 3 | -------------------------------------------------------------------------------- /lib/cache.js: -------------------------------------------------------------------------------- 1 | 2 | "use strict"; 3 | 4 | var LRUCache = require('./lru'); 5 | 6 | /** 7 | * Api cache 8 | */ 9 | function ApiCache(limit) { 10 | this.lru = new LRUCache(limit); 11 | } 12 | 13 | ApiCache.prototype = { 14 | 15 | get: function(key, cb) { 16 | var maybeEntry = this.lru.get(key); 17 | if(maybeEntry && !this.isExpired(key)) { 18 | return cb(null, maybeEntry.data); 19 | } 20 | return cb(); 21 | }, 22 | 23 | set: function(key, value, ttl, cb) { 24 | this.lru.remove(key); 25 | this.lru.put(key, { 26 | data: value, 27 | expiredIn: ttl ? (Date.now() + (ttl * 1000)) : 0 28 | }); 29 | 30 | return cb(); 31 | }, 32 | 33 | isExpired: function(key) { 34 | var entry = this.lru.get(key); 35 | if(entry) { 36 | return entry.expiredIn !== 0 && entry.expiredIn < Date.now(); 37 | } else { 38 | return false; 39 | } 40 | }, 41 | 42 | remove: function(key, cb) { 43 | this.lru.remove(key); 44 | return cb(); 45 | }, 46 | 47 | clear: function(cb) { 48 | this.lru.removeAll(); 49 | return cb(); 50 | } 51 | }; 52 | 53 | module.exports = ApiCache; 54 | -------------------------------------------------------------------------------- /lib/cookies.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Some portions of code from https://github.com/jshttp/cookie 4 | 5 | var decode = decodeURIComponent; 6 | 7 | function tryDecode(str, decode) { 8 | try { 9 | return decode(str); 10 | } catch (e) { 11 | return str; 12 | } 13 | } 14 | 15 | function parse(str, options) { 16 | if (typeof str !== 'string') { 17 | throw new TypeError('argument str must be a string'); 18 | } 19 | 20 | var obj = {}; 21 | var opt = options || {}; 22 | var pairs = str.split(/; */); 23 | var dec = opt.decode || decode; 24 | 25 | pairs.forEach(function(pair) { 26 | var eq_idx = pair.indexOf('='); 27 | 28 | // skip things that don't look like key=value 29 | if (eq_idx < 0) { 30 | return; 31 | } 32 | 33 | var key = pair.substr(0, eq_idx).trim(); 34 | var val = pair.substr(++eq_idx, pair.length).trim(); 35 | 36 | // quoted values 37 | if ('"' == val[0]) { 38 | val = val.slice(1, -1); 39 | } 40 | 41 | // only assign once 42 | if (undefined == obj[key]) { 43 | obj[key] = tryDecode(val, dec); 44 | } 45 | }); 46 | 47 | return obj; 48 | } 49 | 50 | module.exports = { 51 | parse: parse 52 | }; 53 | 54 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "prismic.io", 3 | "description": "JavaScript development kit for prismic.io", 4 | "license": "Apache-2.0", 5 | "url": "https://github.com/prismicio/javascript-kit", 6 | "keywords": [ 7 | "prismic", 8 | "prismic.io", 9 | "cms", 10 | "content", 11 | "api" 12 | ], 13 | "version": "3.6.1", 14 | "engines": { 15 | "node": ">=4.8.1", 16 | "npm": ">=2.15.11" 17 | }, 18 | "devDependencies": { 19 | "babel-preset-es2015": "~6.24.0", 20 | "babelify": "~7.3.0", 21 | "browserify": "~14.1.0", 22 | "chai": "~3.5.0", 23 | "codeclimate-test-reporter": "~0.4.1", 24 | "es6-promise": "~4.1.0", 25 | "eslint": "~3.18.0", 26 | "istanbul": "~0.4.5", 27 | "jsdoc": "~3.4.3", 28 | "mocha": "~3.2.0", 29 | "rimraf": "~2.6.1", 30 | "uglify-js": "~2.8.16", 31 | "vinyl-buffer": "~1.0.0", 32 | "vinyl-source-stream": "~1.1.0" 33 | }, 34 | "repository": { 35 | "type": "git", 36 | "url": "http://github.com/prismicio/javascript-kit.git" 37 | }, 38 | "main": "lib/prismic.js", 39 | "scripts": { 40 | "build": "scripts/browser.js", 41 | "postbuild": "npm run docs", 42 | "uglify": "uglifyjs -c -o=dist/prismic.io.min.js dist/prismic.io.js", 43 | "preuglify": "npm run build", 44 | "prepublish": "npm run uglify", 45 | "lint": "eslint lib", 46 | "test": "istanbul cover _mocha -- -t 3000 test/", 47 | "posttest": "eslint lib", 48 | "predocs": "rimraf ./docs", 49 | "docs": "jsdoc lib/*.js README.md -d docs" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /examples/browser/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | title 6 | 7 | 8 | 9 | 10 | 34 | 35 | 36 |

Fetching Prismic.io data from a browser

37 |
The Javascript kit can be used server-side, but also client-side.
38 |
39 | API enpoint: 40 | 41 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /docs/styles/prettify-jsdoc.css: -------------------------------------------------------------------------------- 1 | /* JSDoc prettify.js theme */ 2 | 3 | /* plain text */ 4 | .pln { 5 | color: #000000; 6 | font-weight: normal; 7 | font-style: normal; 8 | } 9 | 10 | /* string content */ 11 | .str { 12 | color: #006400; 13 | font-weight: normal; 14 | font-style: normal; 15 | } 16 | 17 | /* a keyword */ 18 | .kwd { 19 | color: #000000; 20 | font-weight: bold; 21 | font-style: normal; 22 | } 23 | 24 | /* a comment */ 25 | .com { 26 | font-weight: normal; 27 | font-style: italic; 28 | } 29 | 30 | /* a type name */ 31 | .typ { 32 | color: #000000; 33 | font-weight: normal; 34 | font-style: normal; 35 | } 36 | 37 | /* a literal value */ 38 | .lit { 39 | color: #006400; 40 | font-weight: normal; 41 | font-style: normal; 42 | } 43 | 44 | /* punctuation */ 45 | .pun { 46 | color: #000000; 47 | font-weight: bold; 48 | font-style: normal; 49 | } 50 | 51 | /* lisp open bracket */ 52 | .opn { 53 | color: #000000; 54 | font-weight: bold; 55 | font-style: normal; 56 | } 57 | 58 | /* lisp close bracket */ 59 | .clo { 60 | color: #000000; 61 | font-weight: bold; 62 | font-style: normal; 63 | } 64 | 65 | /* a markup tag name */ 66 | .tag { 67 | color: #006400; 68 | font-weight: normal; 69 | font-style: normal; 70 | } 71 | 72 | /* a markup attribute name */ 73 | .atn { 74 | color: #006400; 75 | font-weight: normal; 76 | font-style: normal; 77 | } 78 | 79 | /* a markup attribute value */ 80 | .atv { 81 | color: #006400; 82 | font-weight: normal; 83 | font-style: normal; 84 | } 85 | 86 | /* a declaration */ 87 | .dec { 88 | color: #000000; 89 | font-weight: bold; 90 | font-style: normal; 91 | } 92 | 93 | /* a variable name */ 94 | .var { 95 | color: #000000; 96 | font-weight: normal; 97 | font-style: normal; 98 | } 99 | 100 | /* a function name */ 101 | .fun { 102 | color: #000000; 103 | font-weight: bold; 104 | font-style: normal; 105 | } 106 | 107 | /* Specify class=linenums on a pre to get line numbering */ 108 | ol.linenums { 109 | margin-top: 0; 110 | margin-bottom: 0; 111 | } 112 | -------------------------------------------------------------------------------- /lib/experiments.js: -------------------------------------------------------------------------------- 1 | 2 | "use strict"; 3 | 4 | /** 5 | * A collection of experiments currently available 6 | * @param data the json data received from the Prismic API 7 | * @constructor 8 | */ 9 | function Experiments(data) { 10 | var drafts = []; 11 | var running = []; 12 | if (data) { 13 | data.drafts && data.drafts.forEach(function (exp) { 14 | drafts.push(new Experiment(exp)); 15 | }); 16 | data.running && data.running.forEach(function (exp) { 17 | running.push(new Experiment(exp)); 18 | }); 19 | } 20 | this.drafts = drafts; 21 | this.running = running; 22 | } 23 | 24 | Experiments.prototype.current = function() { 25 | return this.running.length > 0 ? this.running[0] : null; 26 | }; 27 | 28 | /** 29 | * Get the current running experiment variation ref from a cookie content 30 | */ 31 | Experiments.prototype.refFromCookie = function(cookie) { 32 | if (!cookie || cookie.trim() === "") return null; 33 | var splitted = cookie.trim().split(" "); 34 | if (splitted.length < 2) return null; 35 | var expId = splitted[0]; 36 | var varIndex = parseInt(splitted[1], 10); 37 | var exp = this.running.filter(function(exp) { 38 | return exp.googleId() == expId && exp.variations.length > varIndex; 39 | })[0]; 40 | return exp ? exp.variations[varIndex].ref() : null; 41 | }; 42 | 43 | function Experiment(data) { 44 | this.data = data; 45 | var variations = []; 46 | data.variations && data.variations.forEach(function(v) { 47 | variations.push(new Variation(v)); 48 | }); 49 | this.variations = variations; 50 | } 51 | 52 | Experiment.prototype.id = function() { 53 | return this.data.id; 54 | }; 55 | 56 | Experiment.prototype.googleId = function() { 57 | return this.data.googleId; 58 | }; 59 | 60 | Experiment.prototype.name = function() { 61 | return this.data.name; 62 | }; 63 | 64 | function Variation(data) { 65 | this.data = data; 66 | } 67 | 68 | Variation.prototype.id = function() { 69 | return this.data.id; 70 | }; 71 | 72 | Variation.prototype.ref = function() { 73 | return this.data.ref; 74 | }; 75 | 76 | Variation.prototype.label = function() { 77 | return this.data.label; 78 | }; 79 | 80 | module.exports = { 81 | Experiments: Experiments, 82 | Variation: Variation 83 | }; 84 | -------------------------------------------------------------------------------- /docs/styles/prettify-tomorrow.css: -------------------------------------------------------------------------------- 1 | /* Tomorrow Theme */ 2 | /* Original theme - https://github.com/chriskempson/tomorrow-theme */ 3 | /* Pretty printing styles. Used with prettify.js. */ 4 | /* SPAN elements with the classes below are added by prettyprint. */ 5 | /* plain text */ 6 | .pln { 7 | color: #4d4d4c; } 8 | 9 | @media screen { 10 | /* string content */ 11 | .str { 12 | color: #718c00; } 13 | 14 | /* a keyword */ 15 | .kwd { 16 | color: #8959a8; } 17 | 18 | /* a comment */ 19 | .com { 20 | color: #8e908c; } 21 | 22 | /* a type name */ 23 | .typ { 24 | color: #4271ae; } 25 | 26 | /* a literal value */ 27 | .lit { 28 | color: #f5871f; } 29 | 30 | /* punctuation */ 31 | .pun { 32 | color: #4d4d4c; } 33 | 34 | /* lisp open bracket */ 35 | .opn { 36 | color: #4d4d4c; } 37 | 38 | /* lisp close bracket */ 39 | .clo { 40 | color: #4d4d4c; } 41 | 42 | /* a markup tag name */ 43 | .tag { 44 | color: #c82829; } 45 | 46 | /* a markup attribute name */ 47 | .atn { 48 | color: #f5871f; } 49 | 50 | /* a markup attribute value */ 51 | .atv { 52 | color: #3e999f; } 53 | 54 | /* a declaration */ 55 | .dec { 56 | color: #f5871f; } 57 | 58 | /* a variable name */ 59 | .var { 60 | color: #c82829; } 61 | 62 | /* a function name */ 63 | .fun { 64 | color: #4271ae; } } 65 | /* Use higher contrast and text-weight for printable form. */ 66 | @media print, projection { 67 | .str { 68 | color: #060; } 69 | 70 | .kwd { 71 | color: #006; 72 | font-weight: bold; } 73 | 74 | .com { 75 | color: #600; 76 | font-style: italic; } 77 | 78 | .typ { 79 | color: #404; 80 | font-weight: bold; } 81 | 82 | .lit { 83 | color: #044; } 84 | 85 | .pun, .opn, .clo { 86 | color: #440; } 87 | 88 | .tag { 89 | color: #006; 90 | font-weight: bold; } 91 | 92 | .atn { 93 | color: #404; } 94 | 95 | .atv { 96 | color: #060; } } 97 | /* Style */ 98 | /* 99 | pre.prettyprint { 100 | background: white; 101 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 102 | font-size: 12px; 103 | line-height: 1.5; 104 | border: 1px solid #ccc; 105 | padding: 10px; } 106 | */ 107 | 108 | /* Specify class=linenums on a pre to get line numbering */ 109 | ol.linenums { 110 | margin-top: 0; 111 | margin-bottom: 0; } 112 | 113 | /* IE indents via margin-left */ 114 | li.L0, 115 | li.L1, 116 | li.L2, 117 | li.L3, 118 | li.L4, 119 | li.L5, 120 | li.L6, 121 | li.L7, 122 | li.L8, 123 | li.L9 { 124 | /* */ } 125 | 126 | /* Alternate shading for lines */ 127 | li.L1, 128 | li.L3, 129 | li.L5, 130 | li.L7, 131 | li.L9 { 132 | /* */ } 133 | -------------------------------------------------------------------------------- /lib/quickRoutes.js: -------------------------------------------------------------------------------- 1 | 2 | var Kind = { 3 | Dynamic: 'dynamic', 4 | Static: 'static' 5 | }; 6 | 7 | var Condition = { 8 | ID: 'withId', 9 | UID: 'withUid', 10 | Singleton: 'singleton' 11 | }; 12 | 13 | function toUrl(route, doc) { 14 | if(!route.fragments || route.fragments.length == 0) { 15 | return '/'; 16 | } else { 17 | return route.fragments.reduce(function (acc, f) { 18 | switch(f.kind) { 19 | case Kind.Dynamic: 20 | if (doc) 21 | return acc + '/' + getFragmentValue(f, doc); 22 | else 23 | return acc + '/:' + toKey(f.key); 24 | 25 | case Kind.Static: 26 | return acc + '/' + f.value; 27 | 28 | default: 29 | return acc; 30 | } 31 | }, ''); 32 | } 33 | } 34 | 35 | function getFragmentValue(fragment, doc) { 36 | var steps = fragment.key.split('.'); 37 | if (steps[0] == doc.type) { 38 | switch(steps[1]) { 39 | case 'uid': 40 | return doc.uid; 41 | case 'id': 42 | return doc.id; 43 | default: 44 | throw Error("Unsupported dynamic fragment: " + fragment); 45 | } 46 | } else { 47 | throw Error("Wrong doc type error: got " + doc.type + ", expected " + steps[0]); 48 | } 49 | } 50 | 51 | 52 | function toKey(dotty) { 53 | return dotty.split('.').join('_'); 54 | } 55 | 56 | function fetchData(req, res, fetchers) { 57 | return new Promise(function(resolve, reject) { 58 | var pData = fetchers.map(function(f) { 59 | return fetcherAction(f, req) 60 | .then(function(doc) { 61 | return { name: f.name, doc: doc }; 62 | }) 63 | .catch(function(err) { 64 | reject(err); 65 | }); 66 | }); 67 | 68 | Promise.all(pData).then(function(results) { 69 | var data = {}; 70 | results.forEach(function(result) { 71 | data[result.name] = result.doc; 72 | }); 73 | resolve(data); 74 | }); 75 | }); 76 | } 77 | 78 | function fetcherAction(f, req) { 79 | switch(f.condition.kind) { 80 | case Condition.ID: 81 | return req.prismic.api.getByID(f.mask, req.params[toKey(f.condition.key)]); 82 | 83 | case Condition.UID: 84 | return req.prismic.api.getByUID(f.mask, req.params[toKey(f.condition.key)]); 85 | 86 | case Condition.Singleton: 87 | return req.prismic.api.getSingle(f.mask); 88 | 89 | default: 90 | return Promise.reject(new Error("Unknown fetcher condition: " + f.condition.kind)); 91 | } 92 | } 93 | 94 | 95 | 96 | function makeLinkResolver(dynRoutes, linkResolver) { 97 | return function(doc) { 98 | var docRoute = dynRoutes.find(function(dr) { 99 | return dr.forMask === doc.type; 100 | }); 101 | if(docRoute) return toUrl(docRoute, doc); 102 | else return linkResolver(doc); 103 | }; 104 | } 105 | 106 | module.exports = { 107 | toUrl: toUrl, 108 | makeLinkResolver: makeLinkResolver, 109 | fetchData: fetchData 110 | }; 111 | -------------------------------------------------------------------------------- /lib/prismic.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var experiments = require('./experiments'), 4 | Predicates = require('./predicates'), 5 | api = require('./api'), 6 | Fragments = require('./fragments'), 7 | QuickRoutes = require('./quickRoutes'), 8 | documents = require('./documents'); 9 | 10 | var Api = api.Api, 11 | Experiments = experiments.Experiments; 12 | 13 | /** 14 | * The kit's main entry point; initialize your API like this: Prismic.api(url, {accessToken: "XXX"}) 15 | * 16 | * @global 17 | * @alias Api 18 | * @constructor 19 | * @param {string} url - The mandatory URL of the prismic.io API endpoint (like: https://lesbonneschoses.prismic.io/api) 20 | * @param {function} options.callback - Optional callback function that is called after the API was retrieved, which will be called with two parameters: a potential error object and the API object 21 | * @param {string} options.accessToken - The accessToken, necessary if the API is set as private 22 | * @param {string} options.req - The NodeJS request (only use in a NodeJS context) 23 | * @param {function} options.requestHandler - Environment specific HTTP request handling function 24 | * @param {object} options.apiCache - A cache object with get/set functions for caching API responses 25 | * @param {int} options.apiDataTTL - How long (in seconds) to cache data used by the client to make calls (e.g. refs). Defaults to 5 seconds 26 | * @returns {Api} - The Api object that can be manipulated 27 | */ 28 | function getApi(url, options) { 29 | options = options || {}; 30 | if (typeof arguments[1] == 'function') { 31 | // Legacy (1) the second argument is the callback 32 | options = { 33 | "complete": arguments[1], 34 | "accessToken": arguments[2], 35 | "requestHandler": arguments[3], 36 | "apiCache": arguments[4], 37 | "apiDataTTL": arguments[5] 38 | }; 39 | } else if (typeof arguments[1] == 'string') { 40 | // Legacy (2) the second argument is the accessToken 41 | options = { 42 | "accessToken": arguments[1], 43 | "requestHandler": arguments[2], 44 | "apiCache": arguments[3], 45 | "apiDataTTL": arguments[4] 46 | }; 47 | } 48 | var api = new Api(url, options || {}); 49 | //Use cached api data if available 50 | return new Promise(function(resolve, reject) { 51 | var cb = function(err, value, xhr) { 52 | if (options.complete) options.complete(err, value, xhr); 53 | if (err) { 54 | reject(err); 55 | } else { 56 | resolve(value); 57 | } 58 | }; 59 | api.get(function (err, data) { 60 | if (!err && data) { 61 | api.data = data; 62 | api.bookmarks = data.bookmarks; 63 | api.experiments = new Experiments(data.experiments); 64 | } 65 | 66 | cb(err, api); 67 | }); 68 | 69 | return api; 70 | }); 71 | } 72 | 73 | module.exports = { 74 | experimentCookie: api.experimentCookie, 75 | previewCookie: api.previewCookie, 76 | Document: documents.Document, 77 | SearchForm: api.SearchForm, 78 | Form: api.Form, 79 | Experiments: Experiments, 80 | Predicates: Predicates, 81 | Fragments: Fragments, 82 | QuickRoutes: QuickRoutes, 83 | getApi: getApi, 84 | api: getApi, 85 | Api: getApi, // Backward compatibility 86 | parseDoc: api.parseDoc 87 | }; 88 | 89 | module.exports.Prismic = module.exports; // Backward compatibility 90 | -------------------------------------------------------------------------------- /docs/cache.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Source: cache.js 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Source: cache.js

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 |
29 |

 30 | "use strict";
 31 | 
 32 | var LRUCache = require('./lru');
 33 | 
 34 | /**
 35 |  * Api cache
 36 |  */
 37 | function ApiCache(limit) {
 38 |   this.lru = new LRUCache(limit);
 39 | }
 40 | 
 41 | ApiCache.prototype = {
 42 | 
 43 |   get: function(key, cb) {
 44 |     var maybeEntry = this.lru.get(key);
 45 |     if(maybeEntry && !this.isExpired(key)) {
 46 |       return cb(null, maybeEntry.data);
 47 |     }
 48 |     return cb();
 49 |   },
 50 | 
 51 |   set: function(key, value, ttl, cb) {
 52 |     this.lru.remove(key);
 53 |     this.lru.put(key, {
 54 |       data: value,
 55 |       expiredIn: ttl ? (Date.now() + (ttl * 1000)) : 0
 56 |     });
 57 | 
 58 |     return cb();
 59 |   },
 60 | 
 61 |   isExpired: function(key) {
 62 |     var entry = this.lru.get(key);
 63 |     if(entry) {
 64 |       return entry.expiredIn !== 0 && entry.expiredIn < Date.now();
 65 |     } else {
 66 |       return false;
 67 |     }
 68 |   },
 69 | 
 70 |   remove: function(key, cb) {
 71 |     this.lru.remove(key);
 72 |     return cb();
 73 |   },
 74 | 
 75 |   clear: function(cb) {
 76 |     this.lru.removeAll();
 77 |     return cb();
 78 |   }
 79 | };
 80 | 
 81 | module.exports = ApiCache;
 82 | 
83 |
84 |
85 | 86 | 87 | 88 | 89 |
90 | 91 | 94 | 95 |
96 | 97 | 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /docs/Fragments_Separator.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: Fragments:Separator 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Fragments:Separator

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

Fragments:Separator

32 | 33 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 |

new Fragments:Separator()

44 | 45 | 46 | 47 | 48 | 49 |
50 | Embodies a fragment of type "Separator" (only used in Slices) 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
Source:
93 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 |
141 | 142 |
143 | 144 | 145 | 146 | 147 |
148 | 149 | 152 | 153 |
154 | 155 | 158 | 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## JavaScript development kit for prismic.io 2 | 3 | # DEPRECATED please use https://github.com/prismicio/prismic-javascript 4 | [![npm version](https://badge.fury.io/js/prismic.io.svg)](http://badge.fury.io/js/prismic.io) 5 | [![Build Status](https://api.travis-ci.org/prismicio/javascript-kit.png)](https://travis-ci.org/prismicio/javascript-kit) 6 | [![Code Climate](https://codeclimate.com/github/prismicio/javascript-kit.png)](https://codeclimate.com/github/prismicio/javascript-kit) 7 | [![Test Coverage](https://codeclimate.com/github/prismicio/javascript-kit/badges/coverage.svg)](https://codeclimate.com/github/prismicio/javascript-kit/coverage) 8 | 9 | * The [source code](https://github.com/prismicio/javascript-kit) is on Github. 10 | * The [Changelog](https://github.com/prismicio/javascript-kit/releases) is on Github's releases tab. 11 | 12 | ### Installation 13 | 14 | #### NPM 15 | 16 | ```sh 17 | npm install prismic.io --save 18 | ``` 19 | 20 | #### CDN 21 | 22 | ``` 23 | https://unpkg.com/prismic.io/dist/prismic.io.min.js 24 | ``` 25 | 26 | (You may need to adapt the version number) 27 | 28 | #### Downloadable version 29 | 30 | On our release page: [https://github.com/prismicio/javascript-kit/releases](https://github.com/prismicio/javascript-kit/releases). 31 | 32 | The kit is universal, it can be used: 33 | 34 | * Server-side with NodeJS 35 | * Client-side as part of your build with Browserify, Webpack (you need a [Promise polyfill](https://github.com/jakearchibald/es6-promise) to support IE11 and below) 36 | * Client-side with a simple script tag 37 | 38 | ### Starter kits 39 | 40 | For new project, you can start from a sample project: 41 | 42 | * [Node.js project](https://github.com/prismicio/nodejs-sdk) 43 | * [Node.js blog](https://github.com/prismicio/nodejs-blog) 44 | 45 | ### Usage 46 | 47 | To fetch documents from your repository, you need to fetch the Api data first. 48 | 49 | ```javascript 50 | var Prismic = require('prismic.io'); 51 | 52 | Prismic.api("http://your_repository_name.prismic.io/api", function(error, api) { 53 | var options = {}; // In Node.js, pass the request as 'req' to read the reference from the cookies 54 | api.query("", options, function(err, response) { // An empty query will return all the documents 55 | if (err) { 56 | console.log("Something went wrong: ", err); 57 | } 58 | console.log("Documents: ", response.documents); 59 | }); 60 | }); 61 | ``` 62 | 63 | All asynchronous calls return ES2015 promises, so alternatively you can use them instead of callbacks. 64 | 65 | ```javascript 66 | var Prismic = require('prismic.io'); 67 | 68 | Prismic.api("https://lesbonneschoses.prismic.io/api").then(function(api) { 69 | return api.query(""); // An empty query will return all the documents 70 | }).then(function(response) { 71 | console.log("Documents: ", response.results); 72 | }, function(err) { 73 | console.log("Something went wrong: ", err); 74 | }); 75 | ``` 76 | 77 | See the [developer documentation](https://prismic.io/docs) or the [API documentation](http://prismicio.github.io/javascript-kit/) for more details on how to use it. 78 | 79 | ### Contribute to the kit 80 | 81 | Contribution is open to all developer levels, read our "[Contribute to the official kits](https://developers.prismic.io/documentation/UszOeAEAANUlwFpp/contribute-to-the-official-kits)" documentation to learn more. 82 | 83 | #### Install the kit locally 84 | 85 | Source files are in the `lib/` directory. You only need [Node.js and npm](http://www.joyent.com/blog/installing-node-and-npm/) 86 | to work on the codebase. 87 | 88 | ``` 89 | npm install 90 | npm test 91 | ``` 92 | 93 | #### Documentation 94 | 95 | Please document any new feature or bugfix using the [JSDoc](http://usejsdoc.org/) syntax. You don't need to generate the documentation, we'll do that. 96 | 97 | If you feel an existing area of code is lacking documentation, feel free to write it; but please do so on its own branch and pull-request. 98 | 99 | If you find existing code that is not optimally documented and wish to make it better, we really appreciate it; but you should document it on its own branch and its own pull request. 100 | 101 | ### License 102 | 103 | This software is licensed under the Apache 2 license, quoted below. 104 | 105 | Copyright 2013-2016 Zengularity (http://www.zengularity.com). 106 | 107 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 108 | 109 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 110 | -------------------------------------------------------------------------------- /docs/experiments.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Source: experiments.js 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Source: experiments.js

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 |
29 |

 30 | "use strict";
 31 | 
 32 | /**
 33 |  * A collection of experiments currently available
 34 |  * @param data the json data received from the Prismic API
 35 |  * @constructor
 36 |  */
 37 | function Experiments(data) {
 38 |   var drafts = [];
 39 |   var running = [];
 40 |   if (data) {
 41 |     data.drafts && data.drafts.forEach(function (exp) {
 42 |       drafts.push(new Experiment(exp));
 43 |     });
 44 |     data.running && data.running.forEach(function (exp) {
 45 |       running.push(new Experiment(exp));
 46 |     });
 47 |   }
 48 |   this.drafts = drafts;
 49 |   this.running = running;
 50 | }
 51 | 
 52 | Experiments.prototype.current = function() {
 53 |   return this.running.length > 0 ? this.running[0] : null;
 54 | };
 55 | 
 56 | /**
 57 |  * Get the current running experiment variation ref from a cookie content
 58 |  */
 59 | Experiments.prototype.refFromCookie = function(cookie) {
 60 |   if (!cookie || cookie.trim() === "") return null;
 61 |   var splitted = cookie.trim().split(" ");
 62 |   if (splitted.length < 2) return null;
 63 |   var expId = splitted[0];
 64 |   var varIndex = parseInt(splitted[1], 10);
 65 |   var exp = this.running.filter(function(exp) {
 66 |     return exp.googleId() == expId && exp.variations.length > varIndex;
 67 |   })[0];
 68 |   return exp ? exp.variations[varIndex].ref() : null;
 69 | };
 70 | 
 71 | function Experiment(data) {
 72 |   this.data = data;
 73 |   var variations = [];
 74 |   data.variations && data.variations.forEach(function(v) {
 75 |     variations.push(new Variation(v));
 76 |   });
 77 |   this.variations = variations;
 78 | }
 79 | 
 80 | Experiment.prototype.id = function() {
 81 |   return this.data.id;
 82 | };
 83 | 
 84 | Experiment.prototype.googleId = function() {
 85 |   return this.data.googleId;
 86 | };
 87 | 
 88 | Experiment.prototype.name = function() {
 89 |   return this.data.name;
 90 | };
 91 | 
 92 | function Variation(data) {
 93 |   this.data = data;
 94 | }
 95 | 
 96 | Variation.prototype.id = function() {
 97 |   return this.data.id;
 98 | };
 99 | 
100 | Variation.prototype.ref = function() {
101 |   return this.data.ref;
102 | };
103 | 
104 | Variation.prototype.label = function() {
105 |   return this.data.label;
106 | };
107 | 
108 | module.exports = {
109 |   Experiments: Experiments,
110 |   Variation: Variation
111 | };
112 | 
113 |
114 |
115 | 116 | 117 | 118 | 119 |
120 | 121 | 124 | 125 |
126 | 127 | 130 | 131 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /docs/Experiments.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: Experiments 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Experiments

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

Experiments

32 | 33 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 |

new Experiments(data)

44 | 45 | 46 | 47 | 48 | 49 |
50 | A collection of experiments currently available 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |
Parameters:
62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 |
NameTypeDescription
data 90 | 91 | the json data received from the Prismic API
103 | 104 | 105 | 106 | 107 | 108 | 109 |
110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 |
Source:
137 |
140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 |
148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 |
166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 |

Methods

181 | 182 | 183 | 184 | 185 | 186 | 187 |

refFromCookie()

188 | 189 | 190 | 191 | 192 | 193 |
194 | Get the current running experiment variation ref from a cookie content 195 |
196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 |
210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 |
Source:
237 |
240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 |
248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 |
271 | 272 |
273 | 274 | 275 | 276 | 277 |
278 | 279 | 282 | 283 |
284 | 285 | 288 | 289 | 290 | 291 | 292 | -------------------------------------------------------------------------------- /docs/prismic.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Source: prismic.js 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Source: prismic.js

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 |
29 |
"use strict";
 30 | 
 31 | var experiments = require('./experiments'),
 32 |     Predicates = require('./predicates'),
 33 |     api = require('./api'),
 34 |     Fragments = require('./fragments'),
 35 |     QuickRoutes = require('./quickRoutes'),
 36 |     documents = require('./documents');
 37 | 
 38 | var Api = api.Api,
 39 |     Experiments = experiments.Experiments;
 40 | 
 41 | /**
 42 |  * The kit's main entry point; initialize your API like this: Prismic.api(url, {accessToken: "XXX"})
 43 |  *
 44 |  * @global
 45 |  * @alias Api
 46 |  * @constructor
 47 |  * @param {string} url - The mandatory URL of the prismic.io API endpoint (like: https://lesbonneschoses.prismic.io/api)
 48 |  * @param {function} options.callback - Optional callback function that is called after the API was retrieved, which will be called with two parameters: a potential error object and the API object
 49 |  * @param {string} options.accessToken - The accessToken, necessary if the API is set as private
 50 |  * @param {string} options.req - The NodeJS request (only use in a NodeJS context)
 51 |  * @param {function} options.requestHandler - Environment specific HTTP request handling function
 52 |  * @param {object} options.apiCache - A cache object with get/set functions for caching API responses
 53 |  * @param {int} options.apiDataTTL - How long (in seconds) to cache data used by the client to make calls (e.g. refs). Defaults to 5 seconds
 54 |  * @returns {Api} - The Api object that can be manipulated
 55 |  */
 56 | function getApi(url, options) {
 57 |   options = options || {};
 58 |   if (typeof arguments[1] == 'function') {
 59 |     // Legacy (1) the second argument is the callback
 60 |     options = {
 61 |       "complete": arguments[1],
 62 |       "accessToken": arguments[2],
 63 |       "requestHandler": arguments[3],
 64 |       "apiCache": arguments[4],
 65 |       "apiDataTTL": arguments[5]
 66 |     };
 67 |   } else if (typeof arguments[1] == 'string') {
 68 |     // Legacy (2) the second argument is the accessToken
 69 |     options = {
 70 |       "accessToken": arguments[1],
 71 |       "requestHandler": arguments[2],
 72 |       "apiCache": arguments[3],
 73 |       "apiDataTTL": arguments[4]
 74 |     };
 75 |   }
 76 |   var api = new Api(url, options || {});
 77 |   //Use cached api data if available
 78 |   return new Promise(function(resolve, reject) {
 79 |     var cb = function(err, value, xhr) {
 80 |       if (options.complete) options.complete(err, value, xhr);
 81 |       if (err) {
 82 |         reject(err);
 83 |       } else {
 84 |         resolve(value);
 85 |       }
 86 |     };
 87 |     api.get(function (err, data) {
 88 |       if (!err && data) {
 89 |         api.data = data;
 90 |         api.bookmarks = data.bookmarks;
 91 |         api.experiments = new Experiments(data.experiments);
 92 |       }
 93 | 
 94 |       cb(err, api);
 95 |     });
 96 | 
 97 |     return api;
 98 |   });
 99 | }
100 | 
101 | module.exports = {
102 |   experimentCookie: api.experimentCookie,
103 |   previewCookie: api.previewCookie,
104 |   Document: documents.Document,
105 |   SearchForm: api.SearchForm,
106 |   Form: api.Form,
107 |   Experiments: Experiments,
108 |   Predicates: Predicates,
109 |   Fragments: Fragments,
110 |   QuickRoutes: QuickRoutes,
111 |   getApi: getApi,
112 |   api: getApi,
113 |   Api: getApi, // Backward compatibility
114 |   parseDoc: api.parseDoc
115 | };
116 | 
117 | module.exports.Prismic = module.exports; // Backward compatibility
118 | 
119 |
120 |
121 | 122 | 123 | 124 | 125 |
126 | 127 | 130 | 131 |
132 | 133 | 136 | 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /docs/Fragments_Text.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: Fragments:Text 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Fragments:Text

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

Fragments:Text

32 | 33 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 |

new Fragments:Text()

44 | 45 | 46 | 47 | 48 | 49 |
50 | Embodies a plain text fragment (beware: not a structured text) 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
Source:
93 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 |

Methods

137 | 138 | 139 | 140 | 141 | 142 | 143 |

asHtml() → {string}

144 | 145 | 146 | 147 | 148 | 149 |
150 | Turns the fragment into a useable HTML version of it. 151 | If the native HTML code doesn't suit your design, this function is meant to be overriden. 152 |
153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 |
167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 |
Source:
194 |
197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 |
205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 |
Returns:
219 | 220 | 221 |
222 | - basic HTML code for the fragment 223 |
224 | 225 | 226 | 227 |
228 |
229 | Type 230 |
231 |
232 | 233 | string 234 | 235 | 236 |
237 |
238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 |

asText() → {string}

249 | 250 | 251 | 252 | 253 | 254 |
255 | Turns the fragment into a useable text version of it. 256 |
257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 |
271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 |
Source:
298 |
301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 |
309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 |
Returns:
323 | 324 | 325 |
326 | - basic text version of the fragment 327 |
328 | 329 | 330 | 331 |
332 |
333 | Type 334 |
335 |
336 | 337 | string 338 | 339 | 340 |
341 |
342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 |
354 | 355 |
356 | 357 | 358 | 359 | 360 |
361 | 362 | 365 | 366 |
367 | 368 | 371 | 372 | 373 | 374 | 375 | -------------------------------------------------------------------------------- /docs/Fragments_SliceZone.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: Fragments:SliceZone 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Fragments:SliceZone

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

Fragments:SliceZone

32 | 33 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 |

new Fragments:SliceZone()

44 | 45 | 46 | 47 | 48 | 49 |
50 | Embodies a SliceZone fragment 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
Source:
93 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 |

Methods

137 | 138 | 139 | 140 | 141 | 142 | 143 |

asHtml() → {string}

144 | 145 | 146 | 147 | 148 | 149 |
150 | Turns the fragment into a useable HTML version of it. 151 | If the native HTML code doesn't suit your design, this function is meant to be overriden. 152 |
153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 |
167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 |
Source:
194 |
197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 |
205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 |
Returns:
219 | 220 | 221 |
222 | - basic HTML code for the fragment 223 |
224 | 225 | 226 | 227 |
228 |
229 | Type 230 |
231 |
232 | 233 | string 234 | 235 | 236 |
237 |
238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 |

asText() → {string}

249 | 250 | 251 | 252 | 253 | 254 |
255 | Turns the fragment into a useable text version of it. 256 |
257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 |
271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 |
Source:
298 |
301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 |
309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 |
Returns:
323 | 324 | 325 |
326 | - basic text version of the fragment 327 |
328 | 329 | 330 | 331 |
332 |
333 | Type 334 |
335 |
336 | 337 | string 338 | 339 | 340 |
341 |
342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 |
354 | 355 |
356 | 357 | 358 | 359 | 360 |
361 | 362 | 365 | 366 |
367 | 368 | 371 | 372 | 373 | 374 | 375 | -------------------------------------------------------------------------------- /docs/styles/jsdoc-default.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'Open Sans'; 3 | font-weight: normal; 4 | font-style: normal; 5 | src: url('../fonts/OpenSans-Regular-webfont.eot'); 6 | src: 7 | local('Open Sans'), 8 | local('OpenSans'), 9 | url('../fonts/OpenSans-Regular-webfont.eot?#iefix') format('embedded-opentype'), 10 | url('../fonts/OpenSans-Regular-webfont.woff') format('woff'), 11 | url('../fonts/OpenSans-Regular-webfont.svg#open_sansregular') format('svg'); 12 | } 13 | 14 | @font-face { 15 | font-family: 'Open Sans Light'; 16 | font-weight: normal; 17 | font-style: normal; 18 | src: url('../fonts/OpenSans-Light-webfont.eot'); 19 | src: 20 | local('Open Sans Light'), 21 | local('OpenSans Light'), 22 | url('../fonts/OpenSans-Light-webfont.eot?#iefix') format('embedded-opentype'), 23 | url('../fonts/OpenSans-Light-webfont.woff') format('woff'), 24 | url('../fonts/OpenSans-Light-webfont.svg#open_sanslight') format('svg'); 25 | } 26 | 27 | html 28 | { 29 | overflow: auto; 30 | background-color: #fff; 31 | font-size: 14px; 32 | } 33 | 34 | body 35 | { 36 | font-family: 'Open Sans', sans-serif; 37 | line-height: 1.5; 38 | color: #4d4e53; 39 | background-color: white; 40 | } 41 | 42 | a, a:visited, a:active { 43 | color: #0095dd; 44 | text-decoration: none; 45 | } 46 | 47 | a:hover { 48 | text-decoration: underline; 49 | } 50 | 51 | header 52 | { 53 | display: block; 54 | padding: 0px 4px; 55 | } 56 | 57 | tt, code, kbd, samp { 58 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 59 | } 60 | 61 | .class-description { 62 | font-size: 130%; 63 | line-height: 140%; 64 | margin-bottom: 1em; 65 | margin-top: 1em; 66 | } 67 | 68 | .class-description:empty { 69 | margin: 0; 70 | } 71 | 72 | #main { 73 | float: left; 74 | width: 70%; 75 | } 76 | 77 | article dl { 78 | margin-bottom: 40px; 79 | } 80 | 81 | section 82 | { 83 | display: block; 84 | background-color: #fff; 85 | padding: 12px 24px; 86 | border-bottom: 1px solid #ccc; 87 | margin-right: 30px; 88 | } 89 | 90 | .variation { 91 | display: none; 92 | } 93 | 94 | .signature-attributes { 95 | font-size: 60%; 96 | color: #aaa; 97 | font-style: italic; 98 | font-weight: lighter; 99 | } 100 | 101 | nav 102 | { 103 | display: block; 104 | float: right; 105 | margin-top: 28px; 106 | width: 30%; 107 | box-sizing: border-box; 108 | border-left: 1px solid #ccc; 109 | padding-left: 16px; 110 | } 111 | 112 | nav ul { 113 | font-family: 'Lucida Grande', 'Lucida Sans Unicode', arial, sans-serif; 114 | font-size: 100%; 115 | line-height: 17px; 116 | padding: 0; 117 | margin: 0; 118 | list-style-type: none; 119 | } 120 | 121 | nav ul a, nav ul a:visited, nav ul a:active { 122 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 123 | line-height: 18px; 124 | color: #4D4E53; 125 | } 126 | 127 | nav h3 { 128 | margin-top: 12px; 129 | } 130 | 131 | nav li { 132 | margin-top: 6px; 133 | } 134 | 135 | footer { 136 | display: block; 137 | padding: 6px; 138 | margin-top: 12px; 139 | font-style: italic; 140 | font-size: 90%; 141 | } 142 | 143 | h1, h2, h3, h4 { 144 | font-weight: 200; 145 | margin: 0; 146 | } 147 | 148 | h1 149 | { 150 | font-family: 'Open Sans Light', sans-serif; 151 | font-size: 48px; 152 | letter-spacing: -2px; 153 | margin: 12px 24px 20px; 154 | } 155 | 156 | h2, h3.subsection-title 157 | { 158 | font-size: 30px; 159 | font-weight: 700; 160 | letter-spacing: -1px; 161 | margin-bottom: 12px; 162 | } 163 | 164 | h3 165 | { 166 | font-size: 24px; 167 | letter-spacing: -0.5px; 168 | margin-bottom: 12px; 169 | } 170 | 171 | h4 172 | { 173 | font-size: 18px; 174 | letter-spacing: -0.33px; 175 | margin-bottom: 12px; 176 | color: #4d4e53; 177 | } 178 | 179 | h5, .container-overview .subsection-title 180 | { 181 | font-size: 120%; 182 | font-weight: bold; 183 | letter-spacing: -0.01em; 184 | margin: 8px 0 3px 0; 185 | } 186 | 187 | h6 188 | { 189 | font-size: 100%; 190 | letter-spacing: -0.01em; 191 | margin: 6px 0 3px 0; 192 | font-style: italic; 193 | } 194 | 195 | table 196 | { 197 | border-spacing: 0; 198 | border: 0; 199 | border-collapse: collapse; 200 | } 201 | 202 | td, th 203 | { 204 | border: 1px solid #ddd; 205 | margin: 0px; 206 | text-align: left; 207 | vertical-align: top; 208 | padding: 4px 6px; 209 | display: table-cell; 210 | } 211 | 212 | thead tr 213 | { 214 | background-color: #ddd; 215 | font-weight: bold; 216 | } 217 | 218 | th { border-right: 1px solid #aaa; } 219 | tr > th:last-child { border-right: 1px solid #ddd; } 220 | 221 | .ancestors { color: #999; } 222 | .ancestors a 223 | { 224 | color: #999 !important; 225 | text-decoration: none; 226 | } 227 | 228 | .clear 229 | { 230 | clear: both; 231 | } 232 | 233 | .important 234 | { 235 | font-weight: bold; 236 | color: #950B02; 237 | } 238 | 239 | .yes-def { 240 | text-indent: -1000px; 241 | } 242 | 243 | .type-signature { 244 | color: #aaa; 245 | } 246 | 247 | .name, .signature { 248 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 249 | } 250 | 251 | .details { margin-top: 14px; border-left: 2px solid #DDD; } 252 | .details dt { width: 120px; float: left; padding-left: 10px; padding-top: 6px; } 253 | .details dd { margin-left: 70px; } 254 | .details ul { margin: 0; } 255 | .details ul { list-style-type: none; } 256 | .details li { margin-left: 30px; padding-top: 6px; } 257 | .details pre.prettyprint { margin: 0 } 258 | .details .object-value { padding-top: 0; } 259 | 260 | .description { 261 | margin-bottom: 1em; 262 | margin-top: 1em; 263 | } 264 | 265 | .code-caption 266 | { 267 | font-style: italic; 268 | font-size: 107%; 269 | margin: 0; 270 | } 271 | 272 | .prettyprint 273 | { 274 | border: 1px solid #ddd; 275 | width: 80%; 276 | overflow: auto; 277 | } 278 | 279 | .prettyprint.source { 280 | width: inherit; 281 | } 282 | 283 | .prettyprint code 284 | { 285 | font-size: 100%; 286 | line-height: 18px; 287 | display: block; 288 | padding: 4px 12px; 289 | margin: 0; 290 | background-color: #fff; 291 | color: #4D4E53; 292 | } 293 | 294 | .prettyprint code span.line 295 | { 296 | display: inline-block; 297 | } 298 | 299 | .prettyprint.linenums 300 | { 301 | padding-left: 70px; 302 | -webkit-user-select: none; 303 | -moz-user-select: none; 304 | -ms-user-select: none; 305 | user-select: none; 306 | } 307 | 308 | .prettyprint.linenums ol 309 | { 310 | padding-left: 0; 311 | } 312 | 313 | .prettyprint.linenums li 314 | { 315 | border-left: 3px #ddd solid; 316 | } 317 | 318 | .prettyprint.linenums li.selected, 319 | .prettyprint.linenums li.selected * 320 | { 321 | background-color: lightyellow; 322 | } 323 | 324 | .prettyprint.linenums li * 325 | { 326 | -webkit-user-select: text; 327 | -moz-user-select: text; 328 | -ms-user-select: text; 329 | user-select: text; 330 | } 331 | 332 | .params .name, .props .name, .name code { 333 | color: #4D4E53; 334 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 335 | font-size: 100%; 336 | } 337 | 338 | .params td.description > p:first-child, 339 | .props td.description > p:first-child 340 | { 341 | margin-top: 0; 342 | padding-top: 0; 343 | } 344 | 345 | .params td.description > p:last-child, 346 | .props td.description > p:last-child 347 | { 348 | margin-bottom: 0; 349 | padding-bottom: 0; 350 | } 351 | 352 | .disabled { 353 | color: #454545; 354 | } 355 | -------------------------------------------------------------------------------- /lib/requests.js: -------------------------------------------------------------------------------- 1 | 2 | "use strict"; 3 | 4 | var createError = function(status, message) { 5 | var err = new Error(message); 6 | err.status = status; 7 | return err; 8 | }; 9 | 10 | // -- Request handlers 11 | 12 | var ajaxRequest = (function() { 13 | if(typeof XMLHttpRequest != 'undefined' && 'withCredentials' in new XMLHttpRequest()) { 14 | return function(url, callback) { 15 | 16 | var xhr = new XMLHttpRequest(); 17 | 18 | // Called on success 19 | var resolve = function() { 20 | var ttl, cacheControl = /max-age\s*=\s*(\d+)/.exec( 21 | xhr.getResponseHeader('Cache-Control')); 22 | if (cacheControl && cacheControl.length > 1) { 23 | ttl = parseInt(cacheControl[1], 10); 24 | } 25 | callback(null, JSON.parse(xhr.responseText), xhr, ttl); 26 | }; 27 | 28 | // Called on error 29 | var reject = function() { 30 | var status = xhr.status; 31 | callback(createError(status, "Unexpected status code [" + status + "] on URL "+url), null, xhr); 32 | }; 33 | 34 | // Bind the XHR finished callback 35 | xhr.onreadystatechange = function() { 36 | if (xhr.readyState === 4) { 37 | if(xhr.status && xhr.status == 200) { 38 | resolve(); 39 | } else { 40 | reject(); 41 | } 42 | } 43 | }; 44 | 45 | // Open the XHR 46 | xhr.open('GET', url, true); 47 | 48 | // Kit version (can't override the user-agent client side) 49 | // xhr.setRequestHeader("X-Prismic-User-Agent", "Prismic-javascript-kit/%VERSION%".replace("%VERSION%", Global.Prismic.version)); 50 | 51 | // Json request 52 | xhr.setRequestHeader('Accept', 'application/json'); 53 | 54 | // Send the XHR 55 | xhr.send(); 56 | }; 57 | } 58 | return null; 59 | }); 60 | 61 | var xdomainRequest = (function() { 62 | if(typeof XDomainRequest != 'undefined') { // Internet Explorer 63 | return function(url, callback) { 64 | 65 | var xdr = new XDomainRequest(); 66 | 67 | // Called on success 68 | var resolve = function() { 69 | callback(null, JSON.parse(xdr.responseText), xdr, 0); 70 | }; 71 | 72 | // Called on error 73 | var reject = function(msg) { 74 | callback(new Error(msg), null, xdr); 75 | }; 76 | 77 | // Bind the XDR finished callback 78 | xdr.onload = function() { 79 | resolve(xdr); 80 | }; 81 | 82 | // Bind the XDR error callback 83 | xdr.onerror = function() { 84 | reject("Unexpected status code on URL " + url); 85 | }; 86 | 87 | // Open the XHR 88 | xdr.open('GET', url, true); 89 | 90 | // Bind the XDR timeout callback 91 | xdr.ontimeout = function () { 92 | reject("Request timeout"); 93 | }; 94 | 95 | // Empty callback. IE sometimes abort the reqeust if 96 | // this is not present 97 | xdr.onprogress = function () { }; 98 | 99 | xdr.send(); 100 | }; 101 | } 102 | return null; 103 | }); 104 | 105 | 106 | // The experimental fetch API, required by React Native for example. 107 | // We still use browser requests by default because there could be an 108 | // incomplete polyfill in the context (lacking CORS for example) 109 | var fetchRequest = (function() { 110 | if (typeof fetch == "function") { 111 | var pjson = require('../package.json'); 112 | return function(requestUrl, callback) { 113 | fetch(requestUrl, { 114 | headers: { 115 | 'Accept': 'application/json', 116 | 'User-Agent': 'Prismic-javascript-kit/' + pjson.version + " NodeJS/" + process.version 117 | } 118 | }).then(function (response) { 119 | if (~~(response.status / 100 != 2)) { 120 | throw new createError(response.status, "Unexpected status code [" + response.status + "] on URL " + requestUrl); 121 | } else { 122 | return response.json().then(function(json) { 123 | return { 124 | response: response, 125 | json: json 126 | }; 127 | }); 128 | } 129 | }).then(function(next) { 130 | var response = next.response; 131 | var json = next.json; 132 | var cacheControl = response.headers['cache-control']; 133 | var ttl = cacheControl && /max-age=(\d+)/.test(cacheControl) ? parseInt(/max-age=(\d+)/.exec(cacheControl)[1], 10) : undefined; 134 | callback(null, json, response, ttl); 135 | }).catch(function (error) { 136 | callback(error); 137 | }); 138 | }; 139 | } 140 | return null; 141 | }); 142 | 143 | var nodeJSRequest = (function() { 144 | if(typeof require == 'function' && require('http')) { 145 | var http = require('http'), 146 | https = require('https'), 147 | url = require('url'), 148 | pjson = require('../package.json'); 149 | 150 | return function(requestUrl, callback) { 151 | var parsed = url.parse(requestUrl), 152 | h = parsed.protocol == 'https:' ? https : http, 153 | options = { 154 | hostname: parsed.hostname, 155 | path: parsed.path, 156 | query: parsed.query, 157 | headers: { 158 | 'Accept': 'application/json', 159 | 'User-Agent': 'Prismic-javascript-kit/' + pjson.version + " NodeJS/" + process.version 160 | } 161 | }; 162 | 163 | if (!requestUrl) { 164 | var e = new Error('dummy'); 165 | var stack = e.stack.replace(/^[^\(]+?[\n$]/gm, '') 166 | .replace(/^\s+at\s+/gm, '') 167 | .replace(/^Object.\s*\(/gm, '{anonymous}()@') 168 | .split('\n'); 169 | console.log(stack); 170 | } 171 | var request = h.get(options, function(response) { 172 | if (response.statusCode && response.statusCode == 200) { 173 | var jsonStr = ''; 174 | 175 | response.setEncoding('utf8'); 176 | response.on('data', function (chunk) { 177 | jsonStr += chunk; 178 | }); 179 | 180 | response.on('end', function () { 181 | var json; 182 | try { 183 | json = JSON.parse(jsonStr); 184 | } catch (ex) { 185 | console.log("Failed to parse json: " + jsonStr, ex); 186 | } 187 | var cacheControl = response.headers['cache-control']; 188 | var ttl = cacheControl && /max-age=(\d+)/.test(cacheControl) ? parseInt(/max-age=(\d+)/.exec(cacheControl)[1], 10) : undefined; 189 | 190 | callback(null, json, response, ttl); 191 | }); 192 | } else { 193 | callback(createError(response.statusCode, "Unexpected status code [" + response.statusCode + "] on URL "+requestUrl), null, response); 194 | } 195 | }); 196 | 197 | // properly handle timeouts 198 | request.on('error', function(err) { 199 | callback(new Error("Unexpected error on URL "+requestUrl), null, err); 200 | }); 201 | 202 | 203 | }; 204 | } 205 | return null; 206 | }); 207 | 208 | // Number of maximum simultaneous connections to the prismic server 209 | var MAX_CONNECTIONS = 20; 210 | // Number of requests currently running (capped by MAX_CONNECTIONS) 211 | var running = 0; 212 | // Requests in queue 213 | var queue = []; 214 | 215 | var processQueue = function() { 216 | if (queue.length === 0 || running >= MAX_CONNECTIONS) { 217 | return; 218 | } 219 | running++; 220 | var next = queue.shift(); 221 | var fn = ajaxRequest() || xdomainRequest() || fetchRequest() || nodeJSRequest() || 222 | (function() { throw new Error("No request handler available (tried XMLHttpRequest, fetch & NodeJS)"); })(); 223 | fn.call(this, next.url, function(error, result, xhr, ttl) { 224 | running--; 225 | next.callback(error, result, xhr, ttl); 226 | processQueue(); 227 | }); 228 | }; 229 | 230 | var request = function (url, callback) { 231 | queue.push({ 232 | 'url': url, 233 | 'callback': callback 234 | }); 235 | processQueue(); 236 | }; 237 | 238 | module.exports = { 239 | MAX_CONNECTIONS: MAX_CONNECTIONS, // Number of maximum simultaneous connections to the prismic server 240 | request: request 241 | }; 242 | -------------------------------------------------------------------------------- /test/unit.js: -------------------------------------------------------------------------------- 1 | /*eslint-env node, mocha */ 2 | /*eslint no-unused-vars: 0 */ 3 | 4 | var Prismic = require('../lib/prismic.js'); 5 | var chai = require('chai'); 6 | 7 | var assert = chai.assert; 8 | 9 | var structuredText = { 10 | type: 'StructuredText', 11 | value: [{ 12 | type: 'paragraph', 13 | text: 'Hi everyone, I am an awesome text!', 14 | spans: [{ 15 | start: 0, 16 | end: 11, 17 | type: 'strong' 18 | },{ 19 | start: 3, 20 | end: 11, 21 | type: 'em' 22 | },{ 23 | start: 13, 24 | end: 17, 25 | type: 'strong' 26 | },{ 27 | start: 17, 28 | end: 28, 29 | type: 'em' 30 | }] 31 | }] 32 | }; 33 | 34 | function getLinkResolver(ref) { 35 | return function(doc, isBroken) { 36 | if (isBroken) return '#broken'; 37 | return "/testing_url/" + doc.id + "/" + doc.slug + (ref ? ('?ref=' + ref) : ''); 38 | }; 39 | } 40 | 41 | describe("Unit tests", function() { 42 | 43 | it('should init and render StructuredText', function () { 44 | var html = '

Hi everyone, I am an awesome text!

'; 45 | var fragment = Prismic.Fragments.initField(structuredText); 46 | 47 | assert.equal(html, fragment.asHtml()); 48 | }); 49 | 50 | it('should init Timestamp without value', function () { 51 | assert.doesNotThrow(function() { 52 | var field = Prismic.Fragments.initField({"type" : "Timestamp", "value" : null }); 53 | assert.equal(field.value, null); 54 | }); 55 | }); 56 | 57 | it('should init Timestamp with valid date string', function () { 58 | var dateString = '1970-11-23T00:00:00.000'; 59 | var field = Prismic.Fragments.initField({"type" : "Timestamp", "value" : dateString }); 60 | assert.deepEqual(field.value, new Date(dateString)); 61 | }); 62 | 63 | }); 64 | 65 | describe("HTML content", function() { 66 | 67 | it('2 spans on the same text - one bigger 1', function() { 68 | var text = 'abcdefghijklmnopqrstuvwxyz'; 69 | var spans = [{ 70 | "type": "em", 71 | "start": 2, 72 | "end": 6 73 | }, { 74 | "type": "strong", 75 | "start": 2, 76 | "end": 4 77 | }]; 78 | var html = Prismic.Fragments.insertSpans(text, spans, {}); 79 | assert.equal(html, 'abcdefghijklmnopqrstuvwxyz'); 80 | }); 81 | 82 | it('2 spans on the same text - one bigger 2', function() { 83 | var text = 'abcdefghijklmnopqrstuvwxyz'; 84 | var spans = [{ 85 | "type": "em", 86 | "start": 2, 87 | "end": 4 88 | }, { 89 | "type": "strong", 90 | "start": 2, 91 | "end": 6 92 | }]; 93 | var html = Prismic.Fragments.insertSpans(text, spans, {}); 94 | assert.equal(html, 'abcdefghijklmnopqrstuvwxyz'); 95 | }); 96 | 97 | it ("with span labels", function() { 98 | var text = 'abcdefghijklmnopqrstuvwxyz'; 99 | var spans = [{ 100 | "type": "label", 101 | "start": 2, 102 | "end": 6, 103 | "data": { 104 | "label": "tip" 105 | } 106 | }]; 107 | var html = Prismic.Fragments.insertSpans(text, spans, {}); 108 | assert.equal(html, 'abcdefghijklmnopqrstuvwxyz'); 109 | }); 110 | 111 | }); 112 | 113 | it('List items are correctly grouped', function() { 114 | var jsonString = '{ "type":"StructuredText", "value":[ { "spans":[], "text":"Here is some introductory text.", "type":"paragraph" }, { "spans":[], "text":"first item", "type":"list-item" }, { "spans":[], "text":"second item", "type":"list-item" }, { "spans":[], "text":"The following image is linked.", "type":"paragraph" }, { "spans":[], "text":"first item 2", "type":"list-item" }, { "spans":[], "text":"second item 2", "type":"list-item" } ] }'; 115 | var jsonObject = JSON.parse(jsonString); 116 | var text = Prismic.Fragments.initField(jsonObject); 117 | assert.equal(text.asHtml(getLinkResolver()), '

Here is some introductory text.

The following image is linked.

'); 118 | }); 119 | 120 | 121 | it('Dates are well retrieved', function() { 122 | var timestampHtml = Prismic.Fragments.initField({"type" : "Date", "value" : "2014-04-01"}).asHtml(); 123 | assert.equal( 124 | (new RegExp('')).test(timestampHtml), 125 | true 126 | ); 127 | }); 128 | 129 | it('Timestamps are well retrieved', function() { 130 | var timestampHtml = Prismic.Fragments.initField({"type" : "Timestamp", "value" : "2014-06-18T15:30:00+0000"}).asHtml(); 131 | assert.equal( 132 | (new RegExp('')).test(timestampHtml), 133 | true, 134 | timestampHtml 135 | ); 136 | }); 137 | 138 | it('Link in images are parsed', function() { 139 | var jsonString = '{ "type": "StructuredText", "value": [ { "spans": [], "text": "Here is some introductory text.", "type": "paragraph" }, { "spans": [], "text": "The following image is linked.", "type": "paragraph" }, { "alt": "", "copyright": "", "dimensions": { "height": 129, "width": 260 }, "linkTo": { "type": "Link.web", "value": { "url": "http://google.com/", "target": "_blank" } }, "type": "image", "url": "http://fpoimg.com/129x260" }, { "spans": [ { "end": 20, "start": 0, "type": "strong" } ], "text": "More important stuff", "type": "paragraph" }, { "spans": [], "text": "The next is linked to a valid document:", "type": "paragraph" }, { "alt": "", "copyright": "", "dimensions": { "height": 400, "width": 400 }, "linkTo": { "type": "Link.document", "value": { "document": { "id": "UxCQFFFFFFFaaYAH", "slug": "something-fantastic", "type": "lovely-thing" }, "isBroken": false } }, "type": "image", "url": "http://fpoimg.com/400x400" }, { "spans": [], "text": "The next is linked to a broken document:", "type": "paragraph" }, { "alt": "", "copyright": "", "dimensions": { "height": 250, "width": 250 }, "linkTo": { "type": "Link.document", "value": { "document": { "id": "UxERPAEAAHQcsBUH", "slug": "-", "type": "event-calendar" }, "isBroken": true } }, "type": "image", "url": "http://fpoimg.com/250x250" }, { "spans": [], "text": "One more image, this one is not linked:", "type": "paragraph" }, { "alt": "", "copyright": "", "dimensions": { "height": 199, "width": 300 }, "type": "image", "url": "http://fpoimg.com/199x300" } ] }'; 140 | var jsonObject = JSON.parse(jsonString); 141 | var text = Prismic.Fragments.initField(jsonObject); 142 | assert.equal(text.asHtml(getLinkResolver()), '

Here is some introductory text.

The following image is linked.

\"\"

More important stuff

The next is linked to a valid document:

\"\"

The next is linked to a broken document:

\"\"

One more image, this one is not linked:

\"\"

'); 143 | }); 144 | 145 | it('Link should support target', function() { 146 | var jsonString = '{ "type": "Link.web", "value": { "url": "https://prismic.io", "target": "_blank" }}'; 147 | var jsonObject = JSON.parse(jsonString); 148 | var text = Prismic.Fragments.initField(jsonObject); 149 | assert.equal(text.asHtml(getLinkResolver()), 'https://prismic.io'); 150 | }); 151 | 152 | it('Link in StructuredText should support target', function() { 153 | var jsonString = '{ "type": "StructuredText", "value": [{ "type": "paragraph", "text": "description link description", "spans": [{ "start": 12, "end": 16, "type": "hyperlink", "data": {"type": "Link.web", "value": { "url": "https://google.com", "target": "_blank" }}}]}]}'; 154 | var jsonObject = JSON.parse(jsonString); 155 | var text = Prismic.Fragments.initField(jsonObject); 156 | assert.equal(text.asHtml(getLinkResolver()), '

description link description

'); 157 | }); 158 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Home 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Home

21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |

30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |

JavaScript development kit for prismic.io

npm version 47 | Build Status 48 | Code Climate 49 | Test Coverage

50 | 54 |

Installation

NPM

npm install prismic.io --save

CDN

https://unpkg.com/prismic.io/dist/prismic.io.min.js

(You may need to adapt the version number)

55 |

Downloadable version

On our release page: https://github.com/prismicio/javascript-kit/releases.

56 |

The kit is universal, it can be used:

57 |
    58 |
  • Server-side with NodeJS
  • 59 |
  • Client-side as part of your build with Browserify, Webpack (you need a Promise polyfill to support IE11 and below)
  • 60 |
  • Client-side with a simple script tag
  • 61 |
62 |

Starter kits

For new project, you can start from a sample project:

63 | 67 |

Usage

To fetch documents from your repository, you need to fetch the Api data first.

68 |
var Prismic = require('prismic.io');
 69 | 
 70 | Prismic.api("http://your_repository_name.prismic.io/api", function(error, api) {
 71 |   var options = {}; // In Node.js, pass the request as 'req' to read the reference from the cookies
 72 |   api.query("", options, function(err, response) { // An empty query will return all the documents
 73 |     if (err) {
 74 |       console.log("Something went wrong: ", err);
 75 |     }
 76 |     console.log("Documents: ", response.documents);
 77 |   });
 78 | });

All asynchronous calls return ES2015 promises, so alternatively you can use them instead of callbacks.

79 |
var Prismic = require('prismic.io');
 80 | 
 81 | Prismic.api("https://lesbonneschoses.prismic.io/api").then(function(api) {
 82 |   return api.query(""); // An empty query will return all the documents
 83 | }).then(function(response) {
 84 |   console.log("Documents: ", response.results);
 85 | }, function(err) {
 86 |   console.log("Something went wrong: ", err);
 87 | });

See the developer documentation or the API documentation for more details on how to use it.

88 |

Contribute to the kit

Contribution is open to all developer levels, read our "Contribute to the official kits" documentation to learn more.

89 |

Install the kit locally

Source files are in the lib/ directory. You only need Node.js and npm 90 | to work on the codebase.

91 |
npm install
 92 | npm test

Documentation

Please document any new feature or bugfix using the JSDoc syntax. You don't need to generate the documentation, we'll do that.

93 |

If you feel an existing area of code is lacking documentation, feel free to write it; but please do so on its own branch and pull-request.

94 |

If you find existing code that is not optimally documented and wish to make it better, we really appreciate it; but you should document it on its own branch and its own pull request.

95 |

License

This software is licensed under the Apache 2 license, quoted below.

96 |

Copyright 2013-2016 Zengularity (http://www.zengularity.com).

97 |

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

98 |

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

99 |
100 | 101 | 102 | 103 | 104 | 105 | 106 |
107 | 108 | 111 | 112 |
113 | 114 | 117 | 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /docs/Fragments_Num.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: Fragments:Num 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Fragments:Num

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

Fragments:Num

32 | 33 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 |

new Fragments:Num()

44 | 45 | 46 | 47 | 48 | 49 |
50 | Embodies a Number fragment 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
Source:
93 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 |

Members

135 | 136 | 137 | 138 |

value

139 | 140 | 141 | 142 | 143 |
144 | the integer value of the fragment 145 |
146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 |
154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 |
Source:
181 |
184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 |
192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 |

Methods

203 | 204 | 205 | 206 | 207 | 208 | 209 |

asHtml() → {string}

210 | 211 | 212 | 213 | 214 | 215 |
216 | Turns the fragment into a useable HTML version of it. 217 | If the native HTML code doesn't suit your design, this function is meant to be overriden. 218 |
219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 |
233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 |
Source:
260 |
263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 |
271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 |
Returns:
285 | 286 | 287 |
288 | - basic HTML code for the fragment 289 |
290 | 291 | 292 | 293 |
294 |
295 | Type 296 |
297 |
298 | 299 | string 300 | 301 | 302 |
303 |
304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 |

asText() → {string}

315 | 316 | 317 | 318 | 319 | 320 |
321 | Turns the fragment into a useable text version of it. 322 |
323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 |
337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 |
Source:
364 |
367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 |
375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 |
Returns:
389 | 390 | 391 |
392 | - basic text version of the fragment 393 |
394 | 395 | 396 | 397 |
398 |
399 | Type 400 |
401 |
402 | 403 | string 404 | 405 | 406 |
407 |
408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 |
420 | 421 |
422 | 423 | 424 | 425 | 426 |
427 | 428 | 431 | 432 |
433 | 434 | 437 | 438 | 439 | 440 | 441 | -------------------------------------------------------------------------------- /docs/Fragments_Color.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: Fragments:Color 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Fragments:Color

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

Fragments:Color

32 | 33 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 |

new Fragments:Color()

44 | 45 | 46 | 47 | 48 | 49 |
50 | Embodies a color fragment 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
Source:
93 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 |

Members

135 | 136 | 137 | 138 |

value

139 | 140 | 141 | 142 | 143 |
144 | the text value of the fragment 145 |
146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 |
154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 |
Source:
181 |
184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 |
192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 |

Methods

203 | 204 | 205 | 206 | 207 | 208 | 209 |

asHtml() → {string}

210 | 211 | 212 | 213 | 214 | 215 |
216 | Turns the fragment into a useable HTML version of it. 217 | If the native HTML code doesn't suit your design, this function is meant to be overriden. 218 |
219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 |
233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 |
Source:
260 |
263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 |
271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 |
Returns:
285 | 286 | 287 |
288 | - basic HTML code for the fragment 289 |
290 | 291 | 292 | 293 |
294 |
295 | Type 296 |
297 |
298 | 299 | string 300 | 301 | 302 |
303 |
304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 |

asText() → {string}

315 | 316 | 317 | 318 | 319 | 320 |
321 | Turns the fragment into a useable text version of it. 322 |
323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 |
337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 |
Source:
364 |
367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 |
375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 |
Returns:
389 | 390 | 391 |
392 | - basic text version of the fragment 393 |
394 | 395 | 396 | 397 |
398 |
399 | Type 400 |
401 |
402 | 403 | string 404 | 405 | 406 |
407 |
408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 |
420 | 421 |
422 | 423 | 424 | 425 | 426 |
427 | 428 | 431 | 432 |
433 | 434 | 437 | 438 | 439 | 440 | 441 | -------------------------------------------------------------------------------- /docs/Fragments_Select.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: Fragments:Select 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Fragments:Select

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

Fragments:Select

32 | 33 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 |

new Fragments:Select()

44 | 45 | 46 | 47 | 48 | 49 |
50 | Embodies a select fragment 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
Source:
93 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 |

Members

135 | 136 | 137 | 138 |

value

139 | 140 | 141 | 142 | 143 |
144 | the text value of the fragment 145 |
146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 |
154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 |
Source:
181 |
184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 |
192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 |

Methods

203 | 204 | 205 | 206 | 207 | 208 | 209 |

asHtml() → {string}

210 | 211 | 212 | 213 | 214 | 215 |
216 | Turns the fragment into a useable HTML version of it. 217 | If the native HTML code doesn't suit your design, this function is meant to be overriden. 218 |
219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 |
233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 |
Source:
260 |
263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 |
271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 |
Returns:
285 | 286 | 287 |
288 | - basic HTML code for the fragment 289 |
290 | 291 | 292 | 293 |
294 |
295 | Type 296 |
297 |
298 | 299 | string 300 | 301 | 302 |
303 |
304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 |

asText() → {string}

315 | 316 | 317 | 318 | 319 | 320 |
321 | Turns the fragment into a useable text version of it. 322 |
323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 |
337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 |
Source:
364 |
367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 |
375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 |
Returns:
389 | 390 | 391 |
392 | - basic text version of the fragment 393 |
394 | 395 | 396 | 397 |
398 |
399 | Type 400 |
401 |
402 | 403 | string 404 | 405 | 406 |
407 |
408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 |
420 | 421 |
422 | 423 | 424 | 425 | 426 |
427 | 428 | 431 | 432 |
433 | 434 | 437 | 438 | 439 | 440 | 441 | -------------------------------------------------------------------------------- /docs/Fragments_Date.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: Fragments:Date 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Fragments:Date

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

Fragments:Date

32 | 33 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 |

new Fragments:Date()

44 | 45 | 46 | 47 | 48 | 49 |
50 | Embodies a Date fragment 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
Source:
93 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 |

Members

135 | 136 | 137 | 138 |

value

139 | 140 | 141 | 142 | 143 |
144 | the Date value of the fragment (as a regular JS Date object) 145 |
146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 |
154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 |
Source:
181 |
184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 |
192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 |

Methods

203 | 204 | 205 | 206 | 207 | 208 | 209 |

asHtml() → {string}

210 | 211 | 212 | 213 | 214 | 215 |
216 | Turns the fragment into a useable HTML version of it. 217 | If the native HTML code doesn't suit your design, this function is meant to be overriden. 218 |
219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 |
233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 |
Source:
260 |
263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 |
271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 |
Returns:
285 | 286 | 287 |
288 | - basic HTML code for the fragment 289 |
290 | 291 | 292 | 293 |
294 |
295 | Type 296 |
297 |
298 | 299 | string 300 | 301 | 302 |
303 |
304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 |

asText() → {string}

315 | 316 | 317 | 318 | 319 | 320 |
321 | Turns the fragment into a useable text version of it. 322 |
323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 |
337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 |
Source:
364 |
367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 |
375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 |
Returns:
389 | 390 | 391 |
392 | - basic text version of the fragment 393 |
394 | 395 | 396 | 397 |
398 |
399 | Type 400 |
401 |
402 | 403 | string 404 | 405 | 406 |
407 |
408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 |
420 | 421 |
422 | 423 | 424 | 425 | 426 |
427 | 428 | 431 | 432 |
433 | 434 | 437 | 438 | 439 | 440 | 441 | -------------------------------------------------------------------------------- /docs/Fragments_Timestamp.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: Fragments:Timestamp 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Fragments:Timestamp

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

Fragments:Timestamp

32 | 33 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 |

new Fragments:Timestamp()

44 | 45 | 46 | 47 | 48 | 49 |
50 | Embodies a Timestamp fragment 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
Source:
93 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 |

Members

135 | 136 | 137 | 138 |

value

139 | 140 | 141 | 142 | 143 |
144 | the Date value of the fragment (as a regular JS Date object) 145 |
146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 |
154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 |
Source:
181 |
184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 |
192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 |

Methods

203 | 204 | 205 | 206 | 207 | 208 | 209 |

asHtml() → {string}

210 | 211 | 212 | 213 | 214 | 215 |
216 | Turns the fragment into a useable HTML version of it. 217 | If the native HTML code doesn't suit your design, this function is meant to be overriden. 218 |
219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 |
233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 |
Source:
260 |
263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 |
271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 |
Returns:
285 | 286 | 287 |
288 | - basic HTML code for the fragment 289 |
290 | 291 | 292 | 293 |
294 |
295 | Type 296 |
297 |
298 | 299 | string 300 | 301 | 302 |
303 |
304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 |

asText() → {string}

315 | 316 | 317 | 318 | 319 | 320 |
321 | Turns the fragment into a useable text version of it. 322 |
323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 |
337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 |
Source:
364 |
367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 |
375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 |
Returns:
389 | 390 | 391 |
392 | - basic text version of the fragment 393 |
394 | 395 | 396 | 397 |
398 |
399 | Type 400 |
401 |
402 | 403 | string 404 | 405 | 406 |
407 |
408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 |
420 | 421 |
422 | 423 | 424 | 425 | 426 |
427 | 428 | 431 | 432 |
433 | 434 | 437 | 438 | 439 | 440 | 441 | -------------------------------------------------------------------------------- /lib/lru.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * A doubly linked list-based Least Recently Used (LRU) cache. Will keep most 4 | * recently used items while discarding least recently used items when its limit 5 | * is reached. 6 | * 7 | * Licensed under MIT. Copyright (c) 2010 Rasmus Andersson 8 | * See README.md for details. 9 | * 10 | * Illustration of the design: 11 | * 12 | * entry entry entry entry 13 | * ______ ______ ______ ______ 14 | * | head |.newer => | |.newer => | |.newer => | tail | 15 | * | A | | B | | C | | D | 16 | * |______| <= older.|______| <= older.|______| <= older.|______| 17 | * 18 | * removed <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- added 19 | */ 20 | function LRUCache (limit) { 21 | // Current size of the cache. (Read-only). 22 | this.size = 0; 23 | // Maximum number of items this cache can hold. 24 | this.limit = limit; 25 | this._keymap = {}; 26 | } 27 | 28 | /** 29 | * Put into the cache associated with . Returns the entry which was 30 | * removed to make room for the new entry. Otherwise undefined is returned 31 | * (i.e. if there was enough room already). 32 | */ 33 | LRUCache.prototype.put = function(key, value) { 34 | var entry = {key:key, value:value}; 35 | // Note: No protection agains replacing, and thus orphan entries. By design. 36 | this._keymap[key] = entry; 37 | if (this.tail) { 38 | // link previous tail to the new tail (entry) 39 | this.tail.newer = entry; 40 | entry.older = this.tail; 41 | } else { 42 | // we're first in -- yay 43 | this.head = entry; 44 | } 45 | // add new entry to the end of the linked list -- it's now the freshest entry. 46 | this.tail = entry; 47 | if (this.size === this.limit) { 48 | // we hit the limit -- remove the head 49 | return this.shift(); 50 | } else { 51 | // increase the size counter 52 | this.size++; 53 | } 54 | return null; 55 | }; 56 | 57 | /** 58 | * Purge the least recently used (oldest) entry from the cache. Returns the 59 | * removed entry or undefined if the cache was empty. 60 | * 61 | * If you need to perform any form of finalization of purged items, this is a 62 | * good place to do it. Simply override/replace this function: 63 | * 64 | * var c = new LRUCache(123); 65 | * c.shift = function() { 66 | * var entry = LRUCache.prototype.shift.call(this); 67 | * doSomethingWith(entry); 68 | * return entry; 69 | * } 70 | */ 71 | LRUCache.prototype.shift = function() { 72 | // todo: handle special case when limit == 1 73 | var entry = this.head; 74 | if (entry) { 75 | if (this.head.newer) { 76 | this.head = this.head.newer; 77 | this.head.older = undefined; 78 | } else { 79 | this.head = undefined; 80 | } 81 | // Remove last strong reference to and remove links from the purged 82 | // entry being returned: 83 | entry.newer = entry.older = undefined; 84 | // delete is slow, but we need to do this to avoid uncontrollable growth: 85 | delete this._keymap[entry.key]; 86 | } 87 | return entry; 88 | }; 89 | 90 | /** 91 | * Get and register recent use of . Returns the value associated with 92 | * or undefined if not in cache. 93 | */ 94 | LRUCache.prototype.get = function(key, returnEntry) { 95 | // First, find our cache entry 96 | var entry = this._keymap[key]; 97 | if (entry === undefined) return null; // Not cached. Sorry. 98 | // As was found in the cache, register it as being requested recently 99 | if (entry === this.tail) { 100 | // Already the most recenlty used entry, so no need to update the list 101 | return returnEntry ? entry : entry.value; 102 | } 103 | // HEAD--------------TAIL 104 | // <.older .newer> 105 | // <--- add direction -- 106 | // A B C E 107 | if (entry.newer) { 108 | if (entry === this.head) 109 | this.head = entry.newer; 110 | entry.newer.older = entry.older; // C <-- E. 111 | } 112 | if (entry.older) 113 | entry.older.newer = entry.newer; // C. --> E 114 | entry.newer = undefined; // D --x 115 | entry.older = this.tail; // D. --> E 116 | if (this.tail) 117 | this.tail.newer = entry; // E. <-- D 118 | this.tail = entry; 119 | return returnEntry ? entry : entry.value; 120 | }; 121 | 122 | // ---------------------------------------------------------------------------- 123 | // Following code is optional and can be removed without breaking the core 124 | // functionality. 125 | 126 | /** 127 | * Check if is in the cache without registering recent use. Feasible if 128 | * you do not want to chage the state of the cache, but only "peek" at it. 129 | * Returns the entry associated with if found, or undefined if not found. 130 | */ 131 | LRUCache.prototype.find = function(key) { 132 | return this._keymap[key]; 133 | }; 134 | 135 | /** 136 | * Update the value of entry with . Returns the old value, or undefined if 137 | * entry was not in the cache. 138 | */ 139 | LRUCache.prototype.set = function(key, value) { 140 | var oldvalue, entry = this.get(key, true); 141 | if (entry) { 142 | oldvalue = entry.value; 143 | entry.value = value; 144 | } else { 145 | oldvalue = this.put(key, value); 146 | if (oldvalue) oldvalue = oldvalue.value; 147 | } 148 | return oldvalue; 149 | }; 150 | 151 | /** 152 | * Remove entry from cache and return its value. Returns undefined if not 153 | * found. 154 | */ 155 | LRUCache.prototype.remove = function(key) { 156 | var entry = this._keymap[key]; 157 | if (!entry) return null; 158 | delete this._keymap[entry.key]; // need to do delete unfortunately 159 | if (entry.newer && entry.older) { 160 | // relink the older entry with the newer entry 161 | entry.older.newer = entry.newer; 162 | entry.newer.older = entry.older; 163 | } else if (entry.newer) { 164 | // remove the link to us 165 | entry.newer.older = undefined; 166 | // link the newer entry to head 167 | this.head = entry.newer; 168 | } else if (entry.older) { 169 | // remove the link to us 170 | entry.older.newer = undefined; 171 | // link the newer entry to head 172 | this.tail = entry.older; 173 | } else { // if(entry.older === undefined && entry.newer === undefined) { 174 | this.head = this.tail = undefined; 175 | } 176 | 177 | this.size--; 178 | return entry.value; 179 | }; 180 | 181 | /** Removes all entries */ 182 | LRUCache.prototype.removeAll = function() { 183 | // This should be safe, as we never expose strong refrences to the outside 184 | this.head = this.tail = undefined; 185 | this.size = 0; 186 | this._keymap = {}; 187 | }; 188 | 189 | /** 190 | * Return an array containing all keys of entries stored in the cache object, in 191 | * arbitrary order. 192 | */ 193 | if (typeof Object.keys === 'function') { 194 | LRUCache.prototype.keys = function() { return Object.keys(this._keymap); }; 195 | } else { 196 | LRUCache.prototype.keys = function() { 197 | var keys = []; 198 | for (var k in this._keymap) keys.push(k); 199 | return keys; 200 | }; 201 | } 202 | 203 | /** 204 | * Call `fun` for each entry. Starting with the newest entry if `desc` is a true 205 | * value, otherwise starts with the oldest (head) enrty and moves towards the 206 | * tail. 207 | * 208 | * `fun` is called with 3 arguments in the context `context`: 209 | * `fun.call(context, Object key, Object value, LRUCache self)` 210 | */ 211 | LRUCache.prototype.forEach = function(fun, context, desc) { 212 | var entry; 213 | if (context === true) { desc = true; context = undefined; } 214 | else if (typeof context !== 'object') context = this; 215 | if (desc) { 216 | entry = this.tail; 217 | while (entry) { 218 | fun.call(context, entry.key, entry.value, this); 219 | entry = entry.older; 220 | } 221 | } else { 222 | entry = this.head; 223 | while (entry) { 224 | fun.call(context, entry.key, entry.value, this); 225 | entry = entry.newer; 226 | } 227 | } 228 | }; 229 | 230 | /** Returns a JSON (array) representation */ 231 | LRUCache.prototype.toJSON = function() { 232 | var s = [], entry = this.head; 233 | while (entry) { 234 | s.push({key:entry.key.toJSON(), value:entry.value.toJSON()}); 235 | entry = entry.newer; 236 | } 237 | return s; 238 | }; 239 | 240 | /** Returns a String representation */ 241 | LRUCache.prototype.toString = function() { 242 | var s = '', entry = this.head; 243 | while (entry) { 244 | s += String(entry.key)+':'+entry.value; 245 | entry = entry.newer; 246 | if (entry) 247 | s += ' < '; 248 | } 249 | return s; 250 | }; 251 | 252 | module.exports = LRUCache; 253 | -------------------------------------------------------------------------------- /docs/Fragments_Embed.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: Fragments:Embed 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Fragments:Embed

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

Fragments:Embed

32 | 33 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 |

new Fragments:Embed()

44 | 45 | 46 | 47 | 48 | 49 |
50 | Embodies an embed fragment 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
Source:
93 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 |

Members

135 | 136 | 137 | 138 |

value

139 | 140 | 141 | 142 | 143 |
144 | the JSON object exactly as is returned in the "data" field of the JSON responses (see API documentation: https://developers.prismic.io/documentation/UjBe8bGIJ3EKtgBZ/api-documentation#json-responses) 145 |
146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 |
154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 |
Source:
181 |
184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 |
192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 |

Methods

203 | 204 | 205 | 206 | 207 | 208 | 209 |

asHtml() → {string}

210 | 211 | 212 | 213 | 214 | 215 |
216 | Turns the fragment into a useable HTML version of it. 217 | If the native HTML code doesn't suit your design, this function is meant to be overriden. 218 |
219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 |
233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 |
Source:
260 |
263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 |
271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 |
Returns:
285 | 286 | 287 |
288 | - basic HTML code for the fragment 289 |
290 | 291 | 292 | 293 |
294 |
295 | Type 296 |
297 |
298 | 299 | string 300 | 301 | 302 |
303 |
304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 |

asText() → {string}

315 | 316 | 317 | 318 | 319 | 320 |
321 | Turns the fragment into a useable text version of it. 322 |
323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 |
337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 |
Source:
364 |
367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 |
375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 |
Returns:
389 | 390 | 391 |
392 | - basic text version of the fragment 393 |
394 | 395 | 396 | 397 |
398 |
399 | Type 400 |
401 |
402 | 403 | string 404 | 405 | 406 |
407 |
408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 |
420 | 421 |
422 | 423 | 424 | 425 | 426 |
427 | 428 | 431 | 432 |
433 | 434 |
435 | Documentation generated by JSDoc 3.4.3 on Mon Oct 02 2017 12:18:09 GMT+0200 (CEST) 436 |
437 | 438 | 439 | 440 | 441 | -------------------------------------------------------------------------------- /docs/Ref.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: Ref 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Ref

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

Ref

32 | 33 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 |

new Ref()

44 | 45 | 46 | 47 | 48 | 49 |
50 | Embodies a prismic.io ref (a past or future point in time you can query) 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
Source:
93 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 |

Members

135 | 136 | 137 | 138 |

id

139 | 140 | 141 | 142 | 143 |
144 | the name of the ref 145 |
146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 |
154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 |
Source:
181 |
184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 |
192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 |

isMaster

201 | 202 | 203 | 204 | 205 |
206 | is true if the ref is the master ref 207 |
208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 |
216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 |
Source:
243 |
246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 |
254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 |

label

263 | 264 | 265 | 266 | 267 |
268 | the label of the ref 269 |
270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 |
278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 |
Source:
305 |
308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 |
316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 |

ref

325 | 326 | 327 | 328 | 329 |
330 | the ID of the ref 331 |
332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 |
340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 |
Source:
367 |
370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 |
378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 |

scheduledAt

387 | 388 | 389 | 390 | 391 |
392 | the scheduled date of the ref 393 |
394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 |
402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 |
Source:
429 |
432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 |
440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 |
455 | 456 |
457 | 458 | 459 | 460 | 461 |
462 | 463 | 466 | 467 |
468 | 469 |
470 | Documentation generated by JSDoc 3.4.3 on Mon Oct 02 2017 12:18:09 GMT+0200 (CEST) 471 |
472 | 473 | 474 | 475 | 476 | -------------------------------------------------------------------------------- /docs/Fragments_SimpleSlice.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: Fragments:SimpleSlice 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Fragments:SimpleSlice

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

Fragments:SimpleSlice

32 | 33 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 |

new Fragments:SimpleSlice()

44 | 45 | 46 | 47 | 48 | 49 |
50 | Embodies a simple slice (fragment or group) 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
Source:
93 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 |

Methods

137 | 138 | 139 | 140 | 141 | 142 | 143 |

asHtml() → {string}

144 | 145 | 146 | 147 | 148 | 149 |
150 | Turns the fragment into a useable HTML version of it. 151 | If the native HTML code doesn't suit your design, this function is meant to be overriden. 152 |
153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 |
167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 |
Source:
194 |
197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 |
205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 |
Returns:
219 | 220 | 221 |
222 | - basic HTML code for the fragment 223 |
224 | 225 | 226 | 227 |
228 |
229 | Type 230 |
231 |
232 | 233 | string 234 | 235 | 236 |
237 |
238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 |

asText() → {string}

249 | 250 | 251 | 252 | 253 | 254 |
255 | Turns the fragment into a useable text version of it. 256 |
257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 |
271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 |
Source:
298 |
301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 |
309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 |
Returns:
323 | 324 | 325 |
326 | - basic text version of the fragment 327 |
328 | 329 | 330 | 331 |
332 |
333 | Type 334 |
335 |
336 | 337 | string 338 | 339 | 340 |
341 |
342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 |

getFirstImage() → {object}

353 | 354 | 355 | 356 | 357 | 358 |
359 | Get the first Image in slice. 360 |
361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 |
375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 |
Source:
402 |
405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 |
413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 |
Returns:
427 | 428 | 429 | 430 | 431 |
432 |
433 | Type 434 |
435 |
436 | 437 | object 438 | 439 | 440 |
441 |
442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 |
454 | 455 |
456 | 457 | 458 | 459 | 460 |
461 | 462 | 465 | 466 |
467 | 468 |
469 | Documentation generated by JSDoc 3.4.3 on Mon Oct 02 2017 12:18:09 GMT+0200 (CEST) 470 |
471 | 472 | 473 | 474 | 475 | -------------------------------------------------------------------------------- /docs/Fragments_CompositeSlice.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: Fragments:CompositeSlice 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Fragments:CompositeSlice

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

Fragments:CompositeSlice

32 | 33 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 |

new Fragments:CompositeSlice()

44 | 45 | 46 | 47 | 48 | 49 |
50 | Embodies a composite slice with repeatable and non repeatable parts 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
Source:
93 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 |

Methods

137 | 138 | 139 | 140 | 141 | 142 | 143 |

asHtml() → {string}

144 | 145 | 146 | 147 | 148 | 149 |
150 | Turns the fragment into a useable HTML version of it. 151 | If the native HTML code doesn't suit your design, this function is meant to be overriden. 152 |
153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 |
167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 |
Source:
194 |
197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 |
205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 |
Returns:
219 | 220 | 221 |
222 | - basic HTML code for the fragment 223 |
224 | 225 | 226 | 227 |
228 |
229 | Type 230 |
231 |
232 | 233 | string 234 | 235 | 236 |
237 |
238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 |

asText() → {string}

249 | 250 | 251 | 252 | 253 | 254 |
255 | Turns the fragment into a useable text version of it. 256 |
257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 |
271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 |
Source:
298 |
301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 |
309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 |
Returns:
323 | 324 | 325 |
326 | - basic text version of the fragment 327 |
328 | 329 | 330 | 331 |
332 |
333 | Type 334 |
335 |
336 | 337 | string 338 | 339 | 340 |
341 |
342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 |

getFirstImage() → {object}

353 | 354 | 355 | 356 | 357 | 358 |
359 | Get the first Image in slice. 360 |
361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 |
375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 |
Source:
402 |
405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 |
413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 |
Returns:
427 | 428 | 429 | 430 | 431 |
432 |
433 | Type 434 |
435 |
436 | 437 | object 438 | 439 | 440 |
441 |
442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 |
454 | 455 |
456 | 457 | 458 | 459 | 460 |
461 | 462 | 465 | 466 |
467 | 468 |
469 | Documentation generated by JSDoc 3.4.3 on Mon Oct 02 2017 12:18:09 GMT+0200 (CEST) 470 |
471 | 472 | 473 | 474 | 475 | -------------------------------------------------------------------------------- /docs/Fragments_Group.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: Fragments:Group 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Fragments:Group

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

Fragments:Group

32 | 33 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 |

new Fragments:Group()

44 | 45 | 46 | 47 | 48 | 49 |
50 | Embodies a fragment of type "Group" (which is a group of subfragments) 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
Source:
93 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 |

Methods

137 | 138 | 139 | 140 | 141 | 142 | 143 |

asHtml() → {string}

144 | 145 | 146 | 147 | 148 | 149 |
150 | Turns the fragment into a useable HTML version of it. 151 | If the native HTML code doesn't suit your design, this function is meant to be overriden. 152 |
153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 |
167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 |
Source:
194 |
197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 |
205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 |
Returns:
219 | 220 | 221 |
222 | - basic HTML code for the fragment 223 |
224 | 225 | 226 | 227 |
228 |
229 | Type 230 |
231 |
232 | 233 | string 234 | 235 | 236 |
237 |
238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 |

asText() → {string}

249 | 250 | 251 | 252 | 253 | 254 |
255 | Turns the fragment into a useable text version of it. 256 |
257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 |
271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 |
Source:
298 |
301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 |
309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 |
Returns:
323 | 324 | 325 |
326 | - basic text version of the fragment 327 |
328 | 329 | 330 | 331 |
332 |
333 | Type 334 |
335 |
336 | 337 | string 338 | 339 | 340 |
341 |
342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 |

toArray() → {Array}

353 | 354 | 355 | 356 | 357 | 358 |
359 | Turns the Group fragment into an array in order to access its items (groups of fragments), 360 | or to loop through them. 361 |
362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 |
376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 |
Source:
403 |
406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 |
414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 |
Returns:
428 | 429 | 430 |
431 | - the array of groups, each group being a JSON object with subfragment name as keys, and subfragment as values 432 |
433 | 434 | 435 | 436 |
437 |
438 | Type 439 |
440 |
441 | 442 | Array 443 | 444 | 445 |
446 |
447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 |
459 | 460 |
461 | 462 | 463 | 464 | 465 |
466 | 467 | 470 | 471 |
472 | 473 |
474 | Documentation generated by JSDoc 3.4.3 on Mon Oct 02 2017 12:18:09 GMT+0200 (CEST) 475 |
476 | 477 | 478 | 479 | 480 | -------------------------------------------------------------------------------- /docs/Fragments_GeoPoint.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: Fragments:GeoPoint 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Fragments:GeoPoint

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

Fragments:GeoPoint

32 | 33 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 |

new Fragments:GeoPoint()

44 | 45 | 46 | 47 | 48 | 49 |
50 | Embodies a geopoint 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
Source:
93 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 |

Members

135 | 136 | 137 | 138 |

latitude

139 | 140 | 141 | 142 | 143 |
144 | the latitude of the geo point 145 |
146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 |
154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 |
Source:
181 |
184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 |
192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 |

longitude

201 | 202 | 203 | 204 | 205 |
206 | the longitude of the geo point 207 |
208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 |
216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 |
Source:
243 |
246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 |
254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 |

Methods

265 | 266 | 267 | 268 | 269 | 270 | 271 |

asHtml() → {string}

272 | 273 | 274 | 275 | 276 | 277 |
278 | Turns the fragment into a useable HTML version of it. 279 | If the native HTML code doesn't suit your design, this function is meant to be overriden. 280 |
281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 |
295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 |
Source:
322 |
325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 |
333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 |
Returns:
347 | 348 | 349 |
350 | - basic HTML code for the fragment 351 |
352 | 353 | 354 | 355 |
356 |
357 | Type 358 |
359 |
360 | 361 | string 362 | 363 | 364 |
365 |
366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 |

asText() → {string}

377 | 378 | 379 | 380 | 381 | 382 |
383 | Turns the fragment into a useable text version of it. 384 |
385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 |
399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 |
Source:
426 |
429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 |
437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 |
Returns:
451 | 452 | 453 |
454 | - basic text version of the fragment 455 |
456 | 457 | 458 | 459 |
460 |
461 | Type 462 |
463 |
464 | 465 | string 466 | 467 | 468 |
469 |
470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 |
482 | 483 |
484 | 485 | 486 | 487 | 488 |
489 | 490 | 493 | 494 |
495 | 496 |
497 | Documentation generated by JSDoc 3.4.3 on Mon Oct 02 2017 12:18:09 GMT+0200 (CEST) 498 |
499 | 500 | 501 | 502 | 503 | -------------------------------------------------------------------------------- /docs/Fragments_WebLink.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: Fragments:WebLink 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Fragments:WebLink

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

Fragments:WebLink

32 | 33 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | Embodies a web link fragment 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
Source:
93 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 |

Members

135 | 136 | 137 | 138 |

value

139 | 140 | 141 | 142 | 143 |
144 | the JSON object exactly as is returned in the "data" field of the JSON responses (see API documentation: https://developers.prismic.io/documentation/UjBe8bGIJ3EKtgBZ/api-documentation#json-responses) 145 |
146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 |
154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 |
Source:
181 |
184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 |
192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 |

Methods

203 | 204 | 205 | 206 | 207 | 208 | 209 |

asHtml() → {string}

210 | 211 | 212 | 213 | 214 | 215 |
216 | Turns the fragment into a useable HTML version of it. 217 | If the native HTML code doesn't suit your design, this function is meant to be overriden. 218 |
219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 |
233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 |
Source:
260 |
263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 |
271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 |
Returns:
285 | 286 | 287 |
288 | - basic HTML code for the fragment 289 |
290 | 291 | 292 | 293 |
294 |
295 | Type 296 |
297 |
298 | 299 | string 300 | 301 | 302 |
303 |
304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 |

asText() → {string}

315 | 316 | 317 | 318 | 319 | 320 |
321 | Turns the fragment into a useable text version of it. 322 |
323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 |
337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 |
Source:
364 |
367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 |
375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 |
Returns:
389 | 390 | 391 |
392 | - basic text version of the fragment 393 |
394 | 395 | 396 | 397 |
398 |
399 | Type 400 |
401 |
402 | 403 | string 404 | 405 | 406 |
407 |
408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 |

url() → {string}

419 | 420 | 421 | 422 | 423 | 424 |
425 | Returns the URL of the link. 426 |
427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 |
441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 |
Source:
468 |
471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 |
479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 |
Returns:
493 | 494 | 495 |
496 | - the proper URL to use 497 |
498 | 499 | 500 | 501 |
502 |
503 | Type 504 |
505 |
506 | 507 | string 508 | 509 | 510 |
511 |
512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 |
524 | 525 |
526 | 527 | 528 | 529 | 530 |
531 | 532 | 535 | 536 |
537 | 538 |
539 | Documentation generated by JSDoc 3.4.3 on Mon Oct 02 2017 12:18:09 GMT+0200 (CEST) 540 |
541 | 542 | 543 | 544 | 545 | --------------------------------------------------------------------------------