Jquery Base64 Source __jquery

Source: Internet
Author: User
Tags base64 string back
Copy a copy of the jquery base64 source code.
/*!
 * Jquery.base64.js 0.1-https://github.com/yckart/jquery.base64.js * makes Base64 en &-decoding simpler as it is. * * Based upon:https://gist.github.com/yaffle/1284012 * * Copyright (c) Yannick Albert (http://yckart.com) * Li
 Censed under the MIT license (http://www.opensource.org/licenses/mit-license.php).
        * 2013/02/10 **/;(function ($) {var b64 = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/",

    a256 = ', R64 = [256], r256 = [256], i = 0;
         var UTF8 = {/** * Encode multi-byte Unicode string into utf-8 multiple single-byte characters * (Bmp/basic Multilingual plane only) * * Chars in range u+0080-u+07ff are encoded in 2 Chars, u+080 0-U+FFFF in 3 chars * * @param {string} Struni Unicode string to is encoded as UTF-8 * @retur NS {STRING} encoded String */encode:function (Struni) {//Use regular EXPressions & String.Replace callback function for better efficiency//than procedural-approaches var Strutf = Struni.replace (/[\u0080-\u07ff]/g,//u+0080-u+07ff => 2 bytes 110yyyyy, 10zzzzzz functio
                N (c) {var cc = c.charcodeat (0);
            Return String.fromCharCode (0xc0 | cc >> 6, 0x80 | cc & 0x3f); }). replace (/[\u0800-\uffff]/g,//u+0800-u+ffff => 3 bytes 1110xxxx, 10yyyyyy, 10zzzzzz func
                tion (c) {var cc = c.charcodeat (0);
            Return String.fromCharCode (0xe0 | cc >> 0x80 | cc >> 6 & 0x3F, 0x80 | cc & 0x3F);
            });
        return STRUTF; },/** * Decode utf-8 encoded string back into multi-byte Unicode characters * * @para
        m {string} Strutf UTF-8 string to is decoded back to Unicode * @returns {string} decoded String * * Decode:functIon (STRUTF) {//Note:decode 3-byte chars-A-decoded 2-byte strings could to be appear 3-byte var Struni = Strutf.replace (/[\u00e0-\u00ef][\u0080-\u00bf][\u0080-\u00bf]/g,//3-byte chars Functi On (c) {//(note parentheses for precence) var cc = ((c.charcodeat (0) & 0x0f) << 12) | ((C.charcodeat (1) & 0x3f) << 6) |
                (C.charcodeat (2) & 0x3f);
            return String.fromCharCode (CC); ). replace (/[\u00c0-\u00df][\u0080-\u00bf]/g,//2-byte chars function (c) {//(note parentheses For precence var cc = (c.charcodeat (0) & 0x1f) << 6 |
                C.charcodeat (1) & 0x3f;
            return String.fromCharCode (CC);
            });
        return Struni;

    }
    };
        while (I < 256) {var c = string.fromcharcode (i);
        a256 + = C;
        R256[i] = i;
        R64[i] = B64.indexof (c);
    ++i; } functionCode (s, discard, alpha, beta, W1, w2) {s = String (s);

        var buffer = 0, i = 0, length = s.length, result = ', Bitsinbuffer = 0;
            while (I < length) {var c = s.charcodeat (i); c = C < 256?

            ALPHA[C]:-1;
            Buffer = (buffer << W1) + C;

            Bitsinbuffer + = W1;
                while (Bitsinbuffer >= W2) {bitsinbuffer-= W2;
                var tmp = buffer >> bitsinbuffer;
                result = Beta.charat (TMP);
            Buffer ^= tmp << Bitsinbuffer;
        } ++i;
        } if (!discard && bitsinbuffer > 0) result + = Beta.charat (buffer << (w2-bitsinbuffer));
    return result; var Plugin = $.base64 = function (dir, input, encode) {return input? Plugin[dir] (input, encode): Dir?
        Null:this;

    }; Plugin.btoa = Plugin.encode = function (plain, UTF8encode) {plain = Plugin.raw = = False | | Plugin.utf8encode | | Utf8encode?
        Utf8.encode (plain): plain;
        Plain = code (plain, False, r256, b64, 8, 6);
    return plain + ' = = Slice ' ((plain.length% 4) | | 4);

    };
        Plugin.atob = Plugin.decode = function (coded, utf8decode) {coded = String (coded). Split (' = ');
        var i = coded.length;
            do {I.;
        Coded[i] = code (Coded[i], True, R64, a256, 6, 8);
        while (i > 0);
        coded = Coded.join ("); return Plugin.raw = = False | | Plugin.utf8decode | | Utf8decode?
    Utf8.decode (coded): coded;
}; } (JQuery));

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.