From 1a053bdf358b29494a81055885029cfb7c60bf43 Mon Sep 17 00:00:00 2001 From: Eric Holscher Date: Tue, 12 Dec 2017 14:10:05 -0800 Subject: [PATCH] Integrate Embed API where we expect it. (#3356) * Integrate Embed where we expect it. * Re-enable ImportedFile creation * Filter files to only HTML. * Fix tests * Update media files --- .../projects/static-src/projects/js/tools.js | 4 ++-- readthedocs/projects/static/projects/js/tools.js | 2 +- readthedocs/projects/tasks.py | 13 +++++-------- readthedocs/projects/urls/public.py | 5 +++++ readthedocs/projects/views/public.py | 4 ++-- readthedocs/settings/base.py | 9 +++++---- readthedocs/templates/projects/project_embed.html | 2 +- readthedocs/urls.py | 7 +++++++ 8 files changed, 28 insertions(+), 18 deletions(-) diff --git a/readthedocs/projects/static-src/projects/js/tools.js b/readthedocs/projects/static-src/projects/js/tools.js index 8d68a2b5129..7b97f712cd4 100644 --- a/readthedocs/projects/static-src/projects/js/tools.js +++ b/readthedocs/projects/static-src/projects/js/tools.js @@ -110,7 +110,7 @@ function EmbedView (config) { self.api_example = ko.observable(null); self.show_help = function () { - var embed = new rtd.Embed(); + var embed = new rtd.Embed(self.config); embed.section( 'docs', 'latest', 'features/embed', 'Content Embedding', _show_modal @@ -118,7 +118,7 @@ function EmbedView (config) { }; self.show_embed = function () { - var embed = new rtd.Embed(); + var embed = new rtd.Embed(self.config); _show_modal(self.response()); }; } diff --git a/readthedocs/projects/static/projects/js/tools.js b/readthedocs/projects/static/projects/js/tools.js index 0e481bf19c9..2e6115a7c88 100644 --- a/readthedocs/projects/static/projects/js/tools.js +++ b/readthedocs/projects/static/projects/js/tools.js @@ -1 +1 @@ -require=function e(t,n,r){function s(i,a){if(!n[i]){if(!t[i]){var l="function"==typeof require&&require;if(!a&&l)return l(i,!0);if(o)return o(i,!0);var c=new Error("Cannot find module '"+i+"'");throw c.code="MODULE_NOT_FOUND",c}var u=n[i]={exports:{}};t[i][0].call(u.exports,function(e){var n=t[i][1][e];return s(n?n:e)},u,u.exports,e,t,n,r)}return n[i].exports}for(var o="function"==typeof require&&require,i=0;i0;)e.firstChild.remove();e.appendChild(t)}var n=t.contentWindow;n.document.open(),n.document.write(this.content),n.document.close();var r=n.document.head,s=(n.document.body,null);if(r){s=n.document.createElement("base"),s.target="_parent",s.href=this.url,r.appendChild(s);for(var o=document.head.getElementsByTagName("link"),i=0;i0;)self._completeHandlers.shift()(e)}function success(resp){var type=o.type||resp&&setType(resp.getResponseHeader("Content-Type"));resp="jsonp"!==type?self.request:resp;var filteredResponse=globalSetupOptions.dataFilter(resp.responseText,type),r=filteredResponse;try{resp.responseText=r}catch(e){}if(r)switch(type){case"json":try{resp=win.JSON?win.JSON.parse(r):eval("("+r+")")}catch(err){return error(resp,"Could not parse JSON in response",err)}break;case"js":resp=eval(r);break;case"html":resp=r;break;case"xml":resp=resp.responseXML&&resp.responseXML.parseError&&resp.responseXML.parseError.errorCode&&resp.responseXML.parseError.reason?null:resp.responseXML}for(self._responseArgs.resp=resp,self._fulfilled=!0,fn(resp),self._successHandler(resp);self._fulfillmentHandlers.length>0;)resp=self._fulfillmentHandlers.shift()(resp);complete(resp)}function timedOut(){self._timedOut=!0,self.request.abort()}function error(e,t,n){for(e=self.request,self._responseArgs.resp=e,self._responseArgs.msg=t,self._responseArgs.t=n,self._erred=!0;self._errorHandlers.length>0;)self._errorHandlers.shift()(e,t,n);complete(e)}this.url="string"==typeof o?o:o.url,this.timeout=null,this._fulfilled=!1,this._successHandler=function(){},this._fulfillmentHandlers=[],this._errorHandlers=[],this._completeHandlers=[],this._erred=!1,this._responseArgs={};var self=this;fn=fn||function(){},o.timeout&&(this.timeout=setTimeout(function(){timedOut()},o.timeout)),o.success&&(this._successHandler=function(){o.success.apply(o,arguments)}),o.error&&this._errorHandlers.push(function(){o.error.apply(o,arguments)}),o.complete&&this._completeHandlers.push(function(){o.complete.apply(o,arguments)}),this.request=getRequest.call(this,success,error)}function reqwest(e,t){return new Reqwest(e,t)}function normalize(e){return e?e.replace(/\r?\n/g,"\r\n"):""}function serial(e,t){var n,r,s,o,i=e.name,a=e.tagName.toLowerCase(),l=function(e){e&&!e.disabled&&t(i,normalize(e.attributes.value&&e.attributes.value.specified?e.value:e.text))};if(!e.disabled&&i)switch(a){case"input":/reset|button|image|file/i.test(e.type)||(n=/checkbox/i.test(e.type),r=/radio/i.test(e.type),s=e.value,(!(n||r)||e.checked)&&t(i,normalize(n&&""===s?"on":s)));break;case"textarea":t(i,normalize(e.value));break;case"select":if("select-one"===e.type.toLowerCase())l(e.selectedIndex>=0?e.options[e.selectedIndex]:null);else for(o=0;e.length&&o0}),t.section=l.observable(null),t.has_section=l.computed(function(){return null!=t.section()&&""!=t.section()}),t.response=l.observable(null),l.computed(function(){var e=t.file(),n=t.section();if(null==e||null==n)return t.response(null);t.help("Loading..."),t.error(null),t.response(null),t.api_example(null);var r=new a.Embed(t.config);r.section(t.project(),"latest",t.file(),t.section(),function(e){t.help(null),t.error(null),t.api_example("var embed = Embed();\nembed.section(\n '"+t.project()+"', 'latest', '"+t.file()+"', '"+t.section()+"',\n function (section) {\n section.insertContent($('#help'));\n }\n);\n"),t.response(e)},function(e){t.help(null),t.error("There was a problem retrieving data from the API")})}),t.has_response=l.computed(function(){return null!=t.response()}),t.api_example=l.observable(null),t.show_help=function(){var e=new a.Embed;e.section("docs","latest","features/embed","Content Embedding",i)},t.show_embed=function(){new a.Embed;i(t.response())}}function o(e){var t=this;t.config=e||{},"undefined"==typeof t.config.api_host&&(t.config.api_host="https://readthedocs.org"),t.show_help=function(){var e=new a.Embed;e.section("docs","latest","business/analytics","Analytics",i)}}function i(e){var t=u("#embed-container");t.length||(t=u('