FeedWindow.js
上传用户:dawnssy
上传日期:2022-08-06
资源大小:9345k
文件大小:4k
源码类别:

JavaScript

开发平台:

JavaScript

  1. /*!  * Ext JS Library 3.1.0  * Copyright(c) 2006-2009 Ext JS, LLC  * licensing@extjs.com  * http://www.extjs.com/license  */ FeedWindow = function() {
  2.     this.feedUrl = new Ext.form.ComboBox({
  3.         id: 'feed-url',
  4.         fieldLabel: 'Enter the URL of the feed to add',
  5.         emptyText: 'http://example.com/blog/feed',
  6.         width: 450,
  7.         validationEvent: false,
  8.         validateOnBlur: false,
  9.         msgTarget: 'under',
  10.         triggerAction: 'all',
  11.         displayField: 'url',
  12.         mode: 'local',
  13.         listeners:{
  14.             valid: this.syncShadow,
  15.             invalid: this.syncShadow,
  16.             scope: this
  17.         },
  18.         tpl: new Ext.XTemplate(
  19.                 '<tpl for="."><div class="x-combo-list-item">',
  20.                 '<em>{url}</em><strong>{text}</strong>',
  21.                 '<div class="x-clear"></div>',
  22.                 '</div></tpl>'),
  23.         store: new Ext.data.ArrayStore({
  24.             fields: ['url', 'text'],
  25.             data : this.defaultFeeds
  26.         })
  27.     });
  28.     this.form = new Ext.FormPanel({
  29.         labelAlign:'top',
  30.         items:this.feedUrl,
  31.         border: false,
  32.         bodyStyle:'background:transparent;padding:10px;'
  33.     });
  34.     FeedWindow.superclass.constructor.call(this, {
  35.         title: 'Add Feed',
  36.         iconCls: 'feed-icon',
  37.         id: 'add-feed-win',
  38.         autoHeight: true,
  39.         width: 500,
  40.         resizable: false,
  41.         plain:true,
  42.         modal: true,
  43.         y: 100,
  44.         autoScroll: true,
  45.         closeAction: 'hide',
  46.         buttons:[{
  47.             text: 'Add Feed!',
  48.             handler: this.onFeedAdd,
  49.             scope: this
  50.         },{
  51.             text: 'Cancel',
  52.             handler: this.hide.createDelegate(this, [])
  53.         }],
  54.         items: this.form
  55.     });
  56.     this.addEvents({add:true});
  57. }
  58. Ext.extend(FeedWindow, Ext.Window, {
  59.     defaultFeeds : [
  60.         ['http://www.divergingpath.com/rss.cfm?mode=full', 'Aaron Conran's Blog'],
  61.         ['http://feeds.yuiblog.com/YahooUserInterfaceBlog',  'Yahoo! UI Blog'],
  62.         ['http://feeds.feedburner.com/jquery/', 'jQuery Blog'],
  63.         ['http://sports.yahoo.com/nba/rss.xml', 'NBA News'],
  64.         ['http://feeds.dzone.com/dzone/frontpage', 'DZone.com']
  65.     ],
  66.     show : function(){
  67.         if(this.rendered){
  68.             this.feedUrl.setValue('');
  69.         }
  70.         FeedWindow.superclass.show.apply(this, arguments);
  71.     },
  72.     onFeedAdd: function() {
  73.         this.el.mask('Validating Feed...', 'x-mask-loading');
  74.         var url = this.feedUrl.getValue();
  75.         Ext.Ajax.request({
  76.             url: 'feed-proxy.php',
  77.             params: {feed: url},
  78.             success: this.validateFeed,
  79.             failure: this.markInvalid,
  80.             scope: this,
  81.             feedUrl: url
  82.         });
  83.     },
  84.     markInvalid : function(){
  85.         this.feedUrl.markInvalid('The URL specified is not a valid RSS2 feed.');
  86.         this.el.unmask();
  87.     },
  88.     validateFeed : function(response, options){
  89.         var dq = Ext.DomQuery;
  90.         var url = options.feedUrl;
  91.         try{
  92.             var xml = response.responseXML;
  93.             var channel = xml.getElementsByTagName('channel')[0];
  94.             if(channel){
  95.                 var text = dq.selectValue('title', channel, url);
  96.                 var description = dq.selectValue('description', channel, 'No description available.');
  97.                 this.el.unmask();
  98.                 this.hide();
  99.                 return this.fireEvent('validfeed', {
  100.                     url: url,
  101.                     text: text,
  102.                     description: description
  103.                 });
  104.             }
  105.         }catch(e){
  106.         }
  107.         this.markInvalid();
  108.     }
  109. });