Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
有用的js函数
var defaultTimer = 500000;
/**
* 成功消息
*
* @param {String} title
* @param {String} message
* @param {Integer} timer
*
* @return {boolean}
*/
function success(title, message, timer) {
return swal({
title: title,
text: message,
type: "success",
html: true,
timer: timer || defaultTimer
});
}
/**
* 普通消息
*
* @param {String} title
* @param {String} message
* @param {Integer} timer
*
* @return {boolean}
*/
function info(title, message, timer) {
return swal({
title: title,
text: message,
type: "info",
html: true,
timer: timer || defaultTimer
});
}
/**
* 失败消息
*
* @param {String} title
* @param {String} message
* @param {Integer} timer
*
* @return {boolean}
*/
function error(title, message, timer) {
return swal({
title: title,
text: message,
type: "error",
html: true,
timer: timer || defaultTimer
});
}
/**
* 警告消息
*
* @param {String} title
* @param {String} message
* @param {Function} callback
* @param {String} confirmButtonText
* @param {Boolean} closeOnConfirm
* @param {Boolean} showCancelButton
*
* @return {Boolean}
*/
function warning(title, message, callback, confirmButtonText, closeOnConfirm, showCancelButton) {
return swal({
title: title,
text: message,
type: "warning",
showCancelButton: showCancelButton,
confirmButtonColor: "#DD6B55",
confirmButtonText: confirmButtonText || 'OK,没问题!',
closeOnConfirm: closeOnConfirm,
html: true
}, callback);
}
/**
* 自动关闭
*
* @param {String} title
* @param {String} message
* @param {Integer} timer
*
* @return {boolean}
*/
function flush(title, message, timer) {
return swal({ title: title, text: message, timer: timer || 2000 });
}
window.alert = function(string){
swal('' + string);
};
window.confirm = function(title){
sweetAlert({
title: title,
showCancelButton: true,
confirmButtonText: '确认',
cancelButtonText: '取消'
}, function() {
if (window.event && window.event.toElement) {
var btn = $(window.event.toElement);
window.location.href=btn.attr('href');
};
});
return false;
};
function video_parse(url){
if ( !url ) return '';
url = utils.trim(url)
.replace(/v\.youku\.com\/v_show\/id_([\w\-=]+)\.html/i, 'player.youku.com/player.php/sid/$1/v.swf')
.replace(/(www\.)?youtube\.com\/watch\?v=([\w\-]+)/i, "www.youtube.com/v/$2")
.replace(/youtu.be\/(\w+)$/i, "www.youtube.com/v/$1")
.replace(/v\.ku6\.com\/.+\/([\w\.]+)\.html.*$/i, "player.ku6.com/refer/$1/v.swf")
.replace(/www\.56\.com\/u\d+\/v_([\w\-]+)\.html/i, "player.56.com/v_$1.swf")
.replace(/www.56.com\/w\d+\/play_album\-aid\-\d+_vid\-([^.]+)\.html/i, "player.56.com/v_$1.swf")
.replace(/v\.pps\.tv\/play_([\w]+)\.html.*$/i, "player.pps.tv/player/sid/$1/v.swf")
.replace(/www\.letv\.com\/ptv\/vplay\/([\d]+)\.html.*$/i, "i7.imgs.letv.com/player/swfPlayer.swf?id=$1&autoplay=0")
.replace(/www\.tudou\.com\/programs\/view\/([\w\-]+)\/?/i, "www.tudou.com/v/$1")
.replace(/v\.qq\.com\/cover\/[\w]+\/[\w]+\/([\w]+)\.html/i, "static.video.qq.com/TPout.swf?vid=$1")
.replace(/v\.qq\.com\/.+[\?\&]vid=([^&]+).*$/i, "static.video.qq.com/TPout.swf?vid=$1")
.replace(/my\.tv\.sohu\.com\/[\w]+\/[\d]+\/([\d]+)\.shtml.*$/i, "share.vrs.sohu.com/my/v.swf&id=$1");
return url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.