| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- let library = {
- //数组元素位置替换
- swapArray: function(arr, index1, index2) {
- arr[index1] = arr.splice(index2, 1, arr[index1])[0];
- return arr;
- },
- swapLeft : function(arr) {
- let element = arr.shift();
- arr.push(element);
- },
- //生成指定范围随机整数
- randomFromIntRange: function(min, max) {
- return Math.floor(Math.random() * (max - min)) + min;
- },
- happenRate: function(rate) {
- let result = this.randomFromIntRange(0,100);
- if(result<rate)
- {
- return true;
- }
- else
- {
- return false;
- }
- return;
- },
- openInWebview () {
- let sUserAgent = navigator.userAgent.toLowerCase()
- let bIsMobile = /AppleWebKit.*Mobile/i.test(navigator.userAgent)
- let bIsIpad = sUserAgent.match(/ipad/i) !== null
- let bIsIphoneOs = sUserAgent.match(/iphone os/i) !== null
- let bIsMidp = sUserAgent.match(/midp/i) !== null
- let bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) !== null
- let bIsUc = sUserAgent.match(/ucbrowser/i) !== null
- let bIsAndroid = sUserAgent.match(/android/i) !== null
- let bIsCE = sUserAgent.match(/windows ce/i) !== null
- let bIsWM = sUserAgent.match(/windows mobile/i) !== null
- if (
- bIsMobile ||
- bIsIpad ||
- bIsIphoneOs ||
- bIsMidp ||
- bIsUc7 ||
- bIsUc ||
- bIsAndroid ||
- bIsCE ||
- bIsWM
- ) {
- return false;
- } else {
- return true;
- }
- },
- indexOf (arr,item) {
- for (let i = 0; i < arr.length; i++) {
- if (arr[i] == item) return i;
- }
- return -1;
- },
- remove(arr, item) {
- let index = arr.indexOf(item);
- if (index > -1) {
- arr.splice(index, 1);
- }
- },
- setImageBase64(base64Url,callback){
- let img = new Image();
- img.src = base64Url;
- img.onload = function(){
- let texture = new cc.Texture2D();
- texture.initWithElement(img);
- texture.handleLoadedTexture();
- if (callback)
- callback(texture);
- }
- },
- isExitsFunction(funcName) {
- try {
- if (typeof(eval(funcName)) == "function") {
- return true;
- }
- } catch(e) {}
- return false;
- }
- };
- module.exports = library;
|