看来 jQuery 你已经用得很爽了,想学习如何自己编写插件。非常好,这篇文档正适合你。用插件和方法来扩展 jQuery 非常强大,把最聪明的功能封装到插件中可以为你及团队节省大量开发时间。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function hexToHSL(hex) { | |
| var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); | |
| r = parseInt(result[1], 16); | |
| g = parseInt(result[2], 16); | |
| b = parseInt(result[3], 16); | |
| r /= 255, g /= 255, b /= 255; | |
| var max = Math.max(r, g, b), min = Math.min(r, g, b); | |
| var h, s, l = (max + min) / 2; | |
| if(max == min){ | |
| h = s = 0; // achromatic |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| byte=`curl -s https://packagecontrol.io/channel_v3.json | wc -c` | |
| if [ $byte -gt 2000000 ]; then | |
| echo "OK! mirror it" | |
| cp channel_v3.json channel_v3.json-old | |
| curl -s https://packagecontrol.io/channel_v3.json -o channel_v3.json | |
| cmp -s channel_v3.json channel_v3.json-old | |
| if [ $? == 0 ]; then | |
| echo "We don't need update now" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var digitUppercase = function(n) { | |
| var fraction = ['角', '分']; | |
| var digit = [ | |
| '零', '壹', '贰', '叁', '肆', | |
| '伍', '陆', '柒', '捌', '玖' | |
| ]; | |
| var unit = [ | |
| ['元', '万', '亿'], | |
| ['', '拾', '佰', '仟'] | |
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 判断两个版本字符串的大小 | |
| * @param {string} v1 原始版本 | |
| * @param {string} v2 目标版本 | |
| * @return {number} 如果原始版本大于目标版本,则返回大于0的数值, 如果原始小于目标版本则返回小于0的数值。0当然是两个版本都相等拉。 | |
| */ | |
| function compareVersion(v1, v2) { | |
| var _v1 = v1.split("."), | |
| _v2 = v2.split("."), |