var profile_loaded = false; var questions_loaded = false; var set_title = true; var dataset_name = ''; var dataset_title = ''; var preview_document = null; var use_lawatlas_host = false; var startedQuerying = null; var isTouchSupported = 'ontouchstart' in window; var isTouchEnd = 'touchend' in window; var clickEvent = isTouchSupported && isTouchEnd ? 'touchend' : 'mouseup'; var mouseOutEvent = isTouchSupported && isTouchEnd ? '' : 'mouseout'; var mouseMoveEvent = isTouchSupported && isTouchEnd ? '' : 'mousemove'; var mouseOverEvent = isTouchSupported && isTouchEnd ? '' : 'mouseover'; $(document).ready(function () { $('.site-loading').show(); $.when( $.ajax( "/site/api" ), $.ajax( "/site/id" ) ).done(function( a1, a2 ) { monocle_host = a1[0]; set_title = true; dataset_name = getDatasetName(); $('#lead').html("description"); var stateQueryResult_alltime = []; var currentState = ''; //var monocle_url = monocle_host + 'preview/' + dataset_name; gpid = getPreviewId(); sview = loadPreviews_Data(); sview.done(function (sv) { //console.log("SV is loaded."); pview = asyncPreviewer(gpid); pview.done(function (pv) { loadDatasetPage(pv); $('.site-loading').hide(); dl = queryString('download'); if(typeof dl != 'undefined'){ if (dl !== 'false'){ window.open(dl,'_blank'); //window.location = dl; } } try { shared = queryString('do_get'); if(typeof shared != 'undefined'){ if (shared !== 'false'){ //window.open(dl,'_blank'); //window.location = dl; do_state = queryString('do_state'); if(typeof do_state != 'undefined'){ if (do_state !== 'false'){ //console.log("State query shared"); state = queryString('state'); dataset = queryString('dataset'); if (state !== 'false' && dataset !== 'false'){ //console.log(state); //console.log(dataset); state = {id: state, properties: {name: getStateName(state) }}; runQuery(state, dataset); states = [state.id]; highlightStates(states, map); } else { //console.log("False?"); } } } do_form = queryString('do_form'); if(typeof do_form != 'undefined'){ if (do_form !== 'false'){ //console.log("Full query shared"); $("a.compare_bold").click(); use_lawatlas = queryString('use_lawatlas'); if(typeof use_lawatlas != 'undefined' && use_lawatlas !== 'false'){ //console.log(use_lawatlas); use_lawatlas = true; } else { use_lawatlas = false; } setTimeout(function(){ $('.site-loading').show(); var re = /([^&=]+)=?([^&]*)/g; var decodeRE = /\+/g; // Regex for replacing addition symbol with a space var decode = function (str) {return decodeURIComponent( str.replace(decodeRE, " ") );}; $.parseParams = function(query) { var params = {}, e; while ( e = re.exec(query) ) { var k = decode( e[1] ), v = decode( e[2] ); if (k.substring(k.length - 2) === '[]') { k = k.substring(0, k.length - 2); (params[k] || (params[k] = [])).push(v); } else params[k] = v; } return params; }; queryObj = $.parseParams( location.search ); //url.split('?')[1] || '' ); //console.log(queryObj); _.each(queryObj, function(k, q){ console.log("------------------"); regExp = /\[([^\]]+)\]/; matches = regExp.exec(q); if(matches !== null){ //console.log(q); selection = matches[1]; //console.log(selection); /* if(k == "Yes"){ ksel = "Yes"; } else { ksel = eval(k); }*/ //console.log(k); ksel = k; //ksel = JSON.parse('"' + k + '"'); //console.log(ksel); if($.isArray(ksel)){ _.each(ksel, function(ks){ //setTimeout(function(){ $("a." + selection + '[data-value="' + ks + '"]').click(); //}, 500); }); } else { //setTimeout(function(){ $("a." + selection + '[data-value="' + ksel + '"]').click(); //}, 500); } //console.log(k); //console.log("------------------"); } else {} //console.log(matches); }); $('.site-loading').hide(); //submitQueryForm($("#filter-map-form"), use_lawatlas); }, 1000); setTimeout(function(){ submitQueryForm($("#filter-map-form"), use_lawatlas); }, 2000); //submitQueryForm(formobj, use_lawatlas) } } //console.log(location.search); } } //end of shared } catch(err) { console.log(err); } //$('.datamaps-hoverover').hide(); }); //end of loading the previewer }); //end of loading the site //SHARE $(".shareResults").on("click", function(e){ bitly = getBitly($(this).prop("href")); bitly.done(function (bitly_results) { //console.log("Bit.ly"); bitly_url = JSON.parse(bitly_results); //console.log(bitly_url); body = 'PDAPS | Share Results | ' + bitly_url.url + "\n\n"; $(".share-message").html(body); $("#share").val(body); $("#referrer").val(window.location.href); $('#shareModal').modal({}); //$("#bitly_url").val(bitly_url.url); }); e.preventDefault(); }); $(".shareStateResults").on("click", function(e){ bitly = getBitly($(this).prop("href")); bitly.done(function (bitly_results) { //console.log("Bit.ly"); bitly_url = JSON.parse(bitly_results); //console.log(bitly_url); body = 'PDAPS | Share Results | ' + bitly_url.url + "\n\n"; $(".share-message").html(body); $("#share").val(body); $("#referrer").val(window.location.href); $('#shareModal').modal({}); //$("#bitly_url").val(bitly_url.url); }); e.preventDefault(); }); // have to add click even this way because the button is created dynamically $(document).on('click', '#btnViewLaw', function () { $("#lawModal").modal('show'); }); $(document).on('click', '.show-law', function () { $("#lawModal").modal('show'); }); $(document).on('click', '.view-section', function () { $("#lawModal").modal('show'); }); $(document).on('click', '#btnViewTimeLine', function () { $('ul.nav-tabs li:eq(2) a').tab('show'); }); //view-law-table $(document).on('click', '.view-law-table', function () { zstate = $(this).data("state"); zid = $(this).data("id"); try { rzdata = submitQueryForm_rows[zid] pid = getPreviewId(); //WRONG!!!!! //console.log("WRONG WRONG WRONG"); //getPreviewer(pid); } catch(err){ rzdata = false; } decoded_questions = ''; if(rzdata){ decoded_questions = formatDisplayQuestions(rzdata, previewer.questions); } decoded = $('
').html($("."+zid).html()).text(); zbody = unescape(decoded); $("#law").html(zbody); $("#lawModal").modal('show'); }); $('#btnSelectStates').on('click', function(){ // this is how you select a state var states = ['PA', 'MD', 'VA', 'WV', 'DE', 'ID', 'NY', 'OH', 'MA', 'MN', 'CO','DC']; highlightStates(states); ////console.log('clicked') }); // TABS clicks - main routines // ======================================================================================== $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { //STATE TAB if(e.currentTarget.hash=="#profile") { /* this is a deadend */ //console.log("Use LawAtlas Host"); //console.log(preview_document[0].use_lawatlas_host); if(preview_document[0].use_lawatlas_host){ populateStateClicksTab(true); } else { populateStateClicksTab(); } //END of State-clicks tab map.resize(); $('.datamap svg').attr("height", 800); //console.log("Map and SVG resized on load."); } //QUESTIONS TAB else if(e.currentTarget.hash == "#messages") { //console.log("Use LawAtlas Host"); //console.log(preview_document[0].use_lawatlas_host); //console.log("Make the new MAP"); /**** mapper = new Mapper({canvas: "#mapper", onjurisdictionclick: function(jurisdiction){ state = {id:jurisdiction.code, properties: {name:jurisdiction.name}} mapClick(state) //console.log(jurisdiction) } }); *****/ if(preview_document[0].use_lawatlas_host){ populateQuestionAnswersTab(true); } else { populateQuestionAnswersTab(); } //END of Q&A tab } else if(e.currentTarget.hash == "#settings"){ populateTimelineTab(); } else { ////console.log("NOT FOUND"); } }); $('#btnClearStates').on('click', function(){ clearHighlightStates(); $("#stateProfile").html(""); //$("#queryHeading").html(""); $("#queryResults").html(""); }); $('.text-area').on('click', function(){ expandTextArea(this); }); $('#btnLoadForm').on('click', function(){ loadForm(); }); //end of /site/api, site/id }); $("#btnExportExcel").on("click" ,function (e) { monqcle_juris = $('.monqcle_juris').text(); var table_html = '"State","' + monqcle_juris + '",' + "\n"; $("tr.query-table-row").each(function() { $('td', this).each(function () { var cell = $(this); cell_html = ''; if(typeof cell.find('.state-query-answer').html() != 'undefined'){ //console.log(cell.find('.state-query-answer').html()); cell_html = '"' + cell.find('.state-query-answer').html() + '"'; } else { //console.log(cell.text()); cell_html = '"' + cell.text() + '"'; } table_html += cell_html + ", "; }); table_html += "\n"; }); csvData = 'data:application/csv;charset=utf-8,' + encodeURIComponent(table_html); filename = monqcle_juris + '-pdaps.csv'; $(this) .attr({ 'download': filename, 'href': csvData, 'target': '_blank' }); }); $("#btnExportPdf").on("click" ,function (e) { //window.open('data:application/vnd.ms-excel,' + $('#queryResults').html()); e.preventDefault(); }); $(".confirm-login").on("click",function (e) { //window.open('data:application/vnd.ms-excel,' + $('#queryResults').html()); var download = $(this).prop("href"); var terms = ` Except as expressly otherwise noted, all data, codebooks and protocols you download from PDAPS are made available to you in accordance with the Creative Commons Attribution-4.0 International License (https://creativecommons.org/licenses/by/4.0/) , as amended and updated by Creative Commons from time to time (“CC BY-4.0”), which is incorporated herein by this reference. The CC BY-4.0 License allows you to freely share and adapt pdaps.org content for any purpose, even commercial ones, provided that you give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. Appropriate Credit means, if supplied, you must provide the name of the creator and attribution parties, a copyright notice, a license notice, and a disclaimer notice. Notice: No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as publicity, privacy or moral rights may limit how you use the material. Please consult the CC BY-4.0. By clicking [OK], you acknowledge you have read and accepted these terms.`; $.ajax({ url: '/is_auth', method: 'GET', success: function (result) { //console.log("Authenticated?"); //console.log(result.authenticated); if(result.authenticated){ window.location = download; } else { window.location = "/signup?download=" + download + "&url=" + window.location.href; } } }); e.preventDefault(); /* if(!confirm(terms)){ e.preventDefault(); } */ }); }); function loadDatasetPage(pv){ //console.log("loadDatasetPage: function"); ////console.log(pv); //console.log("PV is loaded"); //previewer = JSON.parse(pv); previewer = pv; //console.log("previewer Object, linky dinky doodle"); //console.log(previewer); //console.log("can I pass something from this? "); //console.log(previewer); //console.log("document"); preview_document = previewer.document; //console.log("Use LawAtlas Host"); //console.log(preview_document[0].use_lawatlas_host); use_lawatlas_host = preview_document[0].use_lawatlas_host; if(use_lawatlas_host){ in_edit_mode = sessionStorage.getItem('in_edit_mode'); if(in_edit_mode == "true"){ //can't edit LawAtlas previews, must use LawAtlas //enableEditing(); sessionStorage.getItem('in_edit_mode', false); editModeToggle("off"); disableEditing(); $("#editModeText").html("Editing disabled "); $("#editModeWrapper").removeClass("text-primary").removeClass("text-warning").addClass("text-muted"); //console.log("can't edit LawAtlas previews, must use LawAtlas"); $("#editModeWrapper").attr("title", "LawAtlas previews must be editied in LawAtlas"); $("#editModeWrapper").tooltip({placement:"bottom"}); } } //always get it no_id_so_get_last = true; if(no_id_so_get_last) { pid = getPreviewId(); if(pid){ if(pid == "last") { //monocle_url = monocle_host + 'last/preview/' + dataset_name; } else { if(preview_document[0].use_lawatlas_host){ //monocle_url = monocle_host + 'previews/' + dataset_name + '/' + pid + '?use_lawatlas=true'; } else { //monocle_url = monocle_host + 'previews/' + dataset_name + '/' + pid; } } } else { //get the last preview you can find //monocle_url = monocle_host + 'last/preview/' + dataset_name; } } if (previewer.preview[0]) { $('#form_id').val(previewer.preview[0]._id['$id']); $('#description').html(previewer.preview[0].description); $('#sidebar').html(previewer.preview[0].sidebar); //sidebar_profile $('#curator').html(previewer.preview[0].sidebar_profile); if(previewer.preview[0].Preview){ $('.dataset_id').val(previewer.preview[0].Preview.dataset); $('#preview_id').val(previewer.preview[0].Preview.id); } $('#display_id').val(previewer.preview[0]._id['$id']); //console.log("What's the title?"); if(previewer.preview[0].title){ //console.log(previewer.preview[0].title); setTitle(previewer.preview[0].title); //console.log("Loaded title from previewer"); } else { //console.log(previewer.document[0].title); setTitle(previewer.document[0].title); //console.log("Loaded title from document"); //console.log(previewer.document); } //MonQcle-style datasets if(no_id_so_get_last){ //console.log("NOT calling getPreviewr, b/c: MonQcle-style datasets???"); } //console.log("Making files"); //console.log(monocle_host); if(previewer.preview[0].data_id !== undefined && previewer.preview[0].data_id != '') { $(".btn-lawatlas-data").prop("href", "http://monqcle-mark-dev.50status.com/upload/" + previewer.preview[0].data_id + "/download"); } else { if(previewer.preview[0].data_data !== undefined && previewer.preview[0].data_data != '') { $(".btn-lawatlas-data").prop("href", "http://lawatlas.org/files/upload/" + previewer.preview[0].data_data); } else { $(".btn-lawatlas-data").hide(); } } if(previewer.preview[0].codebook_id !== undefined && previewer.preview[0].codebook_id != '') //if it has "id" it comes from MonQcle { $(".btn-lawatlas-codebook").prop("href", "http://monqcle-mark-dev.50status.com/upload/" + previewer.preview[0].codebook_id + "/download"); } else { if(previewer.preview[0].data_codebook !== undefined && previewer.preview[0].data_codebook != '') { $(".btn-lawatlas-codebook").prop("href", "http://lawatlas.org/files/upload/" + previewer.preview[0].data_codebook); } else { $(".btn-lawatlas-codebook").hide(); } } if(previewer.preview[0].protocol_id !== undefined && previewer.preview[0].protocol_id != '') { //console.log("Found the protocol"); //console.log(previewer.preview[0].protocol_id); $(".btn-lawatlas-protocol").prop("href", "http://monqcle-mark-dev.50status.com/upload/" + previewer.preview[0].protocol_id + "/download"); } else { if(previewer.preview[0].data_protocol !== undefined && previewer.preview[0].data_protocol != '') { $(".btn-lawatlas-protocol").prop("href", "http://lawatlas.org/files/upload/" + previewer.preview[0].data_protocol); } else { $(".btn-lawatlas-protocol").hide(); } } if(previewer.preview[0].report_id !== undefined && previewer.preview[0].report_id != '') { $(".btn-lawatlas-report").prop("href", "http://monqcle-mark-dev.50status.com/upload/" + previewer.preview[0].report_id + "/download"); } else { if(previewer.preview[0].final_report !== undefined && previewer.preview[0].final_report != '') { $(".btn-lawatlas-report").prop("href", "http://lawatlas.org/files/upload/" + previewer.preview[0].final_report); } else { $(".btn-lawatlas-report").hide(); } } if(previewer.preview[0].end_year !== undefined && previewer.preview[0].end_year != '') { //SliderInput $("#form_end_year").val(previewer.preview[0].end_year); } if(previewer.preview[0].start_year !== undefined && previewer.preview[0].start_year != '') { //SliderInput $("#form_start_year").val(previewer.preview[0].start_year); } if(preview_document[0].use_lawatlas_host){ populateStateClicksTab(true); } else { populateStateClicksTab(); } map.resize(); $('.datamap svg').attr("height", 800); $('#container').attr("style", "position: relative;padding-bottom: 68.25%;"); //console.log("Map and SVG and .map_1 adjusted on load."); //$('.leaflet-control-container').removeClass('hide'); //$('#mapButtons').removeClass("hide"); $(".nav-pills").removeClass("hide"); $('#data_report_block').removeClass("hide"); $(".stateHeading").removeClass("hide"); //fix description walk($("#description").children()); //fix sidebar walk($("#sidebar").children()); //fix curator walk($("#curator").children()); } } function getDatasetName() { var dataset_name = location.pathname.match(/\/dataset\/overview\/(.*)/)[1]; var pathArray = window.location.pathname.split( '/' ); //console.log(pathArray); //console.log(pathArray[2]); dataset_name = pathArray[3]; return dataset_name; } function getPreviewId() { var dataset_name = location.pathname.match(/\/dataset\/overview\/(.*)/)[1]; var pathArray = window.location.pathname.split( '/' ); //console.log(pathArray); //console.log(pathArray[3]); dataset_id = pathArray[4]; if(dataset_id !== undefined) { return dataset_id; } else { return false; } }