<commit_before>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs

//= require utf8_encode
//= require base64_encode

//= require helper

//= require plupload/moxie
//= require plupload/plupload.full.min
//= require plupload/i18n/zh_CN

//= require jquery.percentageloader-0.1

$(function() {

  // Upload page
  var $loader = $("#loader").percentageLoader({
    width: 256,
    height: 256,
    controllable : false,
    progress : 0,
    onProgressUpdate : function(val) {
      $loader.setValue(Math.round(val * 100.0));
    }
  });

  if($loader.size()){
    var uploader = new plupload.Uploader({
      runtimes : 'html5', //,flash,silverlight,html4
      browse_button : 'loader', // you can pass in id...
      // drop_element: 'body',
      multi_selection: false,
      // container: document.getElementById('container'), // ... or DOM Element itself
      url : "http://upload.qiniu.com/",

      filters : {
        // max_file_size : '10mb'
      },
      multipart_params: {
        token: $('#uptoken').val()
      }
    });

    uploader.bind("FilesAdded", function(up, files) {
      $loader.setValue(plupload.formatSize(files.slice(-1)[0].size));
      up.start();
    });

    // Fires when a file is successfully uploaded.
    uploader.bind("FileUploaded", function(up, file, result) {
      var response = jQuery.parseJSON(result.response);
      $.post( "/file", { hash: response.hash, key: response.key }, function(url){
        // similar behavior as an HTTP redirect
        window.location.replace(url);
        // similar behavior as clicking on a link
        // window.location.href = url;
      });
    });

    uploader.bind("UploadProgress", function(up, file) {
      $loader.setProgress(file.percent / 100);
    });

    uploader.bind("Error", function(up, err) {
      alert("Error #" + err.code + ":\n" + err.message);
    });

    uploader.init();
  }

  // Download page
  var $downloader = $("#downloader").percentageLoader({
    width: 256,
    height: 256,
    controllable : false,
    progress : 0,
    onProgressUpdate : function(val) {
      $downloader.setValue(Math.round(val * 100.0));
    }
  });

  if($downloader.size()){
    var deadline = $downloader.data('deadline');
    var fsize = $downloader.data('fsize')

    $downloader.setValue(plupload.formatSize(fsize));

    var interval = setInterval(function(){
      var current = new Date();

      var percent = (deadline - current.getTime()/1000) / (60 * 30);
          percent = Math.round(percent*100)/100

      $downloader.setProgress( percent );
    }, 1000);
  }

});<commit_msg>Update application.js<commit_after>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs

//= require utf8_encode
//= require base64_encode

//= require helper

//= require plupload/moxie
//= require plupload/plupload.full.min
//= require plupload/i18n/zh_CN

//= require jquery.percentageloader-0.1

$(function() {

  // Upload page
  var $loader = $("#loader").percentageLoader({
    width: 256,
    height: 256,
    controllable : false,
    progress : 0
  });

  if($loader.size()){
    var uploader = new plupload.Uploader({
      runtimes : 'html5', //,flash,silverlight,html4
      browse_button : 'loader', // you can pass in id...
      // drop_element: 'body',
      multi_selection: false,
      // container: document.getElementById('container'), // ... or DOM Element itself
      url : "http://upload.qiniu.com/",

      filters : {
        // max_file_size : '10mb'
      },
      multipart_params: {
        token: $('#uptoken').val()
      }
    });

    uploader.bind("FilesAdded", function(up, files) {
      $loader.setValue(plupload.formatSize(files.slice(-1)[0].size));
      up.start();
    });

    // Fires when a file is successfully uploaded.
    uploader.bind("FileUploaded", function(up, file, result) {
      var response = jQuery.parseJSON(result.response);
      $.post( "/file", { hash: response.hash, key: response.key }, function(url){
        // similar behavior as an HTTP redirect
        window.location.replace(url);
        // similar behavior as clicking on a link
        // window.location.href = url;
      });
    });

    uploader.bind("UploadProgress", function(up, file) {
      $loader.setProgress(file.percent / 100);
    });

    uploader.bind("Error", function(up, err) {
      alert("Error #" + err.code + ":\n" + err.message);
    });

    uploader.init();
  }

  // Download page
  var $downloader = $("#downloader").percentageLoader({
    width: 256,
    height: 256,
    controllable : false,
    progress : 100
  });

  if($downloader.size()){
    var deadline = $downloader.data('deadline');
    var fsize = $downloader.data('fsize')

    $downloader.setValue(plupload.formatSize(fsize));

    var updateDownloaderProgress = function(){
      var current = new Date();
      var percent = (deadline - current.getTime()/1000) / (60 * 30);
          percent = Math.round(percent*100)/100
      $downloader.setProgress( percent );
    }

    updateDownloaderProgress();

    var interval = setInterval(updateDownloaderProgress, 1000);
  }

});<|endoftext|>


<commit_before>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .

//= require bootstrap/dist/js/bootstrap.min

$(document).on('ready page:load', function(){
  $('form.fetch-url').on('ajax:success', function(e, data, status, xhr){
    $(this).siblings('input.url').val(data["presigned_url"]);
  }).on('ajax:error', function(e, xhr, status, error){
    alert('Failed.');
  });
})
<commit_msg>Fix bug<commit_after>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .

//= require bootstrap/dist/js/bootstrap.min

$(document).on('ready page:load', function(){
  $(document).on('ajax:success', 'form.fetch-url', function(e, data, status, xhr){
    $(this).siblings('input.url').val(data["presigned_url"]);
  });

  $(document).on('ajax:error', 'form.fetch-url', function(e, data, status, xhr){
    $(this).siblings('input.url').val(data["presigned_url"]);
    alert('Failed.');
  });
})
<|endoftext|>


<commit_before>/*
  The following comments are parsed by Gulp include
  (https://www.npmjs.com/package/gulp-include) which uses
  Sprockets-style (https://github.com/sstephenson/sprockets)
  directives to concatenate multiple Javascript files into one.
*/
//= include ../../../node_modules/govuk_frontend_toolkit/javascripts/vendor/polyfills/bind.js
//= include ../../../node_modules/jquery/dist/jquery.js
//= include ../../../node_modules/hogan.js/web/builds/3.0.2/hogan-3.0.2.js
//= include ../../../node_modules/scrolldepth/jquery.scrolldepth.js
//= include ../../../node_modules/digitalmarketplace-frontend-toolkit/toolkit/javascripts/option-select.js
//= include ../../../node_modules/digitalmarketplace-frontend-toolkit/toolkit/javascripts/support.js
//= include ../../../node_modules/digitalmarketplace-frontend-toolkit/toolkit/javascripts/live-search.js
//= include ../../../node_modules/digitalmarketplace-frontend-toolkit/toolkit/javascripts/list-entry.js
//= include ../../../node_modules/digitalmarketplace-frontend-toolkit/toolkit/javascripts/clear-filters.js
//= include ../../../node_modules/digitalmarketplace-frontend-toolkit/toolkit/javascripts/word-counter.js
//= include ../../../node_modules/digitalmarketplace-frontend-toolkit/toolkit/javascripts/validation.js
//= include ../../../node_modules/digitalmarketplace-frontend-toolkit/toolkit/javascripts/report-a-problem.js
//= include ../../../node_modules/govuk_frontend_toolkit/javascripts/govuk/selection-buttons.js
//= include ../../../node_modules/govuk_frontend_toolkit/javascripts/govuk/shim-links-with-button-role.js
//= include ../../../node_modules/digitalmarketplace-frontend-toolkit/toolkit/javascripts/shim-links-with-button-role.js
//= include ../../../node_modules/digitalmarketplace-frontend-toolkit/toolkit/javascripts/show-hide-content.js
//= include _analytics.js'
//= include _onready.js'
//= include _selection-buttons.js

(function(GOVUK, GDM) {

  "use strict";

  var module;

  if(typeof console === 'undefined') {
    console = {
      log: function () {},
      time: function () {},
      timeEnd: function () {}
    };
  }

  if (
    (GDM.debug = !window.location.href.match(/gov.uk/) && !window.jasmine)
  ) {
    console.log(
      "%cDebug mode %cON",
      "color:#550; background:yellow; font-size: 11pt",
      "color:yellow; background: #550;font-size:11pt"
    );
    if (typeof console.time !== "undefined") console.time("Modules loaded");
  }

  // Initialise our modules
  for (module in GDM) {

    if (GDM.debug && module !== "debug") {
      console.log(
        "%cLoading module %c" + module,
        "color:#6a6; background:#dfd; font-size: 11pt",
        "color:#dfd; background:green; font-size: 11pt"
      );
    }

    if ("function" === typeof GDM[module].init) {
      // If a module has an init() method then we want that to be called here
      GDM[module].init();
    } else if ("function" === typeof GDM[module]) {
      // If a module doesn't have an interface then call it directly
      GDM[module]();
    }

  }

  GOVUK.GDM = GDM;

  if (GDM.debug && typeof console.timeEnd !== "undefined") console.timeEnd("Modules loaded");

}).apply(this, [GOVUK||{}, GOVUK.GDM||{}]);
<commit_msg>Use "require" instead of "include" to load once only<commit_after>/*
  The following comments are parsed by Gulp include
  (https://www.npmjs.com/package/gulp-include) which uses
  Sprockets-style (https://github.com/sstephenson/sprockets)
  directives to concatenate multiple Javascript files into one.
*/
//= require ../../../node_modules/govuk_frontend_toolkit/javascripts/vendor/polyfills/bind.js
//= require ../../../node_modules/jquery/dist/jquery.js
//= require ../../../node_modules/hogan.js/web/builds/3.0.2/hogan-3.0.2.js
//= require ../../../node_modules/scrolldepth/jquery.scrolldepth.js
//= require ../../../node_modules/digitalmarketplace-frontend-toolkit/toolkit/javascripts/option-select.js
//= require ../../../node_modules/digitalmarketplace-frontend-toolkit/toolkit/javascripts/support.js
//= require ../../../node_modules/digitalmarketplace-frontend-toolkit/toolkit/javascripts/live-search.js
//= require ../../../node_modules/digitalmarketplace-frontend-toolkit/toolkit/javascripts/list-entry.js
//= require ../../../node_modules/digitalmarketplace-frontend-toolkit/toolkit/javascripts/clear-filters.js
//= require ../../../node_modules/digitalmarketplace-frontend-toolkit/toolkit/javascripts/word-counter.js
//= require ../../../node_modules/digitalmarketplace-frontend-toolkit/toolkit/javascripts/validation.js
//= require ../../../node_modules/digitalmarketplace-frontend-toolkit/toolkit/javascripts/report-a-problem.js
//= require ../../../node_modules/govuk_frontend_toolkit/javascripts/govuk/selection-buttons.js
//= require ../../../node_modules/govuk_frontend_toolkit/javascripts/govuk/shim-links-with-button-role.js
//= require ../../../node_modules/digitalmarketplace-frontend-toolkit/toolkit/javascripts/shim-links-with-button-role.js
//= require ../../../node_modules/digitalmarketplace-frontend-toolkit/toolkit/javascripts/show-hide-content.js
//= require _analytics.js'
//= require _onready.js'
//= require _selection-buttons.js

(function(GOVUK, GDM) {

  "use strict";

  var module;

  if(typeof console === 'undefined') {
    console = {
      log: function () {},
      time: function () {},
      timeEnd: function () {}
    };
  }

  if (
    (GDM.debug = !window.location.href.match(/gov.uk/) && !window.jasmine)
  ) {
    console.log(
      "%cDebug mode %cON",
      "color:#550; background:yellow; font-size: 11pt",
      "color:yellow; background: #550;font-size:11pt"
    );
    if (typeof console.time !== "undefined") console.time("Modules loaded");
  }

  // Initialise our modules
  for (module in GDM) {

    if (GDM.debug && module !== "debug") {
      console.log(
        "%cLoading module %c" + module,
        "color:#6a6; background:#dfd; font-size: 11pt",
        "color:#dfd; background:green; font-size: 11pt"
      );
    }

    if ("function" === typeof GDM[module].init) {
      // If a module has an init() method then we want that to be called here
      GDM[module].init();
    } else if ("function" === typeof GDM[module]) {
      // If a module doesn't have an interface then call it directly
      GDM[module]();
    }

  }

  GOVUK.GDM = GDM;

  if (GDM.debug && typeof console.timeEnd !== "undefined") console.timeEnd("Modules loaded");

}).apply(this, [GOVUK||{}, GOVUK.GDM||{}]);
<|endoftext|>


<commit_before>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear in whatever order it
// gets included (e.g. say you have require_tree . then the code will appear after all the directories
// but before any files alphabetically greater than 'application.js'
//
// The available directives right now are require, require_directory, and require_tree
//
//= require ../components/jquery/jquery.min.js
//= require ../components/bootstrap/dist/js/bootstrap.min.js
//= require ../components/spin.js/spin.js
//= require ../components/spin.js/jquery.spin.js
//= require_tree .
var frm = $('#big-search');
$('#big-search').submit(function (ev) {
	frm.find('input[name="facet"]').val('');

						var opts = {
						lines: 13, // The number of lines to draw
						length: 20, // The length of each line
						width: 10, // The line thickness
						radius: 30, // The radius of the inner circle
						corners: 1, // Corner roundness (0..1)
						rotate: 0, // The rotation offset
						direction: 1, // 1: clockwise, -1: counterclockwise
						color: '#000', // #rgb or #rrggbb or array of colors
						speed: 1, // Rounds per second
						trail: 60, // Afterglow percentage
						shadow: false, // Whether to render a shadow
						hwaccel: false, // Whether to use hardware acceleration
						className: 'spinner', // The CSS class to assign to the spinner
						zIndex: 2e9, // The z-index (defaults to 2000000000)
						top: '200', // Top position relative to parent in px
						left: 'auto' // Left position relative to parent in px
						};
						var target = document.getElementById('results-row');
						var spinner = new Spinner(opts).spin(target);

	$.ajax({
		type: frm.attr('method'),
		url: frm.attr('action'),
		data: frm.serialize(),
		dataType: "json",
		success: function (data) {
			spinner.stop();
			$( ".results" ).replaceWith(data.results);
			$( ".list-group-facets" ).replaceWith(data.facets);

			$('#results').on('click', 'a', function(event){
				        event.preventDefault()
				        $('#myModal').removeData("modal")
				        $('#myModal').modal({remote: $(this).attr("href")})
			});

		   $('#myModal').on('hidden.bs.modal', function () {
				$(this).removeData("bs.modal")
			})

			$('#facets-list').on('click', 'a', function(){

				$('#facets-list').children().has("a").each(function(){
					$(this).children().each(function(){
						$(this).children().each(function(){
							$(this).removeClass("active");
						});
					});
				});

				$(this).addClass("active");

				var clickedFacetValue = $(this).attr("id");
				var currentFacetValue = frm.find('input[name="facet"]').val();
				if (clickedFacetValue === currentFacetValue) {
					console.log('Reset to base query');
					frm.find('input[name="facet"]').val('');
				} else {
					frm.find('input[name="facet"]').val(clickedFacetValue);
				}

				var opts = {
				lines: 13, // The number of lines to draw
				length: 20, // The length of each line
				width: 10, // The line thickness
				radius: 30, // The radius of the inner circle
				corners: 1, // Corner roundness (0..1)
				rotate: 0, // The rotation offset
				direction: 1, // 1: clockwise, -1: counterclockwise
				color: '#000', // #rgb or #rrggbb or array of colors
				speed: 1, // Rounds per second
				trail: 60, // Afterglow percentage
				shadow: false, // Whether to render a shadow
				hwaccel: false, // Whether to use hardware acceleration
				className: 'spinner', // The CSS class to assign to the spinner
				zIndex: 2e9, // The z-index (defaults to 2000000000)
				top: '200', // Top position relative to parent in px
				left: 'auto' // Left position relative to parent in px
				};
				var target = document.getElementById('results-row');
				var spinner = new Spinner(opts).spin(target);

								 $.ajax({
										type: frm.attr('method'),
										url: frm.attr('action'),
										data: frm.serialize(),
										dataType: "json",
										success: function (data) {
											spinner.stop();
											$( ".results" ).replaceWith(data.results);

											$('#results').on('click', 'a', function(event){
				        						event.preventDefault()
				        						$('#myModal').removeData("modal")
				        						$('#myModal').modal({remote: $(this).attr("href")})
												});

		  									 $('#myModal').on('hidden.bs.modal', function () {
											$(this).removeData("bs.modal")
											})

										}
								});

				});
			}
	});
	ev.preventDefault();
});<commit_msg>#28 facet deselecting fix<commit_after>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear in whatever order it
// gets included (e.g. say you have require_tree . then the code will appear after all the directories
// but before any files alphabetically greater than 'application.js'
//
// The available directives right now are require, require_directory, and require_tree
//
//= require ../components/jquery/jquery.min.js
//= require ../components/bootstrap/dist/js/bootstrap.min.js
//= require ../components/spin.js/spin.js
//= require ../components/spin.js/jquery.spin.js
//= require_tree .
var frm = $('#big-search');
$('#big-search').submit(function (ev) {
	frm.find('input[name="facet"]').val('');

						var opts = {
						lines: 13, // The number of lines to draw
						length: 20, // The length of each line
						width: 10, // The line thickness
						radius: 30, // The radius of the inner circle
						corners: 1, // Corner roundness (0..1)
						rotate: 0, // The rotation offset
						direction: 1, // 1: clockwise, -1: counterclockwise
						color: '#000', // #rgb or #rrggbb or array of colors
						speed: 1, // Rounds per second
						trail: 60, // Afterglow percentage
						shadow: false, // Whether to render a shadow
						hwaccel: false, // Whether to use hardware acceleration
						className: 'spinner', // The CSS class to assign to the spinner
						zIndex: 2e9, // The z-index (defaults to 2000000000)
						top: '200', // Top position relative to parent in px
						left: 'auto' // Left position relative to parent in px
						};
						var target = document.getElementById('results-row');
						var spinner = new Spinner(opts).spin(target);

	$.ajax({
		type: frm.attr('method'),
		url: frm.attr('action'),
		data: frm.serialize(),
		dataType: "json",
		success: function (data) {
			spinner.stop();
			$( ".results" ).replaceWith(data.results);
			$( ".list-group-facets" ).replaceWith(data.facets);

			$('#results').on('click', 'a', function(event){
				        event.preventDefault()
				        $('#myModal').removeData("modal")
				        $('#myModal').modal({remote: $(this).attr("href")})
			});

		   $('#myModal').on('hidden.bs.modal', function () {
				$(this).removeData("bs.modal")
			})

			$('#facets-list').on('click', 'a', function(){

				var addActive = true
				var classList =$(this).attr('class').split(/\s+/);
				$.each( classList, function(index, item){
				    console.log(item);
					if (item === 'active') {
				       addActive = false;
				    }
				});

				$('#facets-list').children().has("a").each(function(){
					$(this).children().each(function(){
						$(this).children().each(function(){
							$(this).removeClass("active");
						});
					});
				});

				if (addActive) {
					$(this).addClass("active");
				}

				var clickedFacetValue = $(this).attr("id");
				var currentFacetValue = frm.find('input[name="facet"]').val();
				if (clickedFacetValue === currentFacetValue) {
					console.log('Reset to base query');
					frm.find('input[name="facet"]').val('');
				} else {
					frm.find('input[name="facet"]').val(clickedFacetValue);
				}

				var opts = {
				lines: 13, // The number of lines to draw
				length: 20, // The length of each line
				width: 10, // The line thickness
				radius: 30, // The radius of the inner circle
				corners: 1, // Corner roundness (0..1)
				rotate: 0, // The rotation offset
				direction: 1, // 1: clockwise, -1: counterclockwise
				color: '#000', // #rgb or #rrggbb or array of colors
				speed: 1, // Rounds per second
				trail: 60, // Afterglow percentage
				shadow: false, // Whether to render a shadow
				hwaccel: false, // Whether to use hardware acceleration
				className: 'spinner', // The CSS class to assign to the spinner
				zIndex: 2e9, // The z-index (defaults to 2000000000)
				top: '200', // Top position relative to parent in px
				left: 'auto' // Left position relative to parent in px
				};
				var target = document.getElementById('results-row');
				var spinner = new Spinner(opts).spin(target);

								 $.ajax({
										type: frm.attr('method'),
										url: frm.attr('action'),
										data: frm.serialize(),
										dataType: "json",
										success: function (data) {
											spinner.stop();
											$( ".results" ).replaceWith(data.results);

											$('#results').on('click', 'a', function(event){
				        						event.preventDefault()
				        						$('#myModal').removeData("modal")
				        						$('#myModal').modal({remote: $(this).attr("href")})
												});

		  									 $('#myModal').on('hidden.bs.modal', function () {
											$(this).removeData("bs.modal")
											})

										}
								});

				});
			}
	});
	ev.preventDefault();
});<|endoftext|>


<commit_before>//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= require_tree .

document.addEventListener("turbolinks:load", function() {
  $('.archive').click(function() {
    loadTurbolinksArchiveURL(this, 'archive')
  });
  $('.unarchive').click(function() {
    loadTurbolinksArchiveURL(this, 'unarchive')
  });
  $('.toggle-star').click(function() {
    $(this).toggleClass("star-active star-inactive")
    $.get('/notifications/'+$(this).data('id')+'/star')
  });
  $('.sync .octicon').on('click', function() {
    $(this).toggleClass('spinning')
  });
  recoverPreviousCursorPosition()
});

document.addEventListener("turbolinks:before-cache", function() {
  $('td.current').removeClass("current");
});

// Add shortcut events only once
$(document).ready(enableKeyboardShortcuts);

$(document).on('click', '[data-toggle="offcanvas"]', function () {
  $('.row-offcanvas').toggleClass('active')
});

if(!('ontouchstart' in window))
{
  $(function () {
    $('[data-toggle="tooltip"]').tooltip()
  })
}

function enableKeyboardShortcuts() {
  window.row_index = 1

  $(document).keydown(function(e) {
    var shortcutFunction = shortcuts[e.which]
    if (shortcutFunction) { shortcutFunction(e) }
  });
}

var shortcuts = {
  74:  cursorDown,      // j
  75:  cursorUp,        // k
  83:  toggleStar,      // s
  89:  archive,         // y
  13:  openCurrentLink, // Enter
  79:  openCurrentLink, // o
  191: openModal,       // ?
  190: sync,            // .
  82:  sync             // r
}

function cursorDown() {
  moveCursor('up')
}

function cursorUp() {
  moveCursor('down')
}

function archive() {
  clickCurrentRow('.archive')
}

function toggleStar() {
  clickCurrentRow('.toggle-star')
}

function openModal() {
  $("#help-box").modal();
}

function openCurrentLink(e) {
  e.preventDefault(e);
  $('td.current').parent().find('.link')[0].click();
}

function sync() {
  $("a.sync").click();
}

function clickCurrentRow(cssClass) {
  $('td.current').parent().find(cssClass).click();
}

function moveCursor(upOrDown) {
  var current = $('td.current');
  var parent = $(current).parent()
  var target = nextOrPrev === 'up' ? parent.next() : parent.prev()
  if(target.length > 0) {
    $(current).removeClass("current");
    $(target).find('td').first().addClass("current");
    row_index += nextOrPrev === 'up' ? 1 : -1;
  }
}

function recoverPreviousCursorPosition() {
  row_index = Math.min(row_index, $(".table-notifications tr").length);
  row_index = Math.max(row_index, 1);
  $(".table-notifications tbody tr:nth-child(" + row_index + ")").first().find("td").first().addClass("current");
}

function loadTurbolinksArchiveURL(link, route) {
  Turbolinks.visit('/notifications/'+$(link).val()+'/'+route+location.search)
}
<commit_msg>Fix cursor navigation<commit_after>//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= require_tree .

document.addEventListener("turbolinks:load", function() {
  $('.archive').click(function() {
    loadTurbolinksArchiveURL(this, 'archive')
  });
  $('.unarchive').click(function() {
    loadTurbolinksArchiveURL(this, 'unarchive')
  });
  $('.toggle-star').click(function() {
    $(this).toggleClass("star-active star-inactive")
    $.get('/notifications/'+$(this).data('id')+'/star')
  });
  $('.sync .octicon').on('click', function() {
    $(this).toggleClass('spinning')
  });
  recoverPreviousCursorPosition()
});

document.addEventListener("turbolinks:before-cache", function() {
  $('td.current').removeClass("current");
});

// Add shortcut events only once
$(document).ready(enableKeyboardShortcuts);

$(document).on('click', '[data-toggle="offcanvas"]', function () {
  $('.row-offcanvas').toggleClass('active')
});

if(!('ontouchstart' in window))
{
  $(function () {
    $('[data-toggle="tooltip"]').tooltip()
  })
}

function enableKeyboardShortcuts() {
  window.row_index = 1

  $(document).keydown(function(e) {
    var shortcutFunction = shortcuts[e.which]
    if (shortcutFunction) { shortcutFunction(e) }
  });
}

var shortcuts = {
  74:  cursorDown,      // j
  75:  cursorUp,        // k
  83:  toggleStar,      // s
  89:  archive,         // y
  13:  openCurrentLink, // Enter
  79:  openCurrentLink, // o
  191: openModal,       // ?
  190: sync,            // .
  82:  sync             // r
}

function cursorDown() {
  moveCursor('up')
}

function cursorUp() {
  moveCursor('down')
}

function archive() {
  clickCurrentRow('.archive')
}

function toggleStar() {
  clickCurrentRow('.toggle-star')
}

function openModal() {
  $("#help-box").modal();
}

function openCurrentLink(e) {
  e.preventDefault(e);
  $('td.current').parent().find('.link')[0].click();
}

function sync() {
  $("a.sync").click();
}

function clickCurrentRow(cssClass) {
  $('td.current').parent().find(cssClass).click();
}

function moveCursor(upOrDown) {
  var current = $('td.current');
  var parent = $(current).parent()
  var target = upOrDown === 'up' ? parent.next() : parent.prev()
  if(target.length > 0) {
    $(current).removeClass("current");
    $(target).find('td').first().addClass("current");
    row_index += upOrDown === 'up' ? 1 : -1;
  }
}

function recoverPreviousCursorPosition() {
  row_index = Math.min(row_index, $(".table-notifications tr").length);
  row_index = Math.max(row_index, 1);
  $(".table-notifications tbody tr:nth-child(" + row_index + ")").first().find("td").first().addClass("current");
}

function loadTurbolinksArchiveURL(link, route) {
  Turbolinks.visit('/notifications/'+$(link).val()+'/'+route+location.search)
}
<|endoftext|>


<commit_before>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .

$(document).on('ready page:load', function() {

  $(".vote-button").bind("click", function(ev) {
    ev.preventDefault();
    var self = $(this);

    // Vote data is stored on the element as "VoteType/PostId/PostType/VoteId".
    var vote = self.data("vote");
    var voteSplat = vote.split("/");
    var state = {
      voteType: voteSplat[0],
      postId: voteSplat[1],
      postType: voteSplat[2],
      voteId: voteSplat[3],
      target: self
    };

    console.log(state);

    if(state.voteId > -1) {
      // We've already voted; cancel the vote.
      console.log("deleting vote");
      $.ajax({
        'url': '/votes/' + state.voteId,
        'type': 'DELETE',
        'state': state
      })
      .done(function(data) {
        if(data['status'] === "OK") {
          $(this.state.target).attr('src', '/assets/' + (this.state.voteType == '1' ? 'up' : 'down') + '-clear.png');
          $(this.state.target).data('vote', this.state.voteType + '/' + this.state.postId + '/' + this.state.postType + '/-1');
          $(this.state.target).parent().siblings('.post-score').text(data['post_score']);
        }
        else {
          alert("Could not undo vote - please try again. Message: " + data);
          console.error("Vote undo failed: " + data);
        }
      })
      .fail(function(jqXHR, textStatus, errorThrown) {
        alert("Could not undo vote - please try again. Message: " + jqXHR.reponseText);
        console.error("Vote undo failed: status " + jqXHR.status);
        console.log(jqXHR);
      });
    }
    else {
      // We have yet to vote, so cast one.
      console.log("creating vote");
      $.ajax({
        'url': '/votes/new',
        'type': 'POST',
        'data': {
          'post_type': state.postType,
          'post_id': state.postId,
          'vote_type': state.voteType
        },
        'state': state
      })
      .done(function(data) {
        if(data['status'] == "OK") {
          $(this.state.target).attr('src', '/assets/' + (this.state.voteType == '1' ? 'up' : 'down') + '-fill.png');
          $(this.state.target).data('vote', this.state.voteType + '/' + this.state.postId + '/' + this.state.postType + '/' + data['vote_id']);
          $(this.state.target).parent().siblings('.post-score').text(data['post_score']);
        }
        else if(data['status'] == "modified") {
          $(this.state.target).attr('src', '/assets/' + (this.state.voteType == '1' ? 'up' : 'down') + '-fill.png');
          $(this.state.target).data('vote', this.state.voteType + '/' + this.state.postId + '/' + this.state.postType + '/' + data['vote_id']);
          $("#" + (this.state.postType == 'a' ? 'answer-' : 'question-') + this.state.postId + (this.state.voteType == 1 ? '-down' : '-up'))
            .data('vote', (1-this.state.voteType) + '/' + this.state.postId + '/' + this.state.postType + '/-1')
            .attr('src', '/assets/' + (this.state.voteType == '1' ? 'down' : 'up') + '-clear.png');
          $(this.state.target).parent().siblings('.post-score').text(data['post_score']);
        }
        else {
          alert("Could not cast vote - please try again. Message: " + data);
          console.error("Vote cast failed: " + data);
        }
      })
      .fail(function(jqXHR, textStatus, errorThrown) {
        alert("Could not cast vote - please try again. Message: " + jqXHR.responseText);
        console.error("Vote cast failed: status " + jqXHR.status);
        console.log(jqXHR);
      });
    }
  });

  // Notifications handling
  $("span.notifications").bind("click", function(ev) {
    $.ajax({
      'type': 'GET',
      'url': '/users/me/notifications.json',
      'dd': $(this)
    })
    .done(function(data) {
      $dropdown = $(this.dd).children("ul.dropdown-menu").first();
      $dropdown.html("");
      for(var i = 0; i < data.length; i++) {
        $dropdown.append("
" + data[i].content + "
");
      }
    })
    .fail(function(jqXHR, textStatus, errorThrown) {
      $(this.dd).html("
Could not retrieve notifications - try again later.
");
      console.log(jqXHR.responseText);
    });
  });

  $("ul.dropdown a.notification").bind("click", function(ev) {
    ev.preventDefault();
    var self = $(this);
    $.ajax({
      'type': 'POST',
      'url': '/notifications/' + self.data("id") + '/read',
      'src': self
    })
    .fail(function(jqXHR, textStatus, errorThrown) {
      console.log(jqXHR.responseText);
    })
    .always(function(a, b, c) {
      location.href = $(this.src).attr("href");
    });
  });

});
<commit_msg>error on fail<commit_after>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .

$(document).on('ready page:load', function() {

  $(".vote-button").bind("click", function(ev) {
    ev.preventDefault();
    var self = $(this);

    // Vote data is stored on the element as "VoteType/PostId/PostType/VoteId".
    var vote = self.data("vote");
    var voteSplat = vote.split("/");
    var state = {
      voteType: voteSplat[0],
      postId: voteSplat[1],
      postType: voteSplat[2],
      voteId: voteSplat[3],
      target: self
    };

    console.log(state);

    if(state.voteId > -1) {
      // We've already voted; cancel the vote.
      console.log("deleting vote");
      $.ajax({
        'url': '/votes/' + state.voteId,
        'type': 'DELETE',
        'state': state
      })
      .done(function(data) {
        if(data['status'] === "OK") {
          $(this.state.target).attr('src', '/assets/' + (this.state.voteType == '1' ? 'up' : 'down') + '-clear.png');
          $(this.state.target).data('vote', this.state.voteType + '/' + this.state.postId + '/' + this.state.postType + '/-1');
          $(this.state.target).parent().siblings('.post-score').text(data['post_score']);
        }
        else {
          alert("Could not undo vote - please try again. Message: " + data);
          console.error("Vote undo failed: " + data);
        }
      })
      .fail(function(jqXHR, textStatus, errorThrown) {
        alert("Could not undo vote - please try again. Message: " + jqXHR.reponseText);
        console.error("Vote undo failed: status " + jqXHR.status);
        console.log(jqXHR);
      });
    }
    else {
      // We have yet to vote, so cast one.
      console.log("creating vote");
      $.ajax({
        'url': '/votes/new',
        'type': 'POST',
        'data': {
          'post_type': state.postType,
          'post_id': state.postId,
          'vote_type': state.voteType
        },
        'state': state
      })
      .done(function(data) {
        if(data['status'] == "OK") {
          $(this.state.target).attr('src', '/assets/' + (this.state.voteType == '1' ? 'up' : 'down') + '-fill.png');
          $(this.state.target).data('vote', this.state.voteType + '/' + this.state.postId + '/' + this.state.postType + '/' + data['vote_id']);
          $(this.state.target).parent().siblings('.post-score').text(data['post_score']);
        }
        else if(data['status'] == "modified") {
          $(this.state.target).attr('src', '/assets/' + (this.state.voteType == '1' ? 'up' : 'down') + '-fill.png');
          $(this.state.target).data('vote', this.state.voteType + '/' + this.state.postId + '/' + this.state.postType + '/' + data['vote_id']);
          $("#" + (this.state.postType == 'a' ? 'answer-' : 'question-') + this.state.postId + (this.state.voteType == 1 ? '-down' : '-up'))
            .data('vote', (1-this.state.voteType) + '/' + this.state.postId + '/' + this.state.postType + '/-1')
            .attr('src', '/assets/' + (this.state.voteType == '1' ? 'down' : 'up') + '-clear.png');
          $(this.state.target).parent().siblings('.post-score').text(data['post_score']);
        }
        else {
          alert("Could not cast vote - please try again. Message: " + data);
          console.error("Vote cast failed: " + data);
        }
      })
      .fail(function(jqXHR, textStatus, errorThrown) {
        alert("Could not cast vote - please try again. Message: " + jqXHR.responseText);
        console.error("Vote cast failed: status " + jqXHR.status);
        console.log(jqXHR);
      });
    }
  });

  // Notifications handling
  $("span.notifications").bind("click", function(ev) {
    $.ajax({
      'type': 'GET',
      'url': '/users/me/notifications.json',
      'dd': $(this)
    })
    .done(function(data) {
      $dropdown = $(this.dd).children("ul.dropdown-menu").first();
      $dropdown.html("");
      for(var i = 0; i < data.length; i++) {
        $dropdown.append("
" + data[i].content + "
");
      }
    })
    .fail(function(jqXHR, textStatus, errorThrown) {
      $(this.dd).html("
Could not retrieve notifications - try again later.
");
      console.log(jqXHR.responseText);
    });
  });

  $("ul.dropdown a.notification").bind("click", function(ev) {
    ev.preventDefault();
    var self = $(this);
    $.ajax({
      'type': 'POST',
      'url': '/notifications/' + self.data("id") + '/read',
      'src': self
    })
    .done(function(data) {
      if(data['status'] !== 'success') {
        console.error("Failed to mark notification as read.");
      }
    })
    .fail(function(jqXHR, textStatus, errorThrown) {
      console.log(jqXHR.responseText);
    })
    .always(function(a, b, c) {
      location.href = $(this.src).attr("href");
    });
  });

});
<|endoftext|>


<commit_before>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require_tree .
//= require turbolinks
//= require materialize-sprockets
//= require social-share-button

<commit_msg>include typedjs<commit_after>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require_tree .
//= require turbolinks
//= require materialize-sprockets
//= require social-share-button
//= require typed

<|endoftext|>


<commit_before>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
$( document ).ready(function() {
  $(".show-if-accept").hide();
  $("#show-accept").click(function(){
    $(".hide-if-accept").hide();
    $(".show-if-accept").show();
  });
});
<commit_msg>Mark notes as checkbox as checked if focus on textarea<commit_after>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
$( document ).ready(function() {
  $(".show-if-accept").hide();
  $("#show-accept").click(function(){
    $(".hide-if-accept").hide();
    $(".show-if-accept").show();
  });
  $("#notes").focus(function(){
    $("#actions_notes").prop('checked', true);
  });
});
<|endoftext|>


<commit_before>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= require bootstrap-datepicker
//= require_tree .

/*
 * Datepicker
 */
var datepickerReady = function() {

  $('.input-group.date').datepicker({
    format: "yyyy-mm-dd",
    autoclose: true
  });

};

$(document).ready(datepickerReady);
$(document).on('page:load', datepickerReady);
<commit_msg>Datepicker defaults to current date and highlights date in calendar.<commit_after>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= require bootstrap-datepicker
//= require_tree .

/*
 * Datepicker
 */
var datepickerReady = function() {

  $('.input-group.date')
    .datepicker({
      dateFormat: "yyyy-mm-dd",
      todayHighlight: true,
      autoclose: true
    })
    .datepicker('setDate', new Date());
};

$(document).ready(datepickerReady);
$(document).on('page:load', datepickerReady);
<|endoftext|>


<commit_before>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require RRSSB
//= require_tree .
<commit_msg>Remove tree from application.js<commit_after>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require RRSSB
<|endoftext|>


<commit_before>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//
// Required by Blacklight
//= require blacklight/blacklight
//= require_tree .
<commit_msg>google analytics. Loads the 1x1 gif on page load.<commit_after>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//
// Required by Blacklight
//= require blacklight/blacklight
//= require_tree .

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-60323667-1', 'auto');
ga('send', 'pageview');
<|endoftext|>


<commit_before>//= require require_config

require(['common', 'jquery'], function(MAS, $) {
  'use strict';

  if (MAS.fonts.loadWithJS && MAS.fonts.url && !MAS.fonts.localstorage) {
    require(['jquery', 'common'], function($, MAS) {

      MAS.log('FONTS: load via ajax');
      $.ajax({
        url: MAS.fonts.url,
        success: function(res) {
          MAS.log('FONTS: ajax load success > stylesheet appended to page > load class added');
          $('html').addClass(MAS.fonts.loadClass);
          $('head').append('<style>' + res + '</style>');
          if (MAS.supports.localstorage) {
            MAS.log('FONTS: localstorage supported, fonts saved');
            localStorage.setItem(MAS.fonts.cacheName, res);
          }
        },
        dataType: 'text'
      });
    });
  }

  if (window.enableScrollTracking) {
    require(['jquery', 'scrollTracking'], function($, scrollTracking) {
      // Analytics scroll tracking on editorial pages
      scrollTracking({
        el: '.editorial',
        triggerPoints: [0.25, 0.5, 0.75, 1]
      });
    });
  }

  require(['jquery', 'collapsable'], function($, Collapsable) {
    $(document).ready(function() {
      // Mobile Search Button
      new Collapsable({
        name: 'mobileSearch',
        closeOffFocus: false,
        accordion: true,
        triggerEl: '.mobile-nav__link--search',
        targetType: 'href',
      });

      // Article Collapsables
      new Collapsable({
        name: 'articleCollapsables',
        showOnlyFirst: true,
        showIcon: true,
        useButton: true
      });

      // Category Collapsables
      new Collapsable({
        name: 'categoryCollapsables',
        triggerEl: '.js-category-detail__toggle-view',
        targetEl: '.js-category-detail__list--extended'
      });

      // Debt Campaign Companies affected
      new Collapsable({
        name: 'companiesAffected',
        showIcon: true,
        useButton: true,
        triggerEl: '.l-debtmanagement__companies-heading',
        targetEl: '.l-debtmanagement__companies-list'
      });

      if($(this).width() <= 720){
        new Collapsable({
          name: 'contactCollapsables',
          showIcon: true,
          useButton: true,
          triggerEl: '.contact-detail__heading',
          targetEl: '.contact-detail__content'
        });
      }

    });
  });

  require(['jquery', 'ujs'], function($) {

    $(document).ready(function() {
      // Cookie message
      $('.js-cookie-message').bind('ajax:success', function() {
        $('.cookie-message').hide();
        $('.footer-site-links__cookie-link').removeClass('is-on');
      });
    });
  });

  // Kick off component loader
  var engines = [];
  $('[data-engine]').each(function() {
    engines.push($(this).attr('data-engine') + 'Config');
  });

  require(engines, function() {
    require(['componentLoader', 'eventsWithPromises'], function(componentLoader, eventsWithPromises) {
      componentLoader.init($('body'));
      eventsWithPromises.subscribe('component:contentChange', function(data) {
        componentLoader.init(data.$container);
      });
    });
  });
});
<commit_msg>Update application.js to replace deprecated bind()<commit_after>//= require require_config

require(['common', 'jquery'], function(MAS, $) {
  'use strict';

  if (MAS.fonts.loadWithJS && MAS.fonts.url && !MAS.fonts.localstorage) {
    require(['jquery', 'common'], function($, MAS) {

      MAS.log('FONTS: load via ajax');
      $.ajax({
        url: MAS.fonts.url,
        success: function(res) {
          MAS.log('FONTS: ajax load success > stylesheet appended to page > load class added');
          $('html').addClass(MAS.fonts.loadClass);
          $('head').append('<style>' + res + '</style>');
          if (MAS.supports.localstorage) {
            MAS.log('FONTS: localstorage supported, fonts saved');
            localStorage.setItem(MAS.fonts.cacheName, res);
          }
        },
        dataType: 'text'
      });
    });
  }

  if (window.enableScrollTracking) {
    require(['jquery', 'scrollTracking'], function($, scrollTracking) {
      // Analytics scroll tracking on editorial pages
      scrollTracking({
        el: '.editorial',
        triggerPoints: [0.25, 0.5, 0.75, 1]
      });
    });
  }

  require(['jquery', 'collapsable'], function($, Collapsable) {
    $(document).ready(function() {
      // Mobile Search Button
      new Collapsable({
        name: 'mobileSearch',
        closeOffFocus: false,
        accordion: true,
        triggerEl: '.mobile-nav__link--search',
        targetType: 'href',
      });

      // Article Collapsables
      new Collapsable({
        name: 'articleCollapsables',
        showOnlyFirst: true,
        showIcon: true,
        useButton: true
      });

      // Category Collapsables
      new Collapsable({
        name: 'categoryCollapsables',
        triggerEl: '.js-category-detail__toggle-view',
        targetEl: '.js-category-detail__list--extended'
      });

      // Debt Campaign Companies affected
      new Collapsable({
        name: 'companiesAffected',
        showIcon: true,
        useButton: true,
        triggerEl: '.l-debtmanagement__companies-heading',
        targetEl: '.l-debtmanagement__companies-list'
      });

      if($(this).width() <= 720){
        new Collapsable({
          name: 'contactCollapsables',
          showIcon: true,
          useButton: true,
          triggerEl: '.contact-detail__heading',
          targetEl: '.contact-detail__content'
        });
      }

    });
  });

  require(['jquery', 'ujs'], function($) {

    $(document).ready(function() {
      // Cookie message
      $('.js-cookie-message').on('ajax:success', function() {
        $('.cookie-message').hide();
        $('.footer-site-links__cookie-link').removeClass('is-on');
      });
    });
  });

  // Kick off component loader
  var engines = [];
  $('[data-engine]').each(function() {
    engines.push($(this).attr('data-engine') + 'Config');
  });

  require(engines, function() {
    require(['componentLoader', 'eventsWithPromises'], function(componentLoader, eventsWithPromises) {
      componentLoader.init($('body'));
      eventsWithPromises.subscribe('component:contentChange', function(data) {
        componentLoader.init(data.$container);
      });
    });
  });
});
<|endoftext|>


<commit_before>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require chartkick
//= require Chart.bundle
//= require jquery_ujs
//= require_tree .

window.QPixel = {
  csrfToken: () => {
    const token = $('meta[name="csrf-token"]').attr('content');
    QPixel.csrfToken = () => token;
    return token;
  },

  createNotification: function(type, message, relativeElement) {
    const offset = QPixel.offset(relativeElement);
    $("

")
      .addClass("notice has-shadow-3 is-" + type)
      .html('<button type="button" class="button is-close-button" data-dismiss="alert" aria-label="Close">×</button>
' + message+"
")
      .css({
        'position': 'fixed',
        'top': "50px",
        'left': "50%",
        'transform': "translateX(-50%)",
        'z-index': 100,
        'width': '100%',
        'max-width': "800px",
        'cursor': 'pointer'
      })
      .on('click', function(ev) {
        $(this).fadeOut(200, function() {
          $(this).remove();
        });
      })
      .appendTo(document.body);
  },

  offset: function(el) {
    const topLeft = $(el).offset();
    return {
      top: topLeft.top,
      left: topLeft.left,
      bottom: topLeft.top + $(el).outerHeight(),
      right: topLeft.left + $(el).outerWidth()
    };
  }
};

$(document).on('ready', function() {
  $("a.flag-dialog-link").bind("click", function(ev) {
    ev.preventDefault();
    const self = $(this);
    self.parents(".post--body").find(".js-flag-box").toggleClass("is-active");
  });
  $("button.flag-link").bind("click", function(ev) {
    ev.preventDefault();
    const self = $(this);
    const data = {
      'post_id': self.data("post-id"),
      'reason': self.parents(".js-flag-box").find(".js-flag-comment").val()
    };

    if (data['reason'].length < 10) {
      QPixel.createNotification('danger', "Please enter at least 10 characters.", self);
      return;
    }

    $.ajax({
      'type': 'POST',
      'url': '/flags/new',
      'data': data,
      'target': self
    })
    .done((response) => {
      if(response.status !== 'success') {
        QPixel.createNotification('danger', 'Failed: ' + response.message, this);
      }
      else {
        QPixel.createNotification('success', 'Thanks! A moderator will review your flag.', this);
        self.parents(".js-flag-box").find(".js-flag-comment").val("");
      }
      self.parents(".js-flag-box").removeClass("is-active");
    })
    .fail((jqXHR, textStatus, errorThrown) => {
      QPixel.createNotification('danger', 'Failed: ' + jqXHR.status, this);
      console.log(jqXHR.responseText);
      self.parents(".js-flag-box").removeClass("is-active");
    });
  });

  $("a.close-dialog-link").on("click", function(ev) {
    ev.preventDefault();
    const self = $(this);
    console.log(self);
    console.log(self.parents(".post--body").find(".js-close-box").toggleClass("is-active"));
  });
  $("button.close-question").on("click", function(ev) {
    ev.preventDefault();
    const self = $(this);
    active_radio = self.parents(".js-close-box").find("input[type='radio'][name='close-reason']:checked");
    const data = {
      'reason_id': active_radio.val(),
      'other_post': active_radio.parents(".widget--body").find(".js-close-other-post").val()
      // option will be silently discarded if no input element
    };

    if (data["other_post"]) {
      if (data["other_post"].match(/\/[0-9]+$/)) {
        data["other_post"] = data["other_post"].replace(/.*\/([0-9]+)$/, "$1");
      }
    }

    $.ajax({
      'type': 'POST',
      'url': '/questions/' + self.data("post-id") + '/close',
      'data': data,
      'target': self
    })
    .done((response) => {
      if(response.status !== 'success') {
        QPixel.createNotification('danger', 'Failed: ' + response.message, ev.target);
      }
      else {
        location.reload();
      }
    })
    .fail((jqXHR, textStatus, errorThrown) => {
      QPixel.createNotification('danger', 'Failed: ' + jqXHR.status, ev.target);
      console.log(jqXHR.responseText);
    });
  });

  $("a.flag-resolve").bind("click", function(ev) {
    ev.preventDefault();
    var self = $(this);
    var id = self.data("flag-id");
    var data = {
      'result': self.data("result"),
      'message': self.parent().parent().find(".flag-resolve-comment").val()
    };

    $.ajax({
      'type': 'POST',
      'url': '/mod/flags/' + id + '/resolve',
      'data': data,
      'el': self
    })
    .done(function(response) {
      if(response['status'] !== 'success') {
        QPixel.createNotification('danger', "Failed: " + response['message'], this.el);
      }
      else {
        $(this.el).parent().parent().parent().fadeOut(200, function() {
          $(this).remove();
        });
      }
    })
    .fail(function(jqXHR, textStatus, errorThrown) {
      QPixel.createNotification('danger', "Failed: " + jqXHR.status, this.el);
      console.log(jqXHR.responseText);
    });
  });

  $('.js-first-visit-notice').on('close.bs.alert', async () => {
    document.cookie = 'dismiss_fvn=true; path=/; expires=Fri, 31 Dec 9999 23:59:59 GMT';
  });
});
<commit_msg>Implement JavaScript fixes from review<commit_after>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require chartkick
//= require Chart.bundle
//= require jquery_ujs
//= require_tree .

window.QPixel = {
  csrfToken: () => {
    const token = $('meta[name="csrf-token"]').attr('content');
    QPixel.csrfToken = () => token;
    return token;
  },

  createNotification: function(type, message, relativeElement) {
    $("

")
      .addClass("notice has-shadow-3 is-" + type)
      .html('<button type="button" class="button is-close-button" data-dismiss="alert" aria-label="Close">×</button>
' + message+"
")
      .css({
        'position': 'fixed',
        'top': "50px",
        'left': "50%",
        'transform': "translateX(-50%)",
        'z-index': 100,
        'width': '100%',
        'max-width': "800px",
        'cursor': 'pointer'
      })
      .on('click', function(ev) {
        $(this).fadeOut(200, function() {
          $(this).remove();
        });
      })
      .appendTo(document.body);
  },

  offset: function(el) {
    const topLeft = $(el).offset();
    return {
      top: topLeft.top,
      left: topLeft.left,
      bottom: topLeft.top + $(el).outerHeight(),
      right: topLeft.left + $(el).outerWidth()
    };
  }
};

$(document).on('ready', function() {
  $("a.flag-dialog-link").bind("click", (ev) => {
    ev.preventDefault();
    const self = $(ev.target);
    self.parents(".post--body").find(".js-flag-box").toggleClass("is-active");
  });
  $("button.flag-link").bind("click", (ev) => {
    ev.preventDefault();
    const self = $(ev.target);
    const data = {
      'post_id': self.data("post-id"),
      'reason': self.parents(".js-flag-box").find(".js-flag-comment").val()
    };

    if (data['reason'].length < 10) {
      QPixel.createNotification('danger', "Please enter at least 10 characters.", self);
      return;
    }

    $.ajax({
      'type': 'POST',
      'url': '/flags/new',
      'data': data,
      'target': self
    })
    .done((response) => {
      if(response.status !== 'success') {
        QPixel.createNotification('danger', 'Failed: ' + response.message, this);
      }
      else {
        QPixel.createNotification('success', 'Thanks! A moderator will review your flag.', this);
        self.parents(".js-flag-box").find(".js-flag-comment").val("");
      }
      self.parents(".js-flag-box").removeClass("is-active");
    })
    .fail((jqXHR, textStatus, errorThrown) => {
      QPixel.createNotification('danger', 'Failed: ' + jqXHR.status, this);
      console.log(jqXHR.responseText);
      self.parents(".js-flag-box").removeClass("is-active");
    });
  });

  $("a.close-dialog-link").on("click", (ev) => {
    ev.preventDefault();
    const self = $(ev.target);
    console.log(self.parents(".post--body").find(".js-close-box").toggleClass("is-active"));
  });
  $("button.close-question").on("click", (ev) => {
    ev.preventDefault();
    const self = $(ev.target);
    active_radio = self.parents(".js-close-box").find("input[type='radio'][name='close-reason']:checked");
    const data = {
      'reason_id': active_radio.val(),
      'other_post': active_radio.parents(".widget--body").find(".js-close-other-post").val()
      // option will be silently discarded if no input element
    };

    if (data["other_post"]) {
      if (data["other_post"].match(/\/[0-9]+$/)) {
        data["other_post"] = data["other_post"].replace(/.*\/([0-9]+)$/, "$1");
      }
    }

    $.ajax({
      'type': 'POST',
      'url': '/questions/' + self.data("post-id") + '/close',
      'data': data,
      'target': self
    })
    .done((response) => {
      if(response.status !== 'success') {
        QPixel.createNotification('danger', 'Failed: ' + response.message, ev.target);
      }
      else {
        location.reload();
      }
    })
    .fail((jqXHR, textStatus, errorThrown) => {
      QPixel.createNotification('danger', 'Failed: ' + jqXHR.status, ev.target);
      console.log(jqXHR.responseText);
    });
  });

  $("a.flag-resolve").bind("click", function(ev) {
    ev.preventDefault();
    var self = $(this);
    var id = self.data("flag-id");
    var data = {
      'result': self.data("result"),
      'message': self.parent().parent().find(".flag-resolve-comment").val()
    };

    $.ajax({
      'type': 'POST',
      'url': '/mod/flags/' + id + '/resolve',
      'data': data,
      'el': self
    })
    .done(function(response) {
      if(response['status'] !== 'success') {
        QPixel.createNotification('danger', "Failed: " + response['message'], this.el);
      }
      else {
        $(this.el).parent().parent().parent().fadeOut(200, function() {
          $(this).remove();
        });
      }
    })
    .fail(function(jqXHR, textStatus, errorThrown) {
      QPixel.createNotification('danger', "Failed: " + jqXHR.status, this.el);
      console.log(jqXHR.responseText);
    });
  });

  $('.js-first-visit-notice').on('close.bs.alert', async () => {
    document.cookie = 'dismiss_fvn=true; path=/; expires=Fri, 31 Dec 9999 23:59:59 GMT';
  });
});
<|endoftext|>


<commit_before>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require angular-resource
//= require bootstrap
//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require_tree .

<commit_msg>modal menu fix<commit_after>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require angular
//= require angular-resource
//= require bootstrap
//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require_tree .

<|endoftext|>


<commit_before>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require jquery.turbolinks
//= require bootstrap
//= require turbolinks
//= require_tree .
//
// Vendor Files
//= require metisMenu.js
//= require sb_admin_2.js
//= require dataTables.responsive.js
<commit_msg>Add depend_on lines to application.js<commit_after>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require jquery.turbolinks
//= require bootstrap
//= require turbolinks
//= require_tree .
//
// Vendor Files
//= require metisMenu.js
//= require sb_admin_2.js
//= require dataTables.responsive.js
//= depend_on_asset "metisMenu.js"
//= depend_on_asset "sb_admin_2.js"
//= depend_on_asset "dataTables.responsive.js"
<|endoftext|>


<commit_before>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require jquery-ui/accordion
//= require jquery-ui/datepicker
//= require chosen-jquery
//= require magnific-popup
//= require jquery.timepicker.js
//= require ckeditor/init

var ready = function(){
  // datepicker
  $( ".datepicker" ).datepicker({dateFormat: 'yy-mm-dd'});
  // timepicker
  $( ".timepicker" ).timepicker({timeFormat: "H:i:s", scrollDefault: '00:00:00', step: 0.25});
  $( ".monthpicker" ).datepicker( {
    changeMonth: true,
    changeYear: true,
    showButtonPanel: true,
    dateFormat: 'yy-mm-dd',
    minDate: new Date(2014, 10, 1),
    maxDate: new Date,
    onClose: function(dateText, inst) {
        var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
        var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
        $(this).datepicker('setDate', new Date(year, month, 1));
    }
  });
  // enable chosen js
  $('.chosen-select').chosen({
    search_contains: true,
    allow_single_deselect: true,
    no_results_text: 'No results matched',
    width: '200px',
  });
  $(".chosen-select").trigger('chosen:updated');
  $(".recent-search-form-select").change(function() {
    var selected_value = this.value;
    $.each(this.children, function(){
      var form_class = '.' + this.value + '-search';
      if (selected_value == this.value){
        $(form_class).show();
      }else{
        $(form_class).hide();
      }
    });
  });

  $(".video_type").change(function(){
    if (this.value == 'ivod'){
      $('.others_field').hide();
      $('.news_field').hide();
      $('.ivod_field').show();
    } else if (this.value == 'news'){
      $('.others_field').hide();
      $('.ivod_field').hide();
      $('.news_field').show();
    } else if (this.value == 'others'){
      $('.news_field').hide();
      $('.ivod_field').hide();
      $('.others_field').show();
    }
  });
  $(".video_type").change();

  $("#accordion").accordion({
    heightStyle: "content"
  });

  $('.all_party_button').click(function(){
    $('.kmt').show();
    $('.dpp').show();
    $('.pfp').show();
    $('.nsu').show();
    $('.tsu').show();
    $('.null').show();
    $('.all_party_button').addClass('current');
    $('.kmt_party_button').removeClass('current');
    $('.dpp_party_button').removeClass('current');
    $('.pfp_party_button').removeClass('current');
    $('.nsu_party_button').removeClass('current');
    $('.tsu_party_button').removeClass('current');
    $('.null_party_button').removeClass('current');
  });
  $('.kmt_party_button').click(function(){
    $('.kmt').show();
    $('.dpp').hide();
    $('.pfp').hide();
    $('.nsu').hide();
    $('.tsu').hide();
    $('.null').hide();
    $('.all_party_button').removeClass('current');
    $('.kmt_party_button').addClass('current');
    $('.dpp_party_button').removeClass('current');
    $('.pfp_party_button').removeClass('current');
    $('.nsu_party_button').removeClass('current');
    $('.tsu_party_button').removeClass('current');
    $('.null_party_button').removeClass('current');
  });
  $('.dpp_party_button').click(function(){
    $('.kmt').hide();
    $('.dpp').show();
    $('.pfp').hide();
    $('.nsu').hide();
    $('.tsu').hide();
    $('.null').hide();
    $('.all_party_button').removeClass('current');
    $('.kmt_party_button').removeClass('current');
    $('.dpp_party_button').addClass('current');
    $('.pfp_party_button').removeClass('current');
    $('.nsu_party_button').removeClass('current');
    $('.tsu_party_button').removeClass('current');
    $('.null_party_button').removeClass('current');
  });
  $('.pfp_party_button').click(function(){
    $('.kmt').hide();
    $('.dpp').hide();
    $('.pfp').show();
    $('.nsu').hide();
    $('.tsu').hide();
    $('.null').hide();
    $('.all_party_button').removeClass('current');
    $('.kmt_party_button').removeClass('current');
    $('.dpp_party_button').removeClass('current');
    $('.pfp_party_button').addClass('current');
    $('.nsu_party_button').removeClass('current');
    $('.tsu_party_button').removeClass('current');
    $('.null_party_button').removeClass('current');
  });
  $('.nsu_party_button').click(function(){
    $('.kmt').hide();
    $('.dpp').hide();
    $('.pfp').hide();
    $('.nsu').show();
    $('.tsu').hide();
    $('.null').hide();
    $('.all_party_button').removeClass('current');
    $('.kmt_party_button').removeClass('current');
    $('.dpp_party_button').removeClass('current');
    $('.pfp_party_button').removeClass('current');
    $('.nsu_party_button').addClass('current');
    $('.tsu_party_button').removeClass('current');
    $('.null_party_button').removeClass('current');
  });
  $('.tsu_party_button').click(function(){
    $('.kmt').hide();
    $('.dpp').hide();
    $('.pfp').hide();
    $('.nsu').hide();
    $('.tsu').show();
    $('.null').hide();
    $('.all_party_button').removeClass('current');
    $('.kmt_party_button').removeClass('current');
    $('.dpp_party_button').removeClass('current');
    $('.pfp_party_button').removeClass('current');
    $('.nsu_party_button').removeClass('current');
    $('.tsu_party_button').addClass('current');
    $('.null_party_button').removeClass('current');
  });
  $('.null_party_button').click(function(){
    $('.kmt').hide();
    $('.dpp').hide();
    $('.pfp').hide();
    $('.nsu').hide();
    $('.tsu').hide();
    $('.null').show();
    $('.all_party_button').removeClass('current');
    $('.kmt_party_button').removeClass('current');
    $('.dpp_party_button').removeClass('current');
    $('.pfp_party_button').removeClass('current');
    $('.nsu_party_button').removeClass('current');
    $('.tsu_party_button').removeClass('current');
    $('.null_party_button').addClass('current');
  });

  $('.check_all_box').change(function(){
    $.each($('.published_box'), function(){
      this.checked = $('.check_all_box')[0].checked;
    });
  });
  if ($('.alert').length > 0) {
    $.magnificPopup.open({
      items: {
        src: $('.alert'), // can be a HTML string, jQuery object, or CSS selector
        type: 'inline',
        removalDelay: 500
      }
    });
  }

  $("div.text").hide();
  $(".box h3").click(function(){
    $(this).next(".text").slideToggle("slow");
  });

  $('.show-more-snippet').css({height:'100%'});
  var show_more_snippet_height = $('.show-more-snippet').height();
  if(show_more_snippet_height < 34){
    $('.show-more').hide();
  } else {
    $('.show-more').click(function() {
      if($('.show-more-snippet').css('height') != '34px'){
        $('.show-more-snippet').stop().animate({height: '34px'}, 200);
        $(this).text('更多...');
      }else{
        $('.show-more-snippet').stop().animate({height: show_more_snippet_height}, 400);
        $(this).text('收合...');
      }
    });
  }

  CKEDITOR.on( 'dialogDefinition', function( ev ){
    // Take the dialog name and its definition from the event
    // data.
    var dialogName = ev.data.name;
    var dialogDefinition = ev.data.definition;

    // Check if the definition is from the dialog we're
    // interested on (the Link and Image dialog).
    if ( dialogName == 'link' || dialogName == 'image'  || dialogName == 'flash' )
    {
      // remove Upload tab
      dialogDefinition.removeContents('Upload');
      dialogDefinition.removeContents('upload');
    }
  });

};

$(document).ready(ready);
$(document).on('page:load', ready);<commit_msg>fix read more function<commit_after>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require jquery-ui/accordion
//= require jquery-ui/datepicker
//= require chosen-jquery
//= require magnific-popup
//= require jquery.timepicker.js
//= require ckeditor/init

var ready = function(){
  // datepicker
  $( ".datepicker" ).datepicker({dateFormat: 'yy-mm-dd'});
  // timepicker
  $( ".timepicker" ).timepicker({timeFormat: "H:i:s", scrollDefault: '00:00:00', step: 0.25});
  $( ".monthpicker" ).datepicker( {
    changeMonth: true,
    changeYear: true,
    showButtonPanel: true,
    dateFormat: 'yy-mm-dd',
    minDate: new Date(2014, 10, 1),
    maxDate: new Date,
    onClose: function(dateText, inst) {
        var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
        var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
        $(this).datepicker('setDate', new Date(year, month, 1));
    }
  });
  // enable chosen js
  $('.chosen-select').chosen({
    search_contains: true,
    allow_single_deselect: true,
    no_results_text: 'No results matched',
    width: '200px',
  });
  $(".chosen-select").trigger('chosen:updated');
  $(".recent-search-form-select").change(function() {
    var selected_value = this.value;
    $.each(this.children, function(){
      var form_class = '.' + this.value + '-search';
      if (selected_value == this.value){
        $(form_class).show();
      }else{
        $(form_class).hide();
      }
    });
  });

  $(".video_type").change(function(){
    if (this.value == 'ivod'){
      $('.others_field').hide();
      $('.news_field').hide();
      $('.ivod_field').show();
    } else if (this.value == 'news'){
      $('.others_field').hide();
      $('.ivod_field').hide();
      $('.news_field').show();
    } else if (this.value == 'others'){
      $('.news_field').hide();
      $('.ivod_field').hide();
      $('.others_field').show();
    }
  });
  $(".video_type").change();

  $("#accordion").accordion({
    heightStyle: "content"
  });

  $('.all_party_button').click(function(){
    $('.kmt').show();
    $('.dpp').show();
    $('.pfp').show();
    $('.nsu').show();
    $('.tsu').show();
    $('.null').show();
    $('.all_party_button').addClass('current');
    $('.kmt_party_button').removeClass('current');
    $('.dpp_party_button').removeClass('current');
    $('.pfp_party_button').removeClass('current');
    $('.nsu_party_button').removeClass('current');
    $('.tsu_party_button').removeClass('current');
    $('.null_party_button').removeClass('current');
  });
  $('.kmt_party_button').click(function(){
    $('.kmt').show();
    $('.dpp').hide();
    $('.pfp').hide();
    $('.nsu').hide();
    $('.tsu').hide();
    $('.null').hide();
    $('.all_party_button').removeClass('current');
    $('.kmt_party_button').addClass('current');
    $('.dpp_party_button').removeClass('current');
    $('.pfp_party_button').removeClass('current');
    $('.nsu_party_button').removeClass('current');
    $('.tsu_party_button').removeClass('current');
    $('.null_party_button').removeClass('current');
  });
  $('.dpp_party_button').click(function(){
    $('.kmt').hide();
    $('.dpp').show();
    $('.pfp').hide();
    $('.nsu').hide();
    $('.tsu').hide();
    $('.null').hide();
    $('.all_party_button').removeClass('current');
    $('.kmt_party_button').removeClass('current');
    $('.dpp_party_button').addClass('current');
    $('.pfp_party_button').removeClass('current');
    $('.nsu_party_button').removeClass('current');
    $('.tsu_party_button').removeClass('current');
    $('.null_party_button').removeClass('current');
  });
  $('.pfp_party_button').click(function(){
    $('.kmt').hide();
    $('.dpp').hide();
    $('.pfp').show();
    $('.nsu').hide();
    $('.tsu').hide();
    $('.null').hide();
    $('.all_party_button').removeClass('current');
    $('.kmt_party_button').removeClass('current');
    $('.dpp_party_button').removeClass('current');
    $('.pfp_party_button').addClass('current');
    $('.nsu_party_button').removeClass('current');
    $('.tsu_party_button').removeClass('current');
    $('.null_party_button').removeClass('current');
  });
  $('.nsu_party_button').click(function(){
    $('.kmt').hide();
    $('.dpp').hide();
    $('.pfp').hide();
    $('.nsu').show();
    $('.tsu').hide();
    $('.null').hide();
    $('.all_party_button').removeClass('current');
    $('.kmt_party_button').removeClass('current');
    $('.dpp_party_button').removeClass('current');
    $('.pfp_party_button').removeClass('current');
    $('.nsu_party_button').addClass('current');
    $('.tsu_party_button').removeClass('current');
    $('.null_party_button').removeClass('current');
  });
  $('.tsu_party_button').click(function(){
    $('.kmt').hide();
    $('.dpp').hide();
    $('.pfp').hide();
    $('.nsu').hide();
    $('.tsu').show();
    $('.null').hide();
    $('.all_party_button').removeClass('current');
    $('.kmt_party_button').removeClass('current');
    $('.dpp_party_button').removeClass('current');
    $('.pfp_party_button').removeClass('current');
    $('.nsu_party_button').removeClass('current');
    $('.tsu_party_button').addClass('current');
    $('.null_party_button').removeClass('current');
  });
  $('.null_party_button').click(function(){
    $('.kmt').hide();
    $('.dpp').hide();
    $('.pfp').hide();
    $('.nsu').hide();
    $('.tsu').hide();
    $('.null').show();
    $('.all_party_button').removeClass('current');
    $('.kmt_party_button').removeClass('current');
    $('.dpp_party_button').removeClass('current');
    $('.pfp_party_button').removeClass('current');
    $('.nsu_party_button').removeClass('current');
    $('.tsu_party_button').removeClass('current');
    $('.null_party_button').addClass('current');
  });

  $('.check_all_box').change(function(){
    $.each($('.published_box'), function(){
      this.checked = $('.check_all_box')[0].checked;
    });
  });
  if ($('.alert').length > 0) {
    $.magnificPopup.open({
      items: {
        src: $('.alert'), // can be a HTML string, jQuery object, or CSS selector
        type: 'inline',
        removalDelay: 500
      }
    });
  }

  $("div.text").hide();
  $(".box h3").click(function(){
    $(this).next(".text").slideToggle("slow");
  });

  $('.show-more-snippet').css({height:'100%'});
  var show_more_snippet_height = $('.show-more-snippet').height();
  if(show_more_snippet_height < 34){
    $('.show-more').hide();
  } else {
    $('.show-more-snippet').css({height:'34px'});
    $('.show-more').click(function() {
      if($('.show-more-snippet').css('height') != '34px'){
        $('.show-more-snippet').stop().animate({height: '34px'}, 200);
        $(this).text('更多...');
      }else{
        $('.show-more-snippet').stop().animate({height: show_more_snippet_height}, 400);
        $(this).text('收合...');
      }
    });
  }

  CKEDITOR.on( 'dialogDefinition', function( ev ){
    // Take the dialog name and its definition from the event
    // data.
    var dialogName = ev.data.name;
    var dialogDefinition = ev.data.definition;

    // Check if the definition is from the dialog we're
    // interested on (the Link and Image dialog).
    if ( dialogName == 'link' || dialogName == 'image'  || dialogName == 'flash' )
    {
      // remove Upload tab
      dialogDefinition.removeContents('Upload');
      dialogDefinition.removeContents('upload');
    }
  });

};

$(document).ready(ready);
$(document).on('page:load', ready);<|endoftext|>


<commit_before>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require foundation
//= require turbolinks
//= require_tree
//= require d3

$(function(){ $(document).foundation(); });

var loader = document.getElementById('loader');
startLoading();
finishedLoading();
function startLoading() {
  loader.className = '';
}
function finishedLoading() {
  loader.className = 'done';
  setTimeout(function() {
    loader.className = 'hide';
  }, 5000);
}

$('a.close').click(function() {
   var qqq = $(this).closest('.modal');
   $(qqq).removeClass('active');
});

<commit_msg>Change timeout time to 500, remove call for finishedLoading method<commit_after>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require foundation
//= require turbolinks
//= require_tree
//= require d3

$(function(){ $(document).foundation(); });

var loader = document.getElementById('loader');
startLoading();
function startLoading() {
  loader.className = '';
}
function finishedLoading() {
  loader.className = 'done';
  setTimeout(function() {
    loader.className = 'hide';
  }, 500);
}

<|endoftext|>


<commit_before>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require autocomplete-rails
//= require jquery.facebox
//= require_tree .

let getURLParameter = (parameterName) => {
  var sPageURL = window.location.search.substring(1);
  var sURLVariables = sPageURL.split('&');
  for (var i = 0; i < sURLVariables.length; i++)
  {
    var sParameterName = sURLVariables[i].split('=');
    if (sParameterName[0] == parameterName)
    {
      return sParameterName[1];
    }
  }
}

let changeAddressBarUrl = (url) => {
  window.history.pushState({"html": url}, "Title", url);
}

let changeAddressBarUrlForProjectsParams = (projectNames) => {
  if (projectNames.length > 0){
    changeAddressBarUrl(`${ window.location.pathname }?projects=${ projectNames.join(',') }` );
  }else{
    changeAddressBarUrl(window.location.pathname);
  };
}
<commit_msg>FIXED assets precompile error<commit_after>// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require autocomplete-rails
//= require jquery.facebox
//= require_tree .

getURLParameter = function(parameterName){
  var sPageURL = window.location.search.substring(1);
  var sURLVariables = sPageURL.split('&');
  for (var i = 0; i < sURLVariables.length; i++)
  {
    var sParameterName = sURLVariables[i].split('=');
    if (sParameterName[0] == parameterName)
    {
      return sParameterName[1];
    }
  }
}

changeAddressBarUrl = function(url){
  window.history.pushState({"html": url}, "Title", url);
}

changeAddressBarUrlForProjectsParams = function(projectNames){
  if (projectNames.length > 0){
    changeAddressBarUrl(window.location.pathname + '?projects=' +  projectNames.join(','));
  }else{
    changeAddressBarUrl(window.location.pathname);
  };
}
<|endoftext|>


<commit_before>(function() {
  "use strict";
  window.GOVUK = window.GOVUK || {};

  function Collapsible(section){
    this.$section = section;
    this.$clickTarget = this.$section.find('.js-subsection-title');
    this.$clickTarget.on('click', this.toggle.bind(this));
    this.addToggle();
  }

  Collapsible.prototype.addToggle = function addToggle(){
    var $toggleHTML = $("");
    this.$clickTarget.append($toggleHTML);
  };

  Collapsible.prototype.toggle = function toggle(event){
    this.$section.toggleClass('closed');
    event.preventDefault();
  };

  Collapsible.prototype.close = function close(){
    this.$section.addClass('closed');
  };

  Collapsible.prototype.open = function open(){
    this.$section.removeClass('closed');
  };

  Collapsible.prototype.isClosed = function(){
    return this.$section.hasClass('closed');
  };

  GOVUK.Collapsible = Collapsible;
}());
<commit_msg>Show section when focussing on hidden links<commit_after>(function() {
  "use strict";
  window.GOVUK = window.GOVUK || {};

  function Collapsible(section){
    this.$section = section;
    this.$clickTarget = this.$section.find('.js-subsection-title');
    this.$clickTarget.on('click', this.toggle.bind(this));
    this.addToggle();

    this.$section.on('focus', '.js-subsection-body a', this.showSectionWhenLinkFocused.bind(this));
  }

  Collapsible.prototype.showSectionWhenLinkFocused = function() {
    if (this.$section.is('.closed')) {
      this.$section.toggleClass('closed');
    }
  };

  Collapsible.prototype.addToggle = function addToggle(){
    var $toggleHTML = $("");
    this.$clickTarget.append($toggleHTML);
  };

  Collapsible.prototype.toggle = function toggle(event){
    this.$section.toggleClass('closed');
    event.preventDefault();
  };

  Collapsible.prototype.close = function close(){
    this.$section.addClass('closed');
  };

  Collapsible.prototype.open = function open(){
    this.$section.removeClass('closed');
  };

  Collapsible.prototype.isClosed = function(){
    return this.$section.hasClass('closed');
  };

  GOVUK.Collapsible = Collapsible;
}());
<|endoftext|>