<commit_before>/*
  jQuery placeholder plugin
  by <NAME>, @unsoundscapes

  Based on exisitng plugin http://mths.be/placeholder by @mathias
  Adopted to toggle placeholder on user input instead of focus

  Released under the MIT license
*/

;(function (factory) {
  if (typeof define === 'function' && define.amd) {
    // AMD. Register as anonymous module.
    define(['jquery'], factory)
  } else {
    // Browser globals.
    factory(jQuery)
  }
}(function ($) {

  var isInputSupported = 'placeholder' in document.createElement('input')
    , isTextareaSupported = 'placeholder' in document.createElement('textarea')
    , Placeholder
    , $placeholders = $()

  function getAttributes (elem) {
    // Return an object of element attributes
    var newAttrs = {}
      , rinlinejQuery = /^jQuery\d+$/

    $.each(elem.attributes, function () {
      if (this.specified && !rinlinejQuery.test(this.name)) {
        newAttrs[this.name] = this.value
      }
    })
    return newAttrs
  }

  function setCaretTo (el, index) {
    // Set caret to specified @index
    if (el.createTextRange) {
      var range = el.createTextRange()
      range.move('character', index)
      range.select()
    } else if (el.selectionStart != null) {
      el.focus()
      el.setSelectionRange(index, index)
    }
  }


  Placeholder = function (element, options) {
    this.options = options || {}
    this.$replacement = this.$el = $(element)
    if ( this.$el.is('[placeholder]') && (this.options.force ||
        !isInputSupported && this.$el.is('input') ||
        !isTextareaSupported && this.$el.is('textarea'))
       ) {
      this.initialize.apply(this, arguments)
      // Cache all elements with placeholders
      $placeholders = $placeholders.add(element)
    }
  }

  Placeholder.prototype = {

    initialize: function () {
      this.isActive = false
      this.placeholderAttr = this.$el.attr('placeholder')
      // do not mess with default behavior
      this.$el.removeAttr('placeholder')
      this.isPassword = this.$el.is('[type=password]')
      if (this.isPassword) this.makeReplacement()
      this.$replacement
        .on({
            'keydown.placeholder': $.proxy(this.clearPlaceholder, this)
          , 'focus.placeholder drop.placeholder click.placeholder': $.proxy(this.setCaret, this)
          })
      this.$el
        .on('blur.placeholder keyup.placeholder', $.proxy(this.restorePlaceholder, this))
      this.restorePlaceholder()
    }

    // Set value and clear or restore placeholder
  , setValue: function (value) {
      if (value === '') {
        if (this.isActive) {
          return;
        } else {
          this.$el[0].value = value
          this.restorePlaceholder()
        }
      } else {
        if (this.isActive) this.clearPlaceholder()
        this.$el[0].value = value
      }
    }

    // Clear placeholder value at user input
  , clearPlaceholder: function (e) {
      var isActiveElement
      if (!this.isActive) return;
      if (!e || !(e.shiftKey && e.keyCode === 16) && e.keyCode !== 9) {
        this.isActive = false
        if (this.isPassword) {
          isActiveElement = this.$replacement[0] === document.activeElement
          this.$replacement.after(this.$el).detach()
          if (isActiveElement) this.$el.focus()
        } else {
          this.$el[0].value = ''
          this.$el.removeClass(this.options.className)
        }
      }
    }

    // Restore placeholder on blur and keyup
  , restorePlaceholder: function (e) {
      var isActiveElement
      if (this.isActive) return;
      if (this.$el[0].value === '') {
        this.isActive = true
        if (this.isPassword) {
          isActiveElement = this.$el[0] === document.activeElement
          this.$el.after(this.$replacement).detach()
          if (isActiveElement) this.$replacement.focus()
        } else {
          this.$el[0].value = this.placeholderAttr
          this.$el.addClass(this.options.className)
          this.setCaret.apply(this, arguments)
        }
      }
    }

    // Set caret at the beginning of the input
  , setCaret: function (e) {
      var el = this.$el[0]
      if (this.isActive && e) {
        setCaretTo(this.$replacement[0], 0)
        e.preventDefault()
      }
    }<commit_msg>Use jQuery to check focus state<commit_after>/*
  jQuery placeholder plugin
  by <NAME>, @unsoundscapes

  Based on exisitng plugin http://mths.be/placeholder by @mathias
  Adopted to toggle placeholder on user input instead of focus

  Released under the MIT license
*/

;(function (factory) {
  if (typeof define === 'function' && define.amd) {
    // AMD. Register as anonymous module.
    define(['jquery'], factory)
  } else {
    // Browser globals.
    factory(jQuery)
  }
}(function ($) {

  var isInputSupported = 'placeholder' in document.createElement('input')
    , isTextareaSupported = 'placeholder' in document.createElement('textarea')
    , Placeholder
    , $placeholders = $()

  function getAttributes (elem) {
    // Return an object of element attributes
    var newAttrs = {}
      , rinlinejQuery = /^jQuery\d+$/

    $.each(elem.attributes, function () {
      if (this.specified && !rinlinejQuery.test(this.name)) {
        newAttrs[this.name] = this.value
      }
    })
    return newAttrs
  }

  function setCaretTo (el, index) {
    // Set caret to specified @index
    if (el.createTextRange) {
      var range = el.createTextRange()
      range.move('character', index)
      range.select()
    } else if (el.selectionStart != null) {
      el.focus()
      el.setSelectionRange(index, index)
    }
  }


  Placeholder = function (element, options) {
    this.options = options || {}
    this.$replacement = this.$el = $(element)
    if ( this.$el.is('[placeholder]') && (this.options.force ||
        !isInputSupported && this.$el.is('input') ||
        !isTextareaSupported && this.$el.is('textarea'))
       ) {
      this.initialize.apply(this, arguments)
      // Cache all elements with placeholders
      $placeholders = $placeholders.add(element)
    }
  }

  Placeholder.prototype = {

    initialize: function () {
      this.isActive = false
      this.placeholderAttr = this.$el.attr('placeholder')
      // do not mess with default behavior
      this.$el.removeAttr('placeholder')
      this.isPassword = this.$el.is('[type=password]')
      if (this.isPassword) this.makeReplacement()
      this.$replacement
        .on({
            'keydown.placeholder': $.proxy(this.clearPlaceholder, this)
          , 'focus.placeholder drop.placeholder click.placeholder': $.proxy(this.setCaret, this)
          })
      this.$el
        .on('blur.placeholder keyup.placeholder', $.proxy(this.restorePlaceholder, this))
      this.restorePlaceholder()
    }

    // Set value and clear or restore placeholder
  , setValue: function (value) {
      if (value === '') {
        if (this.isActive) {
          return;
        } else {
          this.$el[0].value = value
          this.restorePlaceholder()
        }
      } else {
        if (this.isActive) this.clearPlaceholder()
        this.$el[0].value = value
      }
    }

    // Clear placeholder value at user input
  , clearPlaceholder: function (e) {
      var isActiveElement
      if (!this.isActive) return;
      if (!e || !(e.shiftKey && e.keyCode === 16) && e.keyCode !== 9) {
        this.isActive = false
        if (this.isPassword) {
          isActiveElement = this.$replacement.is(':focus')
          this.$replacement.after(this.$el).detach()
          if (isActiveElement) this.$el.focus()
        } else {
          this.$el[0].value = ''
          this.$el.removeClass(this.options.className)
        }
      }
    }

    // Restore placeholder on blur and keyup
  , restorePlaceholder: function (e) {
      var isActiveElement
      if (this.isActive) return;
      if (this.$el[0].value === '') {
        this.isActive = true
        if (this.isPassword) {
          isActiveElement = this.$el.is(':focus')
          this.$el.after(this.$replacement).detach()
          if (isActiveElement) this.$replacement.focus()
        } else {
          this.$el[0].value = this.placeholderAttr
          this.$el.addClass(this.options.className)
          this.setCaret.apply(this, arguments)
        }
      }
    }

    // Set caret at the beginning of the input
  , setCaret: function (e) {
      var el = this.$el[0]
      if (this.isActive && e) {
        setCaretTo(this.$replacement[0], 0)
        e.preventDefault()
      }
    }
{'fraction_non_alphanumeric': 0.136908962597036, 'fraction_numerical': 0.0028228652081863093, 'mean_word_length': 2.33712715855573, 'pattern_counts': {'":': 0, '<': 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': '1640376', 'n_tokens_mistral': 2536, 'n_tokens_neox': 2486, 'n_words': 559}