9 * @class Roo.bootstrap.MasonryBrick
10 * @extends Roo.bootstrap.Component
11 * Bootstrap MasonryBrick class
14 * Create a new MasonryBrick
15 * @param {Object} config The config object
18 Roo.bootstrap.MasonryBrick = function(config){
20 Roo.bootstrap.MasonryBrick.superclass.constructor.call(this, config);
22 Roo.bootstrap.MasonryBrick.register(this);
28 * When a MasonryBrick is clcik
29 * @param {Roo.bootstrap.MasonryBrick} this
30 * @param {Roo.EventObject} e
36 Roo.extend(Roo.bootstrap.MasonryBrick, Roo.bootstrap.Component, {
47 * @cfg {String} bgimage
51 * @cfg {String} videourl
63 * @cfg {String} size (xs|sm|md|md-left|md-right|tall|wide)
68 * @cfg {String} placetitle (center|bottom)
73 * @cfg {Boolean} isFitContainer defalut true
75 isFitContainer : true,
78 * @cfg {Boolean} preventDefault defalut false
80 preventDefault : false,
83 * @cfg {Boolean} inverse defalut false
87 getAutoCreate : function()
89 if(!this.isFitContainer){
90 return this.getSplitAutoCreate();
93 var cls = 'masonry-brick masonry-brick-full';
96 cls += ' masonry-brick-link';
99 if(this.bgimage.length){
100 cls += ' masonry-brick-image';
103 if(this.maskInverse){
104 cls += ' mask-inverse';
107 if(!this.html.length && !this.maskInverse){
108 cls += ' enable-mask';
112 cls += ' masonry-' + this.size + '-brick';
115 if(this.placetitle.length){
117 switch (this.placetitle) {
119 cls += ' masonry-center-title';
122 cls += ' masonry-bottom-title';
129 if(!this.html.length && !this.bgimage.length){
130 cls += ' masonry-center-title';
133 if(!this.html.length && this.bgimage.length){
134 cls += ' masonry-bottom-title';
139 cls += ' ' + this.cls;
143 tag: (this.href.length) ? 'a' : 'div',
148 cls: 'masonry-brick-paragraph',
154 if(this.href.length){
155 cfg.href = this.href;
158 var cn = cfg.cn[0].cn;
160 if(this.title.length){
163 cls: 'masonry-brick-title',
168 if(this.html.length){
171 cls: 'masonry-brick-text',
175 if (!this.title.length && !this.html.length) {
176 cfg.cn[0].cls += ' hide';
179 if(this.bgimage.length){
182 cls: 'masonry-brick-image-view',
187 if(this.videourl.length){
188 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
189 // youtube support only?
192 cls: 'masonry-brick-image-view',
195 allowfullscreen : true
204 getSplitAutoCreate : function()
206 var cls = 'masonry-brick masonry-brick-split';
208 if(this.href.length){
209 cls += ' masonry-brick-link';
212 if(this.bgimage.length){
213 cls += ' masonry-brick-image';
217 cls += ' masonry-' + this.size + '-brick';
220 switch (this.placetitle) {
222 cls += ' masonry-center-title';
225 cls += ' masonry-bottom-title';
228 if(!this.bgimage.length){
229 cls += ' masonry-center-title';
232 if(this.bgimage.length){
233 cls += ' masonry-bottom-title';
239 cls += ' ' + this.cls;
243 tag: (this.href.length) ? 'a' : 'div',
248 cls: 'masonry-brick-split-head',
252 cls: 'masonry-brick-paragraph',
259 cls: 'masonry-brick-split-body',
265 if(this.href.length){
266 cfg.href = this.href;
269 if(this.title.length){
270 cfg.cn[0].cn[0].cn.push({
272 cls: 'masonry-brick-title',
277 if(this.html.length){
280 cls: 'masonry-brick-text',
285 if(this.bgimage.length){
288 cls: 'masonry-brick-image-view',
293 if(this.videourl.length){
294 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
295 // youtube support only?
296 cfg.cn[0].cn.cn.push({
298 cls: 'masonry-brick-image-view',
301 allowfullscreen : true
308 initEvents: function()
343 this.el.on('touchstart', this.onTouchStart, this);
344 this.el.on('touchmove', this.onTouchMove, this);
345 this.el.on('touchend', this.onTouchEnd, this);
346 this.el.on('contextmenu', this.onContextMenu, this);
348 this.el.on('mouseenter' ,this.enter, this);
349 this.el.on('mouseleave', this.leave, this);
350 this.el.on('click', this.onClick, this);
353 if (typeof(this.parent().bricks) == 'object' && this.parent().bricks != null) {
354 this.parent().bricks.push(this);
359 onClick: function(e, el)
361 var time = this.endTimer - this.startTimer;
362 // Roo.log(e.preventDefault());
370 if(!this.preventDefault){
376 if (this.activcClass != '') {
380 this.fireEvent('click', this);
383 enter: function(e, el)
387 if(!this.isFitContainer || this.maskInverse){
391 if(this.bgimage.length && this.html.length){
392 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
396 leave: function(e, el)
400 if(!this.isFitContainer || this.maskInverse){
404 if(this.bgimage.length && this.html.length){
405 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
409 onTouchStart: function(e, el)
411 // e.preventDefault();
413 this.touchmoved = false;
415 if(!this.isFitContainer){
419 if(!this.bgimage.length || !this.html.length){
423 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
425 this.timer = new Date().getTime();
429 onTouchMove: function(e, el)
431 this.touchmoved = true;
434 onContextMenu : function(e,el)
441 onTouchEnd: function(e, el)
443 // e.preventDefault();
445 if((new Date().getTime() - this.timer > 1000) || !this.href.length || this.touchmoved){
452 if(!this.bgimage.length || !this.html.length){
454 if(this.href.length){
455 window.location.href = this.href;
461 if(!this.isFitContainer){
465 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
467 window.location.href = this.href;
470 //selection on single brick only
471 selectBrick : function() {
473 if (!this.parentId) {
477 var m = Roo.bootstrap.LayoutMasonry.get(this.parentId);
478 var index = m.selectedBrick.indexOf(this.id);
481 m.selectedBrick.splice(index,1);
482 this.el.removeClass(this.activeClass);
486 for(var i = 0; i < m.selectedBrick.length; i++) {
487 var b = Roo.bootstrap.MasonryBrick.get(m.selectedBrick[i]);
488 b.el.removeClass(b.activeClass);
491 m.selectedBrick = [];
493 m.selectedBrick.push(this.id);
494 this.el.addClass(this.activeClass);
500 Roo.apply(Roo.bootstrap.MasonryBrick, {
503 groups : new Roo.util.MixedCollection(false, function(o) { return o.el.id; }),
505 * register a Masonry Brick
506 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
509 register : function(brick)
511 //this.groups[brick.id] = brick;
512 this.groups.add(brick.id, brick);
515 * fetch a masonry brick based on the masonry brick ID
516 * @param {string} the masonry brick to add
517 * @returns {Roo.bootstrap.MasonryBrick} the masonry brick
520 get: function(brick_id)
522 // if (typeof(this.groups[brick_id]) == 'undefined') {
525 // return this.groups[brick_id] ;
527 if(this.groups.key(brick_id)) {
528 return this.groups.key(brick_id);