~didrocks/+junk/face-detection-15.04

« back to all changes in this revision

Viewing changes to facedetection/www/bower_components/iron-location/iron-query-params.html

  • Committer: Didier Roche
  • Date: 2016-05-10 23:09:11 UTC
  • Revision ID: didier.roche@canonical.com-20160510230911-c7xr490zrj3yrzxd
New version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!--
 
2
@license
 
3
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
 
4
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
 
5
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
 
6
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
 
7
Code distributed by Google as part of the polymer project is also
 
8
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
 
9
-->
 
10
 
 
11
<link rel="import" href="../polymer/polymer.html">
 
12
 
 
13
 
 
14
<script>
 
15
  'use strict';
 
16
 
 
17
  Polymer({
 
18
    is: 'iron-query-params',
 
19
    properties: {
 
20
      paramsString: {
 
21
        type: String,
 
22
        notify: true,
 
23
        observer: 'paramsStringChanged',
 
24
      },
 
25
      paramsObject: {
 
26
        type: Object,
 
27
        notify: true,
 
28
        value: function() {
 
29
          return {};
 
30
        }
 
31
      },
 
32
      _dontReact: {
 
33
        type: Boolean,
 
34
        value: false
 
35
      }
 
36
    },
 
37
    hostAttributes: {
 
38
      hidden: true
 
39
    },
 
40
    observers: [
 
41
      'paramsObjectChanged(paramsObject.*)'
 
42
    ],
 
43
    paramsStringChanged: function() {
 
44
      this._dontReact = true;
 
45
      this.paramsObject = this._decodeParams(this.paramsString);
 
46
      this._dontReact = false;
 
47
    },
 
48
    paramsObjectChanged: function() {
 
49
      if (this._dontReact) {
 
50
        return;
 
51
      }
 
52
      this.paramsString = this._encodeParams(this.paramsObject);
 
53
    },
 
54
    _encodeParams: function(params) {
 
55
      var encodedParams = [];
 
56
      for (var key in params) {
 
57
        var value = params[key];
 
58
        if (value === '') {
 
59
          encodedParams.push(encodeURIComponent(key));
 
60
        } else if (value) {
 
61
          encodedParams.push(
 
62
              encodeURIComponent(key) +
 
63
              '=' +
 
64
              encodeURIComponent(value.toString())
 
65
          );
 
66
        }
 
67
      }
 
68
      return encodedParams.join('&');
 
69
    },
 
70
    _decodeParams: function(paramString) {
 
71
      var params = {};
 
72
      var paramList = (paramString || '').split('&');
 
73
      for (var i = 0; i < paramList.length; i++) {
 
74
        var param = paramList[i].split('=');
 
75
        if (param[0]) {
 
76
          params[decodeURIComponent(param[0])] =
 
77
              decodeURIComponent(param[1] || '');
 
78
        }
 
79
      }
 
80
      return params;
 
81
    }
 
82
  });
 
83
</script>