| Index: res/imp/9/url-params-sk.html
|
| diff --git a/res/imp/url-params-sk.html b/res/imp/9/url-params-sk.html
|
| similarity index 67%
|
| copy from res/imp/url-params-sk.html
|
| copy to res/imp/9/url-params-sk.html
|
| index 88bc47f35749a139cdbd770f67eb6d5ae3eb8b80..eb4a5c6033f1a11df5b8434ea50eba38c54db0b0 100644
|
| --- a/res/imp/url-params-sk.html
|
| +++ b/res/imp/9/url-params-sk.html
|
| @@ -57,44 +57,57 @@
|
| Methods:
|
| None
|
| -->
|
| -<polymer-element name="url-param-sk">
|
| +<link rel="import" href="/res/imp/bower_components/paper-toast/paper-toast.html">
|
| +<dom-module id="url-param-sk">
|
| <template>
|
| <paper-toast id="toast"></paper-toast>
|
| </template>
|
| <script>
|
| - Polymer('url-param-sk', {
|
| - publish: {
|
| - name: {
|
| - value: "",
|
| - reflect: true,
|
| - },
|
| - value: {
|
| - value: "",
|
| - reflect: true,
|
| - },
|
| + Polymer({
|
| + is: 'url-param-sk',
|
| + properties: {
|
| multi: {
|
| + type: Boolean,
|
| value: false,
|
| - reflect: true,
|
| + notify: true,
|
| + reflectToAttribute: true
|
| + },
|
| + name: {
|
| + type: String,
|
| + value: '',
|
| + notify: true,
|
| + reflectToAttribute: true
|
| },
|
| valid: {
|
| + type: Array,
|
| value: null,
|
| - reflect: true,
|
| + notify: true,
|
| + reflectToAttribute: true
|
| },
|
| + value: {
|
| + type: String,
|
| + value: '',
|
| + notify: true,
|
| + observer: 'valueChanged',
|
| + },
|
| + _loaded: {
|
| + type: Boolean,
|
| + value: false,
|
| + }
|
| },
|
| -
|
| - ready: function() {
|
| + ready: function () {
|
| + this._loaded = true;
|
| // Read the URL parameters. If our variable is set, save its value.
|
| // Otherwise, place our value in the URL.
|
| var val = this.getURL();
|
| if (val && this.isValid(val)) {
|
| - this.value = val;
|
| + this.set('value', val);
|
| } else {
|
| this.putURL();
|
| }
|
| },
|
| -
|
| // Retrieve the value for our variable from the URL.
|
| - getURL: function() {
|
| + getURL: function () {
|
| var vals = sk.query.toParamSet(window.location.search.substring(1))[this.name];
|
| if (!vals) {
|
| return null;
|
| @@ -103,42 +116,39 @@
|
| return vals;
|
| }
|
| if (vals.length > 1) {
|
| - this.error("Multiple values provided for " + this.name +
|
| - " but only one accepted: " + vals);
|
| + this.error('Multiple values provided for ' + this.name + ' but only one accepted: ' + vals);
|
| return null;
|
| }
|
| return vals[0];
|
| },
|
| -
|
| // Store the value for our variable in the URL.
|
| - putURL: function() {
|
| + putURL: function () {
|
| var params = sk.query.toParamSet(window.location.search.substring(1));
|
| delete params[this.name];
|
| - if (!this.value || (Array.isArray(this.value) && this.value.length == 0)) {
|
| + if (!this.value || Array.isArray(this.value) && this.value.length == 0) {
|
| + } else
|
| // Don't insert undefined/empty values.
|
| - } else {
|
| - if (this.multi) {
|
| - params[this.name] = this.value;
|
| - } else {
|
| - params[this.name] = [this.value];
|
| + {
|
| + if (this.multi) {
|
| + params[this.name] = this.value;
|
| + } else {
|
| + params[this.name] = [this.value];
|
| + }
|
| }
|
| - }
|
| - var newUrl = window.location.href.split("?")[0] + "?" + sk.query.fromParamSet(params);
|
| - window.history.replaceState("", "", newUrl);
|
| + var newUrl = window.location.href.split('?')[0] + '?' + sk.query.fromParamSet(params);
|
| + window.history.replaceState('', '', newUrl);
|
| },
|
| -
|
| // Check to see whether the given value is valid.
|
| - isValid: function(val) {
|
| + isValid: function (val) {
|
| var that = this;
|
| - var checkValid = function(val) {
|
| + var checkValid = function (val) {
|
| if (that.valid) {
|
| for (var i = 0; i < that.valid.length; i++) {
|
| if (val == that.valid[i]) {
|
| return true;
|
| }
|
| }
|
| - that.error("Invalid value for " + that.name + ": \"" + val +
|
| - "\". Must be one of: " + that.valid);
|
| + that.error('Invalid value for ' + that.name + ': "' + val + '". Must be one of: ' + that.valid);
|
| return false;
|
| }
|
| return true;
|
| @@ -146,7 +156,7 @@
|
| if (this.multi) {
|
| // Verify that it's an array and that all elements are valid.
|
| if (!Array.isArray(val)) {
|
| - this.console.error("url-param-sk: Value is not an array: " + val);
|
| + this.console.error('url-param-sk: Value is not an array: ' + val);
|
| return false;
|
| }
|
| for (var i = 0; i < val.length; i++) {
|
| @@ -156,23 +166,22 @@
|
| }
|
| } else {
|
| if (Array.isArray(val)) {
|
| - this.error("Multiple values provided for " + this.name +
|
| - " but only one accepted: " + val);
|
| + this.error('Multiple values provided for ' + this.name + ' but only one accepted: ' + val);
|
| }
|
| return checkValid(val);
|
| }
|
| return true;
|
| },
|
| -
|
| - valueChanged: function() {
|
| - // Save our value to the URL.
|
| - this.putURL();
|
| + valueChanged: function () {
|
| + if (this._loaded) {
|
| + // Save our value to the URL.
|
| + this.putURL();
|
| + }
|
| },
|
| -
|
| - error: function(msg) {
|
| - this.$.toast.text = msg;
|
| + error: function (msg) {
|
| + this.set('$.toast.text', msg);
|
| this.$.toast.show();
|
| - },
|
| + }
|
| });
|
| </script>
|
| -</polymer-element>
|
| +</dom-module>
|
|
|