Skip to content

Commit

Permalink
Change how jquery.js and jquery.dataTables.js dependencies are handled.
Browse files Browse the repository at this point in the history
Includes the original source, rather than minified source.  Provides
a configuration option to select where file is loaded from.
  • Loading branch information
mdboom committed Jan 29, 2014
1 parent 4e69986 commit e611b56
Show file tree
Hide file tree
Showing 9 changed files with 22,536 additions and 183 deletions.
10,337 changes: 10,337 additions & 0 deletions astropy/extern/js/jquery-1.11.0.js

Large diffs are not rendered by default.

12,099 changes: 12,099 additions & 0 deletions astropy/extern/js/jquery.dataTables.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions astropy/extern/setup_package.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst


import os


def get_package_data():
paths = [os.path.join('js', '*.js')]
return {'astropy.extern': paths}


def requires_2to3():
return False
6 changes: 0 additions & 6 deletions astropy/table/data/jquery-1.10.2.min.js

This file was deleted.

157 changes: 0 additions & 157 deletions astropy/table/data/jquery.dataTables.min.js

This file was deleted.

57 changes: 40 additions & 17 deletions astropy/table/jsviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,29 @@
# images/ui-icons_888888_256x240.png
import os

data_path = os.path.join(os.path.abspath(os.path.dirname(__file__)),'data')
from ..config.configuration import ConfigurationItem
from .. import extern

JQUERY_URL = ConfigurationItem(
'jquery_url',
'file://' + os.path.abspath(
os.path.join(
os.path.dirname(extern.__file__), 'js', 'jquery-1.11.0.js')),
'URL to jquery.js')


DATATABLES_URL = ConfigurationItem(
'datatables_url',
'file://' + os.path.abspath(
os.path.join(
os.path.dirname(extern.__file__), 'js', 'jquery.dataTables.js')),
'datatables_url', None, 'URL to jquery.datatables.js')


data_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data')


ipynb_js_script = """
<script class="jsbin" src="{data_path}/jquery.dataTables.min.js"></script>
<script>
function html_repr_full() {{
var kernel = IPython.notebook.kernel;
Expand Down Expand Up @@ -42,6 +61,7 @@
<button id='MakeTableBrowseable{tid}' onclick="make_table_browseable()">Make Table Browseable</button>
"""


commandline_js_script = """
<script>
$(document).ready(function() {{
Expand All @@ -55,45 +75,48 @@
</script>
"""

class JSViewer(object):

class JSViewer(object):
def __init__(self,
css_files=['jquery-ui.css','demo_page.css','demo_table.css'],
css_files=['jquery-ui.css', 'demo_page.css', 'demo_table.css'],
display_length=50):
self.css_urls = ["file://"+os.path.join(data_path,c) for c in css_files]
self.css_urls = ["file://" + os.path.join(data_path, c) for c in css_files]
self.display_length_menu = [[10, 25, 50, 100, 500, 1000, -1],
[10, 25, 50, 100, 500, 1000, "All"]]
self.display_length = display_length
for L in self.display_length_menu:
if display_length not in L:
L.insert(0,display_length)
L.insert(0, display_length)

def _jquery_file(self):
# downloaded from http://ajax.googleapis.com/ajax/libs/jquery/1/
return '<script src="file://{data_path}/jquery-1.10.2.min.js"></script>'.format(data_path=data_path)
return '<script src="{0}"></script>'.format(JQUERY_URL())

def _jstable_file(self):
# downloaded from http://datatables.net/download/build/
return '<script class="jsbin" src="file://{data_path}/jquery.dataTables.min.js"></script>'.format(data_path=data_path)
return '<script class="jsbin" src="{0}"></script>'.format(DATATABLES_URL())

def _css_files(self):
return ['<link rel="stylesheet" href="{css}" type="text/css">'.format(css=css) for css in self.css_urls]
return [
'<link rel="stylesheet" href="{css}" type="text/css">'.format(css=css)
for css in self.css_urls]

def ipynb(self, tableid):
js = self._css_files()
js.append(self._jstable_file())
js.append(ipynb_js_script.format(display_length=self.display_length,
display_length_menu=self.display_length_menu,
tid=tableid,
data_path="file://"+data_path))
js.append(ipynb_js_script.format(
display_length=self.display_length,
display_length_menu=self.display_length_menu,
tid=tableid,
data_path="file://"+data_path))
return js

def command_line(self, tableid='table0'):
js = self._css_files()
js.append(self._jquery_file())
js.append(self._jstable_file())

js.append(commandline_js_script.format(display_length=self.display_length,
display_length_menu=self.display_length_menu,
tid=tableid))
js.append(commandline_js_script.format(
display_length=self.display_length,
display_length_menu=self.display_length_menu,
tid=tableid))
return js
4 changes: 1 addition & 3 deletions astropy/table/setup_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def get_extensions():
return [table_ext]

def get_package_data():
paths = [os.path.join('data', '*.js'),
os.path.join('data', '*.css'),
]
paths = [os.path.join('data', '*.css')]
return {'astropy.table': paths}

def requires_2to3():
Expand Down
29 changes: 29 additions & 0 deletions licenses/DATATABLES_LICENSE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Copyright (c) 2008-2013, Allan Jardine
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

Neither the name of Allan Jardine nor SpryMedia may be used to endorse
or promote products derived from this software without specific prior
written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21 changes: 21 additions & 0 deletions licenses/JQUERY_LICENSE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Copyright 2014 jQuery Foundation and other contributors
http://jquery.com/

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 comments on commit e611b56

Please sign in to comment.