Initial release

This commit is contained in:
Louis Rossmann
2026-05-11 07:39:33 -05:00
commit c661ddc2eb
16967 changed files with 4075897 additions and 0 deletions

View File

@@ -0,0 +1,340 @@
/*------------------ Date Function ------------------------*/
function GetFullToday( )
{
var d=new Date();
var nday=d.getDate();
var nmonth=d.getMonth()+1;
var nyear=d.getFullYear();
var strM=nmonth+'';
if( nmonth<10 )
strM='0'+nmonth;
var strD=nday+'';
if( nday<10 )
strD='0'+nday;
return nyear+'-'+strM+'-'+strD;
}
function GetFullDate()
{
var d=new Date();
var tDate={};
tDate.nyear=d.getFullYear();
tDate.nmonth=d.getMonth()+1;
tDate.nday=d.getDate();
tDate.nhour=d.getHours();
tDate.nminute=d.getMinutes();
tDate.nsecond=d.getSeconds();
tDate.nweek=d.getDay();
tDate.ndate=d.getDate();
var strM=tDate.nmonth+'';
if( tDate.nmonth<10 )
strM='0'+tDate.nmonth;
var strD=tDate.nday+'';
if( tDate.nday<10 )
strD='0'+tDate.nday;
var strH=tDate.nhour+'';
if( tDate.nhour<10 )
strH='0'+tDate.nhour;
var strMin=tDate.nminute+'';
if( tDate.nminute<10 )
strMin='0'+tDate.nminute;
var strS=tDate.nsecond+'';
if( tDate.nsecond<10 )
strS='0'+tDate.nsecond;
tDate.strdate=tDate.nyear+'-'+strM+'-'+strD;
tDate.strFulldate=tDate.strdate+' '+strH+':'+strMin+':'+strS;
return tDate;
}
function Unixtimestamp2Date( nSecond )
{
var d=new Date(nSecond*1000);
var tDate={};
tDate.nyear=d.getFullYear();
tDate.nmonth=d.getMonth()+1;
tDate.nday=d.getDate();
tDate.nhour=d.getHours();
tDate.nminute=d.getMinutes();
tDate.nsecond=d.getSeconds();
tDate.nweek=d.getDay();
tDate.ndate=d.getDate();
var strM=tDate.nmonth+'';
if( tDate.nmonth<10 )
strM='0'+tDate.nmonth;
var strD=tDate.nday+'';
if( tDate.nday<10 )
strD='0'+tDate.nday;
tDate.strdate=tDate.nyear+'-'+strM+'-'+strD;
return tDate.strdate;
}
//------------Array Function-------------
Array.prototype.in_array = function (e) {
let sArray= ',' + this.join(this.S) + ',';
let skey=','+e+',';
if(sArray.indexOf(skey)>=0)
return true;
else
return false;
}
//------------String Function------------------
/**
* Delete Left/Right Side Blank
*/
String.prototype.trim=function()
{
return this.replace(/(^\s*)|(\s*$)/g, '');
}
/**
* Delete Left Side Blank
*/
String.prototype.ltrim=function()
{
return this.replace(/(^\s*)/g,'');
}
/**
* Delete Right Side Blank
*/
String.prototype.rtrim=function()
{
return this.replace(/(\s*$)/g,'');
}
//----------------Get Param-------------
function GetQueryString(name)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r!=null)
{
return unescape(r[2]);
}
else
{
return null;
}
}
function GetGetStr()
{
let strGet="";
//获取当前URL
let url = document.location.href;
//获取?的位置
let index = url.indexOf("?")
if(index != -1) {
//截取出?后面的字符串
strGet = url.substr(index + 1);
}
return strGet;
}
/*--------------------JSON Function------------*/
/*
功能检查一个字符串是不是标准的JSON格式
参数: strJson 被检查的字符串
返回值: 如果字符串是一个标准的JSON格式则返回JSON对象
如果字符串不是标准JSON格式则返回null
*/
function IsJson( strJson )
{
var tJson=null;
try
{
tJson=JSON.parse(strJson);
}
catch(exception)
{
return null;
}
return tJson;
}
/*-----------------------Ajax Function--------------------*/
/*对JQuery的Ajax函数的封装只支持异步
参数说明:
url 目标地址
action post/get
data 字符串格式的发送内容
asyn true---异步模式;false-----同步模式;
*/
function HttpReq( url,action, data,callbackfunc)
{
var strAction=action.toLowerCase();
if( strAction=="post")
{
$.post(url,data,callbackfunc);
}
else if( strAction=="get")
{
$.get(url,callbackfunc);
}
}
/*---------------Cookie Function-------------------*/
function setCookie(name, value, time='',path='') {
if(time && path){
var strsec = time * 1000;
var exp = new Date();
exp.setTime(exp.getTime() + strsec * 1);
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path="+path;
}else if(time){
var strsec = time * 1000;
var exp = new Date();
exp.setTime(exp.getTime() + strsec * 1);
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}else if(path){
document.cookie = name + "=" + escape(value) + ";path="+path;
}else{
document.cookie = name + "=" + escape(value);
}
}
function getCookie(c_name)
{
if(document.cookie.length > 0) {
c_start = document.cookie.indexOf(c_name + "=");//获取字符串的起点
if(c_start != -1) {
c_start = c_start + c_name.length + 1;//获取值的起点
c_end = document.cookie.indexOf(";", c_start);//获取结尾处
if(c_end == -1) c_end = document.cookie.length;//如果是最后一个结尾就是cookie字符串的结尾
return decodeURI(document.cookie.substring(c_start, c_end));//截取字符串返回
}
}
return "";
}
function checkCookie(c_name) {
username = getCookie(c_name);
console.log(username);
if (username != null && username != "")
{ return true; }
else
{ return false; }
}
function clearCookie(name) {
setCookie(name, "", -1);
}
/*--------Studio WX Message-------*/
function IsInSlicer()
{
let bMatch=navigator.userAgent.match( RegExp('BBL-Slicer','i') );
return bMatch;
}
function SendWXMessage( strMsg )
{
let bCheck=IsInSlicer();
if(bCheck!=null)
{
window.wx.postMessage(strMsg);
}
}
/*------CSS Link Control----*/
function RemoveCssLink( LinkPath )
{
let pNow=$("head link[href='"+LinkPath+"']");
let nTotal=pNow.length;
for( let n=0;n<nTotal;n++ )
{
pNow[n].remove();
}
}
function AddCssLink( LinkPath )
{
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.href = LinkPath;
link.rel = 'stylesheet';
link.type = 'text/css';
head.appendChild(link);
}
function CheckCssLinkExist( LinkPath )
{
let pNow=$("head link[href='"+LinkPath+"']");
let nTotal=pNow.length;
return nTotal;
}
/*------Dark Mode------*/
function SwitchDarkMode( DarkCssPath )
{
ExecuteDarkMode( DarkCssPath );
setInterval("ExecuteDarkMode('"+DarkCssPath+"')",1000);
}
function ExecuteDarkMode( DarkCssPath )
{
let nMode=0;
let bDarkMode=navigator.userAgent.match( RegExp('dark','i') );
if( bDarkMode!=null )
nMode=1;
let nNow=CheckCssLinkExist(DarkCssPath);
if( nMode==0 )
{
if(nNow>0)
RemoveCssLink(DarkCssPath);
}
else
{
if(nNow==0)
AddCssLink(DarkCssPath);
}
}
SwitchDarkMode("css/dark.css");

View File

@@ -0,0 +1,511 @@
//var TestData={"sequence_id":"0","command":"get_recent_projects","response":[{"path":"D:\\work\\Models\\Toy\\3d-puzzle-cube-model_files\\3d-puzzle-cube.3mf","time":"2022\/3\/24 20:33:10"},{"path":"D:\\work\\Models\\Art\\Carved Stone Vase - remeshed+drainage\\Carved Stone Vase.3mf","time":"2022\/3\/24 17:11:51"},{"path":"D:\\work\\Models\\Art\\Kity & Cat\\Cat.3mf","time":"2022\/3\/24 17:07:55"},{"path":"D:\\work\\Models\\Toy\\鐩村墤.3mf","time":"2022\/3\/24 17:06:02"},{"path":"D:\\work\\Models\\Toy\\minimalistic-dual-tone-whistle-model_files\\minimalistic-dual-tone-whistle.3mf","time":"2022\/3\/22 21:12:22"},{"path":"D:\\work\\Models\\Toy\\spiral-city-model_files\\spiral-city.3mf","time":"2022\/3\/22 18:58:37"},{"path":"D:\\work\\Models\\Toy\\impossible-dovetail-puzzle-box-model_files\\impossible-dovetail-puzzle-box.3mf","time":"2022\/3\/22 20:08:40"}]};
var m_HotModelList=null;
function OnInit()
{
//-----Official-----
TranslatePage();
SendMsg_GetLoginInfo();
SendMsg_GetRecentFile();
SendMsg_GetStaffPick();
}
//------最佳打开文件的右键菜单功能----------
var RightBtnFilePath='';
var MousePosX=0;
var MousePosY=0;
var sImages = {};
function Set_RecentFile_MouseRightBtn_Event()
{
$(".FileItem").mousedown(
function(e)
{
//FilePath
RightBtnFilePath=$(this).attr('fpath');
if(e.which == 3){
//鼠标点击了右键+$(this).attr('ff') );
ShowRecnetFileContextMenu();
}else if(e.which == 2){
//鼠标点击了中键
}else if(e.which == 1){
//鼠标点击了左键
OnOpenRecentFile( encodeURI(RightBtnFilePath) );
}
});
$(document).bind("contextmenu",function(e){
//在这里书写代码,构建个性右键化菜单
return false;
});
$(document).mousemove( function(e){
MousePosX=e.pageX;
MousePosY=e.pageY;
let ContextMenuWidth=$('#recnet_context_menu').width();
let ContextMenuHeight=$('#recnet_context_menu').height();
let DocumentWidth=$(document).width();
let DocumentHeight=$(document).height();
//$("#DebugText").text( ContextMenuWidth+' - '+ContextMenuHeight+'<br/>'+
// DocumentWidth+' - '+DocumentHeight+'<br/>'+
// MousePosX+' - '+MousePosY +'<br/>' );
} );
$(document).click( function(){
var e = e || window.event;
        var elem = e.target || e.srcElement;
        while (elem) {
if (elem.id && elem.id == 'recnet_context_menu') {
                    return;
}
elem = elem.parentNode;
}
$("#recnet_context_menu").hide();
} );
}
function SetLoginPanelVisibility(visible) {
var leftBoard = document.getElementById("LeftBoard");
if (visible) {
leftBoard.style.display = "block";
} else {
leftBoard.style.display = "none";
}
}
function HandleStudio( pVal )
{
let strCmd = pVal['command'];
if (strCmd == "get_recent_projects") {
ShowRecentFileList(pVal["response"]);
} else if (strCmd == "studio_userlogin") {
SetLoginInfo(pVal["data"]["avatar"], pVal["data"]["name"]);
} else if (strCmd == "studio_useroffline") {
SetUserOffline();
} else if (strCmd == "studio_set_mallurl") {
SetMallUrl(pVal["data"]["url"]);
} else if (strCmd == "studio_clickmenu") {
let strName = pVal["data"]["menu"];
GotoMenu(strName);
} else if (strCmd == "network_plugin_installtip") {
let nShow = pVal["show"] * 1;
if (nShow == 1) {
$("#NoPluginTip").show();
$("#NoPluginTip").css("display", "flex");
} else {
$("#NoPluginTip").hide();
}
} else if (strCmd == "modelmall_model_advise_get") {
//alert('hot');
if (m_HotModelList != null) {
let SS1 = JSON.stringify(pVal["hits"]);
let SS2 = JSON.stringify(m_HotModelList);
if (SS1 == SS2) return;
}
m_HotModelList = pVal["hits"];
ShowStaffPick(m_HotModelList);
} else if (data.cmd === "SetLoginPanelVisibility") {
SetLoginPanelVisibility(data.visible);
}
}
function GotoMenu( strMenu )
{
let MenuList=$(".BtnItem");
let nAll=MenuList.length;
for(let n=0;n<nAll;n++)
{
let OneBtn=MenuList[n];
if( $(OneBtn).attr("menu")==strMenu )
{
$(".BtnItem").removeClass("BtnItemSelected");
$(OneBtn).addClass("BtnItemSelected");
$("div[board]").hide();
$("div[board=\'"+strMenu+"\']").show();
}
}
}
function SetLoginInfo( strAvatar, strName )
{
$("#Login1").hide();
$("#UserName").text(strName);
let OriginAvatar=$("#UserAvatarIcon").prop("src");
if(strAvatar!=OriginAvatar)
$("#UserAvatarIcon").prop("src",strAvatar);
else
{
//alert('Avatar is Same');
}
$("#Login2").show();
$("#Login2").css("display","flex");
}
function SetUserOffline()
{
$("#UserAvatarIcon").prop("src","img/c.jpg");
$("#UserName").text('');
$("#Login2").hide();
$("#Login1").show();
$("#Login1").css("display","flex");
}
function SetMallUrl( strUrl )
{
$("#MallWeb").prop("src",strUrl);
}
function ShowRecentFileList( pList )
{
let nTotal=pList.length;
let strHtml='';
for(let n=0;n<nTotal;n++)
{
let OneFile=pList[n];
let sPath=OneFile['path'];
let sImg=OneFile["image"] || sImages[sPath];
let sTime=OneFile['time'];
let sName=OneFile['project_name'];
sImages[sPath] = sImg;
//let index=sPath.lastIndexOf('\\')>0?sPath.lastIndexOf('\\'):sPath.lastIndexOf('\/');
//let sShortName=sPath.substring(index+1,sPath.length);
let TmpHtml='<div class="FileItem" fpath="'+sPath+'" >'+
'<a class="FileTip" title="'+sPath+'"></a>'+
'<div class="FileImg" ><img src="'+sImg+'" onerror="this.onerror=null;this.src=\'img/d.png\';" alt="No Image" /></div>'+
'<div class="FileName TextS1">'+sName+'</div>'+
'<div class="FileDate">'+sTime+'</div>'+
'</div>';
strHtml+=TmpHtml;
}
$("#FileList").html(strHtml);
Set_RecentFile_MouseRightBtn_Event();
UpdateRecentClearBtnDisplay();
}
function ShowRecnetFileContextMenu()
{
$("#recnet_context_menu").offset({top: 10000, left:-10000});
$('#recnet_context_menu').show();
let ContextMenuWidth=$('#recnet_context_menu').width();
let ContextMenuHeight=$('#recnet_context_menu').height();
let DocumentWidth=$(document).width();
let DocumentHeight=$(document).height();
let RealX=MousePosX;
let RealY=MousePosY;
if( MousePosX + ContextMenuWidth + 24 >DocumentWidth )
RealX=DocumentWidth-ContextMenuWidth-24;
if( MousePosY+ContextMenuHeight+24>DocumentHeight )
RealY=DocumentHeight-ContextMenuHeight-24;
$("#recnet_context_menu").offset({top: RealY, left:RealX});
}
/*-------RecentFile MX Message------*/
function SendMsg_GetLoginInfo()
{
var tSend={};
tSend['sequence_id']=Math.round(new Date() / 1000);
tSend['command']="get_login_info";
SendWXMessage( JSON.stringify(tSend) );
}
function SendMsg_GetRecentFile()
{
var tSend={};
tSend['sequence_id']=Math.round(new Date() / 1000);
tSend['command']="get_recent_projects";
SendWXMessage( JSON.stringify(tSend) );
}
function OnLoginOrRegister()
{
var tSend={};
tSend['sequence_id']=Math.round(new Date() / 1000);
tSend['command']="homepage_login_or_register";
SendWXMessage( JSON.stringify(tSend) );
}
function OnClickModelDepot()
{
var tSend={};
tSend['sequence_id']=Math.round(new Date() / 1000);
tSend['command']="homepage_modeldepot";
SendWXMessage( JSON.stringify(tSend) );
}
function OnClickNewProject()
{
var tSend={};
tSend['sequence_id']=Math.round(new Date() / 1000);
tSend['command']="homepage_newproject";
SendWXMessage( JSON.stringify(tSend) );
}
function OnClickOpenProject()
{
var tSend={};
tSend['sequence_id']=Math.round(new Date() / 1000);
tSend['command']="homepage_openproject";
SendWXMessage( JSON.stringify(tSend) );
}
function OnOpenRecentFile( strPath )
{
var tSend={};
tSend['sequence_id']=Math.round(new Date() / 1000);
tSend['command']="homepage_open_recentfile";
tSend['data']={};
tSend['data']['path']=decodeURI(strPath);
SendWXMessage( JSON.stringify(tSend) );
}
function OnDeleteRecentFile( )
{
//Clear in UI
$("#recnet_context_menu").hide();
let AllFile=$(".FileItem");
let nFile=AllFile.length;
for(let p=0;p<nFile;p++)
{
let pp=AllFile[p].getAttribute("fpath");
if(pp==RightBtnFilePath)
$(AllFile[p]).remove();
}
UpdateRecentClearBtnDisplay();
//Send Msg to C++
var tSend={};
tSend['sequence_id']=Math.round(new Date() / 1000);
tSend['command']="homepage_delete_recentfile";
tSend['data']={};
tSend['data']['path']=RightBtnFilePath;
SendWXMessage( JSON.stringify(tSend) );
}
function OnDeleteAllRecentFiles()
{
$('#FileList').html('');
UpdateRecentClearBtnDisplay();
var tSend={};
tSend['sequence_id']=Math.round(new Date() / 1000);
tSend['command']="homepage_delete_all_recentfile";
SendWXMessage( JSON.stringify(tSend) );
}
function UpdateRecentClearBtnDisplay()
{
let AllFile=$(".FileItem");
let nFile=AllFile.length;
if( nFile>0 )
$("#RecentClearAllBtn").show();
else
$("#RecentClearAllBtn").hide();
}
function OnExploreRecentFile( )
{
var tSend={};
tSend['sequence_id']=Math.round(new Date() / 1000);
tSend['command']="homepage_explore_recentfile";
tSend['data']={};
tSend['data']['path']=decodeURI(RightBtnFilePath);
SendWXMessage( JSON.stringify(tSend) );
$("#recnet_context_menu").hide();
}
function OnLogOut()
{
var tSend={};
tSend['sequence_id']=Math.round(new Date() / 1000);
tSend['command']="homepage_logout";
SendWXMessage( JSON.stringify(tSend) );
}
function BeginDownloadNetworkPlugin()
{
var tSend={};
tSend['sequence_id']=Math.round(new Date() / 1000);
tSend['command']="begin_network_plugin_download";
SendWXMessage( JSON.stringify(tSend) );
}
function OutputKey(keyCode, isCtrlDown, isShiftDown, isCmdDown) {
var tSend = {};
tSend['sequence_id'] = Math.round(new Date() / 1000);
tSend['command'] = "get_web_shortcut";
tSend['key_event'] = {};
tSend['key_event']['key'] = keyCode;
tSend['key_event']['ctrl'] = isCtrlDown;
tSend['key_event']['shift'] = isShiftDown;
tSend['key_event']['cmd'] = isCmdDown;
SendWXMessage(JSON.stringify(tSend));
}
//-------------User Manual------------
function OpenWikiUrl( strUrl )
{
var tSend={};
tSend['sequence_id']=Math.round(new Date() / 1000);
tSend['command']="userguide_wiki_open";
tSend['data']={};
tSend['data']['url']=strUrl;
SendWXMessage( JSON.stringify(tSend) );
}
//--------------Staff Pick-------
var StaffPickSwiper=null;
function InitStaffPick()
{
if( StaffPickSwiper!=null )
{
StaffPickSwiper.destroy(true,true);
StaffPickSwiper=null;
}
StaffPickSwiper = new Swiper('#HotModel_Swiper.swiper', {
slidesPerView : 'auto',
spaceBetween: 16,
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
slidesPerView : 'auto',
slidesPerGroup : 3
// autoplay: {
// delay: 3000,
// stopOnLastSlide: false,
// disableOnInteraction: true,
// disableOnInteraction: false
// },
// pagination: {
// el: '.swiper-pagination',
// },
// scrollbar: {
// el: '.swiper-scrollbar',
// draggable: true
// }
});
}
function SendMsg_GetStaffPick()
{
var tSend={};
tSend['sequence_id']=Math.round(new Date() / 1000);
tSend['command']="modelmall_model_advise_get";
SendWXMessage( JSON.stringify(tSend) );
setTimeout("SendMsg_GetStaffPick()",3600*1000*1);
}
function ShowStaffPick( ModelList )
{
let PickTotal=ModelList.length;
if(PickTotal==0)
{
$('#HotModelList').html('');
$('#HotModelArea').hide();
return;
}
let strPickHtml='';
for(let a=0;a<PickTotal;a++)
{
let OnePickModel=ModelList[a];
let ModelID=OnePickModel['design']['id'];
let ModelName=OnePickModel['design']['title'];
let ModelCover=OnePickModel['design']['cover']+'?image_process=resize,w_200/format,webp';
let DesignerName=OnePickModel['design']['designCreator']['name'];
let DesignerAvatar=OnePickModel['design']['designCreator']['avatar']+'?image_process=resize,w_32/format,webp';
strPickHtml+='<div class="HotModelPiece swiper-slide" onClick="OpenOneStaffPickModel('+ModelID+')" >'+
'<div class="HotModel_Designer_Info"><img src="'+DesignerAvatar+'" /><span class="TextS2">'+DesignerName+'</span></div>'+
' <div class="HotModel_PrevBlock"><img class="HotModel_PrevImg" src="'+ModelCover+'" /></div>'+
' <div class="HotModel_NameText TextS1" title="'+ModelName+'">'+ModelName+'</div>'+
'</div>';
}
$('#HotModelList').html(strPickHtml);
InitStaffPick();
$('#HotModelArea').show();
}
function OpenOneStaffPickModel( ModelID )
{
//alert(ModelID);
var tSend={};
tSend['sequence_id']=Math.round(new Date() / 1000);
tSend['command']="modelmall_model_open";
tSend['data']={};
tSend['data']['id']=ModelID;
SendWXMessage( JSON.stringify(tSend) );
}
//---------------Global-----------------
window.postMessage = HandleStudio;

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,185 @@
var JSON;
if (!JSON) {
JSON = {};
}
(function () {
'use strict';
function f(n) {
// Format integers to have at least two digits.
return n < 10 ? '0' + n : n;
}
if (typeof Date.prototype.toJSON !== 'function') {
Date.prototype.toJSON = function (key) {
return isFinite(this.valueOf())
? this.getUTCFullYear() + '-' +
f(this.getUTCMonth() + 1) + '-' +
f(this.getUTCDate()) + 'T' +
f(this.getUTCHours()) + ':' +
f(this.getUTCMinutes()) + ':' +
f(this.getUTCSeconds()) + 'Z'
: null;
};
String.prototype.toJSON =
Number.prototype.toJSON =
Boolean.prototype.toJSON = function (key) {
return this.valueOf();
};
}
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
gap,
indent,
meta = { // table of character substitutions
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"' : '\\"',
'\\': '\\\\'
},
rep;
function quote(string) {
escapable.lastIndex = 0;
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
var c = meta[a];
return typeof c === 'string'
? c
: '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
}) + '"' : '"' + string + '"';
}
function str(key, holder) {
var i, // The loop counter.
k, // The member key.
v, // The member value.
length,
mind = gap,
partial,
value = holder[key];
if (value && typeof value === 'object' &&
typeof value.toJSON === 'function') {
value = value.toJSON(key);
}
if (typeof rep === 'function') {
value = rep.call(holder, key, value);
}
switch (typeof value) {
case 'string':
return quote(value);
case 'number':
return isFinite(value) ? String(value) : 'null';
case 'boolean':
case 'null':
return String(value);
case 'object':
if (!value) {
return 'null';
}
gap += indent;
partial = [];
if (Object.prototype.toString.apply(value) === '[object Array]') {
length = value.length;
for (i = 0; i < length; i += 1) {
partial[i] = str(i, value) || 'null';
}
v = partial.length === 0
? '[]'
: gap
? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
: '[' + partial.join(',') + ']';
gap = mind;
return v;
}
if (rep && typeof rep === 'object') {
length = rep.length;
for (i = 0; i < length; i += 1) {
if (typeof rep[i] === 'string') {
k = rep[i];
v = str(k, value);
if (v) {
partial.push(quote(k) + (gap ? ': ' : ':') + v);
}
}
}
} else {
for (k in value) {
if (Object.prototype.hasOwnProperty.call(value, k)) {
v = str(k, value);
if (v) {
partial.push(quote(k) + (gap ? ': ' : ':') + v);
}
}
}
}
v = partial.length === 0
? '{}'
: gap
? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
: '{' + partial.join(',') + '}';
gap = mind;
return v;
}
}
if (typeof JSON.stringify !== 'function') {
JSON.stringify = function (value, replacer, space) {
var i;
gap = '';
indent = '';
if (typeof space === 'number') {
for (i = 0; i < space; i += 1) {
indent += ' ';
}
} else if (typeof space === 'string') {
indent = space;
}
rep = replacer;
if (replacer && typeof replacer !== 'function' &&
(typeof replacer !== 'object' ||
typeof replacer.length !== 'number')) {
throw new Error('JSON.stringify');
}
return str('', {'': value});
};
}
if (typeof JSON.parse !== 'function') {
JSON.parse = function (text, reviver) {
var j;
function walk(holder, key) {
var k, v, value = holder[key];
if (value && typeof value === 'object') {
for (k in value) {
if (Object.prototype.hasOwnProperty.call(value, k)) {
v = walk(value, k);
if (v !== undefined) {
value[k] = v;
} else {
delete value[k];
}
}
}
}
return reviver.call(holder, key, value);
}
text = String(text);
cx.lastIndex = 0;
if (cx.test(text)) {
text = text.replace(cx, function (a) {
return '\\u' +
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
});
}
if (/^[\],:{}\s]*$/
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
j = eval('(' + text + ')');
return typeof reviver === 'function'
? walk({'': j}, '')
: j;
}
throw new SyntaxError('JSON.parse');
};
}
}());