Posted by malatestapunk Fri 2nd Mar 2007 10:15 - Syntax is JavaScript - 73 views
Download | New Post | Modify | Hide line numbers
Description:
twangoRotator twidget. See https://pastebin.co.uk/11288 for example usage.

  1. function rotatorTwidget (prefs) {
  2.    
  3.     var divID = "twangoRotator";
  4.     var imgOutDiv;
  5.     var outDiv;
  6.     var twangoImages = new Array();
  7.    
  8.     var _imgWidth = 100;
  9.     var _imgHeight = 100;
  10.     var _divHeight = 0;
  11.     var _divWidth = 0;
  12.     var _scrollerHeight = 10;
  13.     var _scrollerUpBg = false;
  14.     var _scrollerDnBg = false;
  15.     var _onAction = "onclick";
  16.    
  17.     var initDivs = function () {
  18.         _divHeight = (_divHeight) ? _divHeight : _imgHeight + (2*_scrollerHeight);
  19.         _divWidth = (_divWidth) ? _divWidth : _imgWidth;
  20.  
  21.         outDiv.style.position = "relative";
  22.         outDiv.style.width = _divWidth + "px";
  23.         outDiv.style.height = _divHeight + 'px';
  24.         outDiv.style.overflow = "hidden";
  25.        
  26.         imgOutDiv = document.createElement ('div');
  27.         upDiv = document.createElement ('div');
  28.         dnDiv = document.createElement ('div');
  29.        
  30.         upDiv.style.position = "absolute";
  31.         upDiv.style.top = "0";
  32.         upDiv.style.left = "0";
  33.         if (_scrollerUpBg) {
  34.             upDiv.style.width = _divWidth + "px";
  35.             upDiv.style.height = _scrollerHeight + "px";
  36.             upDiv.style.backgroundImage = "url(" + _scrollerUpBg + ")";
  37.             upDiv.style.backgroundPosition = ((_divWidth-_imgWidth)/2) + 'px 0px';
  38.             upDiv.style.backgroundRepeat = "no-repeat";
  39.         } else {
  40.             upDiv.style.width = "0px";
  41.             upDiv.style.height = "0px";
  42.             upDiv.style.borderStyle = "solid";
  43.             upDiv.style.borderTopStyle = "none";
  44.             upDiv.style.borderLeftWidth = _divWidth/2 + 'px';
  45.             upDiv.style.borderLeftColor = 'transparent';
  46.             upDiv.style.borderRightWidth = _divWidth/2 + 'px';
  47.             upDiv.style.borderRightColor = 'transparent';
  48.             upDiv.style.borderBottomColor = "#dddddd";
  49.             upDiv.style.borderBottomWidth = _scrollerHeight + "px";
  50.         }
  51.         upDiv[_onAction] = getPrev;
  52.        
  53.         dnDiv.style.position = "absolute";
  54.         dnDiv.style.top = _divHeight - _scrollerHeight + "px";
  55.         dnDiv.style.left = "0";
  56.         if (_scrollerDnBg) {
  57.             dnDiv.style.width = _divWidth + "px";
  58.             dnDiv.style.height = _scrollerHeight + "px";
  59.             dnDiv.style.backgroundImage = "url(" + _scrollerDnBg + ")";
  60.             dnDiv.style.backgroundPosition = (_divWidth-_imgWidth)/2 + 'px bottom';
  61.             dnDiv.style.backgroundRepeat = "no-repeat";
  62.         } else {
  63.             dnDiv.style.width = "0px";
  64.             dnDiv.style.height = "0px";
  65.             dnDiv.style.borderStyle = "solid";
  66.             dnDiv.style.borderBottomStyle = "none";
  67.             dnDiv.style.borderLeftWidth = _divWidth/2 + 'px';
  68.             dnDiv.style.borderLeftColor = 'transparent';
  69.             dnDiv.style.borderRightWidth = _divWidth/2 + 'px';
  70.             dnDiv.style.borderRightColor = 'transparent';
  71.             dnDiv.style.borderTopColor = "#dddddd";
  72.             dnDiv.style.borderTopWidth = _scrollerHeight + "px";
  73.         }
  74.         dnDiv[_onAction] = getNext;
  75.        
  76.         outDiv.appendChild(upDiv);
  77.         outDiv.appendChild(imgOutDiv);
  78.         outDiv.appendChild(dnDiv);
  79.        
  80.         __current = 0;
  81.     }
  82.    
  83.     var getNext = function () {
  84.         if (__current+1 >= twangoImages.length) return false;
  85.         __current++;
  86.         putImageThumb(__current-1);
  87.     }
  88.    
  89.     var getPrev = function () {
  90.         if (__current == 0) return false;
  91.         __current--;
  92.         putImageThumb(__current+1);
  93.     }
  94.    
  95.     var putImageThumb = function (old) {
  96.         if (old !== false) imgOutDiv.removeChild(twangoImages[old]);
  97.         imgOutDiv.appendChild(twangoImages[__current]);
  98.     }
  99.    
  100.     var init = function () {
  101.         if (twangoImage_array.length <= 0) return false;
  102.         outDiv =  document.getElementById(divID);
  103.         outDiv.innerHTML = '';
  104.         initDivs();
  105.         var im, alink;
  106.         for (i=0; ilength; i++) {
  107.             alink = document.createElement ('a');
  108.             alink.href = "http://www.twango.com/media/"+channelName+"/" + twangoImage_array[i][0];
  109.             alink.target = "_blank";
  110.             im = new Image();
  111.             im.style.border = "none";
  112.             im.id = twangoImage_array[i][0];
  113.             im.alt = twangoImage_array[i][0];
  114.             im.title = twangoImage_array[i][0];
  115.             im.src = twangoImage_array[i][1];
  116.             im.style.position = "absolute";
  117.             im.style.top = (((_divHeight - _imgHeight)/2) > _scrollerHeight) ?
  118.                 ((_divHeight - _imgHeight)/2) + 'px' : _scrollerHeight + "px";
  119.             im.style.left = (_divWidth-_imgWidth)/2 + 'px';
  120.             alink.appendChild(im);
  121.             twangoImages[i] = alink;
  122.         }
  123.         putImageThumb(false);
  124.     }
  125.    
  126.     var parsePrefs = function () {
  127.         if (!prefs) return false;
  128.         if (prefs['divID']) divID = prefs['divID'];
  129.         if (prefs['onAction']) _onAction = prefs['onAction'];
  130.         if (prefs['width']) _divWidth = prefs['width'];
  131.         if (prefs['height']) _divHeight = prefs['height'];
  132.         if (prefs['scrollerUpBg']) _scrollerUpBg = prefs['scrollerUpBg'];
  133.         if (prefs['scrollerDnBg']) _scrollerDnBg = prefs['scrollerDnBg'];
  134.         if (prefs['scrollerHeight']) _scrollerHeight = prefs['scrollerHeight'];
  135.     }
  136.    
  137.     parsePrefs ();
  138.     init();
  139. }

PermaLink to this entry https://pastebin.co.uk/11289
Posted by malatestapunk Fri 2nd Mar 2007 10:15 - Syntax is JavaScript - 73 views
Download | New Post | Modify | Hide line numbers

 

Comments: 1

by: on: Fri Mar 2 23:36:23 2007

Very cool! Do you have a page with this script running?