a
    ߙfb                     @   s   d dl mZmZmZ ddlmZ d dlm  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d	d
Zeeeejdd	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dfddZe	dee dS )    )abspathdirnamejoin   )TableN)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.Zstring_list)ZcfgtypeN)	__name__
__module____qualname____doc___configZ
ConfigItem
jquery_urldatatables_urlcss_urls r   r   5lib/python3.9/site-packages/astropy/table/jsviewer.pyr      s   r   Zjquerydata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   sB   || _ g dg dg| _|| _| jD ]}||vr$|d| q$d S )N)
      r   d       )r   r   r   r   r   r   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 )N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 )Nr%   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 )Nr%   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 ur|nt  d}|tj| j| j|  ||d7 }|S )Nz<style>z</style>)r    r   r   tidsort_columns)DEFAULT_CSS_NBIPYNB_JS_SCRIPTformatr    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_SCRIPTr2   r    r   strip)r"   r3   r/   r   r   r   html_js   s
    zJSViewer.html_js)Fr   )Nr-   )r6   r-   )r	   r
   r   r   r$   propertyr)   r   r,   r5   r9   r   r   r   r   r   l   s   
	


	r   i  zdisplay compactFc	              	   C   s   |d u rdt |  }|pi }tf i |}	dd t| j D }
||||	j|	j|	j||
dd}|rr|| |t	| k r| d | } | j
|d||d d S )Ntablec                 S   s"   g | ]\}}|j jjd v r|qS )Ziufc)infoZdtypekind).0icolr   r   r   
<listcomp>   s   z(write_table_jsviewer.<locals>.<listcomp>)r3   r/   )r3   table_classr   ZcssfilesZjsfilesr   r4   )r2   htmldict	overwrite)idr   	enumeratecolumnsvaluesr   r)   r9   updatelenwrite)r;   filenamer3   Z	max_linesrB   Zjskwargsr   rC   rD   ZjsvZsortable_columnsZhtml_optionsr   r   r   write_table_jsviewer   s&    

rM   Zjsviewer)os.pathr   r   r   r;   r   Zastropy.io.registryioregistryZio_registryZastropy.configZconfigr   Zastropyr   ZConfigNamespacer   r'   __file__r&   r*   Z_SORTING_SCRIPT_PART_1Z_SORTING_SCRIPT_PART_2dictr1   r7   ZDEFAULT_CSSr0   r   rM   Zregister_writerr   r   r   r   <module>   s0   @
