配置 Ext.BLANK_IMAGE_URL 的原因(转载)

本文解释了ExtJS中配置BLANK_IMAGE_URL的原因,通过使用此配置项与CSS结合,可以轻松实现界面换肤功能,无需修改组件代码。

配置 Ext.BLANK_IMAGE_URL 的原因(转载)

2013年09月01日  ⁄ 综合 ⁄ 共 854字 ⁄ 字号  小 中 大  ⁄ 评论关闭
id="iframeu1788635_0" src="http://pos.baidu.com/acom?rdid=1788635&dc=2&di=u1788635&dri=0&dis=0&dai=2&ps=236x716&dcb=BAIDU_UNION_define&dtm=BAIDU_DUP_SETJSONADSLOT&dvi=0.0&dci=-1&dpt=none&tsr=0&tpr=1456828799641&ti=%E9%85%8D%E7%BD%AE%20Ext.BLANK_IMAGE_URL%20%E7%9A%84%E5%8E%9F%E5%9B%A0%EF%BC%88%E8%BD%AC%E8%BD%BD%EF%BC%89%20%7C%20%E5%AD%A6%E6%AD%A5%E5%9B%AD&ari=1&dbv=2&drs=1&pcs=830x519&pss=980x256&cfv=0&cpl=4&chi=1&cce=true&cec=UTF-8&tlm=1456828799&ltu=http%3A%2F%2Fwww.xuebuyuan.com%2F840240.html&ltr=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DPnyfnD1uNZstwtuZ2XGVKFwypMklEdSB4DdVPOB9ASGEMMbiMWSgrXP46SvNyJDh%26wd%3D%26eqid%3Dbf91f6670001776d0000000556d5712a&ecd=1&psr=1366x768&par=1366x728&pis=-1x-1&ccd=24&cja=false&cmi=6&col=zh-CN&cdo=-1&tcn=1456828800&qn=90360b05a0571924&tt=1456828799576.179.683.685" width="336" height="280" align="center,center" vspace="0" hspace="0" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true" style="margin: 0px; padding: 0px; border-width: 0px; border-style: initial; font-size: 13px; vertical-align: bottom; background: transparent;">

在分析ExtJS的源码时,对为什么要在Ext中配置BLANK_IMAGE_URL属性不知所以然。后来也没有刻意对着一细节做研究,大有要不了了之的倾向... ...

   不过最近在看Ext中jack的window导航式例时,看到一个细节,让我顿时明白了作者的这一做法的初衷。

   作者在对一些需要应用图片或者图标的地方,都没有显式写明要应用的图标(片)路径,而都是通过css来配置,许多应用图标的地方刚开始都Ext.BLANK_IMAGE_URL来替代,而在css在加载之后就会替换到真实的图标路径 。这一招就彻底解决了界面的换肤问题。

   看个例子:

 在desktop例子中,快捷方式图标的初始路径是指向空白的images/s.gif

 <dl id="x-shortcuts">
        <dt id="grid-win-shortcut">
            <a href="#"><img src="images/s.gif" />
            <div>Grid Window</div></a>
        </dt>
     </dl>

然后,在css中修改为:

#grid-win-shortcut img {
    width:48px;
    height:48px;
    background-image: url(../images/grid48x48.png);
    filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/grid48x48.png', sizingMethod='scale');
}

 

有些需要图标修饰的组件在动态创建时,图标的src一般都是指向Ext.BLANK_IMAGE_URL ,然后呢,再在css指向特定的图标位置。

然后以后要换肤的话,直接替换css文件就可以了。

      最后实践也证明,如果没有正确配置这个BLANK_IMAGE_URL,可能在许多控件上显示不了css文件中定义的装饰图标。


class FilePreviewHandler(tornado.web.RequestHandler): async def get(self): pool_name = self.get_argument("pool") raw_file_name = self.get_argument("file") file_name = urllib.parse.unquote(raw_file_name) if pool_name not in RESOURCE_POOLS: self.set_status(404) self.render("404.html") return pool_path = RESOURCE_POOLS[pool_name]["path"] file_path = os.path.normpath(os.path.join(pool_path, file_name)) real_request_path = os.path.realpath(file_path) real_pool_path = os.path.realpath(pool_path) if not real_request_path.startswith(real_pool_path): self.set_status(403) self.write("禁止访问此文件路径") return if not os.path.exists(file_path): self.set_status(404) self.render("404.html") return ext = os.path.splitext(file_name)[1].lower() # 特别处理 PDF 文件:使用本地 PDF.js 预览 if ext == ".pdf": # 构造预览链接,不要双重编码 proxy_url = f"/preview?pool={pool_name}&file={urllib.parse.quote(file_name)}" # 传递原始 URL,不要再次编码 pdf_url = f"/static/pdfjs/web/viewer.html?file={proxy_url}" self.redirect(pdf_url) return # 设置 MIME 类型 mime_type = { '.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', '.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', '.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation', '.pdf': 'application/pdf', '.txt': 'text/plain', '.md': 'text/markdown', '.html': 'text/html', '.css': 'text/css', '.js': 'application/javascript', '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.gif': 'image/gif', '.mp4': 'video/mp4', '.webm': 'video/webm', '.ogg': 'video/ogg', '.mp3': 'audio/mpeg', '.wav': 'audio/wav', '.flac': 'audio/flac', }.get(ext, mimetypes.guess_type(file_name)[0] or 'application/octet-stream') encoded_filename = urllib.parse.quote(file_name.encode('utf-8')) self.set_header("Content-Disposition", f'inline; filename*=UTF-8\'\'{encoded_filename}') file_size = os.path.getsize(file_path) range_header = self.request.headers.get('Range') is_download = not range_header and ext in ['.mp4', '.webm', '.ogg', '.pdf'] if is_download: self.set_header('Content-Type', mime_type) self.set_header('Content-Length', str(file_size)) self.set_status(200) if os.name == 'posix': fd = os.open(file_path, os.O_RDONLY) try: await tornado.ioloop.IOLoop.current().run_in_executor( None, os.sendfile, self.request.connection.fileno(), fd, None, file_size ) finally: os.close(fd) else: with open(file_path, 'rb') as f: while True: chunk = f.read(1024 * 1024 * 4) if not chunk: break try: self.write(chunk) await self.flush() except tornado.iostream.StreamClosedError: return self.finish() elif ext in ['.mp4', '.webm', '.ogg', '.pdf', '.mp3', '.wav', '.flac']: self.set_header('Accept-Ranges', 'bytes') start = 0 end = file_size - 1 if range_header: self.set_status(206) start_bytes, end_bytes = range_header.replace('bytes=', '').split('-') start = int(start_bytes) if start_bytes else 0 end = int(end_bytes) if end_bytes else file_size - 1 self.set_header('Content-Range', f'bytes {start}-{end}/{file_size}') self.set_header("Content-Length", str(end - start + 1)) self.set_header('Content-Type', mime_type) chunk_size = 4096 * 16 async with aiofiles.open(file_path, 'rb') as f: await f.seek(start) remaining = end - start + 1 while remaining > 0: chunk = await f.read(min(chunk_size, remaining)) if not chunk: break try: self.write(chunk) await self.flush() except tornado.iostream.StreamClosedError: return remaining -= len(chunk) self.finish() elif ext == '.txt': self.set_header('Content-Type', 'text/plain; charset=UTF-8') async with aiofiles.open(file_path, 'r', encoding='utf-8') as f: content = await f.read() self.write(content) self.finish() elif ext in ['.png', '.jpg', '.jpeg', '.gif', '.md', '.pdf', '.docx', '.xlsx', '.pptx']: self.set_header('Content-Type', mime_type) async with aiofiles.open(file_path, 'rb') as f: data = await f.read() self.write(data) self.finish() else: self.set_status(400) self.write("不支持预览此文件类型") 这是我的这个方法,你在我提供的这个方法代码中修改后给我把修改后的方法代码完整的给我提供过来吧
最新发布
08-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值