(function (global)()

in salesforce/canvas/public/javascripts/canvas-all.js [1:594]


(function (global) {
  if (global.Sfdc && global.Sfdc.canvas && global.Sfdc.canvas.module) {
    return;
  }
  var extmodules = {};
  if (global.Sfdc && global.Sfdc.canvas) {
    for (var key in global.Sfdc.canvas) {
      if (global.Sfdc.canvas.hasOwnProperty(key)) {
        extmodules[key] = global.Sfdc.canvas[key];
      }
    }
  }
  var oproto = Object.prototype,
    aproto = Array.prototype,
    doc = global.document,
    keyStr =
      'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
    $ = {
      hasOwn: function (obj, prop) {
        return oproto.hasOwnProperty.call(obj, prop);
      },
      isUndefined: function (value) {
        var undef;
        return value === undef;
      },
      isNil: function (value) {
        return $.isUndefined(value) || value === null || value === '';
      },
      isNumber: function (value) {
        return !!(
          value === 0 ||
          (value && value.toExponential && value.toFixed)
        );
      },
      isFunction: function (value) {
        return !!(value && value.constructor && value.call && value.apply);
      },
      isArray:
        Array.isArray ||
        function (value) {
          return oproto.toString.call(value) === '[object Array]';
        },
      isArguments: function (value) {
        return !!(value && $.hasOwn(value, 'callee'));
      },
      isObject: function (value) {
        return value !== null && typeof value === 'object';
      },
      isString: function (value) {
        return value !== null && typeof value == 'string';
      },
      appearsJson: function (value) {
        return /^\{.*\}$/.test(value);
      },
      nop: function () {},
      invoker: function (fn) {
        if ($.isFunction(fn)) {
          fn();
        }
      },
      identity: function (obj) {
        return obj;
      },
      each: function (obj, it, ctx) {
        if ($.isNil(obj)) {
          return;
        }
        var nativ = aproto.forEach,
          i = 0,
          l,
          key;
        l = obj.length;
        ctx = ctx || obj;
        if (nativ && nativ === obj.forEach) {
          obj.forEach(it, ctx);
        } else {
          if ($.isNumber(l)) {
            while (i < l) {
              if (it.call(ctx, obj[i], i, obj) === false) {
                return;
              }
              i += 1;
            }
          } else {
            for (key in obj) {
              if (
                $.hasOwn(obj, key) &&
                it.call(ctx, obj[key], key, obj) === false
              ) {
                return;
              }
            }
          }
        }
      },
      startsWithHttp: function (orig, newUrl) {
        return !$.isString(orig)
          ? orig
          : orig.substring(0, 4) === 'http'
          ? orig
          : newUrl;
      },
      map: function (obj, it, ctx) {
        var results = [],
          nativ = aproto.map;
        if ($.isNil(obj)) {
          return results;
        }
        if (nativ && obj.map === nativ) {
          return obj.map(it, ctx);
        }
        ctx = ctx || obj;
        $.each(obj, function (value, i, list) {
          results.push(it.call(ctx, value, i, list));
        });
        return results;
      },
      values: function (obj) {
        return $.map(obj, $.identity);
      },
      slice: function (array, begin, end) {
        return aproto.slice.call(
          array,
          $.isUndefined(begin) ? 0 : begin,
          $.isUndefined(end) ? array.length : end
        );
      },
      toArray: function (iterable) {
        if (!iterable) {
          return [];
        }
        if (iterable.toArray) {
          return iterable.toArray;
        }
        if ($.isArray(iterable)) {
          return iterable;
        }
        if ($.isArguments(iterable)) {
          return $.slice(iterable);
        }
        return $.values(iterable);
      },
      size: function (obj) {
        return $.toArray(obj).length;
      },
      indexOf: function (array, item) {
        var nativ = aproto.indexOf,
          i,
          l;
        if (!array) {
          return -1;
        }
        if (nativ && array.indexOf === nativ) {
          return array.indexOf(item);
        }
        for (i = 0, l = array.length; i < l; i += 1) {
          if (array[i] === item) {
            return i;
          }
        }
        return -1;
      },
      isEmpty: function (obj) {
        if (obj === null) {
          return true;
        }
        if ($.isArray(obj) || $.isString(obj)) {
          return obj.length === 0;
        }
        for (var key in obj) {
          if ($.hasOwn(obj, key)) {
            return false;
          }
        }
        return true;
      },
      remove: function (array, item) {
        var i = $.indexOf(array, item);
        if (i >= 0) {
          array.splice(i, 1);
        }
      },
      param: function (a, encode) {
        var s = [];
        encode = encode || false;
        function add(key, value) {
          if ($.isNil(value)) {
            return;
          }
          value = $.isFunction(value) ? value() : value;
          if ($.isArray(value)) {
            $.each(value, function (v, n) {
              add(key, v);
            });
          } else {
            if (encode) {
              s[s.length] =
                encodeURIComponent(key) + '=' + encodeURIComponent(value);
            } else {
              s[s.length] = key + '=' + value;
            }
          }
        }
        if ($.isArray(a)) {
          $.each(a, function (v, n) {
            add(n, v);
          });
        } else {
          for (var p in a) {
            if ($.hasOwn(a, p)) {
              add(p, a[p]);
            }
          }
        }
        return s.join('&').replace(/%20/g, '+');
      },
      objectify: function (q) {
        var arr,
          obj = {},
          i,
          p,
          n,
          v,
          e;
        if ($.isNil(q)) {
          return obj;
        }
        if (q.substring(0, 1) == '?') {
          q = q.substring(1);
        }
        arr = q.split('&');
        for (i = 0; i < arr.length; i += 1) {
          p = arr[i].split('=');
          n = p[0];
          v = p[1];
          e = obj[n];
          if (!$.isNil(e)) {
            if ($.isArray(e)) {
              e[e.length] = v;
            } else {
              obj[n] = [];
              obj[n][0] = e;
              obj[n][1] = v;
            }
          } else {
            obj[n] = v;
          }
        }
        return obj;
      },
      stripUrl: function (url) {
        return $.isNil(url)
          ? null
          : url.replace(/([^:]+:\/\/[^\/\?#]+).*/, '$1');
      },
      query: function (url, q) {
        if ($.isNil(q)) {
          return url;
        }
        url = url.replace(/#.*$/, '');
        url += /^\#/.test(q) ? q : (/\?/.test(url) ? '&' : '?') + q;
        return url;
      },
      extend: function (dest) {
        $.each($.slice(arguments, 1), function (mixin, i) {
          $.each(mixin, function (value, key) {
            dest[key] = value;
          });
        });
        return dest;
      },
      endsWith: function (str, suffix) {
        return str.indexOf(suffix, str.length - suffix.length) !== -1;
      },
      capitalize: function (str) {
        return str.charAt(0).toUpperCase() + str.slice(1);
      },
      uncapitalize: function (str) {
        return str.charAt(0).toLowerCase() + str.slice(1);
      },
      decode: function (str) {
        var output = [],
          chr1,
          chr2,
          chr3 = '',
          enc1,
          enc2,
          enc3,
          enc4 = '',
          i = 0;
        str = str.replace(/[^A-Za-z0-9\+\/\=]/g, '');
        do {
          enc1 = keyStr.indexOf(str.charAt(i++));
          enc2 = keyStr.indexOf(str.charAt(i++));
          enc3 = keyStr.indexOf(str.charAt(i++));
          enc4 = keyStr.indexOf(str.charAt(i++));
          chr1 = (enc1 << 2) | (enc2 >> 4);
          chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
          chr3 = ((enc3 & 3) << 6) | enc4;
          output.push(String.fromCharCode(chr1));
          if (enc3 !== 64) {
            output.push(String.fromCharCode(chr2));
          }
          if (enc4 !== 64) {
            output.push(String.fromCharCode(chr3));
          }
          chr1 = chr2 = chr3 = '';
          enc1 = enc2 = enc3 = enc4 = '';
        } while (i < str.length);
        return $.escapeToUTF8(output.join(''));
      },
      escapeToUTF8: function (str) {
        var outStr = '';
        var i = 0;
        while (i < str.length) {
          var c = str.charCodeAt(i++);
          var c1;
          if (c < 128) {
            outStr += String.fromCharCode(c);
          } else {
            if (c > 191 && c < 224) {
              c1 = str.charCodeAt(i++);
              outStr += String.fromCharCode(((c & 31) << 6) | (c1 & 63));
            } else {
              c1 = str.charCodeAt(i++);
              var c2 = str.charCodeAt(i++);
              outStr += String.fromCharCode(
                ((c & 15) << 12) | ((c1 & 63) << 6) | (c2 & 63)
              );
            }
          }
        }
        return outStr;
      },
      validEventName: function (name, res) {
        var ns,
          parts = name.split(/\./),
          regex = /^[$A-Z_][0-9A-Z_$]*$/i,
          reserved = {
            sfdc: true,
            canvas: true,
            force: true,
            salesforce: true,
            chatter: true,
            s1: true,
          };
        $.each($.isArray(res) ? res : [res], function (v) {
          reserved[v] = false;
        });
        if (parts.length > 2) {
          return 1;
        }
        if (parts.length === 2) {
          ns = parts[0].toLowerCase();
          if (reserved[ns]) {
            return 2;
          }
        }
        if (!regex.test(parts[0]) || !regex.test(parts[1])) {
          return 3;
        }
        return 0;
      },
      prototypeOf: function (obj) {
        var nativ = Object.getPrototypeOf,
          proto = '__proto__';
        if ($.isFunction(nativ)) {
          return nativ.call(Object, obj);
        } else {
          if (typeof {}[proto] === 'object') {
            return obj[proto];
          } else {
            return obj.constructor.prototype;
          }
        }
      },
      module: function (ns, decl) {
        var parts = ns.split('.'),
          parent = global.Sfdc.canvas,
          i,
          length;
        if (parts[1] === 'canvas') {
          parts = parts.slice(2);
        }
        length = parts.length;
        for (i = 0; i < length; i += 1) {
          if ($.isUndefined(parent[parts[i]])) {
            parent[parts[i]] = {};
          }
          parent = parent[parts[i]];
        }
        if ($.isFunction(decl)) {
          decl = decl();
        }
        return $.extend(parent, decl);
      },
      document: function () {
        return doc;
      },
      byId: function (id) {
        return doc.getElementById(id);
      },
      byClass: function (clazz) {
        return doc.getElementsByClassName(clazz);
      },
      attr: function (el, name) {
        var a = el.attributes,
          i;
        for (i = 0; i < a.length; i += 1) {
          if (name === a[i].name) {
            return a[i].value;
          }
        }
      },
      onReady: function (cb) {
        if ($.isFunction(cb)) {
          readyHandlers.push(cb);
        }
      },
      console: (function () {
        var enabled = false;
        if (window && !window.console) {
          window.console = {};
        }
        if (window && !window.console.log) {
          window.console.log = function () {};
        }
        if (window && !window.console.error) {
          window.console.error = function () {};
        }
        function isSessionStorage() {
          try {
            return 'sessionStorage' in window && window.sessionStorage !== null;
          } catch (e) {
            return false;
          }
        }
        function log() {}
        function error() {}
        function activate() {
          if (Function.prototype.bind) {
            log = Function.prototype.bind.call(console.log, console);
          } else {
            log = function () {
              Function.prototype.apply.call(console.log, console, arguments);
            };
          }
        }
        function deactivate() {
          log = function () {};
        }
        function enable() {
          enabled = true;
          if (isSessionStorage()) {
            sessionStorage.setItem('canvas_console', 'true');
          }
          activate();
        }
        function disable() {
          enabled = false;
          if (isSessionStorage()) {
            sessionStorage.setItem('canvas_console', 'false');
          }
          deactivate();
        }
        enabled =
          isSessionStorage() &&
          sessionStorage.getItem('canvas_console') === 'true';
        if (enabled) {
          activate();
        } else {
          deactivate();
        }
        if (Function.prototype.bind) {
          error = Function.prototype.bind.call(console.error, console);
        } else {
          error = function () {
            Function.prototype.apply.call(console.error, console, arguments);
          };
        }
        return { enable: enable, disable: disable, log: log, error: error };
      })(),
    },
    readyHandlers = [],
    canvas = function (cb) {
      if ($.isFunction(cb)) {
        readyHandlers.push(cb);
      }
    };
  (function () {
    var called = false,
      isFrame,
      fn;
    function ready() {
      if (called) {
        return;
      }
      called = true;
      ready = $.nop;
      $.each(readyHandlers, $.invoker);
      readyHandlers = [];
    }
    function tryScroll() {
      if (called) {
        return;
      }
      try {
        document.documentElement.doScroll('left');
        ready();
      } catch (e) {
        setTimeout(tryScroll, 30);
      }
    }
    if (document.addEventListener) {
      document.addEventListener('DOMContentLoaded', ready, false);
    } else {
      if (document.attachEvent) {
        try {
          isFrame = self !== top;
        } catch (e) {}
        if (document.documentElement.doScroll && !isFrame) {
          tryScroll();
        }
        document.attachEvent('onreadystatechange', function () {
          if (document.readyState === 'complete') {
            ready();
          }
        });
      }
    }
    if (window.addEventListener) {
      window.addEventListener('load', ready, false);
    } else {
      if (window.attachEvent) {
        window.attachEvent('onload', ready);
      } else {
        fn = window.onload;
        window.onload = function () {
          if (fn) {
            fn();
          }
          ready();
        };
      }
    }
  })();
  $.each($, function (fn, name) {
    canvas[name] = fn;
  });
  $.each(extmodules, function (fn, name) {
    canvas[name] = fn;
  });
  (function () {
    var method;
    var noop = function () {};
    var methods = [
      'assert',
      'clear',
      'count',
      'debug',
      'dir',
      'dirxml',
      'error',
      'exception',
      'group',
      'groupCollapsed',
      'groupEnd',
      'info',
      'log',
      'markTimeline',
      'profile',
      'profileEnd',
      'table',
      'time',
      'timeEnd',
      'timeStamp',
      'trace',
      'warn',
    ];
    var length = methods.length;
    var console =
      typeof window !== 'undefined' && window.console ? window.console : {};
    while (length--) {
      method = methods[length];
      if (!console[method]) {
        console[method] = noop;
      }
    }
  })();
  if (!global.Sfdc) {
    global.Sfdc = {};
  }
  global.Sfdc.canvas = canvas;
})(window);