From d4c41873c7558aec5360adae22ce7648c396249c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0lkay=20=C4=B0lknur?= Date: Mon, 19 Oct 2020 11:40:46 +0300 Subject: [PATCH] embed abp.js to the webcomponents assembly. --- ...p.AspNetCore.Components.WebAssembly.csproj | 2 +- .../wwwroot/abp.js | 80 +++++++++++++++++++ .../wwwroot/index.html | 2 +- .../wwwroot/libs/abp/core/abp.js | 76 ------------------ 4 files changed, 82 insertions(+), 78 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/wwwroot/abp.js delete mode 100644 templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/wwwroot/libs/abp/core/abp.js diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo.Abp.AspNetCore.Components.WebAssembly.csproj b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo.Abp.AspNetCore.Components.WebAssembly.csproj index 44a816678c..b7aa91c74e 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo.Abp.AspNetCore.Components.WebAssembly.csproj +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo.Abp.AspNetCore.Components.WebAssembly.csproj @@ -1,4 +1,4 @@ - + diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/wwwroot/abp.js b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/wwwroot/abp.js new file mode 100644 index 0000000000..b945daa56f --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/wwwroot/abp.js @@ -0,0 +1,80 @@ +var abp = abp || {}; +(function () { + abp.utils = abp.utils || {}; + /** + * Sets a cookie value for given key. + * This is a simple implementation created to be used by ABP. + * Please use a complete cookie library if you need. + * @param {string} key + * @param {string} value + * @param {string} expireDate (optional). If not specified the cookie will expire at the end of session. + * @param {string} path (optional) + * @param {bool} secure (optional) + */ + abp.utils.setCookieValue = function (key, value, expireDate, path, secure) { + var cookieValue = encodeURIComponent(key) + '='; + if (value) { + cookieValue = cookieValue + encodeURIComponent(value); + } + + if (expireDate) { + cookieValue = cookieValue + "; expires=" + expireDate; + } + + if (path) { + cookieValue = cookieValue + "; path=" + path; + } + + if (secure) { + cookieValue = cookieValue + "; secure"; + } + + document.cookie = cookieValue; + }; + + /** + * Gets a cookie with given key. + * This is a simple implementation created to be used by ABP. + * Please use a complete cookie library if you need. + * @param {string} key + * @returns {string} Cookie value or null + */ + abp.utils.getCookieValue = function (key) { + var equalities = document.cookie.split('; '); + for (var i = 0; i < equalities.length; i++) { + if (!equalities[i]) { + continue; + } + + var splitted = equalities[i].split('='); + if (splitted.length != 2) { + continue; + } + + if (decodeURIComponent(splitted[0]) === key) { + return decodeURIComponent(splitted[1] || ''); + } + } + + return null; + }; + + /** + * Deletes cookie for given key. + * This is a simple implementation created to be used by ABP. + * Please use a complete cookie library if you need. + * @param {string} key + * @param {string} path (optional) + */ + abp.utils.deleteCookie = function (key, path) { + var cookieValue = encodeURIComponent(key) + '='; + + cookieValue = cookieValue + "; expires=" + (new Date(new Date().getTime() - 86400000)).toUTCString(); + + if (path) { + cookieValue = cookieValue + "; path=" + path; + } + + document.cookie = cookieValue; + } +})(); \ No newline at end of file diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/wwwroot/index.html b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/wwwroot/index.html index b2b716caa2..5bba3d3350 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/wwwroot/index.html +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/wwwroot/index.html @@ -29,7 +29,7 @@ - + diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/wwwroot/libs/abp/core/abp.js b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/wwwroot/libs/abp/core/abp.js deleted file mode 100644 index 1d16d0cc38..0000000000 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/wwwroot/libs/abp/core/abp.js +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Sets a cookie value for given key. - * This is a simple implementation created to be used by ABP. - * Please use a complete cookie library if you need. - * @param {string} key - * @param {string} value - * @param {string} expireDate (optional). If not specified the cookie will expire at the end of session. - * @param {string} path (optional) - * @param {bool} secure (optional) - */ -window.abp.utils.setCookieValue = function (key, value, expireDate, path, secure) { - var cookieValue = encodeURIComponent(key) + '='; - if (value) { - cookieValue = cookieValue + encodeURIComponent(value); - } - - if (expireDate) { - cookieValue = cookieValue + "; expires=" + expireDate; - } - - if (path) { - cookieValue = cookieValue + "; path=" + path; - } - - if (secure) { - cookieValue = cookieValue + "; secure"; - } - - document.cookie = cookieValue; -}; - -/** - * Gets a cookie with given key. - * This is a simple implementation created to be used by ABP. - * Please use a complete cookie library if you need. - * @param {string} key - * @returns {string} Cookie value or null - */ -window.abp.utils.getCookieValue = function (key) { - var equalities = document.cookie.split('; '); - for (var i = 0; i < equalities.length; i++) { - if (!equalities[i]) { - continue; - } - - var splitted = equalities[i].split('='); - if (splitted.length != 2) { - continue; - } - - if (decodeURIComponent(splitted[0]) === key) { - return decodeURIComponent(splitted[1] || ''); - } - } - - return null; -}; - -/** - * Deletes cookie for given key. - * This is a simple implementation created to be used by ABP. - * Please use a complete cookie library if you need. - * @param {string} key - * @param {string} path (optional) - */ -window.abp.utils.deleteCookie = function (key, path) { - var cookieValue = encodeURIComponent(key) + '='; - - cookieValue = cookieValue + "; expires=" + (new Date(new Date().getTime() - 86400000)).toUTCString(); - - if (path) { - cookieValue = cookieValue + "; path=" + path; - } - - document.cookie = cookieValue; -} \ No newline at end of file