Merge pull request #15292 from nextcloud/refactor/oc-navigation-methods-bundle

Move OC navigation methods to the bundle
This commit is contained in:
Morris Jobke 2019-04-30 10:52:14 +02:00 committed by GitHub
commit 2e0199a04a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 17 deletions

View File

@ -117,7 +117,7 @@ function(e){var t,n,i,r,s,o,a,l,u,c,d,h,p,f,m,g,_,v,y,b="sizzle"+1*new Date,w=e.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
function j(e){for(var t,n=[],i=0,r=-1,s=0;i<e.length;){t=e.charAt(i);var o=!s&&"."===t||t>="0"&&t<="9";o!==s&&(n[++r]="",s=o),n[r]+=t,i++}return n}var z={History:{_handlers:[],_pushState:function(e,t,n){var i;if(i="string"==typeof e?e:F.buildQueryString(e),window.history.pushState){if(t=t||location.pathname+"?"+i,navigator.userAgent.toLowerCase().indexOf("firefox")>-1&&parseInt(navigator.userAgent.split("/").pop())<51)for(var r,s=document.querySelectorAll('[fill^="url(#"], [stroke^="url(#"], [filter^="url(#invert"]'),o=0,a=s.length;o<a;o++)(r=s[o]).style.fill=r.style.fill,r.style.stroke=r.style.stroke,r.removeAttribute("filter"),r.setAttribute("filter","url(#invert)");n?window.history.replaceState(e,"",t):window.history.pushState(e,"",t)}else window.location.hash="?"+i,this._cancelPop=!0},pushState:function(e,t){return this._pushState(e,t,!1)},replaceState:function(e,t){return this._pushState(e,t,!0)},addOnPopStateHandler:function(e){this._handlers.push(e)},_parseHashQuery:function(){var e=window.location.hash,t=e.indexOf("?");return t>=0?e.substr(t+1):e.length?e.substr(1):""},_decodeQuery:function(e){return e.replace(/\+/g," ")},parseUrlQuery:function(){var e,t=this._parseHashQuery();return t&&(e=F.parseQueryString(this._decodeQuery(t))),(e=c.a.extend(e||{},F.parseQueryString(this._decodeQuery(location.search))))||{}},_onPopState:function(e){var t;if(this._cancelPop)this._cancelPop=!1;else if(this._handlers.length){t=e&&e.state,c.a.isString(t)?t=F.parseQueryString(t):t||(t=this.parseUrlQuery()||{});for(var n=0;n<this._handlers.length;n++)this._handlers[n](t)}}},humanFileSize:i(74).a,computerFileSize:function(e){if("string"!=typeof e)return null;var t=e.toLowerCase().trim(),n=null,i=t.match(/^[\s+]?([0-9]*)(\.([0-9]+))?( +)?([kmgtp]?b?)$/i);return null===i?null:(n=parseFloat(t),isFinite(n)?(i[5]&&(n*={b:1,k:1024,kb:1024,mb:1048576,m:1048576,gb:1073741824,g:1073741824,tb:1099511627776,t:1099511627776,pb:0x4000000000000,p:0x4000000000000}[i[5]]),n=Math.round(n)):null)},formatDate:function(e,t){return t=t||"LLL",H()(e).format(t)},relativeModifiedDate:function(e){var n=H()().diff(H()(e));return n>=0&&n<45e3?t("core","seconds ago"):H()(e).fromNow()},isIE:function(){return M()("html").hasClass("ie")},getScrollBarWidth:function(){if(this._scrollBarWidth)return this._scrollBarWidth;var e=document.createElement("p");e.style.width="100%",e.style.height="200px";var t=document.createElement("div");t.style.position="absolute",t.style.top="0px",t.style.left="0px",t.style.visibility="hidden",t.style.width="200px",t.style.height="150px",t.style.overflow="hidden",t.appendChild(e),document.body.appendChild(t);var n=e.offsetWidth;t.style.overflow="scroll";var i=e.offsetWidth;return n===i&&(i=t.clientWidth),document.body.removeChild(t),this._scrollBarWidth=n-i,this._scrollBarWidth},stripTime:function(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())},naturalSortCompare:function(e,t){var n,i=j(e),r=j(t);for(n=0;i[n]&&r[n];n++)if(i[n]!==r[n]){var s=Number(i[n]),o=Number(r[n]);return s==i[n]&&o==r[n]?s-o:i[n].localeCompare(r[n],F.getLanguage())}return i.length-r.length},waitFor:function(e,t){!function n(){!0!==e()&&setTimeout(n,t)}()},isCookieSetToValue:function(e,t){for(var n=document.cookie.split(";"),i=0;i<n.length;i++){var r=n[i].split("=");if(r[0].trim()===e&&r[1].trim()===t)return!0}return!1}},F=n.a={Apps:r.a,AppConfig:o,Backbone:b,ContactsMenu:w.a,EventSource:A,L10N:Y,msg:S,Notification:C,PasswordConfirmation:P,Plugins:{_plugins:{},register:function(e,t){var n=this._plugins[e];n||(n=this._plugins[e]=[]),n.push(t)},getPlugins:function(e){return this._plugins[e]||[]},attach:function(e,t,n){for(var i=this.getPlugins(e),r=0;r<i.length;r++)i[r].attach&&i[r].attach(t,n)},detach:function(e,t,n){for(var i=this.getPlugins(e),r=0;r<i.length;r++)i[r].detach&&i[r].detach(t,n)}},search:I,Util:z};
function j(e){for(var t,n=[],i=0,r=-1,s=0;i<e.length;){t=e.charAt(i);var o=!s&&"."===t||t>="0"&&t<="9";o!==s&&(n[++r]="",s=o),n[r]+=t,i++}return n}var z={History:{_handlers:[],_pushState:function(e,t,n){var i;if(i="string"==typeof e?e:F.buildQueryString(e),window.history.pushState){if(t=t||location.pathname+"?"+i,navigator.userAgent.toLowerCase().indexOf("firefox")>-1&&parseInt(navigator.userAgent.split("/").pop())<51)for(var r,s=document.querySelectorAll('[fill^="url(#"], [stroke^="url(#"], [filter^="url(#invert"]'),o=0,a=s.length;o<a;o++)(r=s[o]).style.fill=r.style.fill,r.style.stroke=r.style.stroke,r.removeAttribute("filter"),r.setAttribute("filter","url(#invert)");n?window.history.replaceState(e,"",t):window.history.pushState(e,"",t)}else window.location.hash="?"+i,this._cancelPop=!0},pushState:function(e,t){return this._pushState(e,t,!1)},replaceState:function(e,t){return this._pushState(e,t,!0)},addOnPopStateHandler:function(e){this._handlers.push(e)},_parseHashQuery:function(){var e=window.location.hash,t=e.indexOf("?");return t>=0?e.substr(t+1):e.length?e.substr(1):""},_decodeQuery:function(e){return e.replace(/\+/g," ")},parseUrlQuery:function(){var e,t=this._parseHashQuery();return t&&(e=F.parseQueryString(this._decodeQuery(t))),(e=c.a.extend(e||{},F.parseQueryString(this._decodeQuery(location.search))))||{}},_onPopState:function(e){var t;if(this._cancelPop)this._cancelPop=!1;else if(this._handlers.length){t=e&&e.state,c.a.isString(t)?t=F.parseQueryString(t):t||(t=this.parseUrlQuery()||{});for(var n=0;n<this._handlers.length;n++)this._handlers[n](t)}}},humanFileSize:i(74).a,computerFileSize:function(e){if("string"!=typeof e)return null;var t=e.toLowerCase().trim(),n=null,i=t.match(/^[\s+]?([0-9]*)(\.([0-9]+))?( +)?([kmgtp]?b?)$/i);return null===i?null:(n=parseFloat(t),isFinite(n)?(i[5]&&(n*={b:1,k:1024,kb:1024,mb:1048576,m:1048576,gb:1073741824,g:1073741824,tb:1099511627776,t:1099511627776,pb:0x4000000000000,p:0x4000000000000}[i[5]]),n=Math.round(n)):null)},formatDate:function(e,t){return t=t||"LLL",H()(e).format(t)},relativeModifiedDate:function(e){var n=H()().diff(H()(e));return n>=0&&n<45e3?t("core","seconds ago"):H()(e).fromNow()},isIE:function(){return M()("html").hasClass("ie")},getScrollBarWidth:function(){if(this._scrollBarWidth)return this._scrollBarWidth;var e=document.createElement("p");e.style.width="100%",e.style.height="200px";var t=document.createElement("div");t.style.position="absolute",t.style.top="0px",t.style.left="0px",t.style.visibility="hidden",t.style.width="200px",t.style.height="150px",t.style.overflow="hidden",t.appendChild(e),document.body.appendChild(t);var n=e.offsetWidth;t.style.overflow="scroll";var i=e.offsetWidth;return n===i&&(i=t.clientWidth),document.body.removeChild(t),this._scrollBarWidth=n-i,this._scrollBarWidth},stripTime:function(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())},naturalSortCompare:function(e,t){var n,i=j(e),r=j(t);for(n=0;i[n]&&r[n];n++)if(i[n]!==r[n]){var s=Number(i[n]),o=Number(r[n]);return s==i[n]&&o==r[n]?s-o:i[n].localeCompare(r[n],F.getLanguage())}return i.length-r.length},waitFor:function(e,t){!function n(){!0!==e()&&setTimeout(n,t)}()},isCookieSetToValue:function(e,t){for(var n=document.cookie.split(";"),i=0;i<n.length;i++){var r=n[i].split("=");if(r[0].trim()===e&&r[1].trim()===t)return!0}return!1}},F=n.a={Apps:r.a,AppConfig:o,Backbone:b,ContactsMenu:w.a,EventSource:A,L10N:Y,msg:S,Notification:C,PasswordConfirmation:P,Plugins:{_plugins:{},register:function(e,t){var n=this._plugins[e];n||(n=this._plugins[e]=[]),n.push(t)},getPlugins:function(e){return this._plugins[e]||[]},attach:function(e,t,n){for(var i=this.getPlugins(e),r=0;r<i.length;r++)i[r].attach&&i[r].attach(t,n)},detach:function(e,t,n){for(var i=this.getPlugins(e),r=0;r<i.length;r++)i[r].detach&&i[r].detach(t,n)}},search:I,Util:z,redirect:function(e){return window.location=e},reload:function(){return window.location.reload()}};
/*
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
*

File diff suppressed because one or more lines are too long

View File

@ -206,21 +206,6 @@ Object.assign(window.OC, {
return !!(file.match(oc_config.blacklist_files_regex));
},
/**
* Redirect to the target URL, can also be used for downloads.
* @param {string} targetURL URL to redirect to
*/
redirect: function(targetURL) {
window.location = targetURL;
},
/**
* Reloads the current page
*/
reload: function() {
window.location.reload();
},
/**
* Protocol that is used to access this Nextcloud instance
* @return {string} Used protocol

View File

@ -31,6 +31,7 @@ import PasswordConfirmation from './password-confirmation'
import Plugins from './plugins'
import search from './search'
import Util from './util'
import {redirect, reload} from './navigation'
/** @namespace OC */
export default {
@ -46,4 +47,6 @@ export default {
Plugins,
search,
Util,
redirect,
reload,
}

31
core/src/OC/navigation.js Normal file
View File

@ -0,0 +1,31 @@
/*
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Redirect to the target URL, can also be used for downloads.
* @param {string} targetURL URL to redirect to
*/
export const redirect = targetURL => window.location = targetURL
/**
* Reloads the current page
*/
export const reload = () => window.location.reload()