Blame view

controllets/draggable-element-controllet/draggable-element-controllet.html 7.66 KB
73bcce88   luigser   COMPONENTS
1
2
3
4
5
6
7
  <link rel="import" href="../../bower_components/polymer/polymer.html">

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

  

  <dom-module id="draggable-element-controllet">

      <template>

  

          <style is="custom-style">

74249687   Luigi Serra   Cross browser con...
8
              /*body {

73bcce88   luigser   COMPONENTS
9
10
11
12
                  margin: 0;

                  padding: 1.5em;

                  -webkit-tap-highlight-color: rgba(0,0,0,0);

                  -webkit-touch-callout: none;

74249687   Luigi Serra   Cross browser con...
13
              }*/

73bcce88   luigser   COMPONENTS
14
15
16
17
18
19
20
21
  

              .drag-content-target{

                  height: 12.5em;

                  width: 13.5em;

                  font-weight: bolder;

              }

  

              .drag-content-source{

74249687   Luigi Serra   Cross browser con...
22
                  height: 1.5em;

73bcce88   luigser   COMPONENTS
23
                  width: 12.5em;

74249687   Luigi Serra   Cross browser con...
24
25
26
27
                 /* min-height: 20px;

                  min-width: 70px;

                  max-height: 20px;

                  max-width: 70px;*/

73bcce88   luigser   COMPONENTS
28
29
30
31
32
33
              }

  

              .onTrackOnTarget{

                  position: relative;

                  float: left;

                  margin : 0.625em;

74249687   Luigi Serra   Cross browser con...
34
                  height: 1.6em;

73bcce88   luigser   COMPONENTS
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
                  width: 13.5em;

                  background: #fff;

                  padding: 1em;

                  border-style: solid;

                  border-width : 0.2625em;

                  border-color : var(--paper-blue-500);

                  border-radius: 0.425rem;

                  box-shadow: 0 0.325em 0.3125em 0 rgba(0, 0, 0, 0.25);

                  overflow: hidden;

              }

  

              .draggable-card{

                  position: relative;

                  float: left;

                  margin : 0.625em;

74249687   Luigi Serra   Cross browser con...
50
                  height: 1.5em;

73bcce88   luigser   COMPONENTS
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
                  width: 13.5em;

                  border-width : 0.0625em

                  background: #fff;

                  border-radius: 0.425rem;

                  box-shadow: 0 0.325em 0.3125em 0 rgba(0, 0, 0, 0.25);

                  padding: 1em;

                  overflow: hidden;

              }

  

              .avatar {

                  display: inline-block;

                  position: relative;

                  float: left;

                  height: 2em;

                  width: 2em;

                  border-radius: 50%;

                  background: var(--paper-blue-500);

                  color: white;

                  line-height: 2em;

                  font-size: 0.9375em;

                  text-align: center;

              }

  

              .heading{

                  width: 12.5em;

              }

  

              .big {

                  display: inline-block;

                  position: relative;

                  float: left;

                  font-size: 1em;

                  padding: 0.5em 0.25em 0.5em;

                  color: var(--google-grey-500);

              }

  

              .medium {

                  font-size: 0.8125em;

                  padding-bottom: 0px;

                  display: inline-block;

                  width: 12.5em;

              }

  

              .unselectable {

                  -webkit-touch-callout: none;

                  -webkit-user-select: none;

                  -khtml-user-select: none;

                  -moz-user-select: none;

                  -ms-user-select: none;

                  user-select: none;

              }

  

73bcce88   luigser   COMPONENTS
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
          </style>

  

          <template is="dom-if" if="{{isTarget}}">

              <div class="drag-content-target" draggable="false">

                  <div class="card-content">

                      <div class="heading">

                          <div class="avatar">{{number}}</div>

                          <div class="big">{{heading}}</div><br>

                      </div>

                      <div class="medium">{{description}}</div>

                  </div>

                  <div id="target_dragged_identifier" class='draggable-card dd-content-target unselectable'></div>

              </div>

          </template>

  

          <template is="dom-if" if="{{!isTarget}}">

74249687   Luigi Serra   Cross browser con...
119
              <div id="source" class="drag-content-source" draggable="true" ondragstart="event.dataTransfer.setData('text/plain', 'This text may be dragged')" on-track="_handleTrack" on-drag="_handleOnDrag" on-dragstart="_handleStartDrag" on-dragenter="_handleEnterDrag">

73bcce88   luigser   COMPONENTS
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
                  <div id="{{identifier}}" class='draggable-card unselectable'>{{label}}</div>

              </div>

          </template>

  

      </template>

  

      <script>

  

          Polymer({

  

              is: 'draggable-element-controllet',

  

              targets : null,

  

              properties: {

  

                  isTarget : {

                      type : Boolean,

                      value: false

                  },

  

                  number: {

                      type: String,

                      value : "0"

                  },

  

                  heading : {

                      type : String,

                      value : "Heading"

                  },

  

                  description: {

                      type: String,

                      value: "Description"

                  },

  

                  label : {

                      type : String,

                      value : "Label"

                  },

  

                  identifier : {

                      type : String,

                      value : ""

                  },

  

                  value : {

                      type : String,

                      value : ""

                  }

  

              },

  

74249687   Luigi Serra   Cross browser con...
173
174
175
              ready : function(){

              },

  

73bcce88   luigser   COMPONENTS
176
              _handleStartDrag : function(e){

f974e824   Luigi Serra   Bugs fix
177
178
                  /*var target = EventUtil.getCurrentTarget(e);

                  target.style.cursor = 'move';*/

74249687   Luigi Serra   Cross browser con...
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
                  return true;

              },

  

              _handleEnterDrag : function(e){

                  /*var target = e.target;

                  if(target.draggable == false && (target.className.indexOf("dd-content-target") != -1)){

  

                      target.parentNode.parentNode.value = e.srcElement.id;

                      target.innerHTML = e.srcElement.innerText;

  

                      this.fire('draggable-element-controllet_content-dragged', {target: target, source: e.srcElement});

                  }

  

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

                      this.targets[i].children[0].children[1].className = "draggable-card dd-content-target unselectable style-scope draggable-element-controllet";

                  }*/

                  return false;

f974e824   Luigi Serra   Bugs fix
196
197
198
              },

  

              _handleOnDrag : function(e){

73bcce88   luigser   COMPONENTS
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
                  this.targets = document.querySelectorAll('draggable-element-controllet[is-target=true]');

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

                      this.targets[i].children[0].children[1].className = "onTrackOnTarget dd-content-target unselectable style-scope draggable-element-controllet";

                  }

  

              },

  

              _handleTrack : function(e) {

  

                  switch(e.detail.state) {

                      case 'start':

                          break;

                      case 'track':

                          break;

                      case 'end':

74249687   Luigi Serra   Cross browser con...
214
  

73bcce88   luigser   COMPONENTS
215
                          var target = e.detail.hover();

74249687   Luigi Serra   Cross browser con...
216
  

73bcce88   luigser   COMPONENTS
217
218
                          if(target.draggable == false && (target.className.indexOf("dd-content-target") != -1)){

  

74249687   Luigi Serra   Cross browser con...
219
220
                              target.parentNode.parentNode.value = e.target.id;

                              target.innerHTML = e.target.innerHTML;

73bcce88   luigser   COMPONENTS
221
  

74249687   Luigi Serra   Cross browser con...
222
                              this.fire('draggable-element-controllet_content-dragged', {target: target, source: e.target});

73bcce88   luigser   COMPONENTS
223
224
225
226
227
228
229
230
231
232
233
234
235
236
                          }

  

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

                              this.targets[i].children[0].children[1].className = "draggable-card dd-content-target unselectable style-scope draggable-element-controllet";

                          }

  

                          break;

                  }

              }

          });

  

      </script>

  

  </dom-module>