aboutsummaryrefslogtreecommitdiffstats
path: root/core/js/js.js
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@owncloud.com>2014-05-28 22:57:33 +0200
committerAndreas Fischer <bantu@owncloud.com>2014-05-28 22:57:33 +0200
commit5754b0b9e70824786878b847abb6b728ca0414bb (patch)
tree9ad1fbc35edde8f54f44c9ef7029e007a16815b9 /core/js/js.js
parentf81ee94cad8a997c3a2fef0b6aac4f8d509571f6 (diff)
parentce9d5df6df37e51587dcde638086dfe501892b56 (diff)
downloadnextcloud-server-5754b0b9e70824786878b847abb6b728ca0414bb.tar.gz
nextcloud-server-5754b0b9e70824786878b847abb6b728ca0414bb.zip
Merge remote-tracking branch 'owncloud/master' into add_resetadminpass_command
* owncloud/master: (238 commits) Change visibility of scanner internals [tx-robot] updated from transifex remove legacy OC_Filesystem being used in a hook callback add title property to share dialog forgotten infobox messages translations reverts 188c543 and translates only mail fix warning text and margin Adjust core apps to use "requiremin" instead of "require" Added requiremin/requiremax fields for apps [tx-robot] updated from transifex unwrapped strings fix allow resharing of files with only share permissions don't lose file size during rename drop superflous statement in phpdoc add preRememberedLogin hook and document this and postRememberedLogin in class descripttion. Also fixes documentation of postLogin hook [tx-robot] updated from transifex fix grammar make user_ldap fully translatable [tx-robot] updated from transifex fix typo ... Conflicts: core/register_command.php
Diffstat (limited to 'core/js/js.js')
-rw-r--r--core/js/js.js113
1 files changed, 113 insertions, 0 deletions
diff --git a/core/js/js.js b/core/js/js.js
index 27bc3c651e3..38b97590430 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -1319,6 +1319,114 @@ OC.Util = {
};
/**
+ * Utility class for the history API,
+ * includes fallback to using the URL hash when
+ * the browser doesn't support the history API.
+ */
+OC.Util.History = {
+ _handlers: [],
+
+ /**
+ * Push the current URL parameters to the history stack
+ * and change the visible URL.
+ * Note: this includes a workaround for IE8/IE9 that uses
+ * the hash part instead of the search part.
+ *
+ * @param params to append to the URL, can be either a string
+ * or a map
+ */
+ pushState: function(params) {
+ var strParams;
+ if (typeof(params) === 'string') {
+ strParams = params;
+ }
+ else {
+ strParams = OC.buildQueryString(params);
+ }
+ if (window.history.pushState) {
+ var url = location.pathname + '?' + strParams;
+ window.history.pushState(params, '', url);
+ }
+ // use URL hash for IE8
+ else {
+ window.location.hash = '?' + strParams;
+ // inhibit next onhashchange that just added itself
+ // to the event queue
+ this._cancelPop = true;
+ }
+ },
+
+ /**
+ * Add a popstate handler
+ *
+ * @param handler function
+ */
+ addOnPopStateHandler: function(handler) {
+ this._handlers.push(handler);
+ },
+
+ /**
+ * Parse a query string from the hash part of the URL.
+ * (workaround for IE8 / IE9)
+ */
+ _parseHashQuery: function() {
+ var hash = window.location.hash,
+ pos = hash.indexOf('?');
+ if (pos >= 0) {
+ return hash.substr(pos + 1);
+ }
+ return '';
+ },
+
+ _decodeQuery: function(query) {
+ return query.replace(/\+/g, ' ');
+ },
+
+ /**
+ * Parse the query/search part of the URL.
+ * Also try and parse it from the URL hash (for IE8)
+ *
+ * @return map of parameters
+ */
+ parseUrlQuery: function() {
+ var query = this._parseHashQuery(),
+ params;
+ // try and parse from URL hash first
+ if (query) {
+ params = OC.parseQueryString(this._decodeQuery(query));
+ }
+ // else read from query attributes
+ if (!params) {
+ params = OC.parseQueryString(this._decodeQuery(location.search));
+ }
+ return params || {};
+ },
+
+ _onPopState: function(e) {
+ if (this._cancelPop) {
+ this._cancelPop = false;
+ return;
+ }
+ var params;
+ if (!this._handlers.length) {
+ return;
+ }
+ params = (e && e.state) || this.parseUrlQuery() || {};
+ for (var i = 0; i < this._handlers.length; i++) {
+ this._handlers[i](params);
+ }
+ }
+};
+
+// fallback to hashchange when no history support
+if (window.history.pushState) {
+ window.onpopstate = _.bind(OC.Util.History._onPopState, OC.Util.History);
+}
+else {
+ $(window).on('hashchange', _.bind(OC.Util.History._onPopState, OC.Util.History));
+}
+
+/**
* Get a variable by name
* @param {string} name
* @return {*}
@@ -1368,6 +1476,11 @@ OC.set=function(name, value) {
})();
/**
+ * Namespace for apps
+ */
+window.OCA = {};
+
+/**
* select a range in an input field
* @link http://stackoverflow.com/questions/499126/jquery-set-cursor-position-in-text-area
* @param {type} start