]> projects.mako.cc - scuttle/blobdiff - jsScuttle.php
Merge remote-tracking branch 'remotes/gh-mjjstorey/master'
[scuttle] / jsScuttle.php
index fbe1e20195a145102744f5bee2168cd5fa2834d3..9c6b9b7dbc39d8a2ee210e24de06ecd30dee2ac7 100644 (file)
@@ -1,79 +1,34 @@
 <?php
 header('Content-Type: text/javascript');
 <?php
 header('Content-Type: text/javascript');
-require_once('header.inc.php');
-require_once('functions.inc.php');
+require_once 'header.inc.php';
+require_once 'functions.inc.php';
 $player_root = $root .'includes/player/';
 $player_root = $root .'includes/player/';
-?>
 
 
-function _playerAdd(anchor) {
-    var url = anchor.href;
-    var code = '<object type="application/x-shockwave-flash" data="<?php echo $player_root ?>musicplayer_f6.swf?song_url=' + url +'&amp;b_bgcolor=ffffff&amp;b_fgcolor=000000&amp;b_colors=0000ff,0000ff,ff0000,ff0000&buttons=<?php echo $player_root ?>load.swf,<?php echo $player_root ?>play.swf,<?php echo $player_root ?>stop.swf,<?php echo $player_root ?>error.swf" width="14" height="14">';
-    var code = code + '<param name="movie" value="<?php echo $player_root ?>musicplayer.swf?song_url=' + url +'&amp;b_bgcolor=ffffff&amp;b_fgcolor=000000&amp;b_colors=0000ff,0000ff,ff0000,ff0000&amp;buttons=<?php echo $player_root ?>load.swf,<?php echo $player_root ?>play.swf,<?php echo $player_root ?>stop.swf,<?php echo $player_root ?>error.swf" />';
-    var code = code + '</object>';
-    anchor.parentNode.innerHTML = code +' '+ anchor.parentNode.innerHTML;
+$userservice     =& ServiceFactory::getServiceInstance('UserService');
+if ($userservice->isLoggedOn()) {
+    $currentUser = $userservice->getCurrentUser();
+    $currentUsername = $currentUser[$userservice->getFieldName('username')];
 }
 }
-
-String.prototype.trim = function() {
-    return this.replace(/^\s+|\s+$/g, '');
-};
+?>
 
 var deleted = false;
 
 var deleted = false;
-function deleteBookmark(ele, input){
-    var confirmDelete = "<span><?php echo T_('Are you sure?') ?> <a href=\"#\" onclick=\"deleteConfirmed(this, " + input + ", \'\'); return false;\"><?php echo T_('Yes'); ?></a> - <a href=\"#\" onclick=\"deleteCancelled(this); return false;\"><?php echo T_('No'); ?></a></span>";
-    ele.style.display = 'none';
-    ele.parentNode.innerHTML = ele.parentNode.innerHTML + confirmDelete;
+function deleteBookmark(ele, input) {
+  $(ele).hide();
+  $(ele).parent().append("<span><?php echo T_('Are you sure?') ?> <a href=\"#\" onclick=\"deleteConfirmed(this, " + input + "); return false;\"><?php echo T_('Yes'); ?></a> - <a href=\"#\" onclick=\"deleteCancelled(this); return false;\"><?php echo T_('No'); ?></a></span>");
+  return false;
 }
 }
-
 function deleteCancelled(ele) {
 function deleteCancelled(ele) {
-    var del = previousElement(ele.parentNode);
-    del.style.display = 'inline';
-    ele.parentNode.parentNode.removeChild(ele.parentNode);
-    return false;
-}
-
-function deleteConfirmed(ele, input, response) {
-    if (deleted == false) {
-        deleted = ele.parentNode.parentNode.parentNode;
-    }
-    var post = deleted;
-    post.className = 'xfolkentry deleted';
-    if (response != '') {
-        post.style.display = 'none';
-        deleted = false;
-    } else {
-        loadXMLDoc('<?php echo $root; ?>ajaxDelete.php?id=' + input);
-    }
+  $(ele).parent().prev().show();
+  $(ele).parent().remove();
+  return false;
 }
 }
-
-function previousElement(ele) {
-    ele = ele.previousSibling;
-    while (ele.nodeType != 1) {
-        ele = ele.previousSibling;
-    }
-    return ele;
-}
-
-function isAvailable(input, response){
-    var usernameField = document.getElementById("username");
-    var username = usernameField.value;
-    username = username.toLowerCase();
-    username = username.trim();
-    var availability = document.getElementById("availability");
-    if (username != '') {
-        usernameField.style.backgroundImage = 'url(<?php echo $root; ?>loading.gif)';
-        if (response != '') {
-            usernameField.style.backgroundImage = 'none';
-            if (response == 'true') {
-                availability.className = 'available';
-                availability.innerHTML = '<?php echo T_('Available'); ?>';
-            } else {
-                availability.className = 'not-available';
-                availability.innerHTML = '<?php echo T_('Not Available'); ?>';
-            }
-        } else {
-            loadXMLDoc('<?php echo $root; ?>ajaxIsAvailable.php?username=' + username);
-        }
+function deleteConfirmed(ele, input) {
+  $.get("<?php echo $root; ?>ajaxDelete.php?id=" + input, function(data) {
+    if (1 === parseInt(data)) {
+      $(ele).parents(".xfolkentry").slideUp();
     }
     }
+  });
+  return false;
 }
 
 function useAddress(ele) {
 }
 
 function useAddress(ele) {
@@ -87,55 +42,86 @@ function useAddress(ele) {
     }
 }
 
     }
 }
 
-function getTitle(input, response){
-    var title = document.getElementById('titleField');
-    if (title.value == '') {
-        title.style.backgroundImage = 'url(<?php echo $root; ?>loading.gif)';
-        if (response != null) {
-            title.style.backgroundImage = 'none';
-            title.value = response;
-        } else if (input.indexOf('http') > -1) {
-            loadXMLDoc('<?php echo $root; ?>ajaxGetTitle.php?url=' + input);
-        } else {
-            return false;
-        }
+function getTitle(input) {
+  var title = $("#titleField").val();
+  if (title.length < 1) {
+    $("#titleField").css("background-image", "url(<?php echo $root; ?>loading.gif)");
+    if (input.indexOf("http") > -1) {
+      $.get("<?php echo $root; ?>ajaxGetTitle.php?url=" + input, function(data) {
+        $("#titleField").css("background-image", "none")
+                        .val(data);
+      });
     }
     }
+  }
 }
 
 }
 
-var xmlhttp;
-function loadXMLDoc(url) {
-    // Native
-    if (window.XMLHttpRequest) {
-        xmlhttp = new XMLHttpRequest();
-        xmlhttp.onreadystatechange = processStateChange;
-        xmlhttp.open("GET", url, true);
-        xmlhttp.send(null);
-    // ActiveX
-    } else if (window.ActiveXObject) {
-        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
-        if (xmlhttp) {
-            xmlhttp.onreadystatechange = processStateChange;
-            xmlhttp.open("GET", url, true);
-            xmlhttp.send();
-        }
-    }
+function autocomplete() {
+       $.ajax({
+               url: '<?php echo $root?>alltags/<?php echo $currentUsername?>',
+               success: function(data) {
+                       //console.log($(data));
+                       var availableTags = new Array();
+                       $(data).find('a').each(function() {
+                               availableTags.push($(this).html());
+                               //console.log($(this).html());
+                       });
+                       
+                       $( ".autocomplete" )
+                               // don't navigate away from the field on tab when selecting an item
+                               .bind( "keydown", function( event ) {
+                                       if ( event.keyCode === $.ui.keyCode.TAB &&
+                                                       $( this ).data( "autocomplete" ).menu.active ) {
+                                               event.preventDefault();
+                                       }
+                               })
+                               .autocomplete({
+                                       minLength: 0,
+                                       source: function( request, response ) {
+                                               // delegate back to autocomplete, but extract the last term
+                                               response( $.ui.autocomplete.filter(
+                                                       availableTags, extractLast( request.term ) ) );
+                                       },
+                                       focus: function() {
+                                               // prevent value inserted on focus
+                                               return false;
+                                       },
+                                       select: function( event, ui ) {
+                                               var terms = split( this.value );
+                                               // remove the current input
+                                               terms.pop();
+                                               // add the selected item
+                                               terms.push( ui.item.value );
+                                               // add placeholder to get the comma-and-space at the end
+                                               terms.push( "" );
+                                               this.value = terms.join( ", " );
+                                               return false;
+                                       }
+                               });
+               }
+       });
+       
 }
 
 }
 
-function processStateChange() {
-    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
-        response = xmlhttp.responseXML.documentElement;
-        method = response.getElementsByTagName('method')[0].firstChild.data;
-        result = response.getElementsByTagName('result')[0].firstChild.data;
-        eval(method + '(\'\', result)');
-    }
+function split( val ) {
+               return val.split( /,\s*/ );
+       }
+function extractLast( term ) {
+       return split( term ).pop();
 }
 
 }
 
-function playerLoad() {
-    var anchors = document.getElementsByTagName('a');
-    var anchors_length = anchors.length;
-    for (var i = 0; i < anchors_length; i++) {
-        if (anchors[i].className == 'taggedlink' && anchors[i].href.match(/\.mp3$/i)) {
-            _playerAdd(anchors[i]);
-        }
-    }
-}
\ No newline at end of file
+/* Page load */
+$(function() {
+       
+       autocomplete();
+       
+  // Insert Flash player for MP3 links
+  if ($("#bookmarks").length > 0) {
+    $('a[href$=".mp3"].taggedlink').each(function() {
+      var url  = this.href;
+      var code = '<object type="application/x-shockwave-flash" data="<?php echo $player_root ?>musicplayer_f6.swf?song_url=' + url +'&amp;b_bgcolor=ffffff&amp;b_fgcolor=000000&amp;b_colors=0000ff,0000ff,ff0000,ff0000&buttons=<?php echo $player_root ?>load.swf,<?php echo $player_root ?>play.swf,<?php echo $player_root ?>stop.swf,<?php echo $player_root ?>error.swf" width="14" height="14">';
+          code = code + '<param name="movie" value="<?php echo $player_root ?>musicplayer.swf?song_url=' + url +'&amp;b_bgcolor=ffffff&amp;b_fgcolor=000000&amp;b_colors=0000ff,0000ff,ff0000,ff0000&amp;buttons=<?php echo $player_root ?>load.swf,<?php echo $player_root ?>play.swf,<?php echo $player_root ?>stop.swf,<?php echo $player_root ?>error.swf" />';
+          code = code + '</object> ';
+      $(this).prepend(code);
+    });
+  }
+})

Benjamin Mako Hill || Want to submit a patch?