<commit_before>if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.exports === exports) {
  module.exports = 'highcharts-ng';
}
(function () {
  'use strict';
  /*global angular: false, Highcharts: false */
  angular.module('highcharts-ng', []).factory('highchartsNGUtils', highchartsNGUtils).directive('highchart', [
    'highchartsNGUtils',
    '$timeout',
    highchart
  ]);
  function highchartsNGUtils() {
    return {
      indexOf: function (arr, find, i) {
        if (i === undefined)
          i = 0;
        if (i < 0)
          i += arr.length;
        if (i < 0)
          i = 0;
        for (var n = arr.length; i < n; i++)
          if (i in arr && arr[i] === find)
            return i;
        return -1;
      },
      prependMethod: function (obj, method, func) {
        var original = obj[method];
        obj[method] = function () {
          var args = Array.prototype.slice.call(arguments);
          func.apply(this, args);
          if (original) {
            return original.apply(this, args);
          } else {
            return;
          }
        };
      },
      deepExtend: function deepExtend(destination, source) {
        //Slightly strange behaviour in edge cases (e.g. passing in non objects)
        //But does the job for current use cases.
        if (angular.isArray(source)) {
          destination = angular.isArray(destination) ? destination : [];
          for (var i = 0; i < source.length; i++) {
            destination[i] = deepExtend(destination[i] || {}, source[i]);
          }
        } else if (angular.isObject(source)) {
          for (var property in source) {
            destination[property] = deepExtend(destination[property] || {}, source[property]);
          }
        } else {
          destination = source;
        }
        return destination;
      }
    };
  }
  function highchart(highchartsNGUtils, $timeout) {
    // acceptable shared state
    var seriesId = 0;
    var ensureIds = function (series) {
      var changed = false;
      angular.forEach(series, function (s) {
        if (!angular.isDefined(s.id)) {
          s.id = 'series-' + seriesId++;
          changed = true;
        }
      });
      return changed;
    };
    // immutable
    var axisNames = [
        'xAxis',
        'yAxis'
      ];
    var getMergedOptions = function (scope, element, config) {
      var mergedOptions = {};
      var defaultOptions = {
          chart: { events: {} },
          title: {},
          subtitle: {},
          series: [],
          credits: {},
          plotOptions: {},
          navigator: { enabled: false }
        };
      if (config.options) {
        mergedOptions = highchartsNGUtils.deepExtend(defaultOptions, config.options);
      } else {
        mergedOptions = defaultOptions;
      }
      mergedOptions.chart.renderTo = element[0];
      angular.forEach(axisNames, function (axisName) {
        if (angular.isDefined(config[axisName])) {
          mergedOptions[axisName] = angular.copy(config[axisName]);
          if (angular.isDefined(config[axisName].currentMin) || angular.isDefined(config[axisName].currentMax)) {
            highchartsNGUtils.prependMethod(mergedOptions.chart.events, 'selection', function (e) {
              var thisChart = this;
              if (e[axisName]) {
                scope.$apply(function () {
                  scope.config[axisName].currentMin = e[axisName][0].min;
                  scope.config[axisName].currentMax = e[axisName][0].max;
                });
              } else {
                //handle reset button - zoom out to all
                scope.$apply(function () {
                  scope.config[axisName].currentMin = thisChart[axisName][0].dataMin;
                  scope.config[axisName].currentMax = thisChart[axisName][0].dataMax;
                });
              }
            });
            highchartsNGUtils.prependMethod(mergedOptions.chart.events, 'addSeries', function (e) {
              scope.config[axisName].currentMin = this[axisName][0].min || scope.config[axisName].currentMin;
              scope.config[axisName].currentMax = this[axisName][0].max || scope.config[axisName].currentMax;
            });
          }
        }
      });
      if (config.title) {
        mergedOptions.title = config.title;
      }
      if (config.subtitle) {
        mergedOptions.subtitle = config.subtitle;
      }
      if (config.credits) {
        mergedOptions.credits = config.credits;
      }
      if (config.size) {
        if (config.size.width) {
          mergedOptions.chart.width = config.size.width;
        }
        if (config.size.height) {
          mergedOptions.chart.height = config.size.height;
        }
      }
      return mergedOptions;
    };
    var updateZoom = function (axis, modelAxis) {
      var extremes = axis.getExtremes();
      if (modelAxis.currentMin !== extremes.dataMin || modelAxis.currentMax !== extremes.dataMax) {
        axis.setExtremes(modelAxis.currentMin, modelAxis.currentMax, false);
      }
    };
    var processExtremes = function (chart, axis, axisName) {
      if (axis.currentMin || axis.currentMax) {
        chart[axisName][0].setExtremes(axis.currentMin, axis.currentMax, true);
      }
    };
    var chartOptionsWithoutEasyOptions = function (options) {
      return angular.extend({}, options, {
        data: null,
        visible: null
      });
    };
    return {
      restrict: 'EAC',
      replace: true,
      template: '

',
      scope: {
        config: '=',
        disableDataWatch: '='
      },
      link: function (scope, element, attrs) {
        // We keep some chart-specific variables here as a closure
        // instead of storing them on 'scope'.
        // prevSeriesOptions is maintained by processSeries
        var prevSeriesOptions = {};
        var processSeries = function (series) {
          var i;
          var ids = [];
          if (series) {
            var setIds = ensureIds(series);
            if (setIds) {
              //If we have set some ids this will trigger another digest cycle.
              //In this scenario just return early and let the next cycle take care of changes
              return false;
            }
            //Find series to add or update
            angular.forEach(series, function (s) {
              ids.push(s.id);
              var chartSeries = chart.get(s.id);
              if (chartSeries) {
                if (!angular.equals(prevSeriesOptions[s.id], chartOptionsWithoutEasyOptions(s))) {
                  chartSeries.update(angular.copy(s), false);
                } else {
                  if (s.visible !== undefined && chartSeries.visible !== s.visible) {
                    chartSeries.setVisible(s.visible, false);
                  }
                  chartSeries.setData(angular.copy(s.data), false);
                }
              } else {
                chart.addSeries(angular.copy(s), false);
              }
              prevSeriesOptions[s.id] = chartOptionsWithoutEasyOptions(s);
            });
            //  Shows no data text if all series are empty
            if (scope.config.noData) {
              var chartContainsData = false;
              for (i = 0; i < series.length; i++) {
                if (series[i].data && series[i].data.length > 0) {
                  chartContainsData = true;
                  break;
                }
              }
              if (!chartContainsData) {
                chart.showLoading(scope.config.noData);
              } else {
                chart.hideLoading();
              }
            }
          }
          //Now remove any missing series
          for (i = chart.series.length - 1; i >= 0; i--) {
            var s = chart.series[i];
            if (s.options.id !== 'highcharts-navigator-series' && highchartsNGUtils.indexOf(ids, s.options.id) < 0) {
              s.remove(false);
            }
          }
          return true;
        };
        // chart is maintained by initChart
        var chart = false;
        var initChart = function () {
          if (chart)
            chart.destroy();
          prevSeriesOptions = {};
          var config = scope.config || {};
          var mergedOptions = getMergedOptions(scope, element, config);
          var func = config.func || undefined;
          chart = config.useHighStocks ? new Highcharts.StockChart(mergedOptions, func) : new Highcharts.Chart(mergedOptions, func);
          for (var i = 0; i < axisNames.length; i++) {
            if (config[axisNames[i]]) {
              processExtremes(chart, config[axisNames[i]], axisNames[i]);
            }
          }
          if (config.loading) {
            chart.showLoading();
          }
          config.getHighcharts = function () {
            return chart;
          };
        };
        initChart();
        if (scope.disableDataWatch) {
          scope.$watchCollection('config.series', function (newSeries, oldSeries) {
            processSeries(newSeries);
            chart.redraw();
          });
        } else {
          scope.$watch('config.series', function (newSeries, oldSeries) {
            var needsRedraw = processSeries(newSeries);
            if (needsRedraw) {
              chart.redraw();
            }
          }, true);
        }
        scope.$watch('config.title', function (newTitle) {
          chart.setTitle(newTitle, true);
        }, true);
        scope.$watch('config.subtitle', function (newSubtitle) {
          chart.setTitle(true, newSubtitle);
        }, true);
        scope.$watch('config.loading', function (loading) {
          if (loading) {
            chart.showLoading();
          } else {
            chart.hideLoading();
          }
        });
        scope.$watch('config.credits.enabled', function (enabled) {
          if (enabled) {
            chart.credits.show();
          } else if (chart.credits) {
            chart.credits.hide();
          }
        });
        scope.$watch('config.useHighStocks', function (useHighStocks, oldUseHighStocks) {
          if (useHighStocks === oldUseHighStocks)
            return;
          initChart();
        });
        angular.forEach(axisNames, function (axisName) {
          scope.$watch('config.' + axisName, function (newAxes, oldAxes) {
            if (newAxes === oldAxes)
              return;
            if (newAxes) {
              chart[axisName][0].update(newAxes, false);
              updateZoom(chart[axisName][0], angular.copy(newAxes));
              chart.redraw();
            }
          }, true);
        });
        scope.$watch('config.options', function (newOptions, oldOptions, scope) {
          //do nothing when called on registration
          if (newOptions === oldOptions)
            return;
          initChart();
          processSeries(scope.config.series);
          chart.redraw();
        }, true);
        scope.$watch('config.size', function (newSize, oldSize) {
          if (newSize === oldSize)
            return;
          if (newSize) {
            chart.setSize(newSize.width || undefined, newSize.height || undefined);
          }
        }, true);
        scope.$on('highchartsng.reflow', function () {
          chart.reflow();
        });
        scope.$on('$destroy', function () {
          if (chart) {
            chart.destroy();
            $timeout(function () {
              element.remove();
            }, 0);
          }
        });
      }
    };
  }
}());
<commit_msg>update highcharts-ng<commit_after>if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.exports === exports) {
  module.exports = 'highcharts-ng';
}
(function () {
  'use strict';
  /*global angular: false, Highcharts: false */
  angular.module('highcharts-ng', []).factory('highchartsNGUtils', highchartsNGUtils).directive('highchart', [
    'highchartsNGUtils',
    '$timeout',
    highchart
  ]);
  function highchartsNGUtils() {
    return {
      indexOf: function (arr, find, i) {
        if (i === undefined)
          i = 0;
        if (i < 0)
          i += arr.length;
        if (i < 0)
          i = 0;
        for (var n = arr.length; i < n; i++)
          if (i in arr && arr[i] === find)
            return i;
        return -1;
      },
      prependMethod: function (obj, method, func) {
        var original = obj[method];
        obj[method] = function () {
          var args = Array.prototype.slice.call(arguments);
          func.apply(this, args);
          if (original) {
            return original.apply(this, args);
          } else {
            return;
          }
        };
      },
      deepExtend: function deepExtend(destination, source) {
        //Slightly strange behaviour in edge cases (e.g. passing in non objects)
        //But does the job for current use cases.
        if (angular.isArray(source)) {
          destination = angular.isArray(destination) ? destination : [];
          for (var i = 0; i < source.length; i++) {
            destination[i] = deepExtend(destination[i] || {}, source[i]);
          }
        } else if (angular.isObject(source)) {
          for (var property in source) {
            destination[property] = deepExtend(destination[property] || {}, source[property]);
          }
        } else {
          destination = source;
        }
        return destination;
      }
    };
  }
  function highchart(highchartsNGUtils, $timeout) {
    // acceptable shared state
    var seriesId = 0;
    var ensureIds = function (series) {
      var changed = false;
      angular.forEach(series, function (s) {
        if (!angular.isDefined(s.id)) {
          s.id = 'series-' + seriesId++;
          changed = true;
        }
      });
      return changed;
    };
    // immutable
    var axisNames = [
        'xAxis',
        'yAxis'
      ];
    var chartTypeMap = {
        'stock': 'StockChart',
        'map': 'Map',
        'chart': 'Chart'
      };
    var getMergedOptions = function (scope, element, config) {
      var mergedOptions = {};
      var defaultOptions = {
          chart: { events: {} },
          title: {},
          subtitle: {},
          series: [],
          credits: {},
          plotOptions: {},
          navigator: { enabled: false }
        };
      if (config.options) {
        mergedOptions = highchartsNGUtils.deepExtend(defaultOptions, config.options);
      } else {
        mergedOptions = defaultOptions;
      }
      mergedOptions.chart.renderTo = element[0];
      angular.forEach(axisNames, function (axisName) {
        if (angular.isDefined(config[axisName])) {
          mergedOptions[axisName] = angular.copy(config[axisName]);
          if (angular.isDefined(config[axisName].currentMin) || angular.isDefined(config[axisName].currentMax)) {
            highchartsNGUtils.prependMethod(mergedOptions.chart.events, 'selection', function (e) {
              var thisChart = this;
              if (e[axisName]) {
                scope.$apply(function () {
                  scope.config[axisName].currentMin = e[axisName][0].min;
                  scope.config[axisName].currentMax = e[axisName][0].max;
                });
              } else {
                //handle reset button - zoom out to all
                scope.$apply(function () {
                  scope.config[axisName].currentMin = thisChart[axisName][0].dataMin;
                  scope.config[axisName].currentMax = thisChart[axisName][0].dataMax;
                });
              }
            });
            highchartsNGUtils.prependMethod(mergedOptions.chart.events, 'addSeries', function (e) {
              scope.config[axisName].currentMin = this[axisName][0].min || scope.config[axisName].currentMin;
              scope.config[axisName].currentMax = this[axisName][0].max || scope.config[axisName].currentMax;
            });
          }
        }
      });
      if (config.title) {
        mergedOptions.title = config.title;
      }
      if (config.subtitle) {
        mergedOptions.subtitle = config.subtitle;
      }
      if (config.credits) {
        mergedOptions.credits = config.credits;
      }
      if (config.size) {
        if (config.size.width) {
          mergedOptions.chart.width = config.size.width;
        }
        if (config.size.height) {
          mergedOptions.chart.height = config.size.height;
        }
      }
      return mergedOptions;
    };
    var updateZoom = function (axis, modelAxis) {
      var extremes = axis.getExtremes();
      if (modelAxis.currentMin !== extremes.dataMin || modelAxis.currentMax !== extremes.dataMax) {
        axis.setExtremes(modelAxis.currentMin, modelAxis.currentMax, false);
      }
    };
    var processExtremes = function (chart, axis, axisName) {
      if (axis.currentMin || axis.currentMax) {
        chart[axisName][0].setExtremes(axis.currentMin, axis.currentMax, true);
      }
    };
    var chartOptionsWithoutEasyOptions = function (options) {
      return highchartsNGUtils.deepExtend({}, options, {
        data: null,
        visible: null
      });
    };
    var getChartType = function (scope) {
      if (scope.config === undefined)
        return 'Chart';
      return chartTypeMap[('' + scope.config.chartType).toLowerCase()] || (scope.config.useHighStocks ? 'StockChart' : 'Chart');
    };
    return {
      restrict: 'EAC',
      replace: true,
      template: '

',
      scope: {
        config: '=',
        disableDataWatch: '='
      },
      link: function (scope, element, attrs) {
        // We keep some chart-specific variables here as a closure
        // instead of storing them on 'scope'.
        // prevSeriesOptions is maintained by processSeries
        var prevSeriesOptions = {};
        var processSeries = function (series) {
          var i;
          var ids = [];
          if (series) {
            var setIds = ensureIds(series);
            if (setIds) {
              //If we have set some ids this will trigger another digest cycle.
              //In this scenario just return early and let the next cycle take care of changes
              return false;
            }
            //Find series to add or update
            angular.forEach(series, function (s) {
              ids.push(s.id);
              var chartSeries = chart.get(s.id);
              if (chartSeries) {
                if (!angular.equals(prevSeriesOptions[s.id], chartOptionsWithoutEasyOptions(s))) {
                  chartSeries.update(angular.copy(s), false);
                } else {
                  if (s.visible !== undefined && chartSeries.visible !== s.visible) {
                    chartSeries.setVisible(s.visible, false);
                  }
                  chartSeries.setData(angular.copy(s.data), false);
                }
              } else {
                chart.addSeries(angular.copy(s), false);
              }
              prevSeriesOptions[s.id] = chartOptionsWithoutEasyOptions(s);
            });
            //  Shows no data text if all series are empty
            if (scope.config.noData) {
              var chartContainsData = false;
              for (i = 0; i < series.length; i++) {
                if (series[i].data && series[i].data.length > 0) {
                  chartContainsData = true;
                  break;
                }
              }
              if (!chartContainsData) {
                chart.showLoading(scope.config.noData);
              } else {
                chart.hideLoading();
              }
            }
          }
          //Now remove any missing series
          for (i = chart.series.length - 1; i >= 0; i--) {
            var s = chart.series[i];
            if (s.options.id !== 'highcharts-navigator-series' && highchartsNGUtils.indexOf(ids, s.options.id) < 0) {
              s.remove(false);
            }
          }
          return true;
        };
        // chart is maintained by initChart
        var chart = false;
        var initChart = function () {
          if (chart)
            chart.destroy();
          prevSeriesOptions = {};
          var config = scope.config || {};
          var mergedOptions = getMergedOptions(scope, element, config);
          var func = config.func || undefined;
          var chartType = getChartType(scope);
          chart = new Highcharts[chartType](mergedOptions, func);
          for (var i = 0; i < axisNames.length; i++) {
            if (config[axisNames[i]]) {
              processExtremes(chart, config[axisNames[i]], axisNames[i]);
            }
          }
          if (config.loading) {
            chart.showLoading();
          }
          config.getHighcharts = function () {
            return chart;
          };
        };
        initChart();
        if (scope.disableDataWatch) {
          scope.$watchCollection('config.series', function (newSeries, oldSeries) {
            processSeries(newSeries);
            chart.redraw();
          });
        } else {
          scope.$watch('config.series', function (newSeries, oldSeries) {
            var needsRedraw = processSeries(newSeries);
            if (needsRedraw) {
              chart.redraw();
            }
          }, true);
        }
        scope.$watch('config.title', function (newTitle) {
          chart.setTitle(newTitle, true);
        }, true);
        scope.$watch('config.subtitle', function (newSubtitle) {
          chart.setTitle(true, newSubtitle);
        }, true);
        scope.$watch('config.loading', function (loading) {
          if (loading) {
            chart.showLoading(loading === true ? null : loading);
          } else {
            chart.hideLoading();
          }
        });
        scope.$watch('config.noData', function (noData) {
          if (scope.config && scope.config.loading) {
            chart.showLoading(noData);
          }
        }, true);
        scope.$watch('config.credits.enabled', function (enabled) {
          if (enabled) {
            chart.credits.show();
          } else if (chart.credits) {
            chart.credits.hide();
          }
        });
        scope.$watch(getChartType, function (chartType, oldChartType) {
          if (chartType === oldChartType)
            return;
          initChart();
        });
        angular.forEach(axisNames, function (axisName) {
          scope.$watch('config.' + axisName, function (newAxes, oldAxes) {
            if (newAxes === oldAxes || !newAxes) {
              return;
            }
            if (angular.isArray(newAxes)) {
              for (var axisIndex = 0; axisIndex < newAxes.length; axisIndex++) {
                var axis = newAxes[axisIndex];
                if (axisIndex < chart[axisName].length) {
                  chart[axisName][axisIndex].update(axis, false);
                  updateZoom(chart[axisName][axisIndex], angular.copy(axis));
                }
              }
            } else {
              // update single axis
              chart[axisName][0].update(newAxes, false);
              updateZoom(chart[axisName][0], angular.copy(newAxes));
            }
            chart.redraw();
          }, true);
        });
        scope.$watch('config.options', function (newOptions, oldOptions, scope) {
          //do nothing when called on registration
          if (newOptions === oldOptions)
            return;
          initChart();
          processSeries(scope.config.series);
          chart.redraw();
        }, true);
        scope.$watch('config.size', function (newSize, oldSize) {
          if (newSize === oldSize)
            return;
          if (newSize) {
            chart.setSize(newSize.width || undefined, newSize.height || undefined);
          }
        }, true);
        scope.$on('highchartsng.reflow', function () {
          chart.reflow();
        });
        scope.$on('$destroy', function () {
          if (chart) {
            try {
              chart.destroy();
            } catch (ex) {
            }
            $timeout(function () {
              element.remove();
            }, 0);
          }
        });
      }
    };
  }
}());<|endoftext|>


<commit_before>$(document).ready(toggle());

function toggle(){
  var hide = true;
    $('.custom-toggle').on('click', function (event){
      if (hide) {
            $('#sidebar').css({'margin-left' : '-210px'});
            // $('#sidebar span').css({'margin-left' : '-210px'});
            $('.main-content').addClass('animation');
            $('.main-content').removeClass('reverse-animation');
            $('.hidden-toggle').css({'display' : 'block'});
        hide = false;
      } else {
            $('#sidebar').css({'margin-left' : '0px'});
            // $('#sidebar span').css({'margin-left' : '0px'});
            $('.main-content').removeClass('animation');
            $('.main-content').addClass('reverse-animation');
            $('.hidden-toggle').css({'display' : 'none'});
        hide = true;
      }
  });
}

document.getElementsByClassName('custom-toggle')[0].click();

$(document).ready(function(){

  $("div.tab-menu>div.list-group>a").click(function(e){
    e.preventDefault();
    $(this).siblings('a.active').removeClass("active");
    $(this).addClass("active");
    var index = $(this).index();
    $("div.tab>div.tab-content").removeClass("active");
    $("div.tab>div.tab-content").eq(index).addClass("active");
  });
});

$(document).ready(function(){
    $('#pos-id').on('change', function() {
      var status = document.getElementById("current_status")
      if(this.value == '1'){
        $("#emp_form").show();

      }
      else if( this.value == '2')
      {
        $("#emp_form").hide();
      }

    });
});

$(document).ready(function(){
      $('#table-role').DataTable();
});

//add new record
$(document).ready(function(){
  $("#add-record-form").on('submit',function(e){
    e.preventDefault();
    e.stopImmediatePropagation();
    var form = new FormData(document.getElementById("add-record-form"));
    var link = base_url + 'applicant';
    $.ajax({
      url: base_url + 'applicant/addRecord',
      type: "POST",
      processData: false, // tell jQuery not to process the data
      contentType: false, // tell jQuery not to set contentType
      data:form,
      success: function(data){
        console.log(data);
        var result = JSON.parse(data);
        if(result==='success'){
          location.href = link;

        }else{
          alert('Error');
        }

      }
    })
    e.preventDefault();
  })
})

$(document).ready(function() {
    $('#add-record-form').bootstrapValidator({
    //    container: '#container',
        fields: {
            last_name: {
                validators: {
                    notEmpty: {
                        message: 'The Last name is required and cannot be empty'
                      },
                      regexp: {
                       regexp: /^[a-zA-Z\s]+$/,
                       message: 'The First name can only consist of letters'
                     },
                 }
             },

            first_name: {
                validators: {
                    notEmpty: {
                        message: 'The First name is required and cannot be empty'
                      },
                      regexp: {
                       regexp: /^[a-zA-Z\s]+$/,
                       message: 'The First name can only consist of letters'
                    },
                }
            },

            middle_name: {
                validators: {
                    notEmpty: {
                        message: 'The Middle name is required and cannot be empty'
                      },
                      regexp: {
                       regexp: /^[a-zA-Z\s]+$/,
                       message: 'The Middle name can only consist of letters'
                    },
                }
            },

            email_add: {
                validators: {
                    notEmpty: {
                        message: 'The Email Address is required and cannot be empty'
                    },
                }
            },

            phone_number: {
                validators: {
                    notEmpty: {
                        message: 'The phone number is required and cannot be empty'
                      },
                      regexp: {
                       regexp: /^[-+]?[0-9]+$/,
                       message: 'Phone number can only consist of numbers'
                    },
                }
            },
            tin: {
                validators: {
                      regexp: {
                       regexp: /^[-+]?[0-9]+$/,
                       message: 'TIN can only consist of numbers'
                    },
                }
            },
            sss: {
                validators: {
                      regexp: {
                       regexp: /^[-+]?[0-9]+$/,
                       message: 'SSS can only consist of numbers'
                    },
                }
            },
            philhealth: {
                validators: {
                      regexp: {
                       regexp: /^[-+]?[0-9]+$/,
                       message: 'PhilHealth can only consist of numbers'
                    },
                }
            },
            pagibig: {
                validators: {
                      regexp: {
                       regexp: /^[-+]?[0-9]+$/,
                       message: 'Pag-IBIG can only consist of numbers'
                    },
                }
            },
        }
    });
});

$(document).ready(function(){
  $("#pos-id").on('change', function(){
    var posid = $("#pos-id").val();
    $.ajax({
      url: base_url + "applicant/get_pos_role/" +posid,
      type: "POST",
      data: $("#pos-id").serialize(),//for now
      success: function(data){
        // alert("Hello");
        var result = JSON.parse(data);
        var html = "",roles;
        for(var i = 0; i < result.length; i++) {
          roles = result[i];

          html += '<option value="'+roles.id+'"> '+roles.name+' </option> '
          // console.log(roles.id);
        }
        $("#role").html(html);
        // alert(posid);
        if(posid == 1){
          $("#emp_form").show();
        }else{
          $("#emp_form").hide();
        }
      }
    });
  });
  $("#current_status").on('change',function() {
    var c_status = $("#current_status").val();
    var posid = $("#pos-id").val();
    if(c_status == 'applicant' && posid == 1){
      $("#applicant_div").show();
      $("#emp_form").hide();
      $("#resume").show();
    }
    else if (posid == 2 && c_status == 'applicant' ) {
      $("#emp_form").hide();
      $("#resume").show();
    }
    else if(posid == 2){
      $("#emp_form").hide();
      $("#resume").hide();
    }
    else{
      $("#applicant_div").hide();
      $("#emp_form").show();
      $("#resume").hide();

    }
  })
});

// const baseUrl = "http://localhost/resume-management/";

$(function() {
  $("#add-role-form").on('submit', function(e){
    e.preventDefault();
    e.stopImmediatePropagation();
    $.ajax({
      url: base_url + "insert_role",
      type: 'POST',
      data: $('#add-role-form').serialize(),
      dataType: 'json',
      success: function(data){
      var $tab = null;
         if(data['pos_id']=='1'){
          $tab = $('#employee_tab');
         }
         else if(data['pos_id']=='2'){
          $tab = $('#intern_tab');
         }
         else if (data['pos_id']=='3'){
          $tab = $('#freelance_tab');
         }
         console.log(data);

         $tab.append(`

${data['name']}

                     role_id .'&current_status=applicant">

${data['applicants']}
Applicants

                     role_id .'&current_status=interview">

${data['for_interview']}
For Interview

                       role_id .'&current_status=shortlist">

${data['shortlist']}
Shortlist

                     role_id .'&current_status=archived">

${data['archived']}
Rejected

                       role_id .'&position=2'">

${data['current']}
Current

                     role_id .'&position=2'">

${data['former']}
Former

`);

      }
    });
  });
});

//View Record's Information
$(function(){

  $('[data-name="button-view"]').click(function() {
      var applicantId = $(this).attr('data-id');
      var url = base_url + "applicant/" +  applicantId;
      // console.log('click');
      $.ajax({
          "url": url,
          "method": "GET",
          "success": function(response, status, http) {
            // console.log('click');
              if (http.status == 200) {
                  $('#first-name').html(response.first_name);
                  $('#last-name').html(response.last_name);
                  $('#middle-name').html(response.middle_name);
                  $('#home-address').html(response.home_address);
                  $('#phone_number').html(response.phone_number);
                  $('#birthday').html(response.birthday);
                  $('#degree').html(response.degree);
                  $('#school').html(response.school);
                  $('#role').html(response.name);
                  $('#date_hired').html(response.date_hired);
                  $('#app_date').html(response.application_date);
                  $('#sss').html(response.sss);
                  $('#tin').html(response.tin);
                  $('#philhealth').html(response.philhealth);
                  $('#pagibig').html(response.pagibig);
                  $('#comment').html(response.comment);
                  $('#resume').attr("href", base_url + 'assets/uploads/' + response.file);
                  $('#resume').html(response.file);
                  $('#interviewer').html(response.interviewer);
                  $('#interview-notes').attr("href", base_url + 'assets/uploads/' + response.interview_notes);
                  $('#interview-notes').html(response.interview_notes);
                  if(response.exam_result == 1){
                    $('#exam-result').html("Passed");
                  }
                  else if (response.exam_result == 0){
                    $('#exam-result').html("Failed");
                  }else{
                    $('#interview-result').html("");
                  }
                  if(response.interview_result == 1){
                    $('#interview-result').html("Passed");
                  }
                  else if (response.interview_result == 0){
                    $('#interview-result').html("Failed");
                  }
                  else {
                    $('#interview-result').html("");
                  }

                  $('#viewmodal').modal('show');
              }
          }
      });
  });

});

$(document).on('click','#btn-update',function(){

  var role_name=$(this).closest('tr').find('td[data-role="role_name"]').html();
  var position_name=$(this) .attr('data-value');
  console.log(role_name);
  console.log(position_name);
  var roleId = $(this).attr('data-id');
  $('#role_name').val(role_name);
  $("#roleModal").find("#updateRole").attr("data-id",roleId);
  $('#position_name').val(position_name);

});

$(document).on('click','#updateRole',function(){
  var roleId = $(this).attr('data-id');
  var url = base_url + "roles/edit/"+ roleId;
  var posId= $('#position_name option:selected').val();
  console.log(posId);
  $.ajax({
      "url":url,
      "method":"POST",
     data:{
         'role_name':$("#role_name").val(),
          'pos_id':$('#position_name').val()
      },
      success: function(data){
        if(data.error){

        }
        else{location.reload();}

      }
  });
});
<commit_msg>Added Role Activation<commit_after>$(document).ready(toggle());

function toggle(){
  var hide = true;
    $('.custom-toggle').on('click', function (event){
      if (hide) {
            $('#sidebar').css({'margin-left' : '-210px'});
            // $('#sidebar span').css({'margin-left' : '-210px'});
            $('.main-content').addClass('animation');
            $('.main-content').removeClass('reverse-animation');
            $('.hidden-toggle').css({'display' : 'block'});
        hide = false;
      } else {
            $('#sidebar').css({'margin-left' : '0px'});
            // $('#sidebar span').css({'margin-left' : '0px'});
            $('.main-content').removeClass('animation');
            $('.main-content').addClass('reverse-animation');
            $('.hidden-toggle').css({'display' : 'none'});
        hide = true;
      }
  });
}

document.getElementsByClassName('custom-toggle')[0].click();

$(document).ready(function(){

  $("div.tab-menu>div.list-group>a").click(function(e){
    e.preventDefault();
    $(this).siblings('a.active').removeClass("active");
    $(this).addClass("active");
    var index = $(this).index();
    $("div.tab>div.tab-content").removeClass("active");
    $("div.tab>div.tab-content").eq(index).addClass("active");
  });
});

$(document).ready(function(){
    $('#pos-id').on('change', function() {
      var status = document.getElementById("current_status")
      if(this.value == '1'){
        $("#emp_form").show();

      }
      else if( this.value == '2')
      {
        $("#emp_form").hide();
      }

    });
});

//add new record
$(document).ready(function(){
  $("#add-record-form").on('submit',function(e){
    e.preventDefault();
    e.stopImmediatePropagation();
    var form = new FormData(document.getElementById("add-record-form"));
    var link = base_url + 'applicant';
    $.ajax({
      url: base_url + 'applicant/addRecord',
      type: "POST",
      processData: false, // tell jQuery not to process the data
      contentType: false, // tell jQuery not to set contentType
      data:form,
      success: function(data){
        console.log(data);
        var result = JSON.parse(data);
        if(result==='success'){
          location.href = link;

        }else{
          alert('Error');
        }

      }
    })
    e.preventDefault();
  })
})

$(document).ready(function() {
    $('#add-record-form').bootstrapValidator({
    //    container: '#container',
        fields: {
            last_name: {
                validators: {
                    notEmpty: {
                        message: 'The Last name is required and cannot be empty'
                      },
                      regexp: {
                       regexp: /^[a-zA-Z\s]+$/,
                       message: 'The First name can only consist of letters'
                     },
                 }
             },

            first_name: {
                validators: {
                    notEmpty: {
                        message: 'The First name is required and cannot be empty'
                      },
                      regexp: {
                       regexp: /^[a-zA-Z\s]+$/,
                       message: 'The First name can only consist of letters'
                    },
                }
            },

            middle_name: {
                validators: {
                    notEmpty: {
                        message: 'The Middle name is required and cannot be empty'
                      },
                      regexp: {
                       regexp: /^[a-zA-Z\s]+$/,
                       message: 'The Middle name can only consist of letters'
                    },
                }
            },

            email_add: {
                validators: {
                    notEmpty: {
                        message: 'The Email Address is required and cannot be empty'
                    },
                }
            },

            phone_number: {
                validators: {
                    notEmpty: {
                        message: 'The phone number is required and cannot be empty'
                      },
                      regexp: {
                       regexp: /^[-+]?[0-9]+$/,
                       message: 'Phone number can only consist of numbers'
                    },
                }
            },
            tin: {
                validators: {
                      regexp: {
                       regexp: /^[-+]?[0-9]+$/,
                       message: 'TIN can only consist of numbers'
                    },
                }
            },
            sss: {
                validators: {
                      regexp: {
                       regexp: /^[-+]?[0-9]+$/,
                       message: 'SSS can only consist of numbers'
                    },
                }
            },
            philhealth: {
                validators: {
                      regexp: {
                       regexp: /^[-+]?[0-9]+$/,
                       message: 'PhilHealth can only consist of numbers'
                    },
                }
            },
            pagibig: {
                validators: {
                      regexp: {
                       regexp: /^[-+]?[0-9]+$/,
                       message: 'Pag-IBIG can only consist of numbers'
                    },
                }
            },
        }
    });
});

$(document).ready(function(){
  $("#pos-id").on('change', function(){
    var posid = $("#pos-id").val();
    $.ajax({
      url: base_url + "applicant/get_pos_role/" +posid,
      type: "POST",
      data: $("#pos-id").serialize(),//for now
      success: function(data){
        // alert("Hello");
        var result = JSON.parse(data);
        var html = "",roles;
        for(var i = 0; i < result.length; i++) {
          roles = result[i];

          html += '<option value="'+roles.id+'"> '+roles.name+' </option> '
          // console.log(roles.id);
        }
        $("#role").html(html);
        // alert(posid);
        if(posid == 1){
          $("#emp_form").show();
        }else{
          $("#emp_form").hide();
        }
      }
    });
  });
  $("#current_status").on('change',function() {
    var c_status = $("#current_status").val();
    var posid = $("#pos-id").val();
    if(c_status == 'applicant' && posid == 1){
      $("#applicant_div").show();
      $("#emp_form").hide();
      $("#resume").show();
    }
    else if (posid == 2 && c_status == 'applicant' ) {
      $("#emp_form").hide();
      $("#resume").show();
    }
    else if(posid == 2){
      $("#emp_form").hide();
      $("#resume").hide();
    }
    else{
      $("#applicant_div").hide();
      $("#emp_form").show();
      $("#resume").hide();

    }
  })
});

// const baseUrl = "http://localhost/resume-management/";

$(function() {
  $("#add-role-form").on('submit', function(e){
    e.preventDefault();
    e.stopImmediatePropagation();
    $.ajax({
      url: base_url + "insert_role",
      type: 'POST',
      data: $('#add-role-form').serialize(),
      dataType: 'json',
      success: function(data){
      var $tab = null;
         if(data['pos_id']=='1'){
          $tab = $('#employee_tab');
         }
         else if(data['pos_id']=='2'){
          $tab = $('#intern_tab');
         }
         else if (data['pos_id']=='3'){
          $tab = $('#freelance_tab');
         }
         console.log(data);

         $tab.append(`

${data['name']}

                     role_id .'&current_status=applicant">

${data['applicants']}
Applicants

                     role_id .'&current_status=interview">

${data['for_interview']}
For Interview

                       role_id .'&current_status=shortlist">

${data['shortlist']}
Shortlist

                     role_id .'&current_status=archived">

${data['archived']}
Rejected

                       role_id .'&position=2'">

${data['current']}
Current

                     role_id .'&position=2'">

${data['former']}
Former

`);

      }
    });
  });
});

//View Record's Information
$(function(){

  $('[data-name="button-view"]').click(function() {
      var applicantId = $(this).attr('data-id');
      var url = base_url + "applicant/" +  applicantId;
      // console.log('click');
      $.ajax({
          "url": url,
          "method": "GET",
          "success": function(response, status, http) {
            // console.log('click');
              if (http.status == 200) {
                  $('#first-name').html(response.first_name);
                  $('#last-name').html(response.last_name);
                  $('#middle-name').html(response.middle_name);
                  $('#home-address').html(response.home_address);
                  $('#phone_number').html(response.phone_number);
                  $('#birthday').html(response.birthday);
                  $('#degree').html(response.degree);
                  $('#school').html(response.school);
                  $('#role').html(response.name);
                  $('#date_hired').html(response.date_hired);
                  $('#app_date').html(response.application_date);
                  $('#sss').html(response.sss);
                  $('#tin').html(response.tin);
                  $('#philhealth').html(response.philhealth);
                  $('#pagibig').html(response.pagibig);
                  $('#comment').html(response.comment);
                  $('#resume').attr("href", base_url + 'assets/uploads/' + response.file);
                  $('#resume').html(response.file);
                  $('#interviewer').html(response.interviewer);
                  $('#interview-notes').attr("href", base_url + 'assets/uploads/' + response.interview_notes);
                  $('#interview-notes').html(response.interview_notes);
                  if(response.exam_result == 1){
                    $('#exam-result').html("Passed");
                  }
                  else if (response.exam_result == 0){
                    $('#exam-result').html("Failed");
                  }else{
                    $('#interview-result').html("");
                  }
                  if(response.interview_result == 1){
                    $('#interview-result').html("Passed");
                  }
                  else if (response.interview_result == 0){
                    $('#interview-result').html("Failed");
                  }
                  else {
                    $('#interview-result').html("");
                  }

                  $('#viewmodal').modal('show');
              }
          }
      });
  });

});

$(document).on('click','#btn-update',function(){

  var role_name=$(this).closest('tr').find('td[data-role="role_name"]').html();
  var position_name=$(this) .attr('data-value');
  console.log(role_name);
  console.log(position_name);
  var roleId = $(this).attr('data-id');
  $('#role_name').val(role_name);
  $("#roleModal").find("#updateRole").attr("data-id",roleId);
  $('#position_name').val(position_name);

});

$(document).on('click','#updateRole',function(){
  var roleId = $(this).attr('data-id');
  var url = base_url + "roles/edit/"+ roleId;
  var posId= $('#position_name option:selected').val();
  console.log(posId);
      $.ajax({
          "url":url,
          "method":"POST",
        data:{
            'role_name':$("#role_name").val(),
              'pos_id':$('#position_name').val()
          },
          success: function(data){
            if(data.error){

            }
            else{
              $(document).getRoles().done(function(data){
                $(document).displayRoles(data);
                });

            }

          }
      });
});

$.fn.getRoles=function(){
  var $url = base_url + "roles/get_roles";
 return $.ajax({
    url:$url,
    type:"GET",
    dataType: 'JSON'
  });
};

$.fn.displayRoles=function(items){

    $("#tbody-role").html('');

    $.each(items,function(i,item){
        $('#tbody-role').append(`

                  ${item['name']}
                  ${item['pos_name']}
                  ${item['status']==0?'Deactivated':'Activated'}

                    <button class="btn btn-warning" id="btn-update"data-id="${item['role_id']}"data-value="${item['pos_id']}" data-toggle="modal"data-target="#roleModal">Edit
                    <button class="btn btn-danger" data-id="${item['role_id']}"data-function="${item['status']==0?'Deactivated':'Activated'}" id="btn-status">${item['status']==1?'Deactivate':'Activate'}

`);
                 $('[data-function="Activated"]').removeClass();
                 $('[data-function="Deactivated"]').removeClass();
                $('[data-function="Activated"]').addClass("btn btn-danger");
                $('[data-function="Deactivated"]').addClass("btn btn-success");

    });

};

$(document).ready(function(){
  $('#table-role').DataTable();

  $(document).getRoles().done(function(data){
      $(document).displayRoles(data);
  });
});<|endoftext|>


<commit_before>/*jslint plusplus: true, indent: 2, maxerr: 500 */
/*global define, setTimeout, window, console */

define(['sudokuBoard', 'angular', 'sudokuUtils', 'jquery', 'boards'], function (Board, angular, sudoku, $, pantry) {
  'use strict';

  function SudokuController($scope, $routeParams, $location) {
    $scope.identity = angular.identity;
    if ($scope.info) {
      $scope.info.active = "sudoku";
      $scope.info.title = "Sudoku";
    }
    $scope.board = new Board();
    $scope.selectedRow = 0;
    $scope.selectedCol = 0;
    $scope.locks = {"generate": false};
    $scope.autoPencil = false;
    $scope.checked = false;
    $scope.incorrect = [];
    $scope.inProgress = {"generating": false};
    $scope.error = {"generating": false};
    $scope.difficulties = [
      {name: "Very Easy", value: 15},
      {name: "Easy", value: 30},
      {name: "Medium", value: 40},
      {name: "Hard", value: 50},
      {name: "Very hard", value: 60}
    ];
    $scope.show = {"won": true};
    $scope.difficulty = $scope.difficulties[2];
    $scope.params = $routeParams || {};

    $scope.saveBoard = function () {
      $location.path("/sudoku/" + sudoku.utils.save($scope.board.getBoard()));
    };

    $scope.selectedCell = function () {
      return $scope.board.getCell($scope.selectedRow, $scope.selectedCol);
    };

    $scope.isOriginal = function (row, col) {
      if ($scope.board.getOrigBoard()[row][col] !== 0) {
        return true;
      }
    };

    $scope.selectedCellPencilMarks = function () {
      return $scope.board.getPencilMarks($scope.selectedRow, $scope.selectedCol);
    };

    $scope.checkBoard = function () {
      $scope.incorrect = $scope.getMistakes();
      return $scope.isCorrect();
    };

    $scope.getMistakes = function () {
      var mistakes = $scope.board.mistakes();
      return mistakes;
    };

    $scope.isCorrect = function () {
      var mistakes = $scope.getMistakes();
      for (var i = 0; i < 9; i++) {
        for (var j = 0; j < 9; j++) {
          if (mistakes[i][j] === 1) {
            return false;
          }
        }
      }

      return true;
    };

    $scope.won = function () {
      return $scope.board.isComplete() && $scope.isCorrect();
    };

    $scope.generate = function () {
      $scope.inProgress.generating = true;
      $scope.show.won = true;
      $scope.error.generating = "";
      $scope.board.generate($scope.difficulty.value, function (success) {
        if (success) {
          $scope.$apply($scope.inProgress.generating = false);
          if ($scope.autoPencil) {
            $scope.generatePencils();
          }
        }
      });

      setTimeout(function () {
        if ($scope.inProgress.generating) {
          $scope.error.generating = "Generation seems to be taking a while." +
                                    "Sometimes, sudoku can be very hard to " +
                                    "generate. Feel free to cancel and try " +
                                    "a new one.";
          $scope.$apply();
        }
      }, 2000);
    };

    $scope.autoGenerate = function () {
      if ($scope.autoPencil) {
        $scope.autoPencil = false;
        $scope.board.clearPencilMarks();
      } else {
        $scope.autoPencil = true;
        $scope.generatePencils();
      }
    };

    $scope.generatePencils = function () {
      $scope.board.generatePencilMarks(function (success) {
        if (success) {
          $scope.$apply();
        }
      });
    };

    $scope.cancelGeneration = function () {
      $scope.board.gworker.terminate();
      $scope.board.gworker = undefined;
      $scope.inProgress.generating = false;
    };

    $scope.solve = function () {
      $scope.board.solve(function () {
        $scope.$apply();
      });
      $scope.checkBoard();
    };

    $scope.reset = function () {
      $scope.board.reset();
    };

    $scope.clear = function () {
      $scope.board.clear();
    };

    $scope.check = function () {
      $scope.checked = true;
      $scope.checkBoard();
      window.setTimeout(function () {
        $scope.$apply($scope.checked = false);
      }, 1500);

    };

    $scope.setSelected = function (row, column) {
      $scope.selectedRow = row;
      $scope.selectedCol = column;
    };

    $scope.setValueOfCell = function (value) {
      var cellVal = $scope.board.getCell($scope.selectedRow, $scope.selectedCol),
        pencilMarks = $scope.board.getPencilMarks($scope.selectedRow, $scope.selectedCol);

      if (!$scope.autoPencil) {
        if (cellVal === value) {
          $scope.board.setCell($scope.selectedRow, $scope.selectedCol, 0);
        } else {
          if (!cellVal && pencilMarks.length === 0) {
            $scope.board.setCell($scope.selectedRow, $scope.selectedCol, value);
          } else if (pencilMarks.indexOf(value) > -1) {
            $scope.board.removePencilMark($scope.selectedRow, $scope.selectedCol, value);
            pencilMarks = $scope.board.getPencilMarks($scope.selectedRow, $scope.selectedCol);
            var index, num = 0;
            for (var i = 0; i < pencilMarks.length; i++) {
              if (pencilMarks.indexOf(i) > 0) {
                if (num === 0) {
                  index = i;
                }
                num++;
              }
            }
            if (num === 1) {
              $scope.board.removePencilMark($scope.selectedRow, $scope.selectedCol, index);
              $scope.board.setCell($scope.selectedRow, $scope.selectedCol, index);
            } else if (num === 0) {
              $scope.board.setCell($scope.selectedRow, $scope.selectedCol, value);
            }
          } else {
            $scope.board.addPencilMark($scope.selectedRow, $scope.selectedCol, value);
            if (cellVal !== 0) {
              $scope.board.addPencilMark($scope.selectedRow, $scope.selectedCol, cellVal);
              $scope.board.setCell($scope.selectedRow, $scope.selectedCol, 0);
            }
          }
        }
      } else {
        $('#test').fadeOut(100);
        if (cellVal === value) {
          $scope.board.setCell($scope.selectedRow, $scope.selectedCol, 0);
        } else {
          $scope.board.setCell($scope.selectedRow, $scope.selectedCol, value);
        }
        $scope.generatePencils();
      }
    };

    $scope.setUp = function () {
      $scope.board.generate(null, null, pantry[0].board);
    };

    $scope.undo = function () {
      $scope.board.undo();
    };

    $scope.redo = function () {
      $scope.board.redo();
    };

    $scope.hideWon = function () {
      $scope.show.won = false;
    };

    if ($scope.params.board) {
      $scope.board.generate(null, null, sudoku.utils.load($scope.params.board));
    } else {
      $scope.setUp();
    }
  }

  SudokuController.$inject = ['$scope'];
  return SudokuController;
});<commit_msg>Reset doesn't clear pencil marks on auto-pencil mode.<commit_after>/*jslint plusplus: true, indent: 2, maxerr: 500 */
/*global define, setTimeout, window, console */

define(['sudokuBoard', 'angular', 'sudokuUtils', 'jquery', 'boards'], function (Board, angular, sudoku, $, pantry) {
  'use strict';

  function SudokuController($scope, $routeParams, $location) {
    $scope.identity = angular.identity;
    if ($scope.info) {
      $scope.info.active = "sudoku";
      $scope.info.title = "Sudoku";
    }
    $scope.board = new Board();
    $scope.selectedRow = 0;
    $scope.selectedCol = 0;
    $scope.locks = {"generate": false};
    $scope.autoPencil = false;
    $scope.checked = false;
    $scope.incorrect = [];
    $scope.inProgress = {"generating": false};
    $scope.error = {"generating": false};
    $scope.difficulties = [
      {name: "Very Easy", value: 15},
      {name: "Easy", value: 30},
      {name: "Medium", value: 40},
      {name: "Hard", value: 50},
      {name: "Very hard", value: 60}
    ];
    $scope.show = {"won": true};
    $scope.difficulty = $scope.difficulties[2];
    $scope.params = $routeParams || {};

    $scope.saveBoard = function () {
      $location.path("/sudoku/" + sudoku.utils.save($scope.board.getBoard()));
    };

    $scope.selectedCell = function () {
      return $scope.board.getCell($scope.selectedRow, $scope.selectedCol);
    };

    $scope.isOriginal = function (row, col) {
      if ($scope.board.getOrigBoard()[row][col] !== 0) {
        return true;
      }
    };

    $scope.selectedCellPencilMarks = function () {
      return $scope.board.getPencilMarks($scope.selectedRow, $scope.selectedCol);
    };

    $scope.checkBoard = function () {
      $scope.incorrect = $scope.getMistakes();
      return $scope.isCorrect();
    };

    $scope.getMistakes = function () {
      var mistakes = $scope.board.mistakes();
      return mistakes;
    };

    $scope.isCorrect = function () {
      var mistakes = $scope.getMistakes();
      for (var i = 0; i < 9; i++) {
        for (var j = 0; j < 9; j++) {
          if (mistakes[i][j] === 1) {
            return false;
          }
        }
      }

      return true;
    };

    $scope.won = function () {
      return $scope.board.isComplete() && $scope.isCorrect();
    };

    $scope.generate = function () {
      $scope.inProgress.generating = true;
      $scope.show.won = true;
      $scope.error.generating = "";
      $scope.board.generate($scope.difficulty.value, function (success) {
        if (success) {
          $scope.$apply($scope.inProgress.generating = false);
          if ($scope.autoPencil) {
            $scope.generatePencils();
          }
        }
      });

      setTimeout(function () {
        if ($scope.inProgress.generating) {
          $scope.error.generating = "Generation seems to be taking a while." +
                                    "Sometimes, sudoku can be very hard to " +
                                    "generate. Feel free to cancel and try " +
                                    "a new one.";
          $scope.$apply();
        }
      }, 2000);
    };

    $scope.autoGenerate = function () {
      if ($scope.autoPencil) {
        $scope.autoPencil = false;
        $scope.board.clearPencilMarks();
      } else {
        $scope.autoPencil = true;
        $scope.generatePencils();
      }
    };

    $scope.generatePencils = function () {
      $scope.board.generatePencilMarks(function (success) {
        if (success) {
          $scope.$apply();
        }
      });
    };

    $scope.cancelGeneration = function () {
      $scope.board.gworker.terminate();
      $scope.board.gworker = undefined;
      $scope.inProgress.generating = false;
    };

    $scope.solve = function () {
      $scope.board.solve(function () {
        $scope.$apply();
      });
      $scope.checkBoard();
    };

    $scope.reset = function () {
      $scope.board.reset();
      if ($scope.autoPencil) {
        $scope.generatePencils();
      }
    };

    $scope.clear = function () {
      $scope.board.clear();
    };

    $scope.check = function () {
      $scope.checked = true;
      $scope.checkBoard();
      window.setTimeout(function () {
        $scope.$apply($scope.checked = false);
      }, 1500);

    };

    $scope.setSelected = function (row, column) {
      $scope.selectedRow = row;
      $scope.selectedCol = column;
    };

    $scope.setValueOfCell = function (value) {
      var cellVal = $scope.board.getCell($scope.selectedRow, $scope.selectedCol),
        pencilMarks = $scope.board.getPencilMarks($scope.selectedRow, $scope.selectedCol);

      if (!$scope.autoPencil) {
        if (cellVal === value) {
          $scope.board.setCell($scope.selectedRow, $scope.selectedCol, 0);
        } else {
          if (!cellVal && pencilMarks.length === 0) {
            $scope.board.setCell($scope.selectedRow, $scope.selectedCol, value);
          } else if (pencilMarks.indexOf(value) > -1) {
            $scope.board.removePencilMark($scope.selectedRow, $scope.selectedCol, value);
            pencilMarks = $scope.board.getPencilMarks($scope.selectedRow, $scope.selectedCol);
            var index, num = 0;
            for (var i = 0; i < pencilMarks.length; i++) {
              if (pencilMarks.indexOf(i) > 0) {
                if (num === 0) {
                  index = i;
                }
                num++;
              }
            }
            if (num === 1) {
              $scope.board.removePencilMark($scope.selectedRow, $scope.selectedCol, index);
              $scope.board.setCell($scope.selectedRow, $scope.selectedCol, index);
            } else if (num === 0) {
              $scope.board.setCell($scope.selectedRow, $scope.selectedCol, value);
            }
          } else {
            $scope.board.addPencilMark($scope.selectedRow, $scope.selectedCol, value);
            if (cellVal !== 0) {
              $scope.board.addPencilMark($scope.selectedRow, $scope.selectedCol, cellVal);
              $scope.board.setCell($scope.selectedRow, $scope.selectedCol, 0);
            }
          }
        }
      } else {
        $('#test').fadeOut(100);
        if (cellVal === value) {
          $scope.board.setCell($scope.selectedRow, $scope.selectedCol, 0);
        } else {
          $scope.board.setCell($scope.selectedRow, $scope.selectedCol, value);
        }
        $scope.generatePencils();
      }
    };

    $scope.setUp = function () {
      $scope.board.generate(null, null, pantry[0].board);
    };

    $scope.undo = function () {
      $scope.board.undo();
    };

    $scope.redo = function () {
      $scope.board.redo();
    };

    $scope.hideWon = function () {
      $scope.show.won = false;
    };

    if ($scope.params.board) {
      $scope.board.generate(null, null, sudoku.utils.load($scope.params.board));
    } else {
      $scope.setUp();
    }
  }

  SudokuController.$inject = ['$scope'];
  return SudokuController;
});<|endoftext|>


<commit_before>const savedLang = window.localStorage && window.localStorage.getItem('localization');
const lang = require(`./${savedLang || 'en'}.json`);

export const langs = [
  {
    value: 'en',
    translated: lang.language_en,
    native: 'English',
  }, {
    value: 'de',
    translated: lang.language_de,
    native: 'Deutsch',
  }, {
    value: 'es',
    translated: lang.language_es,
    native: 'Español',
  }, {
    value: 'fi',
    translated: lang.language_fi,
    native: 'Suomi',
  }, {
    value: 'fr',
    translated: lang.language_fr,
    native: 'Français',
  }, {
    value: 'it',
    translated: lang.language_it,
    native: 'Italiano',
  }, {
    value: 'ko',
    translated: lang.language_ko,
    native: '한국어',
  }, {
    value: 'ms',
    translated: lang.language_ms,
    native: 'Malay',
  }, {
    value: 'nl',
    translated: lang.language_nl,
    native: 'Nederlands',
  }, {
    value: 'pl',
    translated: lang.language_pl,
    native: 'Polszczyzna',
  }, {
    value: 'pt',
    translated: lang.language_pt,
    native: 'Português',
  }, {
    value: 'ru',
    translated: lang.language_ru,
    native: 'ру́сский',
  }, {
    value: 'sv',
    translated: lang.language_sv,
    native: 'Svenska',
  }, {
    value: 'tr',
    translated: lang.language_tr,
    native: 'Türkçe',
  }, {
    value: 'uk',
    translated: lang.language_uk,
    native: 'Українська',
  }, {
    value: 'vi',
    translated: lang.language_vi,
    native: 'Tiếng Việt',
  }, {
    value: 'zh',
    translated: lang.language_zh,
    native: '汉语/漢語',
  },
];

export default lang;
<commit_msg>remove extra name for chinese language<commit_after>const savedLang = window.localStorage && window.localStorage.getItem('localization');
const lang = require(`./${savedLang || 'en'}.json`);

export const langs = [
  {
    value: 'en',
    translated: lang.language_en,
    native: 'English',
  }, {
    value: 'de',
    translated: lang.language_de,
    native: 'Deutsch',
  }, {
    value: 'es',
    translated: lang.language_es,
    native: 'Español',
  }, {
    value: 'fi',
    translated: lang.language_fi,
    native: 'Suomi',
  }, {
    value: 'fr',
    translated: lang.language_fr,
    native: 'Français',
  }, {
    value: 'it',
    translated: lang.language_it,
    native: 'Italiano',
  }, {
    value: 'ko',
    translated: lang.language_ko,
    native: '한국어',
  }, {
    value: 'ms',
    translated: lang.language_ms,
    native: 'Malay',
  }, {
    value: 'nl',
    translated: lang.language_nl,
    native: 'Nederlands',
  }, {
    value: 'pl',
    translated: lang.language_pl,
    native: 'Polszczyzna',
  }, {
    value: 'pt',
    translated: lang.language_pt,
    native: 'Português',
  }, {
    value: 'ru',
    translated: lang.language_ru,
    native: 'ру́сский',
  }, {
    value: 'sv',
    translated: lang.language_sv,
    native: 'Svenska',
  }, {
    value: 'tr',
    translated: lang.language_tr,
    native: 'Türkçe',
  }, {
    value: 'uk',
    translated: lang.language_uk,
    native: 'Українська',
  }, {
    value: 'vi',
    translated: lang.language_vi,
    native: 'Tiếng Việt',
  }, {
    value: 'zh',
    translated: lang.language_zh,
    native: '汉语',
  },
];

export default lang;
<|endoftext|>


<commit_before>// configure our routes
app.config(function($routeProvider, $locationProvider) {
	$routeProvider

	// route for the home page
		.when('/', {
			controller  : 'homeController',
			templateUrl : 'angular/templates/home.php'
		})

		// route for the sign in page
		.when('/signin/', {
			controller  : 'signinController',
			templateUrl : 'angular/templates/signin.php'
		})

		// route for the sign up page
		.when('/signup/', {
			controller  : 'SignupController',
			templateUrl : 'angular/templates/signup.php'
		})

		// route for the the compasss page
		.when('/thecompass/', {
			controller  : 'ThecompassController',
			templateUrl : 'angular/templates/compass.php'
		})

		// route for the breweries page
		.when('/breweries/', {
			controller  : 'BreweriesController',
			templateUrl : 'angular/templates/breweries.php'
		})

		// route for the beer page
		.when('/beer/', {
			controller  : 'BeerController',
			templateUrl : 'angular/templates/beer.php'
		})
		// route for the user page
		.when('/user/', {
			controller  : 'UserController',
			templateUrl : 'angular/templates/userProfile.php'
		})
		// route for the review page
		.when('/review/', {
			controller  : 'ReviewController',
			templateUrl : 'angular/templates/review.php'
		})

		// otherwise redirect to home
		.otherwise({
			redirectTo: "/"
		});

	//use the HTML5 History API
	$locationProvider.html5Mode(true);
});
<commit_msg>fixed route path for the compass<commit_after>// configure our routes
app.config(function($routeProvider, $locationProvider) {
	$routeProvider

	// route for the home page
		.when('/', {
			controller  : 'homeController',
			templateUrl : 'angular/templates/home.php'
		})

		// route for the sign in page
		.when('/signin/', {
			controller  : 'signinController',
			templateUrl : 'angular/templates/signin.php'
		})

		// route for the sign up page
		.when('/signup/', {
			controller  : 'SignupController',
			templateUrl : 'angular/templates/signup.php'
		})

		// route for the the compasss page
		.when('/thecompass/', {
			controller  : 'ThecompassController',
			templateUrl : 'angular/templates/thecompass.php'
		})

		// route for the breweries page
		.when('/breweries/', {
			controller  : 'BreweriesController',
			templateUrl : 'angular/templates/breweries.php'
		})

		// route for the beer page
		.when('/beer/', {
			controller  : 'BeerController',
			templateUrl : 'angular/templates/beer.php'
		})

		// route for the user page
		.when('/user/', {
			controller  : 'UserController',
			templateUrl : 'angular/templates/userProfile.php'
		})

		// route for the review page
		.when('/review/', {
			controller  : 'ReviewController',
			templateUrl : 'angular/templates/review.php'
		})

		// otherwise redirect to home
		.otherwise({
			redirectTo: "/"
		});

	//use the HTML5 History API
	$locationProvider.html5Mode(true);
});
<|endoftext|>


<commit_before>//////////////////////////////////////////////////////////////////////////////
//  tareksherif.ca: codebase for www.tareksherif.ca
//  Copyright (C) 2013  Tarek Sherif
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Affero General Public License as
//  published by the Free Software Foundation, either version 3 of the
//  License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Affero General Public License for more details.
//
//  You should have received a copy of the GNU Affero General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////////////

(function() {
  var view_port = $("#webgl");
  var scene = new THREE.Scene();
  var camera = new THREE.PerspectiveCamera(30, view_port.width()/view_port.height(), 0.1, 5000);
  var renderer = new THREE.WebGLRenderer();

  var light1 = new THREE.PointLight(0x555555);
  var light2 = new THREE.PointLight(0xFFFFFF);

  var geometries = [
                      { Shape: THREE.CubeGeometry,   args: [1.4, 1.4, 1.4] },
                      { Shape: THREE.SphereGeometry, args: [1, 24, 18] },
                      { Shape: THREE.TorusGeometry,  args: [0.8, 0.3, 24, 18] }
                   ];

  var g_index = Math.floor(Math.random() * geometries.length);

  var shape = new THREE.Mesh(createGeometry(geometries[g_index]), new THREE.MeshPhongMaterial({color: 0x1BBFE0}));

  var last_frame;
  var current_frame;

  renderer.setSize(view_port.width(), view_port.height());
  renderer.setClearColor(0xFFFFFF)
  view_port.append(renderer.domElement);

  scene.add(cube);
  scene.add(light1);
  scene.add(light2);

  camera.position.z = 5;
  light1.position.z = 5;
  light2.position.set(5, 5, 5);

  camera_controls = new THREE.TrackballControls(camera, document, $("#header")[0]);
  light_controls = new THREE.TrackballControls(light1, document, $("#header")[0]);

  // For dynamic application of constructors.
  function createGeometry(options) {
    var Shape = options.Shape;
    var args  = options.args;

    var geometry = Object.create(Shape.prototype);
    Shape.apply(geometry, args);

    return geometry;
  }

  function render(timestamp) {
    var delta;
    var rotation;
    var timer;

    if (window.performance === undefined) {
      timer = Date;
    } else {
      timer = performance;
    }

    requestAnimationFrame(render);

    last_frame = current_frame || timestamp || timer.now();
    current_frame = timestamp || timer.now();

    camera_controls.update();
    light_controls.update();

    delta = current_frame - last_frame;
    rotation = delta * 0.001;

    cube.rotation.x += rotation;
    cube.rotation.y += rotation;

    renderer.render(scene, camera);
  }

  render();
})();
<commit_msg>Bug fix.<commit_after>//////////////////////////////////////////////////////////////////////////////
//  tareksherif.ca: codebase for www.tareksherif.ca
//  Copyright (C) 2013  Tarek Sherif
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Affero General Public License as
//  published by the Free Software Foundation, either version 3 of the
//  License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Affero General Public License for more details.
//
//  You should have received a copy of the GNU Affero General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////////////

(function() {
  var view_port = $("#webgl");
  var scene = new THREE.Scene();
  var camera = new THREE.PerspectiveCamera(30, view_port.width()/view_port.height(), 0.1, 5000);
  var renderer = new THREE.WebGLRenderer();

  var light1 = new THREE.PointLight(0x555555);
  var light2 = new THREE.PointLight(0xFFFFFF);

  var geometries = [
                      { Shape: THREE.CubeGeometry,   args: [1.4, 1.4, 1.4] },
                      { Shape: THREE.SphereGeometry, args: [1, 24, 18] },
                      { Shape: THREE.TorusGeometry,  args: [0.8, 0.3, 24, 18] }
                   ];

  var g_index = Math.floor(Math.random() * geometries.length);

  var shape = new THREE.Mesh(createGeometry(geometries[g_index]), new THREE.MeshPhongMaterial({color: 0x1BBFE0}));

  var last_frame;
  var current_frame;

  renderer.setSize(view_port.width(), view_port.height());
  renderer.setClearColor(0xFFFFFF)
  view_port.append(renderer.domElement);

  scene.add(shape);
  scene.add(light1);
  scene.add(light2);

  camera.position.z = 5;
  light1.position.z = 5;
  light2.position.set(5, 5, 5);

  camera_controls = new THREE.TrackballControls(camera, document, $("#header")[0]);
  light_controls = new THREE.TrackballControls(light1, document, $("#header")[0]);

  // For dynamic application of constructors.
  function createGeometry(options) {
    var Shape = options.Shape;
    var args  = options.args;

    var geometry = Object.create(Shape.prototype);
    Shape.apply(geometry, args);

    return geometry;
  }

  function render(timestamp) {
    var delta;
    var rotation;
    var timer;

    if (window.performance === undefined) {
      timer = Date;
    } else {
      timer = performance;
    }

    requestAnimationFrame(render);

    last_frame = current_frame || timestamp || timer.now();
    current_frame = timestamp || timer.now();

    camera_controls.update();
    light_controls.update();

    delta = current_frame - last_frame;
    rotation = delta * 0.001;

    shape.rotation.x += rotation;
    shape.rotation.y += rotation;

    renderer.render(scene, camera);
  }

  render();
})();
<|endoftext|>


<commit_before>(function($) {
  // Returns a function, that, as long as it continues to be invoked, will not
  // be triggered. The function will be called after it stops being called for
  // N milliseconds. If `immediate` is passed, trigger the function on the
  // leading edge, instead of the trailing.
  // Source: https://davidwalsh.name/javascript-debounce-function
  window.debounce = function(func, wait, immediate) {
    var timeout;
    return function() {
      var context = this, args = arguments;
      var later = function() {
        timeout = null;
        if (!immediate) func.apply(context, args);
      };
      var callNow = immediate && !timeout;
      clearTimeout(timeout);
      timeout = setTimeout(later, wait);
      if (callNow) func.apply(context, args);
    };
  };

  window.searchHandler = function() {
    var searchContainer = $('.search'),
    searchInput = $('.search input'),
    oldInput = searchInput.val(),
    searchResultsPane = $('.search--results'),
    HORIZONTAL_OFFSET = 40;

    function search(token){
      $.post('/api/quick_search', {token: token}, function(data){
        if(searchContainer.parents('html').length > 0 && token == searchInput.val()) {
          var colls = appendResults(data);
          showSearchResults(colls);
          hover();
          $(document).trigger('content-changed');
        }
      });
    }

    function showSearchResults(colls){
      if(!searchResultsPane.is(":visible")) {
        searchResultsPane.show();
        $('#content').append(searchResultsPane.detach());
        var eOffset = searchContainer.offset();
        // make sure to place it where it would normally go (this could be improved)
        var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0)
        console.log(colls);
        searchResultsPane.css({
            'display': 'block',
            'top': eOffset.top + searchInput.outerHeight() + 10,
            'max-width' : 225*colls,
            'margin' : '0 auto',
            'max-height': h - (eOffset.top + searchInput.outerHeight() + 10)

        });
      }else{
        searchResultsPane.css({
          'max-width' : 225*colls
        })
      }
    }

    function appendResults(results) {
      var object = '';
      if(results.packages.length === 0 && results.topics.length === 0 && results.collaborators.length === 0){
        searchResultsPane.html('
No results found. Press [enter] for full-text search.
');
        return 0;
      }
      var col = 0;
      if(results.packages.length !== 0){
        col++;
      }
      if(results.topics.length !== 0){
        col++;
      }
      if(results.collaborators.length !== 0){
        col++;
      }
      object += "
"
      if(results.packages.length > 0){
        object += '
';
        object += '
Packages
';
        object += '
';
        results.packages.forEach(function(package){
          object += "
" + package.name + "
";
        });
        object += '
';
        object += '
';
      }

      if(results.topics.length > 0){
        object += '
';
        object += '
Functions
';
        object += '
';
        results.topics.forEach(function(topic){
          object += "
" + topic.name + " ("+ topic.package_name + " - " + topic.package_version + ") " + "
";
        });
        object += '
';
        object += '
';
      }

      if(results.collaborators.length > 0){
        object += '
';
        object += '
Collaborators
'
        object += '
';
        results.collaborators.forEach(function(collaborator){
          object += "
" + collaborator.name + "
";
        });
        object += '
';
        object += '
';
      }
      object += "
"
      object += "

Show more results

"
      searchResultsPane.html(object);
      return col;
    }

    function hover(){
      var elements = $(".search--results li");
      elements.each(function(i){
        $(this).mouseenter(function(){
          sethovering($(this).find("a"));
        });
        $(this).mouseleave(function(){
          unsethovering($(this).find("a"));
        });
      });
    }
    function sethovering(element){
      if($("li a.hover").length>0){
        $("li a.hover").eq(0).removeClass("hover");
      }
      element.addClass("hover");
    }
    function unsethovering(element){
      element.removeClass("hover");
    }

    function binding() {
      searchInput.on("keyup",debounce(function(e){
        if(searchInput.val()==""){
          searchResultsPane.hide();
        }
        else if(e.keyCode !== 40&&e.keyCode!==38&&oldInput!==searchInput.val()){
          oldInput = searchInput.val();
          search(searchInput.val());
        }
      }, 100));

      $(document).click(function(event) {
        if(!$(event.target).closest(searchContainer).length &&
           !$(event.target).is(searchContainer)) {
            if(searchResultsPane.is(":visible")) {
              searchResultsPane.hide();
            }
        }
      });

      searchInput.bind('keydown', function(e) {
        // DOWN array (only works with keydown and not keypress)
        if(e.keyCode==13 && $("li a.hover").length>0){
          e.preventDefault();
          document.location =  $("li a.hover").attr('href');
        }else if(e.keyCode == 40){
          if($("li a.hover").length>0){
            var next =($("li a.hover").parent().next("li"));
            if(next.length > 0){
              sethovering(next.find("a"));
            }else if($("li a.hover").parent().parent().hasClass("packages")){
              if($(".search--results .topics li").length > 0){
              sethovering($(".search--results .topics li").eq(0).find("a"));
              }
            }else if($("li a.hover").parent().parent().hasClass("topics")){
              if($(".search--results .collaborators li").length > 0){
              sethovering($(".search--results .collaborators li").eq(0).find("a"));
              }
            }
          }else{
            sethovering($(".search--results li").eq(0).find("a"));
          }
        }else if(e.keyCode == 38){
          if($("li a.hover").length>0){
            e.preventDefault();
            var next =($("li a.hover").parent().prev("li"));
            if(next.length > 0){
              sethovering(next.find("a"));
            }
            else if($("li a.hover").parent().parent().hasClass("topics")){
              if($(".search--results .packages li").length>0){
              sethovering($(".search--results .packages li").last().find("a"));
              }
            }
            else if($("li a.hover").parent().parent().hasClass("collaborators")){
              if($(".search--results .topics li").length>0){
              sethovering($(".search--results .topics li").last().find("a"));
              }
            }
          }else{
            sethovering($(".search--results li").last().find("a"));
          }
        }
      });
    }

    binding();

  };

  $(document).ready(window.searchHandler);
})($jq);
<commit_msg>pressing enter messes with the iframes normal behaviour<commit_after>(function($) {
  // Returns a function, that, as long as it continues to be invoked, will not
  // be triggered. The function will be called after it stops being called for
  // N milliseconds. If `immediate` is passed, trigger the function on the
  // leading edge, instead of the trailing.
  // Source: https://davidwalsh.name/javascript-debounce-function
  window.debounce = function(func, wait, immediate) {
    var timeout;
    return function() {
      var context = this, args = arguments;
      var later = function() {
        timeout = null;
        if (!immediate) func.apply(context, args);
      };
      var callNow = immediate && !timeout;
      clearTimeout(timeout);
      timeout = setTimeout(later, wait);
      if (callNow) func.apply(context, args);
    };
  };

  window.searchHandler = function() {
    var searchContainer = $('.search'),
    searchInput = $('.search input'),
    oldInput = searchInput.val(),
    searchResultsPane = $('.search--results'),
    HORIZONTAL_OFFSET = 40;

    function search(token){
      $.post('/api/quick_search', {token: token}, function(data){
        if(searchContainer.parents('html').length > 0 && token == searchInput.val()) {
          var colls = appendResults(data);
          showSearchResults(colls);
          hover();
          $(document).trigger('content-changed');
        }
      });
    }

    function showSearchResults(colls){
      if(!searchResultsPane.is(":visible")) {
        searchResultsPane.show();
        $('#content').append(searchResultsPane.detach());
        var eOffset = searchContainer.offset();
        // make sure to place it where it would normally go (this could be improved)
        var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0)
        console.log(colls);
        searchResultsPane.css({
            'display': 'block',
            'top': eOffset.top + searchInput.outerHeight() + 10,
            'max-width' : 225*colls,
            'margin' : '0 auto',
            'max-height': h - (eOffset.top + searchInput.outerHeight() + 10)

        });
      }else{
        searchResultsPane.css({
          'max-width' : 225*colls
        })
      }
    }

    function appendResults(results) {
      var object = '';
      if(results.packages.length === 0 && results.topics.length === 0 && results.collaborators.length === 0){
        searchResultsPane.html('
No results found. Press [enter] for full-text search.
');
        return 0;
      }
      var col = 0;
      if(results.packages.length !== 0){
        col++;
      }
      if(results.topics.length !== 0){
        col++;
      }
      if(results.collaborators.length !== 0){
        col++;
      }
      object += "
"
      if(results.packages.length > 0){
        object += '
';
        object += '
Packages
';
        object += '
';
        results.packages.forEach(function(package){
          object += "
" + package.name + "
";
        });
        object += '
';
        object += '
';
      }

      if(results.topics.length > 0){
        object += '
';
        object += '
Functions
';
        object += '
';
        results.topics.forEach(function(topic){
          object += "
" + topic.name + " ("+ topic.package_name + " - " + topic.package_version + ") " + "
";
        });
        object += '
';
        object += '
';
      }

      if(results.collaborators.length > 0){
        object += '
';
        object += '
Collaborators
'
        object += '
';
        results.collaborators.forEach(function(collaborator){
          object += "
" + collaborator.name + "
";
        });
        object += '
';
        object += '
';
      }
      object += "
"
      object += "

Show more results

"
      searchResultsPane.html(object);
      return col;
    }

    function hover(){
      var elements = $(".search--results li");
      elements.each(function(i){
        $(this).mouseenter(function(){
          sethovering($(this).find("a"));
        });
        $(this).mouseleave(function(){
          unsethovering($(this).find("a"));
        });
      });
    }
    function sethovering(element){
      if($("li a.hover").length>0){
        $("li a.hover").eq(0).removeClass("hover");
      }
      element.addClass("hover");
    }
    function unsethovering(element){
      element.removeClass("hover");
    }

    function binding() {
      searchInput.on("keyup",debounce(function(e){
        if(searchInput.val()==""){
          searchResultsPane.hide();
        }
        else if(e.keyCode !== 40&&e.keyCode!==38&&oldInput!==searchInput.val()){
          oldInput = searchInput.val();
          search(searchInput.val());
        }
      }, 100));

      $(document).click(function(event) {
        if(!$(event.target).closest(searchContainer).length &&
           !$(event.target).is(searchContainer)) {
            if(searchResultsPane.is(":visible")) {
              searchResultsPane.hide();
            }
        }
      });

      searchInput.bind('keydown', function(e) {
        // DOWN array (only works with keydown and not keypress)
        if(e.keyCode==13 && $("li a.hover").length>0){
          e.preventDefault();
          $("li a.hover")[0].click();
        }else if(e.keyCode == 40){
          if($("li a.hover").length>0){
            var next =($("li a.hover").parent().next("li"));
            if(next.length > 0){
              sethovering(next.find("a"));
            }else if($("li a.hover").parent().parent().hasClass("packages")){
              if($(".search--results .topics li").length > 0){
              sethovering($(".search--results .topics li").eq(0).find("a"));
              }
            }else if($("li a.hover").parent().parent().hasClass("topics")){
              if($(".search--results .collaborators li").length > 0){
              sethovering($(".search--results .collaborators li").eq(0).find("a"));
              }
            }
          }else{
            sethovering($(".search--results li").eq(0).find("a"));
          }
        }else if(e.keyCode == 38){
          if($("li a.hover").length>0){
            e.preventDefault();
            var next =($("li a.hover").parent().prev("li"));
            if(next.length > 0){
              sethovering(next.find("a"));
            }
            else if($("li a.hover").parent().parent().hasClass("topics")){
              if($(".search--results .packages li").length>0){
              sethovering($(".search--results .packages li").last().find("a"));
              }
            }
            else if($("li a.hover").parent().parent().hasClass("collaborators")){
              if($(".search--results .topics li").length>0){
              sethovering($(".search--results .topics li").last().find("a"));
              }
            }
          }else{
            sethovering($(".search--results li").last().find("a"));
          }
        }
      });
    }

    binding();

  };

  $(document).ready(window.searchHandler);
})($jq);
<|endoftext|>