views:

281

answers:

0

Hi Folk can you help me?

i will create a XML Parser with anchor/hash url. My problem is I get the hash / anchor from the URL does not load.

Here js in HTML Template

<script language="javascript" type="text/javascript">  
$(document).ready(function() {
    BROADCAST.init({  
     xmlPath : "broadcast.xml",  
     swfPath : "swf",  
     perView : 1,
    });   
});  
</script>
<script type="text/javascript">
function load() {
    var urllocation = location.href;
    if(urllocation.indexOf("#0") > -1){
     window.location.hash="0"; 
    } else {
    return false;
    }
}
</script>

And here my Code from the broadcast.js

    var BROADCAST = function(){
var _P = { init: function(params) {
     _P.params = params;
     _P.loadXml();
    },
    params: null,
    data: null,
    loadXml: function() { 
    $.ajax({
      type : "GET",
      cache: false,
      processData: false, 
      url : _P.params.xmlPath,
      dataType: "xml",
      error: function(e){ alert("An Error has occured" + e);}, 
      success : function(data) {    

       _P.data = data;
       _P.max = _P.params.perView;
       _P.count = $("movie", data).length;
       _P.preloadBroadcast();
       _P.browseBroadcast();
       }
     });
},
    first: 0,
    max: 0,
    count: 0, 
    preloadBroadcast : function() {
                        $("movie", _P.data).each(function(i) {    
      var broadcastID = $.trim( $(this).attr("id") );
      var category = $.trim( $("category", this).text() );
      var title = $.trim( $("title", this).text() );
      var description = $.trim( $("description", this).text() );
      var swfurl = $.trim( $("swfurl", this).text() );

      $("div#swfplayer").append(["<object class='swfmovie' id='swfmovie-"+ broadcastID +"'  type='application/x-shockwave-flash' data='swf/videoplayer_my.swf' width='560' height='315'><param name='movie' value='swf/videoplayer_my.swf'><param name='FlashVars' value='video="+ swfurl +"' /><param name='AllowScriptAccess' value='always'><embed type='application/x-shockwave-flash' src='swf/videoplayer_my.swf' width='200' height='100'></embed></object></div>"].join(" ")); 

      $("div#swfdesc").append(["<div class='node movie'><h2><small class='fltrt'>ID:",broadcastID," NR:",i,"</small>",title,"</h2>","<div class='inner'><p>",description,"</p></div></div>"].join(" "));  

      });

    $('#swfmenu .next').click(function() {
     _P.browseBroadcast("next");
        var match = self.location.href.match(/#([0-9]+)$/);
        if (match !== null) {
            var ca = match[1];
            ca++;
            self.location.href = '#' + ca;
      $(this).find("a").attr("href", "#"+ ca );
        } else {
            self.location.href = '#0';
      $(this).find("a").attr("href", "#0");
        }
    });

    $('#swfmenu .prev').click(function(){ 
     _P.browseBroadcast("prev");
        var match = self.location.href.match(/#([0-9]+)$/);
        if (match !== null) {
            var ca = match[1];
            ca--;
            if (ca >= 0) {
                self.location.href = '#' + ca;
       $(this).find("a").attr("href", "#"+ ca );
            }
        }
    });

    },

    browseBroadcast : function(browse) {
     if (browse == "prev") {
      if ( _P.first == _P.count && ( _P.count % _P.max > 0 ) ) {
       _P.first = _P.first - ( ( _P.count % _P.max ) + _P.max );
      } else {
       _P.first = _P.first - ( _P.max * 2 );
      }
     }
     var range = _P.first + _P.max;
     var start = 1;

     if ( range > _P.max ) {
      start = ( ( range - _P.max ) + 1 );
     }
     if ( _P.first == 0 ) {
      $("#swfmenu .prev").css("visibility", "hidden");
     } else {
      $("#swfmenu .prev").css("visibility", "visible");
     }
     if (range < _P.count) {
      $("#swfmenu .next").css("visibility", "visible");
     } else if ( range >= _P.count ) {
      range = _P.count;
      $("#swfmenu .next").css("visibility", "hidden");
     }

     var hash = document.location.hash.substr(1);
     if (hash != (hash = document.location.hash)) {
     var url = document.location.hash.substr(1);

     $("movie", _P.data ).each(function(url) {
      if ( url >= _P.first && url < range ) {
       $("#swfplayer .swfmovie:eq("+ url +"), div#swfdesc div.node:eq("+ url +")").fadeIn("slow");
      } else {
       $("#swfplayer .swfmovie:eq("+ url +"), div#swfdesc div.node:eq("+ url +")").css( "display", "none" );
      }
     });  

     _P.first = range;
     }
    }};

return {
    init : function(params) {
     _P.init(params);
    }
};
}();

What made i wrong?