[Kimchi-devel] [PATCH] [Wok 16/16] Use a CDN to get base64.min.js content

Aline Manera aline.manera at gmail.com
Thu Sep 7 21:50:33 UTC 2017


That way, Wok does not need to import/package the base64.min.js file.
Reducing the imported JS code might be easier to get the Wok package
acceptable on Debian and/or Fedora official repositories.

Signed-off-by: Aline Manera <aline.manera at gmail.com>
---
 COPYING                    |   4 --
 IBM-license-blacklist      |   2 -
 configure.ac               |   1 -
 src/wok/config.py.in       |   6 ---
 tests/test_config.py.in    |   6 ---
 ui/Makefile.am             |   4 +-
 ui/base64/Makefile.am      |  21 --------
 ui/base64/README.md        |  27 ----------
 ui/base64/jquery.base64.js | 122 ---------------------------------------------
 ui/js/src/wok.utils.js     |   4 +-
 ui/pages/login.html.tmpl   |   4 +-
 ui/pages/wok-ui.html.tmpl  |   2 +-
 12 files changed, 7 insertions(+), 196 deletions(-)
 delete mode 100644 ui/base64/Makefile.am
 delete mode 100644 ui/base64/README.md
 delete mode 100644 ui/base64/jquery.base64.js

diff --git a/COPYING b/COPYING
index d36645f4..658a9322 100644
--- a/COPYING
+++ b/COPYING
@@ -4,10 +4,6 @@ Apache License version 2.0.
 
 Wok makes use of different projects and they are placed as below:
 
-Files: ui/base64/jquery.base64.js
-Source: https://plugins.jquery.com/base64
-License: MIT
-
 Files: ui/css/src/bootstrap.custom.scss
        ui/css/src/vendor/bootstrap-sass/bootstrap/*
 Source: https://github.com/twbs/bootstrap
diff --git a/IBM-license-blacklist b/IBM-license-blacklist
index ec14fe06..82aff79f 100644
--- a/IBM-license-blacklist
+++ b/IBM-license-blacklist
@@ -40,8 +40,6 @@ src/wok/plugins/sample/po/POTFILES.in
 src/wok/plugins/sample/po/sample.pot
 src/wok/plugins/sample/ui/config/tab-ext.xml
 src/wok/plugins/sample/ui/pages/help/en_US/.*.html
-ui/base64/README.md
-ui/base64/jquery.base64.js
 ui/css/src/vendor/bootstrap-sass/LICENSE
 ui/css/src/vendor/bootstrap-sass/bootstrap/.*.scss
 ui/css/src/vendor/bootstrap-sass/bootstrap/mixins/.*.scss
diff --git a/configure.ac b/configure.ac
index ca0e21df..72b20f55 100644
--- a/configure.ac
+++ b/configure.ac
@@ -76,7 +76,6 @@ AC_CONFIG_FILES([
     src/wok/xmlutils/Makefile
     src/wok/plugins/Makefile
     ui/Makefile
-    ui/base64/Makefile
     ui/css/Makefile
     ui/images/Makefile
     ui/images/theme-default/Makefile
diff --git a/src/wok/config.py.in b/src/wok/config.py.in
index fed6dbbb..60fbfcab 100644
--- a/src/wok/config.py.in
+++ b/src/wok/config.py.in
@@ -173,12 +173,6 @@ class WokConfig(dict):
                                                       'config/tab-ext.xml'),
             'tools.nocache.on': True
         },
-        '/base64/jquery.base64.js': {
-            'tools.staticfile.on': True,
-            'tools.staticfile.filename': '%s/base64/jquery.base64.js' %
-                                         paths.ui_dir,
-            'tools.nocache.on': True,
-        },
         '/wok-ui.html': {
             'tools.wokauth.on': True
         },
diff --git a/tests/test_config.py.in b/tests/test_config.py.in
index c0b0d385..c7e2a112 100644
--- a/tests/test_config.py.in
+++ b/tests/test_config.py.in
@@ -96,12 +96,6 @@ class ConfigTests(unittest.TestCase):
                                              paths.ui_dir,
                 'tools.nocache.on': True
             },
-            '/base64/jquery.base64.js': {
-                'tools.staticfile.on': True,
-                'tools.staticfile.filename': '%s/base64/jquery.base64.js' %
-                                             paths.ui_dir,
-                'tools.nocache.on': True,
-            },
             '/wok-ui.html': {
                 'tools.wokauth.on': True
             },
diff --git a/ui/Makefile.am b/ui/Makefile.am
index 07218dcd..650d65cf 100644
--- a/ui/Makefile.am
+++ b/ui/Makefile.am
@@ -1,7 +1,7 @@
 #
 # Project Wok
 #
-# Copyright IBM Corp, 2013-2016
+# Copyright IBM Corp, 2013-2017
 #
 # Code derived from Project Kimchi
 #
@@ -17,7 +17,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-SUBDIRS = base64 css images js libs pages config
+SUBDIRS = css images js libs pages config
 
 uidir = $(datadir)/wok/ui
 
diff --git a/ui/base64/Makefile.am b/ui/base64/Makefile.am
deleted file mode 100644
index b3024c1b..00000000
--- a/ui/base64/Makefile.am
+++ /dev/null
@@ -1,21 +0,0 @@
-#
-# Project Wok
-#
-# Copyright IBM Corp, 2015-2016
-#
-# Code derived from Project Kimchi
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-jquerybase64dir = $(datadir)/wok/ui/base64
-dist_jquerybase64_DATA = $(wildcard *.js) $(NULL)
diff --git a/ui/base64/README.md b/ui/base64/README.md
deleted file mode 100644
index bc8a1a94..00000000
--- a/ui/base64/README.md
+++ /dev/null
@@ -1,27 +0,0 @@
-#No documentation yet!
-(feel free to write a bit about it)
-
-You can check for `btoa` and `atob` support and refer to `jQuery.base64`
-
-    if (!window.btoa) window.btoa = $.base64.btoa
-    if (!window.atob) window.atob = $.base64.atob
-
-## Download
- Get the [raw](https://raw.github.com/yckart/jquery.base64.js/master/jquery.base64.js) script, download the complete [package](https://github.com/yckart/jquery.base64.js/zipball/master) or fork it on [GitHub](https://github.com/yckart/jquery.base64.js/).
-
-## Support
-
- [@yckart](http://twitter.com/yckart) #jquery #base64
- [http://yckart.com](http://yckart.com/)
-
-### Thanks
-- https://github.com/carlo/jquery-base64
-
-###License
-Copyright (c) 2013 Yannick Albert ([http://yckart.com/](http://yckart.com/))
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
diff --git a/ui/base64/jquery.base64.js b/ui/base64/jquery.base64.js
deleted file mode 100644
index bbce5f0c..00000000
--- a/ui/base64/jquery.base64.js
+++ /dev/null
@@ -1,122 +0,0 @@
-/*!
- * 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) 2012 Yannick Albert (http://yckart.com)
- * Licensed 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+0800 - U+FFFF in 3 chars
-         *
-         * @param {String} strUni Unicode string to be encoded as UTF-8
-         * @returns {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
-            function(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
-            function(c) {
-                var cc = c.charCodeAt(0);
-                return String.fromCharCode(0xe0 | cc >> 12, 0x80 | cc >> 6 & 0x3F, 0x80 | cc & 0x3f);
-            });
-            return strUtf;
-        },
-
-        /**
-         * Decode utf-8 encoded string back into multi-byte Unicode characters
-         *
-         * @param {String} strUtf UTF-8 string to be decoded back to Unicode
-         * @returns {String} decoded string
-         */
-        decode: function(strUtf) {
-            // note: decode 3-byte chars first as decoded 2-byte strings could appear to be 3-byte char!
-            var strUni = strUtf.replace(/[\u00e0-\u00ef][\u0080-\u00bf][\u0080-\u00bf]/g, // 3-byte chars
-            function(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;
-    }
-
-    function code(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));
\ No newline at end of file
diff --git a/ui/js/src/wok.utils.js b/ui/js/src/wok.utils.js
index 7d030609..ca080311 100644
--- a/ui/js/src/wok.utils.js
+++ b/ui/js/src/wok.utils.js
@@ -202,11 +202,11 @@ wok.escapeStr = function(str) {
 };
 
 wok.urlSafeB64Decode = function(str) {
-    return $.base64.atob(str.replace(/-/g, '+').replace(/_/g, '/'), true);
+    return atob(str.replace(/-/g, '+').replace(/_/g, '/'), true);
 }
 
 wok.urlSafeB64Encode = function(str) {
-    return $.base64.btoa(str, true).replace(/\+/g, '-').replace(/\//g, '_');
+    return btoa(str, true).replace(/\+/g, '-').replace(/\//g, '_');
 }
 
 wok.notificationsLoop = function() {
diff --git a/ui/pages/login.html.tmpl b/ui/pages/login.html.tmpl
index 4e3975af..3044a987 100644
--- a/ui/pages/login.html.tmpl
+++ b/ui/pages/login.html.tmpl
@@ -60,11 +60,11 @@
     <meta name="msapplication-wide310x150logo" content="$href('images/mstile-310x310.png')" />
     <meta name="msapplication-square310x310logo" content="$href('images/mstile-310x150.png')" />
     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/themes/base/jquery-ui.min.css">
-    <link rel="stylesheet" href="$href('css/jquery-ui.custom.css')">
-    <link rel="stylesheet" href="$href('css/bootstrap.custom.css')">
     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.4/css/bootstrap-select.min.css">
     <link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">
     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
+    <link rel="stylesheet" href="$href('css/jquery-ui.custom.css')">
+    <link rel="stylesheet" href="$href('css/bootstrap.custom.css')">
     <link rel="stylesheet" href="$href('css/bootstrap-select.custom.css')">
     <link rel="stylesheet" href="$href('css/wok.css')">
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
diff --git a/ui/pages/wok-ui.html.tmpl b/ui/pages/wok-ui.html.tmpl
index d36e3dca..64b3e26d 100644
--- a/ui/pages/wok-ui.html.tmpl
+++ b/ui/pages/wok-ui.html.tmpl
@@ -84,7 +84,7 @@
     <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
     <script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
     <script src="https://cdn.datatables.net/plug-ins/1.10.12/sorting/ip-address.js"></script>
-    <script src="$href('base64/jquery.base64.js')"></script>
+    <script src="https://cdnjs.cloudflare.com/ajax/libs/Base64/1.0.1/base64.min.js"></script>
     <script src="$href('js/wok.min.js')"></script>
     <!-- This is used for detecting if the UI needs to be built -->
     </head>
-- 
2.13.5



More information about the Kimchi-devel mailing list