Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: pkg/polymer/lib/elements/polymer-cookie/polymer-cookie.html

Issue 175443005: [polymer] import all elements (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: updated from bower Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 <!--
2 Copyright 2013 The Polymer Authors. All rights reserved.
3 Use of this source code is governed by a BSD-style
4 license that can be found in the LICENSE file.
5 -->
6 <link rel="import" href="../polymer/polymer.html">
7
8 <polymer-element name="polymer-cookie" attributes="name value expires secure dom ain path max-age">
9 <template>
10 <style>
11 :host { display: none; }
12 </style>
13 </template>
14 <script>
15 (function() {
16 var EXPIRE_NOW = 'Thu, 01 Jan 1970 00:00:00 GMT';
17 var FOREVER = 'Fri, 31 Dec 9999 23:59:59 GMT';
18 var cookieProps = ['expires', 'secure', 'max-age', 'domain', 'path'];
19 Polymer('polymer-cookie', {
20 expires: FOREVER,
21 ready: function() {
22 this.load();
23 },
24 parseCookie: function() {
25 var pairs = document.cookie.split(/\s*;\s*/);
26 var map = pairs.map(function(kv) {
27 var eq = kv.indexOf('=');
28 return {
29 name: unescape(kv.slice(0, eq)),
30 value: unescape(kv.slice(eq + 1))
31 };
32 });
33 var nom = this.name;
34 return map.filter(function(kv){ return kv.name === nom; })[0];
35 },
36 load: function() {
37 var kv = this.parseCookie();
38 this.value = kv && kv.value;
39 },
40 valueChanged: function() {
41 this.expire = FOREVER;
42 this.save();
43 },
44 // TODO(dfreedman): collapse these when 'multiple props -> single change function' exists in Polymer
45 expiresChanged: function() {
46 this.save();
47 },
48 secureChanged: function() {
49 this.save();
50 },
51 domainChanged: function() {
52 this.save();
53 },
54 pathChanged: function() {
55 this.save();
56 },
57 maxAgeChanged: function() {
58 this.save();
59 },
60 isCookieStored: function() {
61 return Boolean(this.parseCookie());
62 },
63 deleteCookie: function() {
64 this.expires = EXPIRE_NOW;
65 },
66 prepareProperties: function() {
67 var prepared = '';
68 for (var i = 0, k; i < cookieProps.length; i++) {
69 k = cookieProps[i];
70 if (this[k]) {
71 prepared += (';' + k + '=' + this[k]);
72 }
73 }
74 return prepared;
75 },
76 save: function() {
77 document.cookie = escape(this.name) + '=' + escape(this.value) + this. prepareProperties();
78 }
79 });
80 })();
81 </script>
82 </polymer-element>
OLDNEW
« no previous file with comments | « pkg/polymer/lib/elements/polymer-cookie/index.html ('k') | pkg/polymer/lib/elements/polymer-elements/.bower.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698