Fix for Fix for Video tag RegExp

  1. <html>
  2. <head>
  3. <script>
  4. function check() {
  5.   var box = document.getElementById('in_field');
  6.   var data = box.value;
  7.   var videos = [];
  8.  
  9.   //while(/\[video:.*?(youtube|vimeo|capped).(?:com|tv)\/(?:watch\?v=|playeralt.php\?vid=)?([\w-]+)([^\]]*)]/ig.test(data)) {
  10.   while(/\[video:.*?(youtube\.com\/watch\?v=|vimeo\.com\/|capped\.tv\/playeralt\.php\?vid=)([\w-]+)([^\]]*)]/ig.test(data)) {
  11.     var prefix = RegExp.$1;
  12.     var video = RegExp.$2;
  13.     var extra = RegExp.$3;
  14.  
  15.     var service = /(youtube|vimeo|capped)/i.test(prefix) ? RegExp.$1 : 'unknown';
  16.  
  17.     var height = 'default_h';
  18.     var width = 'default_w';
  19.     if (extra.length>0) {
  20.       if(/height:\s*(\d+)/i.test(extra)) {
  21.         height = RegExp.$1;
  22.       }
  23.       if(/width:\s*(\d+)/i.test(extra)) {
  24.         width = RegExp.$1;
  25.       }
  26.     }
  27.     videos.push({s: service, v: video, w: width, h: height});
  28.     data = data.substr();
  29.   }
  30.   var out_box = document.getElementById('out');
  31.   for(var i=0;i<videos.length;i++) {
  32.       var v = videos[i];
  33.       out_box.innerHTML += "<p>Video: " + i + "<br />"
  34.         + "Service: " + v.s + "<br />"
  35.         + "Video: " + v.v + "<br />"
  36.         + "Width: " + v.w + "<br />"
  37.         + "Height: " + v.h + "</p>";
  38.   }
  39. }
  40. </script>
  41. </head>
  42. <body onload="check();">
  43. <textarea id="in_field" cols="80" rows="10">
  44. [video:http://www.youtube.com/watch?v=5hXZxaGZ_Bo]
  45.  
  46. [video:http://www.youtube.com/watch?v=5hXZxaGZ_Bo width:100 height:120]
  47.  
  48. [video:http://www.vimeo.com/6928356]
  49.  
  50. [video:http://capped.tv/playeralt.php?vid=xplsv-blockparty_2009_invite]
  51.  
  52. [video:http://capped.tv/playeralt.php?vid=xplsv-blockparty_2009_invite width: 300 height: 200]
  53.  
  54. [video:http://www.vimeo.com/6928356 height: 250 width:190]
  55.  
  56. </textarea>
  57. <div id="out">
  58. </div>
  59. </body>
  60. </html>

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.