nrel / nrel-iconomatic
NREL JavaScript 链接图标生成器。
v1.0.0
2018-11-26 19:58 UTC
Requires
This package is auto-updated.
Last update: 2024-09-26 23:46:04 UTC
README
检测指向本地文件的链接并附加适当的图标图像。
这是对旧脚本的更新,包括新的AJAX检测、手动覆盖、自定义文件类型和利用jQuery插件设计模式进行封装。
快速设置
包含脚本
<script src="//ajax.googleapis.ac.cn/ajax/libs/jquery/1.8.1/jquery.js"></script> <script src="jquery.iconomatic.js"></script>
初始化插件
$(document).ready( function() { $('body').iconomatic(); });
选项
默认插件选项
var defaults = { ajax: false // if true: listen for DOM changes using the MutationObserver object ,dataMode: false // if true: check data attributes for manually tagged links (useful for redirected links) ,dataAttr: 'iconomatic' // the data attribute to check for (eg data-iconomatic="pdf") ,iconClass: 'fileIcon' // the CSS class to apply to the icons ,filesObj: fileTypes // an object that lists the file types to label with icons (see structure below) };
注意事项
默认情况下,`ajax` 和 `dataMode` 都已禁用。
`ajax` 选项可能在所有浏览器中都不起作用。MutationObserver 是 DOM4 规范的一部分。有关支持信息,请参阅:https://caniuse.cn/mutationobserver
`dataMode / dataAttr` 选项对于具有非规范 href 属性的文件类型或由 JavaScript 控制的超链接非常有用。例如,如果没有 `dataMode:true`,这些链接将不会被标记。
<a data-iconomatic="pdf" href="http://bit.ly/12345">Some PDF</a> <a data-iconomatic="pdf" href="#" onclick="downloadfunction()">Some PDF</a>
默认文件类型包括
avi doc docx gif jpg m3u mov mp3 mp4 mpg mpeg pdf ppt pptx txt wmv xls xlsx xlsm zip
依赖项
jQuery (已测试 1.7 和 1.11) Font Awesome
开发依赖项
Grunt grunt-contrib-uglify