Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

focusbejs

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

focusbejs - npm Package Compare versions

Comparing version
1.0.3
to
1.0.4
+237
bgsound.js
/**
@author:focusbe
@email:1134420693@qq.com
@blog:http://blog.focusbe.com
@github:https://github.com/focusbe
**/
define(['jquery','./prefix'],function($,PREFIX){
alert(1);
// var $ = require('./jquery.js');
// console.log($);
//var PREFIX = require('./prefix.js');
console.log(PREFIX);
var BgSound = function(option){
var audioElement = null;
var volumeclock = null;
var volume = 1;
var self = this;
var cursrc = '';
var curstate;
var shouldplay = false;
var defaultOption = {
file:'',
loop:true,
volume:1,
autoplay:true,
onplay:function(){
},
onpause:function(){
}
}
option = $.extend(defaultOption,option);
self.init = function(){
if($("#SOUND_AUDIO").length==0)
{
var soundaudio_outer = $('<div id="SOUND_AUDIO_outer"></div>');
soundaudio_outer.css({position:'absolute',width:100,height:100,top:'-100%'});
$('body').append(soundaudio_outer);
soundaudio_outer.append('<audio id="SOUND_AUDIO"></audio>');
self.audioElement = document.getElementById('SOUND_AUDIO');
}
self.setAudio();
if(option.autoplay)
{
self.play();
$('body').bind('touchstart',touchPlayZhibo);
function touchPlayZhibo()
{
self.play();
$('body').unbind('touchstart',touchPlayZhibo);
}
}
self.bind();
};
self.bind = function(){
self.audioElement.addEventListener("playing", function(){
if(typeof(option.onplay)=='function')
{
option.onplay();
}
},false);
self.audioElement.addEventListener("pause", function(){
if(typeof(option.onpause)=='function')
{
option.onpause();
}
},false);
self.audioElement.addEventListener("ended", function(){
if(typeof(option.onpause)=='function')
{
option.onpause();
}
},false);
self.bindBackRun();
};
self.setAudio = function(thisoption){
if(typeof(thisoption)=='object')
{
option = $.extend(option,thisoption);
}
if(cursrc!=option.file)
{
SOUND_AUDIO.src = option.file;
cursrc = option.file;
}
if(!option.loop)
{
SOUND_AUDIO.removeAttribute('loop');
}
else
{
SOUND_AUDIO.loop = 'loop';
}
SOUND_AUDIO.volume = option.volume;
volume = option.volume;
};
self.play = function(thisoption){
if(typeof(thisoption)=='object')
{
option = $.extend(option,thisoption);
self.setAudio();
}
else if(typeof(thisoption)=='string')
{
option.file = thisoption;
self.setAudio();
}
self.resume();
curstate = 'play';
};
self.pause = function(huanchun){
if(!self.audioElement)
return;
if(typeof(huanchun)=='undefined')
{
huanchun = true;
}
if(self.volumeclock)
{
clearInterval(self.volumeclock);
self.volumeclock = null;
}
//self.audioElement.pause();
if(huanchun)
{
volume = self.audioElement.volume;
self.volumeclock = setInterval(function(){
volume-=0.2;
if(volume<=0)
{
volume = 0;
self.audioElement.volume = 0;
clearInterval(self.volumeclock);
self.volumeclock = null;
self.audioElement.pause();
return;
}
else{
self.audioElement.volume=volume;
}
},100);
}
else{
self.audioElement.volume = 0;
self.audioElement.pause();
}
curstate = 'pause';
};
self.stop = function(huanchun){
self.pause(huanchun);
self.audioElement.load();
};
self.resume = function(){
if(!self.audioElement)
return;
if(self.volumeclock)
{
clearInterval(self.volumeclock);
self.volumeclock = null;
}
volume = self.audioElement.volume;
self.audioElement.play();
self.volumeclock = setInterval(function(){
volume+=0.2;
if(volume>=option.volume)
{
self.audioElement.volume = option.volume;
clearInterval(self.volumeclock);
self.volumeclock = null;
return;
}
else{
self.audioElement.volume=volume;
}
},100);
curstate = 'play';
};
self.bindBackRun = function(){
// Get Browser Specific Hidden Property
function hiddenProperty(prefix) {
if (prefix) {
return prefix + 'Hidden';
} else {
return 'hidden';
}
}
// Get Browser Specific Visibility State
function visibilityState(prefix) {
if (prefix) {
return prefix + 'VisibilityState';
} else {
return 'visibilityState';
}
}
// Get Browser Specific Event
function visibilityEvent(prefix) {
if (prefix) {
return prefix + 'visibilitychange';
} else {
return 'visibilitychange';
}
}
var prefix = PREFIX.js;
var hidden = hiddenProperty(prefix);
var visibilityState = visibilityState(prefix);
var visibilityEvent = visibilityEvent(prefix);
document.addEventListener(visibilityEvent, function(event) {
if (!document[hidden]) {
// The page is visible.
if(shouldplay)
{
self.resume();
}
} else {
// The page is hidden.
if(curstate=='play')
{
shouldplay = true;
self.pause(false);
}
else{
shouldplay = false;
}
}
});
}
self.init();
}
return BgSound;
});
//获取js,css3浏览器前缀
define(function(){
var prefix = function() {
if (typeof(window.getComputedStyle) == 'undefined') {
return {
dom: '',
lowercase: '',
css: '',
js: ''
};
}
var styles = window.getComputedStyle(document.documentElement, ''),
pre = (Array.prototype.slice
.call(styles)
.join('')
.match(/-(moz|webkit|ms)-/) || (styles.OLink === '' && ['', 'o'])
)[1],
dom = ('WebKit|Moz|MS|O').match(new RegExp('(' + pre + ')', 'i'))[1];
return {
dom: dom,
lowercase: pre,
css: '-' + pre + '-',
js: pre[0].toUpperCase() + pre.substr(1)
};
};
return prefix;
});
+2
-6

@@ -1,6 +0,2 @@

var bgdound = require('./bgsound/v1.js');
define(function(){
return {
bgsound: bgsound
};
});
var bgsound = require('./bgsound.js');
exports.bgsound =bgsound;
{
"name": "focusbejs",
"version": "1.0.3",
"description": "focusbejs",
"version": "1.0.4",
"description": "focusbejs ui",
"main": "index.js",

@@ -9,4 +9,18 @@ "scripts": {

},
"repository": {
"type": "git",
"url": "git+https://github.com/focusbe/focusbejs.git"
},
"keywords": [
"focusbejs"
],
"author": "focusbe",
"license": "ISC"
"license": "ISC",
"bugs": {
"url": "https://github.com/focusbe/focusbejs/issues"
},
"homepage": "https://github.com/focusbe/focusbejs#readme",
"devDependencies": {
"jquery": "^1.9.1"
}
}

Sorry, the diff of this file is too big to display