Blame view

controllets/items-slider-controllet/items-slider-controllet.html 11.2 KB
938d1928   Luigi Serra   Update documentat...
1
2
  <!--

  @license

584d6ecd   Luigi Serra   Update components...
3
      The MIT License (MIT)

938d1928   Luigi Serra   Update documentat...
4
  

584d6ecd   Luigi Serra   Update components...
5
      Copyright (c) 2015 Dipartimento di Informatica - Università di Salerno - Italy

938d1928   Luigi Serra   Update documentat...
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  

      Permission is hereby granted, free of charge, to any person obtaining a copy

      of this software and associated documentation files (the "Software"), to deal

      in the Software without restriction, including without limitation the rights

      to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

      copies of the Software, and to permit persons to whom the Software is

      furnished to do so, subject to the following conditions:

  

      The above copyright notice and this permission notice shall be included in

      all copies or substantial portions of the Software.

  

      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

      IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

      FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

      AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

      LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

      OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN

      THE SOFTWARE.

  -->

  

ae17a8dc   Luigi Serra   Controllet and da...
26
  <!--

950d181d   Luigi Serra   license updates
27
28
  * Developed by :

  * ROUTE-TO-PA Project - grant No 645860. - www.routetopa.eu

ae17a8dc   Luigi Serra   Controllet and da...
29
30
31
  *

  -->

  

73bcce88   luigser   COMPONENTS
32
33
  <link rel="import" href="../../bower_components/polymer/polymer.html">

  <link rel="import" href="../../bower_components/paper-styles/color.html">

73bcce88   luigser   COMPONENTS
34
35
36
37
38
  

  <link rel="import" href="../../bower_components/neon-animation/neon-animated-pages.html">

  <link rel="import" href="../../bower_components/neon-animation/neon-animatable.html">

  <link rel="import" href="../../bower_components/neon-animation/neon-animations.html">

  

f748e9cf   Luigi Serra   new controllet an...
39
  <link rel="import" href="../../bower_components/paper-material">

73bcce88   luigser   COMPONENTS
40
41
42
  <link rel="import" href="../../bower_components/paper-icon-button/paper-icon-button.html">

  <link rel="import" href="../../bower_components/iron-icons/iron-icons.html">

  

584d6ecd   Luigi Serra   Update components...
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  <!--

   `items-slider-controllet` is a carousel of cards with a title and an image. Pass to it an array of objects with name and image fields and

   a responsive slider will be created. Every time the user click on a card an event will be generate in order to get the card clicked information to

   the component that use the slider.

  

  Example:

  

      <items-slider-controllet items='[{name : "myObject1", image : "pathToMyImage1"},...,{name : "myObjectN", image : "pathToMyImageN"}]' \>

      </items-slider-controllet>

  

  

  @element items-slider-controllet

  @status beta

  @homepage index.html

  @group controllets

  -->

  

73bcce88   luigser   COMPONENTS
60
61
62
63
  <dom-module id="items-slider-controllet">

      <template>

  

          <style is="custom-style">

73bcce88   luigser   COMPONENTS
64
  

74249687   Luigi Serra   Cross browser con...
65
              ::content .content-card{

73bcce88   luigser   COMPONENTS
66
67
68
                  position: relative;

                  float: left;

                  margin : .5em;

f748e9cf   Luigi Serra   new controllet an...
69
70
                  width: 80px;

                  height: 72px;

73bcce88   luigser   COMPONENTS
71
                  background: #fff;

73bcce88   luigser   COMPONENTS
72
73
74
                  padding: 1em;

              }

  

73bcce88   luigser   COMPONENTS
75
              .toolbar_button{

73bcce88   luigser   COMPONENTS
76
                  float: left;

f748e9cf   Luigi Serra   new controllet an...
77
                  margin-top: 6%;

73bcce88   luigser   COMPONENTS
78
79
80
81
                  --iron-icon-height: 28px;

                  --iron-icon-width: 28px;

              }

  

74249687   Luigi Serra   Cross browser con...
82
              #pages{

73bcce88   luigser   COMPONENTS
83
84
85
                  position: relative;

                  float:left;

                  display: inline-block;

f748e9cf   Luigi Serra   new controllet an...
86
                  height: 135px;

e619a3b0   Luigi Serra   Controllet cross ...
87
                  width: 100%;

73bcce88   luigser   COMPONENTS
88
89
90
91
92
                  overflow: hidden;

                  text-align: center;

                  /*margin-left: 3em;*/

              }

  

74249687   Luigi Serra   Cross browser con...
93
              img{

f748e9cf   Luigi Serra   new controllet an...
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
                  height: 100%;

                  width: 100%;

              }

  

              .legend {

                  position: absolute;

                  /*background: rgba(0,0,0,0.8);*/

                  background: #9e9e9e;

                  color: #ffffff;

                  height: 30px;

                  padding: 0 16px;

                  left: 0;

                  bottom: 7px;

                  z-index: 1;

                  opacity: 0.87;

                  width: 80px;

                  font-size: 11px;

              }

  

              .legend span{

                  position: relative;

                  top: 8px;

74249687   Luigi Serra   Cross browser con...
116
117
              }

  

73bcce88   luigser   COMPONENTS
118
119
          </style>

  

73bcce88   luigser   COMPONENTS
120
121
122
123
124
          <neon-animated-pages id="pages" class="flex" selected="[[selected]]" entry-animation="[[entryAnimation]]" exit-animation="[[exitAnimation]]">

  

             <template is="dom-repeat" items="{{itemsPages}}" as="page" index-as="p">

  

                  <neon-animatable>

e619a3b0   Luigi Serra   Controllet cross ...
125
126
127
128
  

                     <paper-icon-button class="toolbar_button x-scope" on-click="_onPrevClick" icon="chevron-left" alt="arrow-back" title="arrow-back"></paper-icon-button>

  

                      <template is="dom-repeat" items="{{itemsPerPage}}" as="item" index-as="i">

73bcce88   luigser   COMPONENTS
129
                         <template is="dom-if" if="{{getName(p, i) != 0}}">

f748e9cf   Luigi Serra   new controllet an...
130
131
                               <paper-material elevation="1" class='content-card' id="{{getName(p, i)}}" page="{{p}}" on-click="_cardClick">

                                  <div class="legend"><span>{{getName(p, i)}}</span></div>

74249687   Luigi Serra   Cross browser con...
132
133
                                  <div class="card-content-image">

                                      <img src="{{getImage(p, i)}}">

73bcce88   luigser   COMPONENTS
134
                                  </div>

f748e9cf   Luigi Serra   new controllet an...
135
                              </paper-material>

73bcce88   luigser   COMPONENTS
136
137
                         </template>

                      </template>

e619a3b0   Luigi Serra   Controllet cross ...
138
139
140
  

                      <paper-icon-button  class="toolbar_button x-scope" on-click="_onNextClick" icon="chevron-right" alt="arrow-forward" title="arrow-forward"></paper-icon-button>

  

73bcce88   luigser   COMPONENTS
141
142
143
144
145
                   </neon-animatable>

              </template>

  

          </neon-animated-pages>

  

73bcce88   luigser   COMPONENTS
146
      </template>

73bcce88   luigser   COMPONENTS
147
148
149
150
151
  

      <script>

  

          Polymer({

  

584d6ecd   Luigi Serra   Update components...
152
153
154
155
156
157
158
              is : 'items-slider-controllet',

  

              /**

               * Fired when the user selects a card from slider by clicking on it.

               *

               * @event items-slider-controllet_item-selected

               */

73bcce88   luigser   COMPONENTS
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
  

              properties : {

  

                  entryAnimation : {

                      type  : String,

                      value : ""

                  },

  

                  exitAnimation  : {

                      type  : String,

                      value : ""

                  },

  

                  selected : {

                      type  : Number,

                      value : 0

                  },

  

                  /**

                   * It stores all items to put in the slider

                   *

73bcce88   luigser   COMPONENTS
180
181
182
183
184
                   */

                  items : {

                      type: Array,

                      value: []

                  },

73bcce88   luigser   COMPONENTS
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
                  itemsPages : {

                     type : Array,

                     value : []

                  },

  

                  itemsPerPage : {

                      type : Array,

                      value : []

                  },

  

                  prevSelectedCard : {

                      type: Object,

                      value : null

                  },

  

                  numItemsPerPage : {

                      type: Number,

                      value : 4

24be6abb   Luigi Serra   selection control...
203
204
205
206
207
208
209
                  },

                  /**

                   * Presected card. You can pass the card title to preselect it.

                   */

                  selectedCard:{

                      type: String,

                      value: undefined

73bcce88   luigser   COMPONENTS
210
211
212
213
214
215
216
217
218
219
                  }

  

              },

  

              ready : function(){

  

                  var pages = Math.floor(this.items.length / this.numItemsPerPage);

                  var mod = this.items.length % this.numItemsPerPage;

                  if(mod > 0) pages += 1;

  

0b818d7e   Luigi Serra   Selection control...
220
221
                  this.itemsPages   = new Array();

                  this.itemsPerPage = new Array();

73bcce88   luigser   COMPONENTS
222
223
224
225
226
227
228
229
230
  

                  for(var i = 0; i < pages; i++){

                      this.itemsPages.push(i);

                  }

  

                  for(var i = 0; i < this.numItemsPerPage; i++){

                      this.itemsPerPage.push(i);

                  }

  

f748e9cf   Luigi Serra   new controllet an...
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
                  /*var html = "";

                  for(var p = 0; p < pages; p++){

                      html += '<neon-animatable>' +

                                 '<paper-icon-button class="toolbar_button x-scope" on-click="_onPrevClick" icon="chevron-left" alt="arrow-back" title="arrow-back"></paper-icon-button>';

                      for(var i=0; i < this.numItemsPerPage; i++){

                          html += '<paper-material elevation="1" class="content-card" id="' + this.getName(p, i) + '" page="' + p + '" on-click="_cardClick">' +

                                     '<div class="legend"><span>' + this.getName(p, i) + '</span></div>' +

                                       '<div class="card-content-image">' +

                                       '<img src="' + this.getImage(p, i) +'">' +

                                     '</div>' +

                                  '</paper-material>';

  

                      }

                      html +=    '<paper-icon-button  class="toolbar_button x-scope" on-click="_onNextClick" icon="chevron-right" alt="arrow-forward" title="arrow-forward"></paper-icon-button>' +

                              '</neon-animatable>';

                  }

  

                  this.async(function(){

                      this.$.pages.innerHTML = html;

                  },1000);

  */

73bcce88   luigser   COMPONENTS
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
              },

  

              getPage : function(page){

                 return this.itemsPages[page];

              },

  

              getName : function(page, item){

                  return ( ((page * this.itemsPerPage.length) + item) > this.items.length - 1 ) ? 0 : this.items[(page * this.itemsPerPage.length) + item].name.replace("-datalet","");

              },

  

              getImage : function(page, item){

                  return ( ((page * this.itemsPerPage.length) + item) > this.items.length - 1 ) ? 0 : this.items[(page * this.itemsPerPage.length) + item].image;

              },

  

              _onPrevClick : function() {

                  this.entryAnimation = 'slide-from-left-animation';

                  this.exitAnimation = 'slide-right-animation';

                  this.selected = this.selected === 0 ? (this.itemsPages.length - 1) : (this.selected - 1);

              },

  

              _onNextClick : function() {

                  this.entryAnimation = 'slide-from-right-animation';

                  this.exitAnimation = 'slide-left-animation';

e619a3b0   Luigi Serra   Controllet cross ...
275
                  this.selected = this.selected === (this.itemsPages.length - 1) ? 0 : (this.selected + 1);

73bcce88   luigser   COMPONENTS
276
277
278
279
              },

  

              _cardClick : function(e){

                  if(this.prevSelectedCard != null){

f748e9cf   Luigi Serra   new controllet an...
280
                      this.prevSelectedCard.elevation = "1";

73bcce88   luigser   COMPONENTS
281
282
  

                  }

f748e9cf   Luigi Serra   new controllet an...
283
                  e.currentTarget.elevation = "5";

73bcce88   luigser   COMPONENTS
284
285
286
287
                  this.prevSelectedCard = e.currentTarget;

  

                  this.fire('items-slider-controllet_item-selected', {datalet: e.currentTarget.id + "-datalet"});

  

74249687   Luigi Serra   Cross browser con...
288
289
290
              },

  

              attached : function(){

2b235978   Luigi Serra   Controllet cross ...
291
                  this.selected = 1;

24be6abb   Luigi Serra   selection control...
292
293
294
                  if(this.selectedCard != undefined){

                      this.async(function(){

                          var card = document.getElementById(this.selectedCard);

f748e9cf   Luigi Serra   new controllet an...
295
                          card.elevation = "5";

24be6abb   Luigi Serra   selection control...
296
297
298
299
300
                          this.prevSelectedCard = card;

                          this.fire('items-slider-controllet_item-selected', {datalet: this.selectedCard + "-datalet"});

                          this.selected = card.page;

                      },1000);

                  }

73bcce88   luigser   COMPONENTS
301
302
303
304
305
306
              }

          });

  

      </script>

  

  </dom-module>