├── .gitignore ├── templates ├── notFound.html ├── detail.html ├── footer.html ├── search.html ├── documents.html └── header.html ├── server.sh ├── index.html ├── js ├── main.js ├── templates.js ├── prismic-configuration.js ├── vendor │ ├── text-0.27.0.min.js │ ├── underscore-1.5.2.min.js │ ├── prismic.io-1.0.12.min.js │ ├── require-2.1.8.min.js │ ├── backbone-1.0.0.min.js │ └── jquery-2.0.3.min.js ├── prismic-helper.js └── app.js └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | local-build -------------------------------------------------------------------------------- /templates/notFound.html: -------------------------------------------------------------------------------- 1 | Not found -------------------------------------------------------------------------------- /server.sh: -------------------------------------------------------------------------------- 1 | python -m SimpleHTTPServer -------------------------------------------------------------------------------- /templates/detail.html: -------------------------------------------------------------------------------- 1 |
2 | <%= doc.asHtml(ctx) %> 3 |
-------------------------------------------------------------------------------- /templates/footer.html: -------------------------------------------------------------------------------- 1 | <% if(!ctx.oauth().hasPrivilegedAccess) { %> 2 |
Sign in to preview changes 3 | <% } %> -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Your prismic.io project 6 | 7 | 8 | 9 | 10 |
11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /js/main.js: -------------------------------------------------------------------------------- 1 | require.config({ 2 | 3 | paths: { 4 | jquery: 'vendor/jquery-2.0.3.min', 5 | underscore: 'vendor/underscore-1.5.2.min', 6 | backbone: 'vendor/backbone-1.0.0.min', 7 | prismic: 'vendor/prismic.io-1.0.12.min', 8 | text: 'vendor/text-0.27.0.min' 9 | }, 10 | 11 | shim: { 12 | underscore: { 13 | exports: '_' 14 | }, 15 | backbone: { 16 | deps: ['underscore', 'jquery'], 17 | exports: 'Backbone' 18 | }, 19 | prismic: { 20 | exports: 'Prismic' 21 | } 22 | } 23 | 24 | }); 25 | 26 | require(['app'], function(App) { 27 | App.run(); 28 | }); -------------------------------------------------------------------------------- /js/templates.js: -------------------------------------------------------------------------------- 1 | define([ 2 | 'text!../templates/documents.html', 3 | 'text!../templates/detail.html', 4 | 'text!../templates/search.html', 5 | 'text!../templates/header.html', 6 | 'text!../templates/footer.html', 7 | 'text!../templates/notFound.html' 8 | ], function(DocumentsList, DocumentDetail, SearchResults, Header, Footer, NotFound) { 9 | 10 | return { 11 | DocumentsList: _.template(DocumentsList), 12 | DocumentDetail: _.template(DocumentDetail), 13 | SearchResults: _.template(SearchResults), 14 | Header: _.template(Header), 15 | Footer: _.template(Footer), 16 | NotFound: _.template(NotFound) 17 | }; 18 | 19 | }); -------------------------------------------------------------------------------- /js/prismic-configuration.js: -------------------------------------------------------------------------------- 1 | define(function() { 2 | 3 | /** Prismic Configuration **/ 4 | return { 5 | 6 | apiEndpoint: 'https://lesbonneschoses.prismic.io/api', 7 | 8 | // -- Access token if the Master is not open 9 | // accessToken: 'xxxxxx', 10 | 11 | // OAuth 12 | // clientId: 'xxxxxx', 13 | // clientSecret: 'xxxxxx', 14 | 15 | // -- Links resolution rules 16 | linkResolver: function(ctx, doc) { 17 | return '#documents' + ctx.maybeRefParam + '/' + doc.id + '/' + doc.slug; 18 | }, 19 | 20 | // -- To customize: what to do when an error happens on the prismic.io side 21 | onPrismicError: function(err) { 22 | alert("An error happened on the server side: "+(err ? '#'+err.message : '')); 23 | } 24 | 25 | }; 26 | 27 | }); -------------------------------------------------------------------------------- /templates/search.html: -------------------------------------------------------------------------------- 1 |

2 | <% if(docs.results.length > 0) { %> 3 | <%= docs.results.length %> documents 4 | <% } else { %> 5 | No results found 6 | <% } %> 7 |

8 | 9 | 18 | 19 |
20 | 21 | <% if(docs.total_pages > 1) { %> 22 | 37 | <% } %> -------------------------------------------------------------------------------- /templates/documents.html: -------------------------------------------------------------------------------- 1 |

2 | <% if(docs.total_results_size > 0) { %> 3 | <%= docs.total_results_size %> documents 4 | <% } else { %> 5 | No documents found 6 | <% } %> 7 |

8 | 9 | 18 | 19 |
20 | 21 | <% if(docs.total_pages > 1) { %> 22 | 37 | <% } %> 38 | -------------------------------------------------------------------------------- /templates/header.html: -------------------------------------------------------------------------------- 1 | <% if(ctx.oauth().hasPrivilegedAccess) { %> 2 |
3 | 4 |
5 | 6 | 16 |
17 | 18 |
19 | 20 |
21 | 22 |
23 | 24 |
25 | <% } %> 26 | 27 | 28 |

Your prismic.io project

29 |
30 | 31 |
32 | 33 | 34 |
35 | 36 |
-------------------------------------------------------------------------------- /js/vendor/text-0.27.0.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | RequireJS text 0.27.0 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved. 3 | Available via the MIT or new BSD license. 4 | see: http://github.com/jrburke/requirejs for details 5 | */ 6 | (function(){var k=["Msxml2.XMLHTTP","Microsoft.XMLHTTP","Msxml2.XMLHTTP.4.0"],n=/^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im,o=/]*>\s*([\s\S]+)\s*<\/body>/im,i=typeof location!=="undefined"&&location.href,p=i&&location.protocol&&location.protocol.replace(/\:/,""),q=i&&location.hostname,r=i&&(location.port||void 0),j=[];define(function(){var g,h,l;typeof window!=="undefined"&&window.navigator&&window.document?h=function(a,b){var c=g.createXhr();c.open("GET",a,!0);c.onreadystatechange= 7 | function(){c.readyState===4&&b(c.responseText)};c.send(null)}:typeof process!=="undefined"&&process.versions&&process.versions.node?(l=require.nodeRequire("fs"),h=function(a,b){b(l.readFileSync(a,"utf8"))}):typeof Packages!=="undefined"&&(h=function(a,b){var c=new java.io.File(a),e=java.lang.System.getProperty("line.separator"),c=new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(c),"utf-8")),d,f,g="";try{d=new java.lang.StringBuffer;(f=c.readLine())&&f.length()&& 8 | f.charAt(0)===65279&&(f=f.substring(1));for(d.append(f);(f=c.readLine())!==null;)d.append(e),d.append(f);g=String(d.toString())}finally{c.close()}b(g)});return g={version:"0.27.0",strip:function(a){if(a){var a=a.replace(n,""),b=a.match(o);b&&(a=b[1])}else a="";return a},jsEscape:function(a){return a.replace(/(['\\])/g,"\\$1").replace(/[\f]/g,"\\f").replace(/[\b]/g,"\\b").replace(/[\n]/g,"\\n").replace(/[\t]/g,"\\t").replace(/[\r]/g,"\\r")},createXhr:function(){var a,b,c;if(typeof XMLHttpRequest!== 9 | "undefined")return new XMLHttpRequest;else for(b=0;b<3;b++){c=k[b];try{a=new ActiveXObject(c)}catch(e){}if(a){k=[c];break}}if(!a)throw Error("createXhr(): XMLHttpRequest not available");return a},get:h,parseName:function(a){var b=!1,c=a.indexOf("."),e=a.substring(0,c),a=a.substring(c+1,a.length),c=a.indexOf("!");c!==-1&&(b=a.substring(c+1,a.length),b=b==="strip",a=a.substring(0,c));return{moduleName:e,ext:a,strip:b}},xdRegExp:/^((\w+)\:)?\/\/([^\/\\]+)/,useXhr:function(a,b,c,e){var d=g.xdRegExp.exec(a), 10 | f;if(!d)return!0;a=d[2];d=d[3];d=d.split(":");f=d[1];d=d[0];return(!a||a===b)&&(!d||d===c)&&(!f&&!d||f===e)},finishLoad:function(a,b,c,e,d){c=b?g.strip(c):c;d.isBuild&&d.inlineText&&(j[a]=c);e(c)},load:function(a,b,c,e){var d=g.parseName(a),f=d.moduleName+"."+d.ext,m=b.toUrl(f),h=e&&e.text&&e.text.useXhr||g.useXhr;!i||h(m,p,q,r)?g.get(m,function(b){g.finishLoad(a,d.strip,b,c,e)}):b([f],function(a){g.finishLoad(d.moduleName+"."+d.ext,d.strip,a,c,e)})},write:function(a,b,c){if(b in j){var e=g.jsEscape(j[b]); 11 | c.asModule(a+"!"+b,"define(function () { return '"+e+"';});\n")}},writeFile:function(a,b,c,e,d){var b=g.parseName(b),f=b.moduleName+"."+b.ext,h=c.toUrl(b.moduleName+"."+b.ext)+".js";g.load(f,c,function(){var b=function(a){return e(h,a)};b.asModule=function(a,b){return e.asModule(a,h,b)};g.write(a,f,b,d)},d)}}})})(); -------------------------------------------------------------------------------- /js/prismic-helper.js: -------------------------------------------------------------------------------- 1 | define([ 2 | 'underscore', 3 | 'prismic', 4 | 'prismic-configuration' 5 | ], function(_, Prismic, Configuration) { 6 | 7 | var Helpers = { 8 | 9 | setupLayout: function(Router, setup) { 10 | var maybeRef = _.chain( /^[^~]*~([^\/]+).*$/.exec(document.location.hash) || [] ).rest().first().value(); 11 | Helpers.buildContext(maybeRef, function(ctx) { 12 | setup(ctx); 13 | }); 14 | }, 15 | 16 | saveAccessTokenInSession: function(token) { 17 | if(token) { 18 | sessionStorage.setItem('ACCESS_TOKEN', token); 19 | } else { 20 | sessionStorage.removeItem('ACCESS_TOKEN'); 21 | } 22 | }, 23 | 24 | getApiHome: function(callback) { 25 | Prismic.Api(Configuration.apiEndpoint, callback, sessionStorage.getItem('ACCESS_TOKEN')); 26 | }, 27 | 28 | buildContext: function(ref, callback) { 29 | // retrieve the API 30 | Helpers.getApiHome(function(err, api) { 31 | if (err) { Configuration.onPrismicError(err); return; } 32 | var ctx = { 33 | ref: (ref || api.data.master.ref), 34 | api: api, 35 | maybeRefParam: (ref && ref != api.data.master.ref ? '~' + ref : ''), 36 | 37 | oauth: function() { 38 | var token = sessionStorage.getItem('ACCESS_TOKEN'); 39 | return { 40 | accessToken: token, 41 | hasPrivilegedAccess: !!token 42 | } 43 | }, 44 | 45 | linkResolver: function(ctx, doc) { 46 | return Configuration.linkResolver(ctx, doc); 47 | } 48 | } 49 | callback(ctx); 50 | }); 51 | }, 52 | 53 | prismicRoute: function(routeF) { 54 | return function() { 55 | // first argument is optional ref 56 | var self = this, 57 | ref = _.first(arguments), 58 | args = _.rest(arguments) 59 | 60 | Helpers.buildContext(ref, function(ctx) { 61 | // Call the original function with the Context as first parameter 62 | routeF.apply(self, _.flatten([ctx, args])); 63 | }); 64 | 65 | } 66 | }, 67 | 68 | getDocument: function(ctx, id, callback) { 69 | ctx.api.forms('everything').ref(ctx.ref).query('[[:d = at(document.id, "' + id + '")]]').submit(function(err, documents) { 70 | if (err) callback(err); 71 | else callback(null, _.first(documents.results)); 72 | }); 73 | }, 74 | 75 | getDocuments: function(ctx, ids, callback) { 76 | if(ids && ids.length) { 77 | ctx.api.forms('everything').ref(ctx.ref).query('[[:d = any(document.id, [' + _(ids).map(function(id) { return '"' + id + '"';}).join(',') + '])]]').submit(function(err, documents) { 78 | if (err) callback(err); 79 | else callback(null, documents.results); 80 | }); 81 | } else { 82 | callback(null, []); 83 | } 84 | }, 85 | 86 | getBookmark: function(ctx, bookmark, callback) { 87 | var id = ctx.api.bookmarks[bookmark]; 88 | if(id) { 89 | this.getDocument(ctx, id, callback); 90 | } else { 91 | callback(); 92 | } 93 | } 94 | 95 | }; 96 | 97 | return Helpers; 98 | 99 | }) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Backbone.js starter project for prismic.io 2 | 3 | This is a blank [BackboneJS](http://backbonejs.org/) project that will connect to any [prismic.io](https://prismic.io) repository, and trivially list its documents. It uses the prismic.io JavaScript development kit, and provides a few helpers to integrate with the Backbone framework. 4 | 5 | The project is a single-page application that loads once, and then updates the page DOM to render the website's navigation. It is configured to use hash fragments (`#page`) for the routing, but it's also possible to use standard URLs (`/page`) if you configure your Web server appropriately (ie. serving the index.html page for any incoming URL). 6 | 7 | It uses the browser `sessionStorage` to store the access token when you interactively login to preview the future releases of your repository. Therefore, to preview another release than **Master**, a modern browser supporting HTML5 is required. 8 | 9 | ### Getting started 10 | 11 | #### Launch the starter project 12 | 13 | Since it's all client-side, you don't need more than a web browser: simply open the `index.html` file in your browser. 14 | 15 | If you wish to simulate a client-server architecture anyway, you can also launch a local Web server using the `server.sh` script and open the home page at http://localhost:8000/ (Python is required) 16 | 17 | Your starter project is now working! However, by default, it will list and display documents from our "[Les Bonnes Choses](http://lesbonneschoses.prismic.me)" example repository. 18 | 19 | #### Configure the starter project 20 | 21 | Edit the `js/prismic-configuration.js` file to make the application point to the correct repository: 22 | 23 | ``` 24 | var Configuration = { 25 | 26 | // -- API endpoint 27 | apiEndpoint: 'https://lesbonneschoses.prismic.io/api', 28 | 29 | // -- Access token if the Master is not open 30 | // accessToken: 'xxxxxx', 31 | 32 | // -- OAuth 33 | // clientId: 'xxxxxx', 34 | // clientSecret: 'xxxxxx' 35 | 36 | } 37 | ``` 38 | 39 | To set up the OAuth configuration and interactive signin, go to the _Applications_ panel in your repository's settings, and create a new OAuth application. You simply have to fill in an application name and potentially the callback URL (`localhost` URLs are always authorized, so at development time you can omit to fill in the Callback URL field). After submitting, copy/paste the `clientId` & `clientSecret` tokens into the proper place in your configuration. 40 | 41 | ### Publish your project 42 | 43 | As this application is just made of static files, you can publish it to any web server. One simple way to do that is to use [Github pages](http://pages.github.com/). Just push this Git repository on Github and create a `gh-pages` branch to publish it to your own Github pages: 44 | 45 | ``` 46 | git checkout --orphan gh-pages 47 | git commit -a -m "Push to Github pages" 48 | git push origin gh-pages 49 | ``` 50 | 51 | You can then visit your website at: 52 | 53 | **http://_your-github-user_.github.io/_your-github-repository_**. 54 | 55 | 56 | #### Get started with prismic.io 57 | 58 | You can find out [how to get started with prismic.io](https://developers.prismic.io/documentation/UjBaQsuvzdIHvE4D/getting-started) on our [prismic.io developer's portal](https://developers.prismic.io/). 59 | 60 | #### Understand the JavaScript development kit 61 | 62 | You'll find more information about how to use the development kit included in this starter project, by reading [its README file](https://github.com/prismicio/javascript-kit/blob/master/README.md). 63 | 64 | ### Specifics and helpers of the Backbone.js starter project 65 | 66 | There are several places in this project where you'll be able to find helpful helpers of many kinds. You may want to learn about them in order to know your starter project better, or to take those that you think might be useful to you in order to integrate prismic.io in an existing app. 67 | 68 | * in `js/prismic-configuration.js`: 69 | * this is where you set you API endpoint and security to access your repository's API; 70 | * you will also find the linkResolver closure that gets passed around to resolve your links (read more in the last paragraph of our [API documentation](https://developers.prismic.io/documentation/UjBe8bGIJ3EKtgBZ/api-documentation)); 71 | * you will also find the closure that gets executed when the API returns an error. 72 | * in `js/prismic-helper.js`: 73 | * the most useful helper is `prismicRoute`, that every controller of a page using prismic.io will start with, and which initializes everything (the Api object, the context, ...). It relies on other functions of internal use: `buildContext`, `getApiHome`, `saveAccessTokenInSession`. 74 | * `setupLayout` is called in the main `run` function of `app.js`, and sets up the layout (header and footer). 75 | * and you get a few extra helpers for free to make it easier to perform content queries that tend to come back often: `getDocument(ctx, id, callback)`, `getDocuments(ctx, ids, callback)`, `getBookmark(ctx, bookmark, callback)` (feel free to add yours!) 76 | * in `js/main.js`: 77 | * the configuration of require.js 78 | * and launching the `run()` method, which launches the app 79 | * in `js/app.js`: 80 | * you will find the `run()` method (today, it sets the layout up, and starts the Backbone.js app, but you can add stuff that needs to happen when the app starts) 81 | * the definition of your routes and your controllers: 82 | * `signin` and `authCallback`, that you shouldn't touch if you wish to use the content release preview feature 83 | * `documents`, `detail`, `search`, which are here for the example, and that you can replace, or reuse 84 | * two pre-packaged views: `PreviewToolbar` for the select box that allows to preview content releases, and `SearchEngineForm` for the form to perform searches; you can change them to match your views. 85 | * in `templates/` and `templates.js`, the pre-packaged templates for this example (that you can replace, or reuse). 86 | 87 | ### Contribute to the starter project 88 | 89 | 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. 90 | 91 | ### Licence 92 | 93 | This software is licensed under the Apache 2 license, quoted below. 94 | 95 | Copyright 2013 Zengularity (http://www.zengularity.com). 96 | 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 | 99 | 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. -------------------------------------------------------------------------------- /js/app.js: -------------------------------------------------------------------------------- 1 | define([ 2 | 'jquery', 3 | 'underscore', 4 | 'backbone', 5 | 'prismic', 6 | 'prismic-helper', 7 | 'prismic-configuration', 8 | 'templates' 9 | ], 10 | function($, _, Backbone, Prismic, Helpers, Configuration, Templates) { 11 | 12 | var AppRouter = Backbone.Router.extend({ 13 | 14 | /** Routes **/ 15 | routes: { 16 | '(~:ref)(?p=:page)' : 'documents', 17 | 'documents(~:ref)/:id/:slug' : 'detail', 18 | 'search(~:ref)(/p=:page)/*q' : 'search', 19 | 20 | // OAuth 21 | 'signin' : 'signin', 22 | 'auth_callback/#*data' : 'authCallback' 23 | 24 | }, 25 | 26 | /** Setup layout (used in some routes) **/ 27 | setupLayout : _.once(function() { 28 | Helpers.setupLayout(this, function(ctx) { 29 | 30 | $('header').html( 31 | Templates.Header({ 32 | ctx: ctx 33 | }) 34 | ); 35 | 36 | $('footer').html( 37 | Templates.Footer({ 38 | ctx: ctx 39 | }) 40 | ); 41 | 42 | new PreviewToolbar({ el: $('header') }); 43 | 44 | }); 45 | }), 46 | 47 | /** List all documents **/ 48 | documents: Helpers.prismicRoute(function(ctx, page) { 49 | var router = this; 50 | 51 | // Setup the layout 52 | this.setupLayout(); 53 | 54 | page = parseInt(page); 55 | 56 | // Submit the `everything` form, using the current ref 57 | ctx.api.form('everything').page(page || 1).ref(ctx.ref).submit(function(err, documents) { 58 | if (err) { Configuration.onPrismicError(err); return; } 59 | 60 | // Feed the template and update the DOM 61 | $('#container').html(Templates.DocumentsList({ 62 | docs: documents, 63 | ctx: ctx, 64 | page: documents.page 65 | })); 66 | 67 | new PaginationHome({ el: $('#pagination') }); 68 | 69 | // Handle Search form 70 | $('#container form').submit(function(err, e) { 71 | if (err) { Configuration.onPrismicError(err); return; } 72 | e.preventDefault(); 73 | 74 | router.navigate( 75 | 'search' + ctx.maybeRefParam + '/' + $('input[name=q]', this).val(), 76 | {trigger: true} 77 | ); 78 | }) 79 | 80 | }); 81 | 82 | }), 83 | 84 | /** Display a document **/ 85 | detail: Helpers.prismicRoute(function(ctx, id, slug) { 86 | 87 | // Setup the layout 88 | this.setupLayout(); 89 | 90 | // Fetch the document for the given id 91 | Helpers.getDocument(ctx, id, function(err, maybeResult) { 92 | if (err) { Configuration.onPrismicError(err); return; } 93 | 94 | // Feed the template and update the DOM 95 | $('#container').html( 96 | maybeResult ? Templates.DocumentDetail({ 97 | doc: maybeResult, 98 | ctx: ctx 99 | }) : Templates.NotFound() 100 | ); 101 | 102 | }); 103 | 104 | }), 105 | 106 | /** Search documents **/ 107 | search: Helpers.prismicRoute(function(ctx, page, q) { 108 | page = parseInt(page); 109 | 110 | // Setup the layout 111 | this.setupLayout(); 112 | 113 | // Submit the `everything` form, using the current ref 114 | ctx.api.form('everything').page(page || 1).ref(ctx.ref).query('[[:d = fulltext(document, "' + q + '")]]').submit(function(err, docs) { 115 | if (err) { Configuration.onPrismicError(err); return; } 116 | 117 | // Feed the template and update the DOM 118 | $('#container').html(Templates.SearchResults({ 119 | docs: docs, 120 | ctx: ctx, 121 | page: docs.page 122 | })) 123 | 124 | new PaginationSearch({ el: $('#pagination') }); 125 | 126 | }); 127 | 128 | }), 129 | 130 | /** Sigin to preview changes **/ 131 | signin: function() { 132 | 133 | // Retrieve the prismic API 134 | Helpers.getApiHome(function(err, Api) { 135 | if (err) { Configuration.onPrismicError(err); return; } 136 | document.location = 137 | Api.data.oauthInitiate + 138 | '?response_type=token' + 139 | '&client_id=' + encodeURIComponent(Configuration['clientId']) + 140 | '&redirect_uri=' + encodeURIComponent(document.location.href.replace(/#.*/, '') + '#auth_callback/') + 141 | '&scope=' + encodeURIComponent('master+releases'); 142 | }); 143 | 144 | }, 145 | 146 | /** OAuth callback **/ 147 | authCallback: function(data) { 148 | var data = _.chain(data.split('&')).map(function(params) { 149 | var p = params.split('='); 150 | return [p[0], decodeURIComponent(p[1])]; 151 | }) 152 | .object() 153 | .value(); 154 | 155 | Helpers.saveAccessTokenInSession(data['access_token']); 156 | 157 | // Reload 158 | document.location = document.location.href.replace(/#.*/, '') 159 | } 160 | 161 | }); 162 | 163 | /** Preview toolbar **/ 164 | var PreviewToolbar = Backbone.View.extend({ 165 | 166 | events: { 167 | "change #selectRef select" : "changeRef", 168 | "submit #signout" : "signout", 169 | "submit form#searchengine" : "search" 170 | }, 171 | 172 | changeRef: function(e) { 173 | e.preventDefault(); 174 | var newRef = this.$el.find('select').val(); 175 | document.location = document.location.href.replace(/#.*/, '') + (newRef ? '#~' + newRef : '#'); 176 | }, 177 | 178 | signout: function(e) { 179 | e.preventDefault(); 180 | Helpers.saveAccessTokenInSession(null); 181 | document.location = document.location.href.replace(/#.*/, ''); 182 | }, 183 | 184 | search: function(e) { 185 | e.preventDefault(); 186 | var q = this.$el.find('#q').val(); 187 | var maybeRef = this.$el.find('select').length>0 ? this.$el.find('select').val() : null; 188 | document.location = document.location.href.replace(/#.*/, '') + '#/search'+(maybeRef ? '~'+maybeRef : '')+'/'+q; 189 | } 190 | 191 | }) 192 | 193 | /* View for the pagination that is on the homepage (document list) */ 194 | var PaginationHome = Backbone.View.extend({ 195 | 196 | events:{ 197 | "click a" : "changePage" 198 | }, 199 | 200 | changePage: function(e) { 201 | e.preventDefault(); 202 | var pageParam = '?p='+$(e.target).attr('data-page'); 203 | if (/\?p=[0-9]+/.test(document.location.href)) { // if there's already a known page 204 | document.location = document.location.href.replace(/\?p=[0-9]+/, pageParam); 205 | } 206 | else if (document.location.href.indexOf('#')>-1) { // if there's already a '#' 207 | document.location = document.location.href+pageParam; 208 | } 209 | else { // otherwise 210 | document.location = document.location.href+'#'+pageParam; 211 | } 212 | } 213 | 214 | }); 215 | 216 | /* View for the pagination that is on the search result page */ 217 | var PaginationSearch = Backbone.View.extend({ 218 | 219 | events:{ 220 | "click a" : "changePage" 221 | }, 222 | 223 | changePage: function(e) { 224 | e.preventDefault(); 225 | var pageParam = '/p='+$(e.target).attr('data-page')+'/'; 226 | if (/search\/p=[0-9]+\//.test(document.location.href)) { // if there's already a known page 227 | document.location = document.location.href.replace(/search\/p=[0-9]+\//, 'search'+pageParam); 228 | } 229 | else { // otherwise 230 | document.location = document.location.href.replace(/search\//, 'search'+pageParam); 231 | } 232 | } 233 | 234 | }); 235 | 236 | return { 237 | run: function() { 238 | 239 | var app = new AppRouter(); 240 | 241 | return Backbone.history.start(); 242 | } 243 | }; 244 | 245 | }); -------------------------------------------------------------------------------- /js/vendor/underscore-1.5.2.min.js: -------------------------------------------------------------------------------- 1 | // Underscore.js 1.5.2 2 | // http://underscorejs.org 3 | // (c) 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors 4 | // Underscore may be freely distributed under the MIT license. 5 | (function(){var n=this,t=n._,r={},e=Array.prototype,u=Object.prototype,i=Function.prototype,a=e.push,o=e.slice,c=e.concat,l=u.toString,f=u.hasOwnProperty,s=e.forEach,p=e.map,h=e.reduce,v=e.reduceRight,g=e.filter,d=e.every,m=e.some,y=e.indexOf,b=e.lastIndexOf,x=Array.isArray,w=Object.keys,_=i.bind,j=function(n){return n instanceof j?n:this instanceof j?(this._wrapped=n,void 0):new j(n)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=j),exports._=j):n._=j,j.VERSION="1.5.2";var A=j.each=j.forEach=function(n,t,e){if(null!=n)if(s&&n.forEach===s)n.forEach(t,e);else if(n.length===+n.length){for(var u=0,i=n.length;i>u;u++)if(t.call(e,n[u],u,n)===r)return}else for(var a=j.keys(n),u=0,i=a.length;i>u;u++)if(t.call(e,n[a[u]],a[u],n)===r)return};j.map=j.collect=function(n,t,r){var e=[];return null==n?e:p&&n.map===p?n.map(t,r):(A(n,function(n,u,i){e.push(t.call(r,n,u,i))}),e)};var E="Reduce of empty array with no initial value";j.reduce=j.foldl=j.inject=function(n,t,r,e){var u=arguments.length>2;if(null==n&&(n=[]),h&&n.reduce===h)return e&&(t=j.bind(t,e)),u?n.reduce(t,r):n.reduce(t);if(A(n,function(n,i,a){u?r=t.call(e,r,n,i,a):(r=n,u=!0)}),!u)throw new TypeError(E);return r},j.reduceRight=j.foldr=function(n,t,r,e){var u=arguments.length>2;if(null==n&&(n=[]),v&&n.reduceRight===v)return e&&(t=j.bind(t,e)),u?n.reduceRight(t,r):n.reduceRight(t);var i=n.length;if(i!==+i){var a=j.keys(n);i=a.length}if(A(n,function(o,c,l){c=a?a[--i]:--i,u?r=t.call(e,r,n[c],c,l):(r=n[c],u=!0)}),!u)throw new TypeError(E);return r},j.find=j.detect=function(n,t,r){var e;return O(n,function(n,u,i){return t.call(r,n,u,i)?(e=n,!0):void 0}),e},j.filter=j.select=function(n,t,r){var e=[];return null==n?e:g&&n.filter===g?n.filter(t,r):(A(n,function(n,u,i){t.call(r,n,u,i)&&e.push(n)}),e)},j.reject=function(n,t,r){return j.filter(n,function(n,e,u){return!t.call(r,n,e,u)},r)},j.every=j.all=function(n,t,e){t||(t=j.identity);var u=!0;return null==n?u:d&&n.every===d?n.every(t,e):(A(n,function(n,i,a){return(u=u&&t.call(e,n,i,a))?void 0:r}),!!u)};var O=j.some=j.any=function(n,t,e){t||(t=j.identity);var u=!1;return null==n?u:m&&n.some===m?n.some(t,e):(A(n,function(n,i,a){return u||(u=t.call(e,n,i,a))?r:void 0}),!!u)};j.contains=j.include=function(n,t){return null==n?!1:y&&n.indexOf===y?n.indexOf(t)!=-1:O(n,function(n){return n===t})},j.invoke=function(n,t){var r=o.call(arguments,2),e=j.isFunction(t);return j.map(n,function(n){return(e?t:n[t]).apply(n,r)})},j.pluck=function(n,t){return j.map(n,function(n){return n[t]})},j.where=function(n,t,r){return j.isEmpty(t)?r?void 0:[]:j[r?"find":"filter"](n,function(n){for(var r in t)if(t[r]!==n[r])return!1;return!0})},j.findWhere=function(n,t){return j.where(n,t,!0)},j.max=function(n,t,r){if(!t&&j.isArray(n)&&n[0]===+n[0]&&n.length<65535)return Math.max.apply(Math,n);if(!t&&j.isEmpty(n))return-1/0;var e={computed:-1/0,value:-1/0};return A(n,function(n,u,i){var a=t?t.call(r,n,u,i):n;a>e.computed&&(e={value:n,computed:a})}),e.value},j.min=function(n,t,r){if(!t&&j.isArray(n)&&n[0]===+n[0]&&n.length<65535)return Math.min.apply(Math,n);if(!t&&j.isEmpty(n))return 1/0;var e={computed:1/0,value:1/0};return A(n,function(n,u,i){var a=t?t.call(r,n,u,i):n;ae||r===void 0)return 1;if(e>r||e===void 0)return-1}return n.index-t.index}),"value")};var F=function(n){return function(t,r,e){var u={},i=null==r?j.identity:k(r);return A(t,function(r,a){var o=i.call(e,r,a,t);n(u,o,r)}),u}};j.groupBy=F(function(n,t,r){(j.has(n,t)?n[t]:n[t]=[]).push(r)}),j.indexBy=F(function(n,t,r){n[t]=r}),j.countBy=F(function(n,t){j.has(n,t)?n[t]++:n[t]=1}),j.sortedIndex=function(n,t,r,e){r=null==r?j.identity:k(r);for(var u=r.call(e,t),i=0,a=n.length;a>i;){var o=i+a>>>1;r.call(e,n[o])=0})})},j.difference=function(n){var t=c.apply(e,o.call(arguments,1));return j.filter(n,function(n){return!j.contains(t,n)})},j.zip=function(){for(var n=j.max(j.pluck(arguments,"length").concat(0)),t=new Array(n),r=0;n>r;r++)t[r]=j.pluck(arguments,""+r);return t},j.object=function(n,t){if(null==n)return{};for(var r={},e=0,u=n.length;u>e;e++)t?r[n[e]]=t[e]:r[n[e][0]]=n[e][1];return r},j.indexOf=function(n,t,r){if(null==n)return-1;var e=0,u=n.length;if(r){if("number"!=typeof r)return e=j.sortedIndex(n,t),n[e]===t?e:-1;e=0>r?Math.max(0,u+r):r}if(y&&n.indexOf===y)return n.indexOf(t,r);for(;u>e;e++)if(n[e]===t)return e;return-1},j.lastIndexOf=function(n,t,r){if(null==n)return-1;var e=null!=r;if(b&&n.lastIndexOf===b)return e?n.lastIndexOf(t,r):n.lastIndexOf(t);for(var u=e?r:n.length;u--;)if(n[u]===t)return u;return-1},j.range=function(n,t,r){arguments.length<=1&&(t=n||0,n=0),r=arguments[2]||1;for(var e=Math.max(Math.ceil((t-n)/r),0),u=0,i=new Array(e);e>u;)i[u++]=n,n+=r;return i};var R=function(){};j.bind=function(n,t){var r,e;if(_&&n.bind===_)return _.apply(n,o.call(arguments,1));if(!j.isFunction(n))throw new TypeError;return r=o.call(arguments,2),e=function(){if(!(this instanceof e))return n.apply(t,r.concat(o.call(arguments)));R.prototype=n.prototype;var u=new R;R.prototype=null;var i=n.apply(u,r.concat(o.call(arguments)));return Object(i)===i?i:u}},j.partial=function(n){var t=o.call(arguments,1);return function(){return n.apply(this,t.concat(o.call(arguments)))}},j.bindAll=function(n){var t=o.call(arguments,1);if(0===t.length)throw new Error("bindAll must be passed function names");return A(t,function(t){n[t]=j.bind(n[t],n)}),n},j.memoize=function(n,t){var r={};return t||(t=j.identity),function(){var e=t.apply(this,arguments);return j.has(r,e)?r[e]:r[e]=n.apply(this,arguments)}},j.delay=function(n,t){var r=o.call(arguments,2);return setTimeout(function(){return n.apply(null,r)},t)},j.defer=function(n){return j.delay.apply(j,[n,1].concat(o.call(arguments,1)))},j.throttle=function(n,t,r){var e,u,i,a=null,o=0;r||(r={});var c=function(){o=r.leading===!1?0:new Date,a=null,i=n.apply(e,u)};return function(){var l=new Date;o||r.leading!==!1||(o=l);var f=t-(l-o);return e=this,u=arguments,0>=f?(clearTimeout(a),a=null,o=l,i=n.apply(e,u)):a||r.trailing===!1||(a=setTimeout(c,f)),i}},j.debounce=function(n,t,r){var e,u,i,a,o;return function(){i=this,u=arguments,a=new Date;var c=function(){var l=new Date-a;t>l?e=setTimeout(c,t-l):(e=null,r||(o=n.apply(i,u)))},l=r&&!e;return e||(e=setTimeout(c,t)),l&&(o=n.apply(i,u)),o}},j.once=function(n){var t,r=!1;return function(){return r?t:(r=!0,t=n.apply(this,arguments),n=null,t)}},j.wrap=function(n,t){return function(){var r=[n];return a.apply(r,arguments),t.apply(this,r)}},j.compose=function(){var n=arguments;return function(){for(var t=arguments,r=n.length-1;r>=0;r--)t=[n[r].apply(this,t)];return t[0]}},j.after=function(n,t){return function(){return--n<1?t.apply(this,arguments):void 0}},j.keys=w||function(n){if(n!==Object(n))throw new TypeError("Invalid object");var t=[];for(var r in n)j.has(n,r)&&t.push(r);return t},j.values=function(n){for(var t=j.keys(n),r=t.length,e=new Array(r),u=0;r>u;u++)e[u]=n[t[u]];return e},j.pairs=function(n){for(var t=j.keys(n),r=t.length,e=new Array(r),u=0;r>u;u++)e[u]=[t[u],n[t[u]]];return e},j.invert=function(n){for(var t={},r=j.keys(n),e=0,u=r.length;u>e;e++)t[n[r[e]]]=r[e];return t},j.functions=j.methods=function(n){var t=[];for(var r in n)j.isFunction(n[r])&&t.push(r);return t.sort()},j.extend=function(n){return A(o.call(arguments,1),function(t){if(t)for(var r in t)n[r]=t[r]}),n},j.pick=function(n){var t={},r=c.apply(e,o.call(arguments,1));return A(r,function(r){r in n&&(t[r]=n[r])}),t},j.omit=function(n){var t={},r=c.apply(e,o.call(arguments,1));for(var u in n)j.contains(r,u)||(t[u]=n[u]);return t},j.defaults=function(n){return A(o.call(arguments,1),function(t){if(t)for(var r in t)n[r]===void 0&&(n[r]=t[r])}),n},j.clone=function(n){return j.isObject(n)?j.isArray(n)?n.slice():j.extend({},n):n},j.tap=function(n,t){return t(n),n};var S=function(n,t,r,e){if(n===t)return 0!==n||1/n==1/t;if(null==n||null==t)return n===t;n instanceof j&&(n=n._wrapped),t instanceof j&&(t=t._wrapped);var u=l.call(n);if(u!=l.call(t))return!1;switch(u){case"[object String]":return n==String(t);case"[object Number]":return n!=+n?t!=+t:0==n?1/n==1/t:n==+t;case"[object Date]":case"[object Boolean]":return+n==+t;case"[object RegExp]":return n.source==t.source&&n.global==t.global&&n.multiline==t.multiline&&n.ignoreCase==t.ignoreCase}if("object"!=typeof n||"object"!=typeof t)return!1;for(var i=r.length;i--;)if(r[i]==n)return e[i]==t;var a=n.constructor,o=t.constructor;if(a!==o&&!(j.isFunction(a)&&a instanceof a&&j.isFunction(o)&&o instanceof o))return!1;r.push(n),e.push(t);var c=0,f=!0;if("[object Array]"==u){if(c=n.length,f=c==t.length)for(;c--&&(f=S(n[c],t[c],r,e)););}else{for(var s in n)if(j.has(n,s)&&(c++,!(f=j.has(t,s)&&S(n[s],t[s],r,e))))break;if(f){for(s in t)if(j.has(t,s)&&!c--)break;f=!c}}return r.pop(),e.pop(),f};j.isEqual=function(n,t){return S(n,t,[],[])},j.isEmpty=function(n){if(null==n)return!0;if(j.isArray(n)||j.isString(n))return 0===n.length;for(var t in n)if(j.has(n,t))return!1;return!0},j.isElement=function(n){return!(!n||1!==n.nodeType)},j.isArray=x||function(n){return"[object Array]"==l.call(n)},j.isObject=function(n){return n===Object(n)},A(["Arguments","Function","String","Number","Date","RegExp"],function(n){j["is"+n]=function(t){return l.call(t)=="[object "+n+"]"}}),j.isArguments(arguments)||(j.isArguments=function(n){return!(!n||!j.has(n,"callee"))}),"function"!=typeof/./&&(j.isFunction=function(n){return"function"==typeof n}),j.isFinite=function(n){return isFinite(n)&&!isNaN(parseFloat(n))},j.isNaN=function(n){return j.isNumber(n)&&n!=+n},j.isBoolean=function(n){return n===!0||n===!1||"[object Boolean]"==l.call(n)},j.isNull=function(n){return null===n},j.isUndefined=function(n){return n===void 0},j.has=function(n,t){return f.call(n,t)},j.noConflict=function(){return n._=t,this},j.identity=function(n){return n},j.times=function(n,t,r){for(var e=Array(Math.max(0,n)),u=0;n>u;u++)e[u]=t.call(r,u);return e},j.random=function(n,t){return null==t&&(t=n,n=0),n+Math.floor(Math.random()*(t-n+1))};var I={escape:{"&":"&","<":"<",">":">",'"':""","'":"'"}};I.unescape=j.invert(I.escape);var T={escape:new RegExp("["+j.keys(I.escape).join("")+"]","g"),unescape:new RegExp("("+j.keys(I.unescape).join("|")+")","g")};j.each(["escape","unescape"],function(n){j[n]=function(t){return null==t?"":(""+t).replace(T[n],function(t){return I[n][t]})}}),j.result=function(n,t){if(null==n)return void 0;var r=n[t];return j.isFunction(r)?r.call(n):r},j.mixin=function(n){A(j.functions(n),function(t){var r=j[t]=n[t];j.prototype[t]=function(){var n=[this._wrapped];return a.apply(n,arguments),z.call(this,r.apply(j,n))}})};var N=0;j.uniqueId=function(n){var t=++N+"";return n?n+t:t},j.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var q=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},D=/\\|'|\r|\n|\t|\u2028|\u2029/g;j.template=function(n,t,r){var e;r=j.defaults({},r,j.templateSettings);var u=new RegExp([(r.escape||q).source,(r.interpolate||q).source,(r.evaluate||q).source].join("|")+"|$","g"),i=0,a="__p+='";n.replace(u,function(t,r,e,u,o){return a+=n.slice(i,o).replace(D,function(n){return"\\"+B[n]}),r&&(a+="'+\n((__t=("+r+"))==null?'':_.escape(__t))+\n'"),e&&(a+="'+\n((__t=("+e+"))==null?'':__t)+\n'"),u&&(a+="';\n"+u+"\n__p+='"),i=o+t.length,t}),a+="';\n",r.variable||(a="with(obj||{}){\n"+a+"}\n"),a="var __t,__p='',__j=Array.prototype.join,"+"print=function(){__p+=__j.call(arguments,'');};\n"+a+"return __p;\n";try{e=new Function(r.variable||"obj","_",a)}catch(o){throw o.source=a,o}if(t)return e(t,j);var c=function(n){return e.call(this,n,j)};return c.source="function("+(r.variable||"obj")+"){\n"+a+"}",c},j.chain=function(n){return j(n).chain()};var z=function(n){return this._chain?j(n).chain():n};j.mixin(j),A(["pop","push","reverse","shift","sort","splice","unshift"],function(n){var t=e[n];j.prototype[n]=function(){var r=this._wrapped;return t.apply(r,arguments),"shift"!=n&&"splice"!=n||0!==r.length||delete r[0],z.call(this,r)}}),A(["concat","join","slice"],function(n){var t=e[n];j.prototype[n]=function(){return z.call(this,t.apply(this._wrapped,arguments))}}),j.extend(j.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this); -------------------------------------------------------------------------------- /js/vendor/prismic.io-1.0.12.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * prismic.io 1.0.12 3 | * See release notes: https://github.com/prismicio/javascript-kit/releases 4 | */ 5 | !function(a,b){"use strict";function c(a,b,c,d,e,f){this.name=a,this.fields=b,this.form_method=c,this.rel=d,this.enctype=e,this.action=f}function d(a,b,c){this.api=a,this.form=b,this.data=c||{};for(var d in b.fields)b.fields[d].default&&(this.data[d]=[b.fields[d].default])}function e(a){return this.fragments&&this.fragments[a]?Array.isArray(this.fragments[a])?this.fragments[a]:[this.fragments[a]]:[]}function f(a,b,c,d,e,f,g,h){this.page=a,this.results_per_page=b,this.results_size=c,this.total_results_size=d,this.total_pages=e,this.next_page=f,this.prev_page=g,this.results=h}function g(a,b,c,d){this.id=a,this.slug=b,this.type=c,this.tags=d}function h(a,b,c,d,e,f,g){this.id=a,this.type=b,this.href=c,this.tags=d,this.slug=e?e[0]:"-",this.slugs=e,this.linkedDocuments=f,this.fragments=g}function i(a,b,c,d,e){this.ref=a,this.label=b,this.isMaster=c,this.scheduledAt=d,this.id=e}function j(){this.cache={},this.states={}}var k=function(a,b,c,d,e){var f=new k.fn.init(a,c,d,e);return b&&f.get(b),f},l=function(){return"undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest?function(a,b){var c=new XMLHttpRequest,d=function(){b(null,JSON.parse(c.responseText),c)},e=function(){var d=c.status;b(new Error("Unexpected status code ["+d+"] on URL "+a),null,c)};c.onreadystatechange=function(){4===c.readyState&&(c.status&&200==c.status?d():e())},c.open("GET",a,!0),c.setRequestHeader("Accept","application/json"),c.send()}:void 0},m=function(){return"undefined"!=typeof XDomainRequest?function(a,b){var c=new XDomainRequest,d=function(){b(null,JSON.parse(c.responseText),c)},e=function(a){b(new Error(a),null,c)};c.onload=function(){d(c)},c.onerror=function(){e("Unexpected status code on URL "+a)},c.open("GET",a,!0),c.ontimeout=function(){e("Request timeout")},c.onprogress=function(){},c.send()}:void 0},n=function(){if("function"==typeof require&&require("http")){{var a={},c=require("http"),d=require("https"),e=require("url");require("querystring")}return function(f,g){if(a[f])g(null,a[f]);else{var h=e.parse(f),i="https:"==h.protocol?d:c,j={hostname:h.hostname,path:h.path,query:h.query,headers:{Accept:"application/json"}};i.get(j,function(c){if(c.statusCode&&200==c.statusCode){var d="";c.setEncoding("utf8"),c.on("data",function(a){d+=a}),c.on("end",function(){var e=c.headers["cache-control"],h=e&&/max-age=(\d+)/.test(e)?parseInt(/max-age=(\d+)/.exec(e)[1]):b,i=JSON.parse(d);h&&(a[f]=i),g(null,i,c)})}else g(new Error("Unexpected status code ["+c.statusCode+"] on URL "+f),null,c)})}}}};k.fn=k.prototype={constructor:k,data:null,get:function(a){var b=this,c=this.url+(this.accessToken?"#"+this.accessToken:"");this.apiCache.getOrSet(c,5,function(a){b.requestHandler(b.url,function(c,d,e){c?a&&a(c,null,e):a&&a(null,b.parse(d),e)})},function(c,d,e){c?a&&a(c,null,e):(b.data=d,b.bookmarks=d.bookmarks,a&&a(null,b,e))})},parse:function(a){var b,d,e,f,g,h,j,k={};for(j in a.forms)a.forms.hasOwnProperty(j)&&(h=a.forms[j],this.accessToken&&(h.fields.accessToken={type:"string","default":this.accessToken}),e=new c(h.name,h.fields,h.form_method,h.rel,h.enctype,h.action),k[j]=e);if(b=a.refs.map(function(a){return new i(a.ref,a.label,a.isMasterRef,a.scheduledAt,a.id)})||[],d=b.filter(function(a){return a.isMaster===!0}),f=a.types,g=a.tags,0===d.length)throw"No master ref.";return{bookmarks:a.bookmarks||{},refs:b,forms:k,master:d[0],types:f,tags:g,oauthInitiate:a.oauth_initiate,oauthToken:a.oauth_token}},init:function(a,b,c,d){return this.url=a+(b?(a.indexOf("?")>-1?"&":"?")+"access_token="+b:""),this.accessToken=b,this.requestHandler=c||l()||m()||n()||function(){throw new Error("No request handler available (tried XMLHttpRequest & NodeJS)")}(),this.apiCache=d||new j,this},forms:function(a){return this.form(a)},form:function(a){var b=this.data.forms[a];return b?new d(this,b,{}):void 0},master:function(){return this.data.master.ref},ref:function(a){for(var b=0;b-1?"&":"?";for(var d in this.data){var e=this.data[d];if(e)for(var i=0;i'+d.asHtml(a)+"":"")}return b.join("")},asText:function(a){var b=[];for(var c in this.fragments){var d=this.get(c);b.push(d&&d.asText?d.asText(a):"")}return b.join("")}},i.prototype={},j.prototype={get:function(a){var b=this.cache[a];return b&&(!this.isExpired(a)||this.isExpired(a)&&this.isInProgress(a))?b.data:null},set:function(a,b,c){this.cache[a]={data:b,expiredIn:c?Date.now()+1e3*c:0}},getOrSet:function(a,b,c,d){var e=this.get(a),f=this;if(e)d&&d(null,e);else{this.states[a]="progress";{c(function(c,e,g){f.set(a,e,b),delete f.states[a],d&&d(c,e,g)})}}},isExpired:function(a){var b=this.cache[a];return b?0!=b.expiredIn&&b.expiredIn"+r(a.blocks[0].text,a.blocks[0].spans,b)+"");else if("heading2"==a.tag)f.push("

"+r(a.blocks[0].text,a.blocks[0].spans,b)+"

");else if("heading3"==a.tag)f.push("

"+r(a.blocks[0].text,a.blocks[0].spans,b)+"

");else if("paragraph"==a.tag)f.push("

"+r(a.blocks[0].text,a.blocks[0].spans,b)+"

");else if("preformatted"==a.tag)f.push("
"+a.blocks[0].text+"
");else if("image"==a.tag)f.push('

'+a.blocks[0].alt+'

');else if("embed"==a.tag)f.push('
'+a.blocks[0].oembed.html+"
");else{if("list-item"!=a.tag&&"o-list-item"!=a.tag)throw new Error(a.tag+" not implemented");f.push("list-item"==a.tag?"
    ":"
      "),a.blocks.forEach(function(a){f.push("
    1. "+r(a.text,a.spans,b)+"
    2. ")}),f.push("list-item"==a.tag?"
":"")}})}return f.join("")}function r(a,b,c){var d=[],e=[],f=0,g=[];return b.forEach(function(b){return b.end'),g.push(d.shift()),g.push("")):(g.push("<"+a.type+">"),g.push(d.shift()),g.push(""))}),g.push(d.shift()),g.join("")}function s(a){var o,q;switch(a.type){case"Color":o=new h(a.value);break;case"Number":o=new i(a.value);break;case"Date":o=new j(a.value);break;case"Text":o=new b(a.value);break;case"Embed":o=new k(a.value);break;case"Select":o=new g(a.value);break;case"Image":var q=a.value.main;o=new l(new m(q.url,q.dimensions.width,q.dimensions.height,q.alt),{});for(var r in a.value.views){var q=a.value.views[r];o.views[r]=new m(q.url,q.dimensions.width,q.dimensions.height,q.alt)}break;case"StructuredText":o=new p(a.value);break;case"Link.document":o=new c(a.value);break;case"Link.web":o=new d(a.value);break;case"Link.file":o=new e(a.value);break;case"Link.image":o=new f(a.value);break;case"Group":for(var t=[],u=0;u"+this.value+""},asText:function(){return this.value}},c.prototype={asHtml:function(a){return''+this.url(a)+""},url:function(a){return a.linkResolver(a,this.document,this.isBroken)},asText:function(a){return this.url(a)}},d.prototype={asHtml:function(){return''+this.url()+""},url:function(){return this.value.url},asText:function(){return this.url()}},e.prototype={asHtml:function(){return''+this.value.file.name+""},url:function(){return this.value.file.url},asText:function(){return this.url()}},f.prototype={asHtml:function(){return''+this.alt+''},url:function(){return this.value.image.url},asText:function(){return this.url()}},g.prototype={asHtml:function(){return""+this.value+""},asText:function(){return this.value}},h.prototype={asHtml:function(){return""+this.value+""},asText:function(){return this.value}},i.prototype={asHtml:function(){return""+this.value+""},asText:function(){return this.value.toString()}},j.prototype={asHtml:function(){return""},asText:function(){return this.value.toString()}},k.prototype={asHtml:function(){return this.value.oembed.html},asText:function(){return""}},l.prototype={getView:function(a){return"main"===a?this.main:this.views[a]},asHtml:function(){return this.main.asHtml()},asText:function(){return""}},m.prototype={ratio:function(){return this.width/this.height},asHtml:function(){return"'},asText:function(){return""}},n.prototype={asHtml:function(a){for(var b="",c=0;c',b+=this.value[c][d].asHtml(a),b+="";return b},toArray:function(){return this.value},asText:function(a){for(var b="",c=0;cthis.depCount&&!this.defined){if(H(m)){if(this.events.error&&this.map.isDefine||j.onError!==aa)try{e=i.execCb(c,m,b,e)}catch(d){a=d}else e=i.execCb(c,m,b,e);this.map.isDefine&&((b=this.module)&&void 0!==b.exports&&b.exports!== 19 | this.exports?e=b.exports:void 0===e&&this.usingExports&&(e=this.exports));if(a)return a.requireMap=this.map,a.requireModules=this.map.isDefine?[this.map.id]:null,a.requireType=this.map.isDefine?"define":"require",v(this.error=a)}else e=m;this.exports=e;if(this.map.isDefine&&!this.ignore&&(r[c]=e,j.onResourceLoad))j.onResourceLoad(i,this.map,this.depMaps);x(c);this.defined=!0}this.defining=!1;this.defined&&!this.defineEmitted&&(this.defineEmitted=!0,this.emit("defined",this.exports),this.defineEmitComplete= 20 | !0)}}else this.fetch()}},callPlugin:function(){var a=this.map,b=a.id,d=n(a.prefix);this.depMaps.push(d);t(d,"defined",u(this,function(e){var m,d;d=this.map.name;var g=this.map.parentMap?this.map.parentMap.name:null,h=i.makeRequire(a.parentMap,{enableBuildCallback:!0});if(this.map.unnormalized){if(e.normalize&&(d=e.normalize(d,function(a){return c(a,g,!0)})||""),e=n(a.prefix+"!"+d,this.map.parentMap),t(e,"defined",u(this,function(a){this.init([],function(){return a},null,{enabled:!0,ignore:!0})})), 21 | d=l(p,e.id)){this.depMaps.push(e);if(this.events.error)d.on("error",u(this,function(a){this.emit("error",a)}));d.enable()}}else m=u(this,function(a){this.init([],function(){return a},null,{enabled:!0})}),m.error=u(this,function(a){this.inited=!0;this.error=a;a.requireModules=[b];F(p,function(a){0===a.map.id.indexOf(b+"_unnormalized")&&x(a.map.id)});v(a)}),m.fromText=u(this,function(e,c){var d=a.name,g=n(d),B=O;c&&(e=c);B&&(O=!1);q(g);s(k.config,b)&&(k.config[d]=k.config[b]);try{j.exec(e)}catch(ca){return v(A("fromtexteval", 22 | "fromText eval for "+b+" failed: "+ca,ca,[b]))}B&&(O=!0);this.depMaps.push(g);i.completeLoad(d);h([d],m)}),e.load(a.name,h,m,k)}));i.enable(d,this);this.pluginMaps[d.id]=d},enable:function(){T[this.map.id]=this;this.enabling=this.enabled=!0;y(this.depMaps,u(this,function(a,b){var c,e;if("string"===typeof a){a=n(a,this.map.isDefine?this.map:this.map.parentMap,!1,!this.skipMap);this.depMaps[b]=a;if(c=l(N,a.id)){this.depExports[b]=c(this);return}this.depCount+=1;t(a,"defined",u(this,function(a){this.defineDep(b, 23 | a);this.check()}));this.errback&&t(a,"error",u(this,this.errback))}c=a.id;e=p[c];!s(N,c)&&(e&&!e.enabled)&&i.enable(a,this)}));F(this.pluginMaps,u(this,function(a){var b=l(p,a.id);b&&!b.enabled&&i.enable(a,this)}));this.enabling=!1;this.check()},on:function(a,b){var c=this.events[a];c||(c=this.events[a]=[]);c.push(b)},emit:function(a,b){y(this.events[a],function(a){a(b)});"error"===a&&delete this.events[a]}};i={config:k,contextName:b,registry:p,defined:r,urlFetched:S,defQueue:G,Module:X,makeModuleMap:n, 24 | nextTick:j.nextTick,onError:v,configure:function(a){a.baseUrl&&"/"!==a.baseUrl.charAt(a.baseUrl.length-1)&&(a.baseUrl+="/");var b=k.pkgs,c=k.shim,e={paths:!0,config:!0,map:!0};F(a,function(a,b){e[b]?"map"===b?(k.map||(k.map={}),Q(k[b],a,!0,!0)):Q(k[b],a,!0):k[b]=a});a.shim&&(F(a.shim,function(a,b){I(a)&&(a={deps:a});if((a.exports||a.init)&&!a.exportsFn)a.exportsFn=i.makeShimExports(a);c[b]=a}),k.shim=c);a.packages&&(y(a.packages,function(a){a="string"===typeof a?{name:a}:a;b[a.name]={name:a.name, 25 | location:a.location||a.name,main:(a.main||"main").replace(ja,"").replace(ea,"")}}),k.pkgs=b);F(p,function(a,b){!a.inited&&!a.map.unnormalized&&(a.map=n(b))});if(a.deps||a.callback)i.require(a.deps||[],a.callback)},makeShimExports:function(a){return function(){var b;a.init&&(b=a.init.apply(Z,arguments));return b||a.exports&&ba(a.exports)}},makeRequire:function(a,f){function d(e,c,h){var g,k;f.enableBuildCallback&&(c&&H(c))&&(c.__requireJsBuild=!0);if("string"===typeof e){if(H(c))return v(A("requireargs", 26 | "Invalid require call"),h);if(a&&s(N,e))return N[e](p[a.id]);if(j.get)return j.get(i,e,a,d);g=n(e,a,!1,!0);g=g.id;return!s(r,g)?v(A("notloaded",'Module name "'+g+'" has not been loaded yet for context: '+b+(a?"":". Use require([])"))):r[g]}K();i.nextTick(function(){K();k=q(n(null,a));k.skipMap=f.skipMap;k.init(e,c,h,{enabled:!0});C()});return d}f=f||{};Q(d,{isBrowser:z,toUrl:function(b){var d,f=b.lastIndexOf("."),g=b.split("/")[0];if(-1!==f&&(!("."===g||".."===g)||1h.attachEvent.toString().indexOf("[native code"))&&!W?(O=!0,h.attachEvent("onreadystatechange",b.onScriptLoad)):(h.addEventListener("load",b.onScriptLoad,!1),h.addEventListener("error", 34 | b.onScriptError,!1)),h.src=d,K=h,C?x.insertBefore(h,C):x.appendChild(h),K=null,h;if(da)try{importScripts(d),b.completeLoad(c)}catch(l){b.onError(A("importscripts","importScripts failed for "+c+" at "+d,l,[c]))}};z&&M(document.getElementsByTagName("script"),function(b){x||(x=b.parentNode);if(J=b.getAttribute("data-main"))return q=J,t.baseUrl||(D=q.split("/"),q=D.pop(),fa=D.length?D.join("/")+"/":"./",t.baseUrl=fa),q=q.replace(ea,""),j.jsExtRegExp.test(q)&&(q=J),t.deps=t.deps?t.deps.concat(q):[q],!0}); 35 | define=function(b,c,d){var h,j;"string"!==typeof b&&(d=c,c=b,b=null);I(c)||(d=c,c=null);!c&&H(d)&&(c=[],d.length&&(d.toString().replace(la,"").replace(ma,function(b,d){c.push(d)}),c=(1===d.length?["require"]:["require","exports","module"]).concat(c)));if(O){if(!(h=K))P&&"interactive"===P.readyState||M(document.getElementsByTagName("script"),function(b){if("interactive"===b.readyState)return P=b}),h=P;h&&(b||(b=h.getAttribute("data-requiremodule")),j=E[h.getAttribute("data-requirecontext")])}(j?j.defQueue: 36 | R).push([b,c,d])};define.amd={jQuery:!0};j.exec=function(b){return eval(b)};j(t)}})(this); -------------------------------------------------------------------------------- /js/vendor/backbone-1.0.0.min.js: -------------------------------------------------------------------------------- 1 | (function(){var t=this;var e=t.Backbone;var i=[];var r=i.push;var s=i.slice;var n=i.splice;var a;if(typeof exports!=="undefined"){a=exports}else{a=t.Backbone={}}a.VERSION="1.0.0";var h=t._;if(!h&&typeof require!=="undefined")h=require("underscore");a.$=t.jQuery||t.Zepto||t.ender||t.$;a.noConflict=function(){t.Backbone=e;return this};a.emulateHTTP=false;a.emulateJSON=false;var o=a.Events={on:function(t,e,i){if(!l(this,"on",t,[e,i])||!e)return this;this._events||(this._events={});var r=this._events[t]||(this._events[t]=[]);r.push({callback:e,context:i,ctx:i||this});return this},once:function(t,e,i){if(!l(this,"once",t,[e,i])||!e)return this;var r=this;var s=h.once(function(){r.off(t,s);e.apply(this,arguments)});s._callback=e;return this.on(t,s,i)},off:function(t,e,i){var r,s,n,a,o,u,c,f;if(!this._events||!l(this,"off",t,[e,i]))return this;if(!t&&!e&&!i){this._events={};return this}a=t?[t]:h.keys(this._events);for(o=0,u=a.length;o").attr(t);this.setElement(e,false)}else{this.setElement(h.result(this,"el"),false)}}});a.sync=function(t,e,i){var r=k[t];h.defaults(i||(i={}),{emulateHTTP:a.emulateHTTP,emulateJSON:a.emulateJSON});var s={type:r,dataType:"json"};if(!i.url){s.url=h.result(e,"url")||U()}if(i.data==null&&e&&(t==="create"||t==="update"||t==="patch")){s.contentType="application/json";s.data=JSON.stringify(i.attrs||e.toJSON(i))}if(i.emulateJSON){s.contentType="application/x-www-form-urlencoded";s.data=s.data?{model:s.data}:{}}if(i.emulateHTTP&&(r==="PUT"||r==="DELETE"||r==="PATCH")){s.type="POST";if(i.emulateJSON)s.data._method=r;var n=i.beforeSend;i.beforeSend=function(t){t.setRequestHeader("X-HTTP-Method-Override",r);if(n)return n.apply(this,arguments)}}if(s.type!=="GET"&&!i.emulateJSON){s.processData=false}if(s.type==="PATCH"&&window.ActiveXObject&&!(window.external&&window.external.msActiveXFilteringEnabled)){s.xhr=function(){return new ActiveXObject("Microsoft.XMLHTTP")}}var o=i.xhr=a.ajax(h.extend(s,i));e.trigger("request",e,o,i);return o};var k={create:"POST",update:"PUT",patch:"PATCH","delete":"DELETE",read:"GET"};a.ajax=function(){return a.$.ajax.apply(a.$,arguments)};var S=a.Router=function(t){t||(t={});if(t.routes)this.routes=t.routes;this._bindRoutes();this.initialize.apply(this,arguments)};var $=/\((.*?)\)/g;var T=/(\(\?)?:\w+/g;var H=/\*\w+/g;var A=/[\-{}\[\]+?.,\\\^$|#\s]/g;h.extend(S.prototype,o,{initialize:function(){},route:function(t,e,i){if(!h.isRegExp(t))t=this._routeToRegExp(t);if(h.isFunction(e)){i=e;e=""}if(!i)i=this[e];var r=this;a.history.route(t,function(s){var n=r._extractParameters(t,s);i&&i.apply(r,n);r.trigger.apply(r,["route:"+e].concat(n));r.trigger("route",e,n);a.history.trigger("route",r,e,n)});return this},navigate:function(t,e){a.history.navigate(t,e);return this},_bindRoutes:function(){if(!this.routes)return;this.routes=h.result(this,"routes");var t,e=h.keys(this.routes);while((t=e.pop())!=null){this.route(t,this.routes[t])}},_routeToRegExp:function(t){t=t.replace(A,"\\$&").replace($,"(?:$1)?").replace(T,function(t,e){return e?t:"([^/]+)"}).replace(H,"(.*?)");return new RegExp("^"+t+"$")},_extractParameters:function(t,e){var i=t.exec(e).slice(1);return h.map(i,function(t){return t?decodeURIComponent(t):null})}});var I=a.History=function(){this.handlers=[];h.bindAll(this,"checkUrl");if(typeof window!=="undefined"){this.location=window.location;this.history=window.history}};var N=/^[#\/]|\s+$/g;var P=/^\/+|\/+$/g;var O=/msie [\w.]+/;var C=/\/$/;I.started=false;h.extend(I.prototype,o,{interval:50,getHash:function(t){var e=(t||this).location.href.match(/#(.*)$/);return e?e[1]:""},getFragment:function(t,e){if(t==null){if(this._hasPushState||!this._wantsHashChange||e){t=this.location.pathname;var i=this.root.replace(C,"");if(!t.indexOf(i))t=t.substr(i.length)}else{t=this.getHash()}}return t.replace(N,"")},start:function(t){if(I.started)throw new Error("Backbone.history has already been started");I.started=true;this.options=h.extend({},{root:"/"},this.options,t);this.root=this.options.root;this._wantsHashChange=this.options.hashChange!==false;this._wantsPushState=!!this.options.pushState;this._hasPushState=!!(this.options.pushState&&this.history&&this.history.pushState);var e=this.getFragment();var i=document.documentMode;var r=O.exec(navigator.userAgent.toLowerCase())&&(!i||i<=7);this.root=("/"+this.root+"/").replace(P,"/");if(r&&this._wantsHashChange){this.iframe=a.$('