Advertisement
fruffl

cinema youtube support

Jul 3rd, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 25.36 KB | None | 0 0
  1. /*
  2. @todo: split list as %5-arrays and load sequences
  3. */
  4.  
  5. cinematic : function(__SELF, SETTINGS)
  6. {
  7.     var regName = 'app-cinematic';
  8.  
  9.     var log =
  10.     {
  11.         n    : function(t, l) { $.tri4m.log('tri4m.app.cinematic: ' + t, l); },
  12.         t    : function(t, l) { log.n('trigger: ' + t, l); },
  13.         t107 : function(t, l) { log.t('preload-cinematic-thumb:' + t, l); },
  14.         t108 : function(t, l) { log.t('preload-cinematic-image:' + t, l); },
  15.         t109 : function(t, l) { log.t('-- event: ' + t, l); },
  16.         t110 : function(t, l) { log.t('-- callback: ' + t, l); }
  17.     };
  18.    
  19.     var __settings = jQuery.extend
  20.     (
  21.         true,
  22.         {
  23.             bioscoop : null, // id target
  24.             autoplay :
  25.             {
  26.                 enabled : false,
  27.                 interval : 10,
  28.                 showNext : true,
  29.                 showPlay : true,
  30.                 showPrev : true,
  31.                 showTimer : true,
  32.             },
  33.             thumbs :
  34.             {
  35.                 enabled : true,
  36.                 preloadAllBeforeShow : true,
  37.                 asCssBackgroundImage : false // otherwise img-tag
  38.             },
  39.             images :
  40.             {
  41.                 asCssBackgroundImage : false // otherwise img-tag
  42.             },
  43.             callback :
  44.             {
  45.                 thumbs :
  46.                 {
  47.                     ready       : function(list) { log.t110('thumbs.ready: ' + ILLI.fn.o2s(list)); },
  48.                     beforeShow  : function(item, index) { log.t110('thumbs.beforeShow: index ' + index + ': ' + ILLI.fn.o2s(item)); },
  49.                     afterShow   : function(item, index) { log.t110('thumbs.afterShow: index '  + index + ': ' + ILLI.fn.o2s(item)); }
  50.                 },
  51.                 images :
  52.                 {
  53.                     firstInit   : function() { log.t110('images.firstInit'); },
  54.                     beforeShow  : function() { log.t110('images.beforeShow'); },
  55.                     afterShow   : function() { log.t110('images.afterShow'); }
  56.                 }
  57.             },
  58.             loader :
  59.             {
  60.                 lines           : 16,
  61.                 length          : 50,
  62.                 width           : 1,
  63.                 radius          : 40,
  64.                 rotate          : 0,
  65.                 color           : '#00FF1A',
  66.                 speed           : 1.9,
  67.                 trail           : 100,
  68.                 shadow          : false,
  69.                 hwaccel         : true,
  70.                 className       : 'ddlsl',
  71.                 zIndex          : -1,//2e9,
  72.                 top             : 0,
  73.                 left            : 'auto'
  74.             }
  75.         },
  76.         SETTINGS
  77.     );
  78.  
  79.     var __instance = function(element)
  80.     {
  81.         var _queue = [], _removed = [], _element = element,
  82.         _isset = $.tri4m.global.__INSTANCE_REGISTRY__.isset(element, regName),
  83.         _init, _dom, _reg = {}, _bnd = {}, _update, _insert, _insertArray, _type,
  84.         _ctrl =
  85.         {
  86.             onActivation : function(scrollrollerItem)
  87.             {
  88.                 scrollrollerItem.parent().data('tri4m.ui.scrollroller.listitem.state', {ai : scrollrollerItem});
  89.                 scrollrollerItem.find('a').trigger('tri4m.app.cinematic.reslink.preloadImage');
  90.             }
  91.         };
  92.  
  93.         _c =
  94.         {
  95.             o : function(t)
  96.             {
  97.                 var p = {width: 0, height: 0};
  98.                
  99.                 if(t.innerWidth() > 0)
  100.                 {
  101.                     p.width = t.innerWidth();
  102.                 }
  103.                 else
  104.                 if(t.innerWidth() === 0
  105.                 && t.parent().innerWidth() > 0)
  106.                 {
  107.                     p.width = t.parent().innerWidth();
  108.                 }
  109.                 else
  110.                 {
  111.                     p.width = $(window).width();
  112.                 }
  113.                
  114.                 if(t.innerHeight() > 0)
  115.                 {
  116.                     p.height = t.innerHeight();
  117.                 }
  118.                 else
  119.                 if(t.innerHeight() === 0
  120.                 && t.parent().innerHeight() > 0)
  121.                 {
  122.                     p.height = t.parent().innerHeight();
  123.                 }
  124.                 else
  125.                 {
  126.                     p.height = $(window).height();
  127.                 }
  128.                
  129.                 return p;
  130.             },
  131.             i : function(image, target)
  132.             {
  133.                 var p = {width: 0, height: 0, left: 0, top: 0};
  134.  
  135.                 if(typeof image !== 'object'
  136.                 || typeof image.width === 'undefined'
  137.                 || typeof image.height === 'undefined') return p;
  138.  
  139.                 var iw = image.width, ih = image.height, ir = ih / iw
  140.                     w = _c.o(target), ww = w.width, wh = w.height, wr = wh / ww;
  141.  
  142.                 switch(true)
  143.                 {
  144.                     case (wr > ir):
  145.                         p.width  = Math.round(wh/ir);
  146.                         p.height = wh;
  147.                         break;
  148.                     case (typeof $('body.fit-images').size() !== 'undefined'):
  149.                         p.width  = ww;
  150.                         p.height = wh;
  151.                         break;
  152.                     case (ir > 1 || ir === 1):
  153.                         var j = wh / ih;
  154.                         p.width  = Math.round(iw * j);
  155.                         p.height = wh;
  156.                         break;
  157.                     default:
  158.                         p.width  = ww;
  159.                         p.height = Math.round(ww * ir);
  160.                         break;
  161.                 }
  162.  
  163.                 p.left = Math.round((ww - p.width)  / 2);
  164.                 p.top  = Math.round((wh - p.height) / 2);
  165.  
  166.                 return p;
  167.             }
  168.         };
  169.  
  170.         _j =
  171.         {
  172.             __isw  : false,
  173.             window : function()
  174.             {
  175.                 var d = _reg.j.get('d');
  176.                 var wait = setInterval(function()
  177.                 {
  178.                     clearInterval(wait);
  179.                     _j.__isw = false;
  180.                     d.find('img:visible')
  181.                     .each(function()
  182.                     {
  183.                         $(this).animate(_c.i({width : $(this).width(), height : $(this).height()}, d), 500, 'easeOutCubic');
  184.                     });
  185.                 }, 600);
  186.  
  187.                 if(true === _j.__isw)
  188.                     clearInterval(wait);
  189.  
  190.                 _j.__isw = true;
  191.             }
  192.         };
  193.        
  194.         _update = function()
  195.         {
  196.             var __i = 'li', __a = 'a', _a = '<a />', i = $('li', _reg.j.get('l')), a = $('a:eq(0)', i),
  197.                 ba = _bnd.a.toValueObject(), bi = _bnd.i.toValueObject(), bt = _bnd.t.toValueObject();
  198.                
  199.             _reg.j.set('a', a);
  200.             _reg.j.set('i', i);
  201.            
  202.             _reg.j.get('a').addClass('tri4m-app-cinematic-resourcelink').hide();
  203.             _reg.j.get('i').addClass('tri4m-app-cinematic-resourceitem');
  204.            
  205.             a.each(function(index)
  206.             {
  207.                 for(var i in ba) $(this).unbind(i).bind(i, ba[i]);
  208.             });
  209.            
  210.             i.each(function(index)
  211.             {
  212.                 $(this).addClass('tri4m-app-cinematic-resourceitem');
  213.                 for(var i in bi) $(this).unbind(i).bind(i, bi[i]);
  214.                 var it = $(this).find(__a + '.tri4m-app-cinematic-resourcethumb').eq(0);
  215.                 if(it.length === 0)
  216.                 {
  217.                     $(this).append($(_a).addClass('tri4m-app-cinematic-resourcethumb').hide());
  218.                 }
  219.             });
  220.  
  221.             _reg.j.set('t', $(__a + '.tri4m-app-cinematic-resourcethumb', i), false);
  222.  
  223.             _reg.j.get('t').each(function(index)
  224.             {
  225.                 for(var i in bt) $(this).unbind(i).bind(i, bt[i]);
  226.  
  227.                 var ds = $(this).data(_reg.n.get('dts')), dd = {}; dd.i = index;
  228.                
  229.                 if(typeof ds === 'undefined')
  230.                 {
  231.                     $(this).data(_reg.n.get('dts'), dd);
  232.                     ds = dd;
  233.                 }
  234.                
  235.                 if(typeof ds.qs === 'undefined')
  236.                 {
  237.                     $(this).trigger('tri4m.app.cinematic.thumblink.preloadImage');
  238.                 }
  239.             });
  240.         };
  241.        
  242.         _insert = function(index, src, callback)
  243.         {
  244.             if(typeof src === 'undefined') return;
  245.             var i = $('<a href="' + src + '" />').addClass('tri4m-app-cinematic-resourceitem-insert');
  246.             var h = '<a href="' + src + '" class="tri4m-app-cinematic-resourceitem-insert" />';
  247.            
  248.             if(typeof index === 'undefined' || index === null)
  249.                 _reg.j.get('l').trigger('tri4m.ui.scrollroller.container.appendItem', [i]);
  250.            
  251.             _update();
  252.            
  253.             if(typeof callback === 'function') callback();
  254.         };
  255.        
  256.         _insertArray = function(index, srcArr, callback)
  257.         {
  258.             if(typeof srcArr === 'undefined') return;
  259.            
  260.             var c = new Array();
  261.             for(var i in srcArr)
  262.                 c[i] = $('<a href="' + srcArr[i] + '" />').addClass('tri4m-app-cinematic-resourceitem-insert');
  263.            
  264.             if(typeof index === 'undefined' || index === null)
  265.                 _reg.j.get('l').trigger('tri4m.ui.scrollroller.container.appendItems', [c]);
  266.                    
  267.             _update();
  268.            
  269.             if(typeof callback === 'function') callback();
  270.         };
  271.  
  272.         _dom = function()
  273.         {
  274.             var j = _reg.j, _d = '<div />', _l = '<ul />',
  275.                 __d = 'div', __i = 'li', __a = 'a', _a = '<a />', __l = 'ul',
  276.                 d = $('#' + __settings.bioscoop).find(__d).eq(0),
  277.                 l = _element.find(__l).eq(0); // 0: cur is ul
  278.  
  279.             j.register('b', $('#' + __settings.bioscoop), true);
  280.             j.register('d', ((d.length === 0) ? $(_d).appendTo(j.get('b')) : d), true);
  281.             j.register('l', ((l.length === 0) ? $(_element).wrap(_d) : l), false);
  282.             j.register('c', j.get('l').parent());
  283.  
  284.             j.get('l').addClass('tri4m-app-cinematic-list');
  285.             j.get('b').addClass('tri4m-app-cinematic-bioscoop');
  286.             j.get('d').addClass('tri4m-app-cinematic-decorontwerp')
  287.                 .css({overflow: 'hidden'})
  288.                 .data(_reg.n.get('dcs'), { initialized : false });
  289.             j.get('c').addClass('tri4m-ui-scrollroller-x tri4m-app-gallery-thumbs tri4m-app-cinematics')
  290.             //j.get('c').addClass('tri4m-ui-scrollroller-x tri4m-app-cinematics')
  291.                 .tri4m().proto().ui().scrollroller
  292.                 ({
  293.                     sensitive: true,
  294.                     easing :
  295.                     {
  296.                         duration : 400,
  297.                         callback :
  298.                         {
  299.                             item :
  300.                             {
  301.                                 deactivate : function(e)
  302.                                 {
  303.                                     $(this).trigger('tri4m.ui.scrollroller.container.activateFirst');
  304.                                 }
  305.                             }
  306.                         }
  307.                     }
  308.                 });
  309.            
  310.             _reg.j.register('i', $(__i, _reg.j.get('l')), false);
  311.             _reg.j.register('a', $(__a, _reg.j.get('l')), false);
  312.             _reg.j.register('t', $(__a + '.tri4m-app-cinematic-resourcethumb', _reg.j.get('i')), false);
  313.  
  314.         };
  315.        
  316.         _type = function(src)
  317.         {
  318.             var type = null;
  319.            
  320.             if(src.match(/png/i))
  321.             {
  322.                 log.t108('try load: PNG ' + src);
  323.                 type = 'png';
  324.             }
  325.             else
  326.             if(src.match(/jpg/i))
  327.             {
  328.                 log.t108('try load: JPG ' + src);
  329.                 type = 'jpg';
  330.             }
  331.             else
  332.             if(src.match(/gif/i))
  333.             {
  334.                 log.t108('try load: GIF ' + src);
  335.                 type = 'gif';
  336.             }
  337.             else
  338.             if(src.match(/flv/i))
  339.             {
  340.                 log.t108('try load: FLV ' + src);
  341.                 type = 'flv';
  342.             }
  343.             else
  344.             if(src.match(/mp3/i))
  345.             {
  346.                 log.t108('try load: MP3 ' + src);
  347.                 type = 'mp3';
  348.             }
  349.             else
  350.             if(src.match(/avi/i))
  351.             {
  352.                 log.t108('try load: AVI ' + src);
  353.                 type = 'avi';
  354.             }
  355.             else
  356.             if(src.match(/youtu/i))
  357.             {
  358.                 log.t108('try load: YOUTUBE ' + src);
  359.                 type = 'youtube';
  360.             }
  361.             else
  362.             {
  363.                 log.t108('try load: unknown source ' + src);
  364.             }
  365.            
  366.             return type;
  367.         };
  368.         (function()
  369.         {
  370.             if(true === _isset) return;
  371.            
  372.             _reg.j = new $.tri4m.global.__CLASS__.__VARIABLE__.__REGISTRY__();
  373.             _reg.n = new $.tri4m.global.__CLASS__.__VARIABLE__.__REGISTRY__();
  374.             _bnd.a = new $.tri4m.global.__CLASS__.__VARIABLE__.__REGISTRY__();
  375.             _bnd.t = new $.tri4m.global.__CLASS__.__VARIABLE__.__REGISTRY__();
  376.             _bnd.i = new $.tri4m.global.__CLASS__.__VARIABLE__.__REGISTRY__();
  377.             _bnd.l = new $.tri4m.global.__CLASS__.__VARIABLE__.__REGISTRY__();
  378.             _bnd.r = new $.tri4m.global.__CLASS__.__VARIABLE__.__REGISTRY__();
  379.  
  380.             _reg.n.register('dcs', 'tri4m.app.cinematic.state');
  381.             _reg.n.register('dts', 'tri4m.app.cinematic.thumbstate');
  382.  
  383.             _bnd.i
  384.             .register('click', function()
  385.             {
  386.                 log.t109('tri4m.app.cinematic.listitem.click', 1);
  387.                 $(this).trigger('tri4m.ui.scrollroller.listitem.activate', [_ctrl.onActivation]);
  388.             });
  389.            
  390.             _bnd.l
  391.             .register('tri4m.app.cinematic.container.insertItemAfter', function(e, i, c)
  392.             {
  393.                 log.t109('tri4m.app.cinematic.container.insertItemAfter', 1);
  394.             }, true)
  395.             .register('tri4m.app.cinematic.container.insertItemBefore', function(e, i, c)
  396.             {
  397.                 log.t109('tri4m.app.cinematic.container.insertItemBefore', 1);
  398.             }, true)
  399.             .register('tri4m.app.cinematic.container.appendItem', function(e, imgSrc, c)
  400.             {
  401.                 log.t109('tri4m.app.cinematic.container.appendItem', 1);
  402.                 _insert(null, imgSrc, c);
  403.             }, true)
  404.             .register('tri4m.app.cinematic.container.appendItems', function(e, imgSrcArray, c)
  405.             {
  406.                 log.t109('tri4m.app.cinematic.container.appendItems' + ILLI.fn.o2s(imgSrcArray), 1);
  407.                 _insertArray(null, imgSrcArray, c);
  408.             }, true)
  409.             .register('tri4m.app.cinematic.container.prependItem', function(e, i, item, c)
  410.             {
  411.                 log.t109('tri4m.app.cinematic.container.prependItems', 1);
  412.             }, true)
  413.             .register('tri4m.app.cinematic.container.prependItems', function(e, i, itemArray, c)
  414.             {
  415.                 log.t109('tri4m.app.cinematic.container.prependItems', 1);
  416.             }, true)
  417.             .register('tri4m.app.cinematic.container.removeItem', function(e, i, c)
  418.             {
  419.                 log.t109('tri4m.app.cinematic.container.removeItem', 1);
  420.                 var t  = $(e.target);
  421.                 t.trigger('click');
  422.                 t.trigger('tri4m.ui.scrollroller.container.removeItem', [i, function()
  423.                 {
  424.                     t.trigger('tri4m.app.cinematic.container.nextItem');
  425.                 }]);
  426.                
  427.             }, true)
  428.             .register('tri4m.app.cinematic.container.pause', function(e, c)
  429.             {
  430.                 log.t109('tri4m.app.cinematic.container.pause', 1);
  431.                
  432.             }, true)
  433.             .register('tri4m.app.cinematic.container.play', function(e, c)
  434.             {
  435.                 log.t109('tri4m.app.cinematic.container.play', 1);
  436.            
  437.             }, true)
  438.             .register('tri4m.app.cinematic.container.stop', function(e, c)
  439.             {
  440.                 log.t109('tri4m.app.cinematic.container.stop', 1);
  441.            
  442.             }, true)
  443.             .register('tri4m.app.cinematic.container.nextItem', function(e, c)
  444.             {
  445.                 log.t109('tri4m.app.cinematic.container.nextItem', 1);
  446.                 _reg.j.get('l').trigger('tri4m.ui.scrollroller.container.activateNextOrFirst', [_ctrl.onActivation]);
  447.             }, true)
  448.             .register('tri4m.app.cinematic.container.prevItem', function(e, c)
  449.             {
  450.                 log.t109('tri4m.app.cinematic.container.prevItem', 1);
  451.                 _reg.j.get('l').trigger('tri4m.ui.scrollroller.container.activatePrevOrLast', [_ctrl.onActivation]);
  452.             }, true);
  453.  
  454.             _bnd.t
  455.             .register('tri4m.app.cinematic.thumblink.preloadImage', function(e)
  456.             {
  457.                 log.t109('tri4m.app.cinematic.thumblink.preloadImage', 1);
  458.                
  459.                 if(typeof ILLI === 'undefined')
  460.                 {
  461.                     $(this).parent().prepend('<span>where is ILLI?</span>');
  462.                     log.t107('ILLI is undefined (required for thumb-url)', 2);
  463.                     return;
  464.                 }
  465.  
  466.  
  467.                 var t = $(this), p = t.parent().css({opacity : 0}),
  468.                     i = parseInt(t.data(_reg.n.get('dts')).i, 10), href = $('a.tri4m-app-cinematic-resourcelink', p).attr('href'),
  469.                     ds = t.data(_reg.n.get('dts'));
  470.                
  471.                 if(typeof ds.qs !== 'undefined')
  472.                     return;
  473.  
  474.                 log.t107('init ' + i);
  475.  
  476.                 if(typeof _queue[i] !== 'undefined' && _queue[i].status === true)
  477.                 {
  478.                     log.t107('-- nothing to do ' + i);
  479.                     return;
  480.                 }
  481.  
  482.                 log.t107('push to queue ' + i);
  483.  
  484.                 _queue[i] =
  485.                 {
  486.                     status    : false,
  487.                     error     : false,
  488.                     append    : false,
  489.                     kicked    : false,
  490.                     lookup    : null,
  491.                     islooking : false,
  492.                     attempt   : 0,
  493.                     thumb     : t,
  494.                     parent    : p,
  495.                     src       : null,
  496.                     image     : $('<img />').addClass('tri4m-app-cinematic-thumbnail')
  497.                 };
  498.                
  499.                 ds.qs = _queue[i];
  500.                 t.data(_reg.n.get('dts'), ds);
  501.  
  502.                 var islast = (_queue.length === _reg.j.get('t').length), isfirst = (i === 0);
  503.                
  504.                 log.t107('index ' + i + ' === isfirst = ' + isfirst, (true === isfirst ? 1 : 0));
  505.                 log.t107('index ' + i + ' === islast = ' + islast, (true === islast ? 1 : 0));
  506.                
  507.                
  508.                 var shutdown =
  509.                 {
  510.                     dts : function(i)
  511.                     {
  512.                         var ds = _queue[i].thumb.data(_reg.n.get('dts'));
  513.                         ds.qs = _queue[i];
  514.                         _queue[i].append = true;
  515.                         _queue[i].status = true;
  516.                         _queue[i].thumb.data(_reg.n.get('dts'), ds);
  517.                     },
  518.                     cbs : function(i)
  519.                     {
  520.                         __settings.callback.thumbs.beforeShow(_queue[i].parent, i);
  521.                     },
  522.                     vis : function(i)
  523.                     {
  524.                         _queue[i].parent.css({overflow: 'hidden'});
  525.                        
  526.                         if(typeof ILLI === 'undefined'
  527.                         || false === __settings.thumbs.preloadAllBeforeShow)
  528.                         {
  529.                             _queue[i].parent.animate({opacity : 1}, 500, function()
  530.                             {
  531.                                 __settings.callback.thumbs.afterShow(_queue[i].parent, i);
  532.                             });
  533.                            
  534.                             return;
  535.                         }
  536.                        
  537.                         ILLI.fn.idle(_queue[i].parent, i * 100, function()
  538.                         {
  539.                             _queue[i].parent.animate({opacity : 1}, 500, function()
  540.                             {
  541.                                 __settings.callback.thumbs.afterShow(_queue[i].parent, i);
  542.                             });
  543.                            
  544.                         });
  545.                     },
  546.                     cfs : function(i)
  547.                     {
  548.                         __settings.callback.images.firstInit();
  549.                         _reg.j.get('l').trigger('tri4m.app.cinematic.container.nextItem');
  550.                     },
  551.                     cls : function(i)
  552.                     {
  553.                         __settings.callback.thumbs.ready(_reg.j.get('l'));
  554.                     }
  555.                 };
  556.  
  557.                 var dequeue = function()
  558.                 {
  559.                     log.t107('try dequeue: caller is ' + i);
  560.                    
  561.                     if(true === __settings.thumbs.preloadAllBeforeShow)
  562.                     {
  563.                         if(false === islast)
  564.                             return;
  565.  
  566.                         log.t107('try dequeue: preloadAllBeforeShow = true');
  567.  
  568.                         var success = true;
  569.                        
  570.                         for(var idx in _queue)
  571.                             if(_queue[idx].status === false)
  572.                                 success = false;
  573.  
  574.                         if(false === success)
  575.                         {
  576.                             log.t107('try dequeue: success = false');
  577.                             var refetch = setInterval(function()
  578.                             {
  579.                                 clearInterval(refetch);
  580.  
  581.                                 log.t107('try again; attempt = ' + _queue[i].attempt );
  582.                                 //dequeue();
  583.                             }, 500);
  584.                             //return;
  585.                         }
  586.                     }
  587.                    
  588.  
  589.                     log.t107('try dequeue: start iteration');
  590.                    
  591.                     for(var idx in _queue)
  592.                     {
  593.                         idx = parseInt(idx, 10);
  594.                         if(true === _queue[idx].error)
  595.                         {
  596.                             log.t107('try dequeue: error: ' + _queue[idx].src, 3);
  597.                             log.t107('try dequeue: -- continue');
  598.                             continue;
  599.                         }
  600.  
  601.                         (function(curIndex, caller)
  602.                         {
  603.                             var islast = (_queue.length === (curIndex + 1));
  604.                             var isfirst = curIndex === 0;
  605.                            
  606.                             log.t107('dequeue index ' + curIndex + ' === isfirst = ' + isfirst, (true === isfirst ? 1 : 0));
  607.                             log.t107('dequeue index ' + curIndex + ' === islast = ' + islast, (true === islast ? 1 : 0));
  608.                            
  609.                             if(null !== _queue[curIndex].lookup)
  610.                                 return;
  611.                            
  612.                             _queue[curIndex].lookup = setInterval(function()
  613.                             {
  614.                                 if(true === _queue[curIndex].kicked)
  615.                                 {
  616.                                     log.t107('try dequeue: waiting: -- -- index ' + curIndex + ' already kicked');
  617.                                     clearInterval(_queue[curIndex].lookup);
  618.                                     return;
  619.                                 }
  620.                                
  621.                                 if(_queue[curIndex].status === false)
  622.                                 {
  623.                                     log.t107('try dequeue: waiting: preloadAllBeforeShow = ' + __settings.thumbs.preloadAllBeforeShow + ', status = '+ _queue[curIndex].status +', try = ' + _queue[curIndex].attempt + ' of ' + _queue.length + ', index = ' + curIndex + ', caller = ' + caller, 2);
  624.  
  625.                                     if(_queue[curIndex].attempt > _queue.length || _queue[curIndex].attempt === _queue.length)
  626.                                     {
  627.                                         log.t107('try dequeue: waiting: -- error: ' + _queue[curIndex].src);
  628.                                         log.t107('try dequeue: waiting: -- preloadAllBeforeShow =  ' + __settings.thumbs.preloadAllBeforeShow + ', status = '+ _queue[curIndex].status +', max.attempts = '+_queue.length+', index = ' + curIndex + ', caller = ' + caller, 3);
  629.                                         log.t107('try dequeue: waiting: -- index ' + curIndex + ' was kicked from #list (idle flood), caller = ' + caller + ' in try = ' + _queue[curIndex].attempt + ' of ' + _queue.length, 3);
  630.                                         log.t107('try dequeue: waiting: -- remove ' + ILLI.fn.o2s(_queue[curIndex]), 3);
  631.                                         _queue[curIndex].kicked = true;
  632.                                         _queue[curIndex].error  = true;
  633.                                         clearInterval(_queue[curIndex].lookup);
  634.                                         _removed[curIndex] = _queue[curIndex];
  635.                                         _reg.j.get('l').trigger('tri4m.app.cinematic.container.removeItem', [curIndex]);
  636.                                     }
  637.                                    
  638.                                     _queue[curIndex].attempt++;
  639.  
  640.                                     return;
  641.                                 }
  642.  
  643.                                 clearInterval(_queue[curIndex].lookup);
  644.                                
  645.                                 if(true === _queue[curIndex].append)
  646.                                     return;
  647.                                
  648.                                 shutdown.dts(curIndex);
  649.                                
  650.                                 log.t107('try display: index ' + curIndex + ' isFirst ' + isfirst + ' type ' + ILLI.fn.type(curIndex));                                            
  651.                                 log.t107('try dequeue: asCssBackgroundImage = ' + __settings.thumbs.asCssBackgroundImage + ', index ' + curIndex);
  652.  
  653.                                 if(true === __settings.thumbs.asCssBackgroundImage)
  654.                                 {
  655.                                     _queue[curIndex].parent.css({'background-image' : 'url("' + _queue[curIndex].src + '")'});
  656.                                 }
  657.                                 else
  658.                                 {
  659.                                     _queue[curIndex].parent.prepend(_queue[curIndex].image);
  660.                                 }
  661.                                
  662.                                 shutdown.cbs(curIndex);
  663.                                 shutdown.vis(curIndex);
  664.                                 if(true === isfirst)
  665.                                     shutdown.cfs(curIndex);
  666.  
  667.                                 if(true === islast)
  668.                                     shutdown.cls(curIndex);
  669.  
  670.                             }, 700);
  671.                         })(idx, i);
  672.                     }
  673.                 }
  674.  
  675.                 var load = function(src)
  676.                 {
  677.                     log.t107('try load: ' + src);
  678.                    
  679.                    
  680.                     if(__settings.thumbs.enabled === false)
  681.                     {
  682.                         log.t107(' -- disabled: thumbs', 1);
  683.                        
  684.                         shutdown.dts(i);
  685.                         shutdown.cbs(i);
  686.                         shutdown.vis(i);
  687.                         if(true === isfirst)
  688.                             shutdown.cfs(i);
  689.  
  690.                         if(true === islast)
  691.                             shutdown.cls(i);
  692.                        
  693.                         return;
  694.                     }
  695.                    
  696.                     var IMG = new Image(), src = src;
  697.                    
  698.                     $(IMG)
  699.                     .addClass('dummy')
  700.                     .hide()
  701.                     .load(function()
  702.                     {
  703.                         log.t107('try load: -- complete: ' + src, 1);
  704.                        
  705.                         $(IMG).remove();
  706.                        
  707.                         t.wait = setInterval(function()
  708.                         {
  709.                             clearInterval(t.wait);
  710.                             log.t107('try append: ' + src);
  711.                             _queue[i].image.attr('src', src);
  712.                             _queue[i].src = src;
  713.                             _queue[i].status = true;
  714.                             dequeue();
  715.  
  716.                         }, 100);
  717.  
  718.                         IMG.onload = function(){};
  719.                     })
  720.                     .error(function()
  721.                     {
  722.                         log.t107('try load: error: ' + src, 3);
  723.                        
  724.                         _queue[i].image.attr('src', src);
  725.                         _queue[i].src = src;
  726.                         _queue[i].status = true;
  727.                         _queue[i].error = true;
  728.                        
  729.                         dequeue();
  730.                        
  731.                         IMG.onerror = function(){};
  732.                     });
  733.  
  734.                     $(IMG).attr('src', src);
  735.                     t.append(IMG);
  736.                 };
  737.  
  738.                 t.idle = setInterval(function()
  739.                 {
  740.                     clearInterval(t.idle);
  741.                     log.t107('try POST: thumb for ' + i + ': ' + href);
  742.                    
  743.                     var provider = _type(href), url = null;
  744.                     switch(provider)
  745.                     {
  746.                         case 'jpg':
  747.                         case 'png':
  748.                         case 'gif':
  749.                             // create thumb url from img-a-href
  750.                             ILLI.router.create.thumb(href, p.height(), p.width(), function(url, route, data)
  751.                             {
  752.                                 log.t107('try POST: -- complete: thumb ' + i + ' is ' + url, 1);
  753.                                 t.attr('href', url);                                   
  754.                                 load(url);
  755.                             });
  756.                             break;
  757.                         case 'youtube':
  758.                             // create thumb url from img-a-href
  759.                             ILLI.router.create.json(href, provider, function(json, data)
  760.                             {
  761.                                 log.t107('try POST: -- complete: thumb ' + i + ' is ' + ILLI.fn.o2s(json), 1);
  762.                                 t.data('youtube.json', json.data);
  763.                                
  764.                                 t.attr('title', t.data('youtube.json').title);
  765.                                 t.attr('duration', t.data('youtube.json').duration);
  766.                                
  767.                                 var url = t.data('youtube.json').thumbnail.hqDefault;
  768.                                 t.attr('href', url);                                   
  769.                                 load(url);
  770.                             });
  771.                             break;
  772.                     }
  773.                 }, 50);
  774.             });
  775.  
  776.             _bnd.a.register('tri4m.app.cinematic.reslink.preloadImage', function()
  777.             {
  778.                 log.t109('tri4m.app.cinematic.reslink.preloadImage', 1);
  779.                
  780.                 var src  = $(this).attr('href');
  781.                 log.t108('init ' + src);                           
  782.                 var load = function()
  783.                 {
  784.                     log.t108('try load: ' + src);
  785.                    
  786.                     _reg.j.get('d').html('');
  787.                    
  788.                     switch(_type(src))
  789.                     {
  790.                         case 'jpg':
  791.                         case 'png':
  792.                         case 'gif':
  793.                             if(_reg.j.get('d').children('img' + "[src='" + src + "']").length === 0)
  794.                             {
  795.                                
  796.                                 var IMG = new Image(), img = $('<img />')
  797.                                     .css({position: 'absolute'})
  798.                                     .addClass('tri4m-app-cinematic-image')
  799.                                     .css('position', 'absolute');
  800.                                    
  801.                                 $(IMG).hide()
  802.                                 .load(function()
  803.                                 {
  804.                                     log.t108('try load: -- complete: ' + src, 1);
  805.                                    
  806.                                     var css = _c.i(IMG, _reg.j.get('d'));
  807.                                    
  808.                                     $(IMG).remove();
  809.                                    
  810.                                     var wait = setInterval(function()
  811.                                     {
  812.                                         clearInterval(wait);
  813.                                         log.t108('try load: append: ' + src);
  814.                                         log.t108('try dequeue: asCssBackgroundImage = ' + __settings.images.asCssBackgroundImage);
  815.                                        
  816.                                         if(true === __settings.images.asCssBackgroundImage)
  817.                                         {
  818.                                             _reg.j.get('d').css({'background-image' : 'url("' + src + '")'});
  819.                                         }
  820.                                         else
  821.                                         {
  822.                                             _reg.j.get('d').prepend(img.attr('src', src).css(css));
  823.                                         }
  824.                                        
  825.                                         _reg.j.get('d').animate({opacity : 1}, 500, function()
  826.                                         {
  827.                                             log.t108('try load: -- success: ' + src);
  828.                                         });
  829.                                     }, 100);
  830.  
  831.                                     IMG.onload = function(){};
  832.                                 })
  833.                                 .error(function()
  834.                                 {
  835.                                     log.t108('try load: -- error: ' + src, 3);
  836.                                     IMG.onerror = function(){};
  837.                                 });
  838.  
  839.                                 $(IMG).attr('src', src);
  840.                                 _reg.j.get('d').html(IMG);
  841.  
  842.                             }
  843.                             else
  844.                             {
  845.                                 log.t108('try load: known source ' + src);
  846.                                
  847.                                 var img = _reg.j.get('d').children('img' + "[src='" + src + "']");
  848.                                 img.show();
  849.                                 _reg.j.get('d').animate({opacity : 1}, 500);
  850.                             }
  851.                             break;
  852.                         case 'youtube':                                    
  853.                             var css = _c.i((new Image()), _reg.j.get('d'));
  854.                             var vid = $('<iframe frameborder="0" allowfullscreen></iframe>');
  855.  
  856.                             vid.attr('src', src).attr('height', css.height).attr('width', css.width).css({opacity : 0});
  857.                             vid.animate({opacity : 1}, 500);
  858.                             _reg.j.get('d').html(vid).animate({opacity : 1}, 500);
  859.                             break;
  860.                         default:
  861.                             break;
  862.                     }
  863.                 };
  864.                
  865.                 var construct = function()
  866.                 {
  867.                     log.t108('try load: bioscoop has no images -- construct sequence');
  868.                     _reg.j.get('d').css({opacity : 0});
  869.                     load();
  870.                 };
  871.                
  872.                 var destruct = function()
  873.                 {
  874.                     log.t108('try load: bioscoop has images -- destruct-construct sequence');
  875.                    
  876.                     _reg.j.get('d').stop().animate({opacity : 0}, 500, function()
  877.                     {
  878.                         $('img', _reg.j.get('d')).remove();
  879.                         construct();
  880.                     });
  881.                 };
  882.                
  883.                 (_reg.j.get('d').children('img').length === 0
  884.                 && !_reg.j.get('d').css('background-image'))
  885.                     ? construct()
  886.                     : destruct();
  887.             }, true);
  888.  
  889.             _bnd.r.register('resize.resolutionchange', _j.window, true);
  890.            
  891.             _dom();
  892.            
  893.             var br = _bnd.r.toValueObject(), bl = _bnd.l.toValueObject();
  894.             for(var i in br) { $(window).bind(i, br[i]); }
  895.             for(var i in bl) { _reg.j.get('l').unbind(i).bind(i, bl[i]); }
  896.            
  897.             _update();
  898.         })();
  899.     };
  900.  
  901.     $.tri4m.log('initialize tri4m.app.cinematic: tri4m LABS', 1);
  902.     var instance = new __instance(__SELF);
  903.     $.tri4m.global.__INSTANCE_REGISTRY__.register(__SELF, regName, instance);
  904. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement