jQuery.checkAgent v2

by Tenderfeel

HTML

<h1>jQuery.checkAgent</h1>
<p id="is-smartphone" class="sample">スマホの時だけ青くなります</p>
<div class="sample">
    <div id="info"></div>
</div>

CSS

h1{
    font-weight:bold;
    margin:1em 0;
}

.pc h1{
    color:#1e90ff;
}
.smartphone h1 {
    color:#5f9ea0;
}

.garapagos h1 {
    color:#7b68ee;
}

.sample{
    border: solid 1px #ccc;
    padding: 0.5em;
    margin:1em 0;
}

#is-smartphone.smartphone {
    background: #000099;
    color:#fff;
}

JavaScript

'use strict';

/**
 * User-Agent check Plugin
 * User: Tenderfeel
 * Date: 11/06/20
 * LastModified: 14/12/24
 *
 */


;(function ( $, window, document, undefined ) {

  /**
   * jQuery function 'checkAgent'
   * @param method {string|object|undefined}
   *
   * $(document.body).checkAgent({});
   */

  var pluginName = "checkAgent";

  function checkAgent( element, options ) {
    this.element = $(element);

    this.options = $.extend( {}, this.DEFAULTS, options) ;
    this._name = pluginName;
      
        
      this.ua = navigator.userAgent;
      this.ws = $(window).width();
      this.sw  = screen.width;
    
      this.TYPE = 'PC';
      this.OS = null;
      this.APPLE = false;
      this.ANDROID = false;
      this.GARAPAGOS = false;
      this.BROWSER_NAME = null;
      this.DEVICE_NAME = null;
      this.VERSION = null;
      this.LOCALE = null;
      this.LANG = null;
      this.COUNTRY = null;
      this.SMARTPHONE = false;

    this.init();
  }

  checkAgent.DEFAULTS = {
    'type':true,
    'os':false,
    'device':true,
    'version':false,
    'lang':false,
    'country':false,
    'locale':false,
    'smartphone':false,
    'garapagos':false
  };
    

  checkAgent.prototype = {
    _doLocale : function(){
      this.LOCALE = window.navigator.language || $('html').attr('lang');
      if(this.LOCALE && this.LOCALE.indexOf('-') !== -1){
        var ls = this.LOCALE.split('-');
        this.LANG = ls[0];
        this.COUNTRY = ls[1];
      }else{
        this.LANG = this.LOCALE;
        this.COUNTRY = 'unknown';
      }
    },
      
    _doOS : function(){
      if(this.ua.indexOf('Win') !== -1){
        this.OS = 'win';
      }else if(this.ua.indexOf('Mac') !== -1){
        this.OS = 'mac';
      }else{
        this.OS = 'unknown';
      }
    },
      
    _doGarapagos : function(){

      this._doLocale();
      var m;

      if(this.ua.indexOf('DoCoMo') !== -1 || this.ua.indexOf('FOMA') !== -1){
        this.OS = 'docomo';
        this.TYPE...