<commit_before>//= require jquery_ujs
//= require _both

var hipster = window.hipster = (function() {
  // CACHES ////////////////////////////////////////////////////////////
  var _isShop = null;
  var _isLoading = true;
  var _runAfterLoad = [];

  // PRIVATE ///////////////////////////////////////////////////////////
  function log(text) {
    if(window.console && window.console.log) {
      window.console.log(text);
    }
  }

  function err(text) {
    if(window.console && window.console.error) {
      window.console.error(text);
    } else {
      alert(text);
    }
  }

  function getCookie(name) {
    name = '_hipsterpizza_' + name + '=';
    var cookies = document.cookie.split(/;\s*/);
    for(var i=0; i< cookies.length; i++) {
      c = cookies[i];
      if(c.indexOf(name) === 0) {
        return decodeURIComponent(c.substring(name.length, c.length));
      }
    }
    return null;
  }

  function setCookie(name, value) {
    if(!(new RegExp('^[a-z-]+$').test(name))) {
      err('Cookie Name contains invalid characters');
      return;
    }

    var date;
    if(value === null) {
      // i.e. delete the cookie
      date = 'Thu, 01 Jan 1970 00:00:01 GMT';
    } else {
      var exdate = new Date();
      exdate.setDate(exdate.getDate() + 365);
      date = exdate.toUTCString();
    }
    var data = encodeURIComponent(value) + "; expires=" + date;
    document.cookie = "_hipsterpizza_" + name + "=" + data;
  }

  function getCurrentAction() {
    return getCookie('action');
  }

  function getPostalCode() {
    var input = $('#plzsearch_input');

    function isInputEmpty() {
      return $.trim(input.val()) === '';
    }

    function checkPostalCode(data) {
      log('Reverse Geocoding Result:');
      log(data);
      if(isInputEmpty()) {
        input.val(data['address']['postcode']);
        input.focus();
      }
    }

    function queryNominatim(pos) {
      var url = 'http://nominatim.openstreetmap.org/reverse?format=json&zoom=18';
      var c = pos.coords;
      var coords = '&lat='+c.latitude+'&lon='+c.longitude;
      console.log('Querying Nominatim at ' + coords);
      $.getJSON(url + coords, checkPostalCode);
    }



    if(navigator.geolocation && input.length > 0 && isInputEmpty()) {
      navigator.geolocation.getCurrentPosition(queryNominatim);
    }
  }

  function isShopPage() {
    if(_isShop !== null) return _isShop;

    _isShop = $('body:contains("Warenkorb")').length === 1;
    return _isShop;
  }

  function isLoading() {
    if(!_isLoading) {
      return false;
    }

    _isLoading = $('label:contains("PLZ")').length === 0;
    return _isLoading;
  }

  function getShaAddress() {
    var prefix = 'hipsterpizza_odr_';
    // keep in sync with basket_helper#contact_sha_address
    var addr = '';
    addr += localStorage[prefix + 'zipcode'] + ' ';
    addr += localStorage[prefix + 'street'] + ' ';
    addr += localStorage[prefix + 'street_no'];
    addr = $.trim(addr).toLowerCase().replace(/[^a-z0-9]/g, '');

    if(addr === '') {
      return null;
    }

    return new jsSHA(addr, "TEXT").getHash("SHA-512", "HEX");
  }

  function getCartItemsJson() {
    var data = [];
    $(".cartitems").each(function(ind, elm) {
      var prod = $(elm).find(".cartitems-title div").text();
      var price = $(elm).find(".cartitems-itemsum .cartitems-sprice div").text();
      price = parseFloat(price.replace(/\s/, "").replace(",", "."));

      if($.trim(prod) === "" || isNaN(price)) {
        err("Couldn't detect product properly, maybe the script is broken?");
        return;
      }

      var extra = [];
      // subitems = additional toppings, subsubitems = salad dressing in menus
      var finder = ".cartitems-subitem .cartitems-subtitle a, .cartitems-subsubitem .cartitems-subtitle a"
      $(elm).find(finder).each(function(ind, ingred) {
        extra[ind] = $(ingred).text();
      });

      data[ind] = { "price": price, "prod": prod, "extra": extra.sort() };
    });
    return data;
  }

  function getUserNick() {
    var nick = getCookie('nick');
    do {
      nick = prompt('Your Nick:', nick === null ? '' : nick);
      // user clicked cancel
      if(nick === null) {
        return null;
      }
    } while(nick === '');
    setCookie('nick', nick);
    return nick;
  }

  function findLinkWithText(text) {
    return $('#framek a').filter(function() {
      var el = $(this);
      return el.text() === text || el.attr('title') === text;
    });
  }

  function getPriceOfLastItem() {
    var p = $(".cartitems:last .cartitems-itemsum .cartitems-sprice div").text();
    p = $.trim(p).replace(/\s.*$/, "").replace(",", ".");
    return parseFloat(p);
  }
<commit_msg>only search in link title, otherwise many items will have multiple matches<commit_after>//= require jquery_ujs
//= require _both

var hipster = window.hipster = (function() {
  // CACHES ////////////////////////////////////////////////////////////
  var _isShop = null;
  var _isLoading = true;
  var _runAfterLoad = [];

  // PRIVATE ///////////////////////////////////////////////////////////
  function log(text) {
    if(window.console && window.console.log) {
      window.console.log(text);
    }
  }

  function err(text) {
    if(window.console && window.console.error) {
      window.console.error(text);
    } else {
      alert(text);
    }
  }

  function getCookie(name) {
    name = '_hipsterpizza_' + name + '=';
    var cookies = document.cookie.split(/;\s*/);
    for(var i=0; i< cookies.length; i++) {
      c = cookies[i];
      if(c.indexOf(name) === 0) {
        return decodeURIComponent(c.substring(name.length, c.length));
      }
    }
    return null;
  }

  function setCookie(name, value) {
    if(!(new RegExp('^[a-z-]+$').test(name))) {
      err('Cookie Name contains invalid characters');
      return;
    }

    var date;
    if(value === null) {
      // i.e. delete the cookie
      date = 'Thu, 01 Jan 1970 00:00:01 GMT';
    } else {
      var exdate = new Date();
      exdate.setDate(exdate.getDate() + 365);
      date = exdate.toUTCString();
    }
    var data = encodeURIComponent(value) + "; expires=" + date;
    document.cookie = "_hipsterpizza_" + name + "=" + data;
  }

  function getCurrentAction() {
    return getCookie('action');
  }

  function getPostalCode() {
    var input = $('#plzsearch_input');

    function isInputEmpty() {
      return $.trim(input.val()) === '';
    }

    function checkPostalCode(data) {
      log('Reverse Geocoding Result:');
      log(data);
      if(isInputEmpty()) {
        input.val(data['address']['postcode']);
        input.focus();
      }
    }

    function queryNominatim(pos) {
      var url = 'http://nominatim.openstreetmap.org/reverse?format=json&zoom=18';
      var c = pos.coords;
      var coords = '&lat='+c.latitude+'&lon='+c.longitude;
      console.log('Querying Nominatim at ' + coords);
      $.getJSON(url + coords, checkPostalCode);
    }



    if(navigator.geolocation && input.length > 0 && isInputEmpty()) {
      navigator.geolocation.getCurrentPosition(queryNominatim);
    }
  }

  function isShopPage() {
    if(_isShop !== null) return _isShop;

    _isShop = $('body:contains("Warenkorb")').length === 1;
    return _isShop;
  }

  function isLoading() {
    if(!_isLoading) {
      return false;
    }

    _isLoading = $('label:contains("PLZ")').length === 0;
    return _isLoading;
  }

  function getShaAddress() {
    var prefix = 'hipsterpizza_odr_';
    // keep in sync with basket_helper#contact_sha_address
    var addr = '';
    addr += localStorage[prefix + 'zipcode'] + ' ';
    addr += localStorage[prefix + 'street'] + ' ';
    addr += localStorage[prefix + 'street_no'];
    addr = $.trim(addr).toLowerCase().replace(/[^a-z0-9]/g, '');

    if(addr === '') {
      return null;
    }

    return new jsSHA(addr, "TEXT").getHash("SHA-512", "HEX");
  }

  function getCartItemsJson() {
    var data = [];
    $(".cartitems").each(function(ind, elm) {
      var prod = $(elm).find(".cartitems-title div").text();
      var price = $(elm).find(".cartitems-itemsum .cartitems-sprice div").text();
      price = parseFloat(price.replace(/\s/, "").replace(",", "."));

      if($.trim(prod) === "" || isNaN(price)) {
        err("Couldn't detect product properly, maybe the script is broken?");
        return;
      }

      var extra = [];
      // subitems = additional toppings, subsubitems = salad dressing in menus
      var finder = ".cartitems-subitem .cartitems-subtitle a, .cartitems-subsubitem .cartitems-subtitle a"
      $(elm).find(finder).each(function(ind, ingred) {
        extra[ind] = $(ingred).text();
      });

      data[ind] = { "price": price, "prod": prod, "extra": extra.sort() };
    });
    return data;
  }

  function getUserNick() {
    var nick = getCookie('nick');
    do {
      nick = prompt('Your Nick:', nick === null ? '' : nick);
      // user clicked cancel
      if(nick === null) {
        return null;
      }
    } while(nick === '');
    setCookie('nick', nick);
    return nick;
  }

  function findLinkWithText(text) {
    return $('#framek a').filter(function() {
      var el = $(this);
      return el.attr('title') === text;
    });
  }

  function getPriceOfLastItem() {
    var p = $(".cartitems:last .cartitems-itemsum .cartitems-sprice div").text();
    p = $.trim(p).replace(/\s.*$/, "").replace(",", ".");
    return parseFloat(p);
  }

{'fraction_non_alphanumeric': 0.19880990330464351, 'fraction_numerical': 0.0057379662097545425, 'mean_word_length': 2.4413162705667277, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7199768', 'n_tokens_mistral': 3126, 'n_tokens_neox': 3011, 'n_words': 619}