B
    q\t                 @   s   d dl mZmZmZ ddlmZ d dlmZ d dl	m
Z d dl	mZ G dd dejZe Zeeeejd	Zeeeejd
ZdZdZdeeed Zee d ZdZdZG dd dZddddedfddZedee dS )    )abspathdirnamejoin   )Table)registry)config)externc               @   s:   e Zd ZdZeddZeddZejdgddd	Zd
S )Confz@
    Configuration parameters for `astropy.table.jsviewer`.
    z+https://code.jquery.com/jquery-3.1.1.min.jszThe URL to the jquery library.z>https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.jsz)The URL to the jquery datatables library.z<https://cdn.datatables.net/1.10.12/css/jquery.dataTables.cssz'The URLs to the css file(s) to include.list)ZcfgtypeN)	__name__
__module____qualname____doc___configZ
ConfigItem
jquery_urldatatables_urlcss_urls r   r   5lib/python3.7/site-packages/astropy/table/jsviewer.pyr
      s   r
   jscssad  
var astropy_sort_num = function(a, b) {{
    var a_num = parseFloat(a);
    var b_num = parseFloat(b);

    if (isNaN(a_num) && isNaN(b_num))
        return ((a < b) ? -1 : ((a > b) ? 1 : 0));
    else if (!isNaN(a_num) && !isNaN(b_num))
        return ((a_num < b_num) ? -1 : ((a_num > b_num) ? 1 : 0));
    else
        return isNaN(a_num) ? -1 : 1;
}}
z
jQuery.extend( jQuery.fn.dataTableExt.oSort, {{
    "optionalnum-asc": astropy_sort_num,
    "optionalnum-desc": function (a,b) {{ return -astropy_sort_num(a, b); }}
}});
a  
<script>
%(sorting_script1)s
require.config({{paths: {{
    datatables: '{datatables_url}'
}}}});
require(["datatables"], function(){{
    console.log("$('#{tid}').dataTable()");
    %(sorting_script2)s
    $('#{tid}').dataTable({{
        order: [],
        pageLength: {display_length},
        lengthMenu: {display_length_menu},
        pagingType: "full_numbers",
        columnDefs: [{{targets: {sort_columns}, type: "optionalnum"}}]
    }});
}});
</script>
)Zsorting_script1Zsorting_script2a  
$(document).ready(function() {{
    $('#{tid}').dataTable({{
        order: [],
        pageLength: {display_length},
        lengthMenu: {display_length_menu},
        pagingType: "full_numbers",
        columnDefs: [{{targets: {sort_columns}, type: "optionalnum"}}]
    }});
}} );
zbody {font-family: sans-serif;}
table.dataTable {width: auto !important; margin: 0 !important;}
.dataTables_filter, .dataTables_paginate {float: left !important; margin-left:1em}
ztable.dataTable {clear: both; width: auto !important; margin: 0 !important;}
.dataTables_info, .dataTables_length, .dataTables_filter, .dataTables_paginate{
display: inline-block; margin-right: 1em; }
.paginate_button { margin-right: 5px; }
c               @   sN   e Zd ZdZdddZedd Zedd	 Zd
d ZdddZ	dddZ
dS )JSViewera  Provides an interactive HTML export of a Table.

    This class provides an interface to the `DataTables
    <https://datatables.net/>`_ library, which allow to visualize interactively
    an HTML table. It is used by the `~astropy.table.Table.show_in_browser`
    method.

    Parameters
    ----------
    use_local_files : bool, optional
        Use local files or a CDN for JavaScript libraries. Default False.
    display_length : int, optional
        Number or rows to show. Default to 50.

    F2   c             C   sZ   || _ dddddddgdddddddgg| _|| _x"| jD ]}||kr:|d	| q:W d S )
N
      r   d   i  i  ZAllr   )_use_local_filesdisplay_length_menudisplay_lengthinsert)selfZuse_local_filesr    Lr   r   r   __init__}   s    zJSViewer.__init__c             C   s2   | j r"dttd dttd gS tjtjgS d S )Nzfile://zjquery-3.1.1.min.jszjquery.dataTables.min.js)r   r   EXTERN_JS_DIRconfr   r   )r"   r   r   r   jquery_urls   s    zJSViewer.jquery_urlsc             C   s    | j rdttd gS tjS d S )Nzfile://zjquery.dataTables.css)r   r   EXTERN_CSS_DIRr&   r   )r"   r   r   r   r      s    
zJSViewer.css_urlsc             C   s&   | j rdttd S tjd d S d S )Nzfile://zjquery.dataTables.min)r   r   r%   r&   r   )r"   r   r   r   _jstable_file   s    zJSViewer._jstable_fileN[]c             C   s:   d |d k	r|nt}|tj | j| j|  ||d7 }|S )Nz<style>{0}</style>)r    r   r   tidsort_columns)formatDEFAULT_CSS_NBIPYNB_JS_SCRIPTr    r   r*   )r"   table_idr   r-   htmlr   r   r   ipynb   s    zJSViewer.ipynbtable0c             C   s   t j| j| j||d S )N)r    r   r,   r-   )HTML_JS_SCRIPTr.   r    r   strip)r"   r1   r-   r   r   r   html_js   s    zJSViewer.html_js)Fr   )Nr+   )r4   r+   )r   r   r   r   r$   propertyr'   r   r*   r3   r7   r   r   r   r   r   l   s   
	

r   Ni  zdisplay compactc          	   C   s   |d krdj t| d}|pi }tf |}dd t| j D }	||||j|j|j||	dd}
|rp|
	| |t
| k r| d | } | j|d|
d d S )	Nz	table{id})idc             S   s    g | ]\}}|j jd kr|qS )Ziufc)ZdtypeZkind).0icolr   r   r   
<listcomp>   s    z(write_table_jsviewer.<locals>.<listcomp>)r1   r-   )r1   table_classr   ZcssfilesZjsfilesr   r2   )r.   htmldict)r.   r9   r   	enumeratecolumnsvaluesr   r'   r7   updatelenwrite)tablefilenamer1   Z	max_linesr>   Zjskwargsr   r?   ZjsvZsortable_columnsZhtml_optionsr   r   r   write_table_jsviewer   s     

rH   Zjsviewer)os.pathr   r   r   rF   r   Z
astropy.ior   Zio_registryZastropyr   r   r	   ZConfigNamespacer
   r&   __file__r%   r(   Z_SORTING_SCRIPT_PART_1Z_SORTING_SCRIPT_PART_2dictr0   r5   ZDEFAULT_CSSr/   r   rH   Zregister_writerr   r   r   r   <module>   s*   

	A