Commit 792b80b46c376045a70dcfcc71f6e401615a3c09
Refactor server.py to have a function call to inject JS and CSS for
annotator.
- swtr/server.py 111 -----------------------------------------------------------------------------++++++++++++++++++++++++++++++++++
| | | | 138 | root.make_links_absolute(flask.request.args['where'], | 138 | root.make_links_absolute(flask.request.args['where'], |
---|
139 | resolve_base_href=True) | 139 | resolve_base_href=True) |
---|
140 | | 140 | |
---|
141 | jQuery = root.makeelement('script') | | jQuery = root.makeelement('script') |
---|
142 | root.body.append(jQuery) | | root.body.append(jQuery) |
---|
143 | jQuery.set("src", "//code.jquery.com/jquery-1.11.0.min.js") | | jQuery.set("src", "//code.jquery.com/jquery-1.11.0.min.js") |
---|
144 | jQuery.set("type", "text/javascript") | | jQuery.set("type", "text/javascript") |
---|
| | 141 | addScript("//code.jquery.com/jquery-1.11.0.min.js", root) | | | 142 | addScript(flask.url_for('static', filename="js/annotator-full.min.js"), |
---|
| | 143 | root) |
---|
145 | | 144 | |
---|
146 | annotatorScript = root.makeelement('script') | | annotatorScript = root.makeelement('script') |
---|
147 | root.body.append(annotatorScript) | | root.body.append(annotatorScript) |
---|
148 | annotatorScript.set("src", flask.url_for('static', | | annotatorScript.set("src", flask.url_for('static', |
---|
149 | filename= | | filename= |
---|
150 | "js/annotator-full.min.js")) | | "js/annotator-full.min.js")) |
---|
151 | annotatorScript.set("type", "text/javascript") | | annotatorScript.set("type", "text/javascript") |
---|
| | 145 | addCSS(flask.url_for('static', filename='css/annotator.min.css'), root) | | | 146 | addCSS(flask.url_for('static', filename='css/swtmaker.css'), root) |
---|
| | 147 | addCSS(flask.url_for('static', filename='css/bootstrap.min.css'), root) |
---|
| | 148 | addScript(flask.url_for('static', |
---|
| | 149 | filename="js/lib/underscore-1.5.2.min.js"), |
---|
| | 150 | root) |
---|
| | 151 | addScript(flask.url_for('static', |
---|
| | 152 | filename="js/lib/backbone-1.0.0.min.js"), |
---|
| | 153 | root) |
---|
| | 154 | addCSS(flask.url_for('static', filename='css/annotorious.css'), root) |
---|
| | 155 | addScript(flask.url_for('static', |
---|
| | 156 | filename="js/annotorious.okfn.0.3.js"), |
---|
| | 157 | root) |
---|
152 | | 158 | |
---|
153 | annotatorCSS = root.makeelement('link') | | annotatorCSS = root.makeelement('link') |
---|
154 | root.body.append(annotatorCSS) | | root.body.append(annotatorCSS) |
---|
155 | annotatorCSS.set("href", flask.url_for('static', | | annotatorCSS.set("href", flask.url_for('static', |
---|
156 | filename= | | filename= |
---|
157 | "css/annotator.min.css")) | | "css/annotator.min.css")) |
---|
158 | annotatorCSS.set("rel", "stylesheet") | | annotatorCSS.set("rel", "stylesheet") |
---|
159 | annotatorCSS.set("type", "text/css") | | annotatorCSS.set("type", "text/css") |
---|
160 | | | |
---|
161 | swtmakerCSS = root.makeelement('link') | | swtmakerCSS = root.makeelement('link') |
---|
162 | root.body.append(swtmakerCSS) | | root.body.append(swtmakerCSS) |
---|
163 | swtmakerCSS.set("href", flask.url_for('static', | | swtmakerCSS.set("href", flask.url_for('static', |
---|
164 | filename= | | filename= |
---|
165 | "css/swtmaker.css")) | | "css/swtmaker.css")) |
---|
166 | swtmakerCSS.set("rel", "stylesheet") | | swtmakerCSS.set("rel", "stylesheet") |
---|
167 | swtmakerCSS.set("type", "text/css") | | swtmakerCSS.set("type", "text/css") |
---|
168 | | | |
---|
169 | bootstrapCSS = root.makeelement('link') | | bootstrapCSS = root.makeelement('link') |
---|
170 | root.body.append(bootstrapCSS) | | root.body.append(bootstrapCSS) |
---|
171 | bootstrapCSS.set("href", flask.url_for('static', | | bootstrapCSS.set("href", flask.url_for('static', |
---|
172 | filename= | | filename= |
---|
173 | "css/bootstrap.min.css")) | | "css/bootstrap.min.css")) |
---|
174 | bootstrapCSS.set("rel", "stylesheet") | | bootstrapCSS.set("rel", "stylesheet") |
---|
175 | bootstrapCSS.set("type", "text/css") | | bootstrapCSS.set("type", "text/css") |
---|
176 | | | |
---|
177 | underscoreJS = root.makeelement('script') | | underscoreJS = root.makeelement('script') |
---|
178 | root.body.append(underscoreJS) | | root.body.append(underscoreJS) |
---|
179 | underscoreJS.set("src", flask.url_for('static', | | underscoreJS.set("src", flask.url_for('static', |
---|
180 | filename="js/lib/" + | | filename="js/lib/" + |
---|
181 | "underscore-1.5.2.min.js")) | | "underscore-1.5.2.min.js")) |
---|
182 | underscoreJS.set("type", "text/javascript") | | underscoreJS.set("type", "text/javascript") |
---|
183 | | | |
---|
184 | backboneJS = root.makeelement('script') | | backboneJS = root.makeelement('script') |
---|
185 | root.body.append(backboneJS) | | root.body.append(backboneJS) |
---|
186 | backboneJS.set("src", flask.url_for('static', | | backboneJS.set("src", flask.url_for('static', |
---|
187 | filename= | | filename= |
---|
188 | "js/lib/backbone-1.0.0.min.js")) | | "js/lib/backbone-1.0.0.min.js")) |
---|
189 | backboneJS.set("type", "text/javascript") | | backboneJS.set("type", "text/javascript") |
---|
190 | | | |
---|
191 | # annotorious plugin | | # annotorious plugin |
---|
192 | annotoriousCSS = root.makeelement('link') | | annotoriousCSS = root.makeelement('link') |
---|
193 | root.body.append(annotoriousCSS) | | root.body.append(annotoriousCSS) |
---|
194 | annotoriousCSS.set("href", flask.url_for('static', | | annotoriousCSS.set("href", flask.url_for('static', |
---|
195 | filename='css/annotorious.css')) | | filename='css/annotorious.css')) |
---|
196 | annotoriousCSS.set('rel', 'stylesheet') | | annotoriousCSS.set('rel', 'stylesheet') |
---|
197 | | | |
---|
198 | annotoriousJS = root.makeelement('script') | | annotoriousJS = root.makeelement('script') |
---|
199 | root.body.append(annotoriousJS) | | root.body.append(annotoriousJS) |
---|
200 | annotoriousJS.set('src', flask.url_for('static', | | annotoriousJS.set('src', flask.url_for('static', |
---|
201 | filename='js/annotorious.okfn.0.3.js')) | | filename='js/annotorious.okfn.0.3.js')) |
---|
202 | | | |
---|
203 | if 'auth_tok' in session: | 159 | if 'auth_tok' in session: |
---|
204 | auth_tok = session['auth_tok'] | 160 | auth_tok = session['auth_tok'] |
---|
205 | else: | 161 | else: |
---|
… | | … | |
---|
184 | config.redirect_uri) | 184 | config.redirect_uri) |
---|
185 | configScript.set("type", "text/javascript") | 185 | configScript.set("type", "text/javascript") |
---|
186 | | 186 | |
---|
187 | # swtmakerScript = root.makeelement('script') | | # swtmakerScript = root.makeelement('script') |
---|
188 | # root.body.append(swtmakerScript) | | # root.body.append(swtmakerScript) |
---|
189 | # swtmakerScript.set("src", flask.url_for('static', | | # swtmakerScript.set("src", flask.url_for('static', |
---|
190 | # filename="js/swtmaker.js")) | | # filename="js/swtmaker.js")) |
---|
191 | # swtmakerScript.set("type", "text/javascript") | | # swtmakerScript.set("type", "text/javascript") |
---|
| | 187 | addScript(flask.url_for('static', filename="js/oauth.js"), root) | 192 | | 188 | |
---|
193 | oAuthScript = root.makeelement('script') | | oAuthScript = root.makeelement('script') |
---|
194 | root.body.append(oAuthScript) | | root.body.append(oAuthScript) |
---|
195 | oAuthScript.set("src", flask.url_for('static', | | oAuthScript.set("src", flask.url_for('static', |
---|
196 | filename="js/oauth.js")) | | filename="js/oauth.js")) |
---|
197 | oAuthScript.set("type", "text/javascript") | | oAuthScript.set("type", "text/javascript") |
---|
| | 189 | addScript(flask.url_for('static', filename="js/app.js"), root) | 198 | | 190 | |
---|
199 | appScript = root.makeelement('script') | | appScript = root.makeelement('script') |
---|
200 | root.body.append(appScript) | | root.body.append(appScript) |
---|
201 | appScript.set("src", flask.url_for('static', | | appScript.set("src", flask.url_for('static', |
---|
202 | filename="js/app.js")) | | filename="js/app.js")) |
---|
203 | appScript.set("type", "text/javascript") | | appScript.set("type", "text/javascript") |
---|
204 | | | |
---|
205 | response = flask.make_response() | 191 | response = flask.make_response() |
---|
206 | response.data = lxml.html.tostring(root) | 192 | response.data = lxml.html.tostring(root) |
---|
207 | return response | 193 | return response |
---|
… | | … | |
---|
203 | refresh_token=auth_tok['refresh_token'], | 203 | refresh_token=auth_tok['refresh_token'], |
---|
204 | config=config, | 204 | config=config, |
---|
205 | url=flask.request.args.get('where')) | 205 | url=flask.request.args.get('where')) |
---|
| | 206 | |
---|
| | 207 | |
---|
| | 208 | def addScript(src, el): |
---|
| | 209 | script = el.makeelement('script') |
---|
| | 210 | el.body.append(script) |
---|
| | 211 | script.set("src", src) |
---|
| | 212 | script.set("type", "text/javascript") |
---|
| | 213 | |
---|
| | 214 | |
---|
| | 215 | def addCSS(src, el): |
---|
| | 216 | style = el.makeelement('link') |
---|
| | 217 | el.body.append(style) |
---|
| | 218 | style.set("href", src) |
---|
| | 219 | style.set("rel", "stylesheet") |
---|
| | 220 | style.set("type", "text/css") |
---|
206 | | 221 | |
---|
207 | | 222 | |
---|
208 | # if the app is run directly from command-line | 223 | # if the app is run directly from command-line |
---|