Added Polymer

This commit is contained in:
Thaum
2014-11-26 10:18:35 +00:00
parent 5eea4714b2
commit 3408ba9e8d
1210 changed files with 394645 additions and 47 deletions

View File

@@ -0,0 +1,21 @@
{
"name": "core-localstorage",
"private": true,
"dependencies": {
"polymer": "Polymer/polymer#^0.5.0"
},
"devDependencies": {
"web-component-tester": "Polymer/web-component-tester#^1.1.0"
},
"version": "0.5.1",
"homepage": "https://github.com/Polymer/core-localstorage",
"_release": "0.5.1",
"_resolution": {
"type": "version",
"tag": "0.5.1",
"commit": "920e68ed90fa2d664d995a1d70acd6be0ddcd6c7"
},
"_source": "git://github.com/Polymer/core-localstorage.git",
"_target": "^0.5.0",
"_originalSource": "Polymer/core-localstorage"
}

View File

@@ -0,0 +1,4 @@
core-localstorage
=================
See the [component landing page](http://polymer-project.org/docs/elements/core-elements.html#core-localstorage) for more information.

View File

@@ -0,0 +1,11 @@
{
"name": "core-localstorage",
"private": true,
"dependencies": {
"polymer": "Polymer/polymer#^0.5.0"
},
"devDependencies": {
"web-component-tester": "Polymer/web-component-tester#^1.1.0"
},
"version": "0.5.1"
}

View File

@@ -0,0 +1,128 @@
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<!--
Element access to localStorage. The "name" property
is the key to the data ("value" property) stored in localStorage.
`core-localstorage` automatically saves the value to localStorage when
value is changed. Note that if value is an object auto-save will be
triggered only when value is a different instance.
<core-localstorage name="my-app-storage" value="{{value}}"></core-localstorage>
@group Polymer Core Elements
@element core-localstorage
@blurb Element access to localStorage.
@url github.io
@categories Data
-->
<link rel="import" href="../polymer/polymer.html">
<polymer-element name="core-localstorage" attributes="name value useRaw autoSaveDisabled" hidden>
<script>
Polymer('core-localstorage', {
/**
* Fired when a value is loaded from localStorage.
* @event core-localstorage-load
*/
/**
* The key to the data stored in localStorage.
*
* @attribute name
* @type string
* @default null
*/
name: '',
/**
* The data associated with the specified name.
*
* @attribute value
* @type object
* @default null
*/
value: null,
/**
* If true, the value is stored and retrieved without JSON processing.
*
* @attribute useRaw
* @type boolean
* @default false
*/
useRaw: false,
/**
* If true, auto save is disabled.
*
* @attribute autoSaveDisabled
* @type boolean
* @default false
*/
autoSaveDisabled: false,
attached: function() {
// wait for bindings are all setup
this.async('load');
},
valueChanged: function() {
if (this.loaded && !this.autoSaveDisabled) {
this.save();
}
},
load: function() {
var v = localStorage.getItem(this.name);
if (this.useRaw) {
this.value = v;
} else {
// localStorage has a flaw that makes it difficult to determine
// if a key actually exists or not (getItem returns null if the
// key doesn't exist, which is not distinguishable from a stored
// null value)
// however, if not `useRaw`, an (unparsed) null value unambiguously
// signals that there is no value in storage (a stored null value would
// be escaped, i.e. "null")
// in this case we save any non-null current (default) value
if (v === null) {
if (this.value != null) {
this.save();
}
} else {
try {
v = JSON.parse(v);
} catch(x) {
}
this.value = v;
}
}
this.loaded = true;
this.asyncFire('core-localstorage-load');
},
/**
* Saves the value to localStorage.
*
* @method save
*/
save: function() {
var v = this.useRaw ? this.value : JSON.stringify(this.value);
localStorage.setItem(this.name, v);
}
});
</script>
</polymer-element>

View File

@@ -0,0 +1,50 @@
<!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<!doctype html>
<html>
<head>
<title>polymer-localstorage</title>
<script src="../webcomponentsjs/webcomponents.js"></script>
<link rel="import" href="core-localstorage.html">
</head>
<body>
<x-test1></x-test1>
<polymer-element name="x-test1" noscript>
<template>
string entered below will be stored in localStorage and automatically retrived from localStorage when the page is reloaded<br>
<input value="{{value}}">
<core-localstorage name="polymer-localstorage-x-test1" value="{{value}}"></core-localstorage>
</template>
</polymer-element>
<br><br>
<x-test2></x-test2>
<polymer-element name="x-test2">
<template>
<input type="checkbox" checked="{{mode}}">
<core-localstorage name="polymer-localstorage-x-test2" value="{{mode}}"></core-localstorage>
</template>
<script>
Polymer('x-test2', {
mode: false
});
</script>
</polymer-element>
</body>
</html>

View File

@@ -0,0 +1,22 @@
<!doctype html>
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE
The complete set of authors may be found at http://polymer.github.io/AUTHORS
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS
-->
<html>
<head>
<script src="../webcomponentsjs/webcomponents.js"></script>
<link rel="import" href="../core-component-page/core-component-page.html">
</head>
<body unresolved>
<core-component-page></core-component-page>
</body>
</html>

View File

@@ -0,0 +1,54 @@
<!doctype html>
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<meta charset="UTF-8">
<title>core-localstorage-basic</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<script src="../../webcomponentsjs/webcomponents.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<link rel="import" href="../core-localstorage.html">
</head>
<body>
<core-localstorage id="localstorage" name="core-localstorage-test"></core-localstorage>
<script>
window.localStorage.setItem('core-localstorage-test', '{"foo":"bar"}');
var storage = document.querySelector('#localstorage');
suite('basic', function() {
test('load', function() {
assert.isNotNull(storage.value);
assert.equal(storage.value.foo, 'bar');
});
test('save', function(done) {
var newValue = {'foo': 'zot'};
storage.value = newValue;
asyncPlatformFlush(function() {
var v = window.localStorage.getItem(storage.name);
v = JSON.parse(v);
assert.equal(v.foo, newValue.foo);
done();
});
});
});
</script>
</body>
</html>

View File

@@ -0,0 +1,26 @@
<!doctype html>
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>Tests</title>
<script src="../../web-component-tester/browser.js"></script>
</head>
<body>
<script>
WCT.loadSuites([
'basic.html',
'raw.html',
'value-binding.html'
]);
</script>
</body>
</html>

View File

@@ -0,0 +1,52 @@
<!doctype html>
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<meta charset="UTF-8">
<title>core-localstorage-raw</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<script src="../../webcomponentsjs/webcomponents.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<link rel="import" href="../core-localstorage.html">
</head>
<body>
<core-localstorage id="localstorage" useRaw name="core-localstorage-test"></core-localstorage>
<script>
window.localStorage.setItem('core-localstorage-test', 'hello world');
var storage = document.querySelector('#localstorage');
suite('basic', function() {
test('load', function() {
assert.equal(storage.value, 'hello world');
});
test('save', function(done) {
var m = 'goodbye';
storage.value = m;
asyncPlatformFlush(function() {
var v = window.localStorage.getItem(storage.name);
assert.equal(v, m);
done();
});
});
});
</script>
</body>
</html>

View File

@@ -0,0 +1,78 @@
<!doctype html>
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<meta charset="UTF-8">
<title>core-localstorage-value-binding</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<script src="../../webcomponentsjs/webcomponents.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<link rel="import" href="../core-localstorage.html">
</head>
<body>
<polymer-element name="x-foo" attributes="value" noscript>
<template>
<div>{{value.foo}}</div>
</template>
</polymer-element>
<polymer-element name="x-test" attributes="value" noscript>
<template>
<x-foo value="{{value}}"></x-foo>
<core-localstorage id="localstorage" name="core-localstorage-test" value="{{value}}"></core-localstorage>
</template>
</polymer-element>
<x-test></x-test>
<script>
window.localStorage.setItem('core-localstorage-test', '{"foo":"bar"}');
var xtest = document.querySelector('x-test');
suite('basic', function() {
test('initial value', function() {
assert.isNotNull(xtest.value);
assert.equal(xtest.value.foo, 'bar');
});
test('set value', function(done) {
var newValue = {'foo': 'zot'};
xtest.value = newValue;
asyncPlatformFlush(function() {
var v = window.localStorage.getItem(xtest.$.localstorage.name);
v = JSON.parse(v);
assert.equal(v.foo, newValue.foo);
done();
});
});
test('save', function(done) {
xtest.value.foo = 'quux';
xtest.$.localstorage.save();
asyncPlatformFlush(function() {
var v = window.localStorage.getItem(xtest.$.localstorage.name);
v = JSON.parse(v);
assert.equal(v.foo, 'quux');
done();
});
});
});
</script>
</body>
</html>