]> projects.mako.cc - scuttle/blob - jsScuttle.php
fixed missing quotes around mp3
[scuttle] / jsScuttle.php
1 <?php
2 header('Content-Type: text/javascript');
3 require_once 'header.inc.php';
4 require_once 'functions.inc.php';
5 $player_root = $root .'includes/player/';
6
7 $userservice     =& ServiceFactory::getServiceInstance('UserService');
8 if ($userservice->isLoggedOn()) {
9     $currentUser = $userservice->getCurrentUser();
10     $currentUsername = $currentUser[$userservice->getFieldName('username')];
11 }
12 ?>
13
14 var deleted = false;
15 function deleteBookmark(ele, input) {
16   $(ele).hide();
17   $(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>");
18   return false;
19 }
20 function deleteCancelled(ele) {
21   $(ele).parent().prev().show();
22   $(ele).parent().remove();
23   return false;
24 }
25 function deleteConfirmed(ele, input) {
26   $.get("<?php echo $root; ?>ajaxDelete.php?id=" + input, function(data) {
27     if (1 === parseInt(data)) {
28       $(ele).parents(".xfolkentry").slideUp();
29     }
30   });
31   return false;
32 }
33
34 function useAddress(ele) {
35     var address = ele.value;
36     if (address != '') {
37         if (address.indexOf(':') < 0) {
38             address = 'http:\/\/' + address;
39         }
40         getTitle(address, null);
41         ele.value = address;
42     }
43 }
44
45 function getTitle(input) {
46   var title = $("#titleField").val();
47   if (title.length < 1) {
48     $("#titleField").css("background-image", "url(<?php echo $root; ?>loading.gif)");
49     if (input.indexOf("http") > -1) {
50       $.get("<?php echo $root; ?>ajaxGetTitle.php?url=" + input, function(data) {
51         $("#titleField").css("background-image", "none")
52                         .val(data);
53       });
54     }
55   }
56 }
57
58 function autocomplete() {
59         $.ajax({
60                 url: '<?php echo $root?>alltags/<?php echo $currentUsername?>',
61                 success: function(data) {
62                         //console.log($(data));
63                         var availableTags = new Array();
64                         $(data).find('a').each(function() {
65                                 availableTags.push($(this).html());
66                                 //console.log($(this).html());
67                         });
68                         
69                         $( ".autocomplete" )
70                                 // don't navigate away from the field on tab when selecting an item
71                                 .bind( "keydown", function( event ) {
72                                         if ( event.keyCode === $.ui.keyCode.TAB &&
73                                                         $( this ).data( "autocomplete" ).menu.active ) {
74                                                 event.preventDefault();
75                                         }
76                                 })
77                                 .autocomplete({
78                                         minLength: 0,
79                                         source: function( request, response ) {
80                                                 // delegate back to autocomplete, but extract the last term
81                                                 response( $.ui.autocomplete.filter(
82                                                         availableTags, extractLast( request.term ) ) );
83                                         },
84                                         focus: function() {
85                                                 // prevent value inserted on focus
86                                                 return false;
87                                         },
88                                         select: function( event, ui ) {
89                                                 var terms = split( this.value );
90                                                 // remove the current input
91                                                 terms.pop();
92                                                 // add the selected item
93                                                 terms.push( ui.item.value );
94                                                 // add placeholder to get the comma-and-space at the end
95                                                 terms.push( "" );
96                                                 this.value = terms.join( ", " );
97                                                 return false;
98                                         }
99                                 });
100                 }
101         });
102         
103 }
104
105 function split( val ) {
106                 return val.split( /,\s*/ );
107         }
108 function extractLast( term ) {
109         return split( term ).pop();
110 }
111
112 /* Page load */
113 $(function() {
114         
115         autocomplete();
116         
117   // Insert Flash player for MP3 links
118   if ($("#bookmarks").length > 0) {
119     $('a[href$=".mp3"].taggedlink').each(function() {
120       var url  = this.href;
121       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">';
122           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" />';
123           code = code + '</object> ';
124       $(this).prepend(code);
125     });
126   }
127 })

Benjamin Mako Hill || Want to submit a patch?