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 && !this.videourl.length){
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-mask'
152 cls: 'masonry-brick-paragraph',
158 if(this.href.length){
159 cfg.href = this.href;
162 var cn = cfg.cn[1].cn;
164 if(this.title.length){
167 cls: 'masonry-brick-title',
172 if(this.html.length){
175 cls: 'masonry-brick-text',
180 if (!this.title.length && !this.html.length) {
181 cfg.cn[1].cls += ' hide';
184 if(this.bgimage.length){
187 cls: 'masonry-brick-image-view',
192 if(this.videourl.length){
193 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
194 // youtube support only?
197 cls: 'masonry-brick-image-view',
200 allowfullscreen : true
208 getSplitAutoCreate : function()
210 var cls = 'masonry-brick masonry-brick-split';
212 if(this.href.length){
213 cls += ' masonry-brick-link';
216 if(this.bgimage.length){
217 cls += ' masonry-brick-image';
221 cls += ' masonry-' + this.size + '-brick';
224 switch (this.placetitle) {
226 cls += ' masonry-center-title';
229 cls += ' masonry-bottom-title';
232 if(!this.bgimage.length){
233 cls += ' masonry-center-title';
236 if(this.bgimage.length){
237 cls += ' masonry-bottom-title';
243 cls += ' ' + this.cls;
247 tag: (this.href.length) ? 'a' : 'div',
252 cls: 'masonry-brick-split-head',
256 cls: 'masonry-brick-paragraph',
263 cls: 'masonry-brick-split-body',
269 if(this.href.length){
270 cfg.href = this.href;
273 if(this.title.length){
274 cfg.cn[0].cn[0].cn.push({
276 cls: 'masonry-brick-title',
281 if(this.html.length){
284 cls: 'masonry-brick-text',
289 if(this.bgimage.length){
292 cls: 'masonry-brick-image-view',
297 if(this.videourl.length){
298 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
299 // youtube support only?
300 cfg.cn[0].cn.cn.push({
302 cls: 'masonry-brick-image-view',
305 allowfullscreen : true
312 initEvents: function()
347 this.el.on('touchstart', this.onTouchStart, this);
348 this.el.on('touchmove', this.onTouchMove, this);
349 this.el.on('touchend', this.onTouchEnd, this);
350 this.el.on('contextmenu', this.onContextMenu, this);
352 this.el.on('mouseenter' ,this.enter, this);
353 this.el.on('mouseleave', this.leave, this);
354 this.el.on('click', this.onClick, this);
357 if (typeof(this.parent().bricks) == 'object' && this.parent().bricks != null) {
358 this.parent().bricks.push(this);
363 onClick: function(e, el)
365 var time = this.endTimer - this.startTimer;
366 // Roo.log(e.preventDefault());
374 if(!this.preventDefault){
380 if (this.activeClass != '') {
384 this.fireEvent('click', this, e);
387 enter: function(e, el)
391 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
395 if(this.bgimage.length && this.html.length){
396 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
400 leave: function(e, el)
404 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
408 if(this.bgimage.length && this.html.length){
409 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
413 onTouchStart: function(e, el)
415 // e.preventDefault();
417 this.touchmoved = false;
419 if(!this.isFitContainer){
423 if(!this.bgimage.length || !this.html.length){
427 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
429 this.timer = new Date().getTime();
433 onTouchMove: function(e, el)
435 this.touchmoved = true;
438 onContextMenu : function(e,el)
445 onTouchEnd: function(e, el)
447 // e.preventDefault();
449 if((new Date().getTime() - this.timer > 1000) || !this.href.length || this.touchmoved){
456 if(!this.bgimage.length || !this.html.length){
458 if(this.href.length){
459 window.location.href = this.href;
465 if(!this.isFitContainer){
469 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
471 window.location.href = this.href;
474 //selection on single brick only
475 selectBrick : function() {
477 if (!this.parentId) {
481 var m = Roo.bootstrap.LayoutMasonry.get(this.parentId);
482 var index = m.selectedBrick.indexOf(this.id);
485 m.selectedBrick.splice(index,1);
486 this.el.removeClass(this.activeClass);
490 for(var i = 0; i < m.selectedBrick.length; i++) {
491 var b = Roo.bootstrap.MasonryBrick.get(m.selectedBrick[i]);
492 b.el.removeClass(b.activeClass);
495 m.selectedBrick = [];
497 m.selectedBrick.push(this.id);
498 this.el.addClass(this.activeClass);
502 isSelected : function(){
503 return this.el.hasClass(this.activeClass);
508 Roo.apply(Roo.bootstrap.MasonryBrick, {
511 groups : new Roo.util.MixedCollection(false, function(o) { return o.el.id; }),
513 * register a Masonry Brick
514 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
517 register : function(brick)
519 //this.groups[brick.id] = brick;
520 this.groups.add(brick.id, brick);
523 * fetch a masonry brick based on the masonry brick ID
524 * @param {string} the masonry brick to add
525 * @returns {Roo.bootstrap.MasonryBrick} the masonry brick
528 get: function(brick_id)
530 // if (typeof(this.groups[brick_id]) == 'undefined') {
533 // return this.groups[brick_id] ;
535 if(this.groups.key(brick_id)) {
536 return this.groups.key(brick_id);