text
stringlengths 1
2.83M
| id
stringlengths 16
152
| metadata
dict | __index_level_0__
int64 0
949
|
---|---|---|---|
// Copyright (c) 2022 8th Wall, Inc.
/* globals AFRAME */
AFRAME.registerComponent('target-video', {
schema: {
name: {type: 'string'},
video: {type: 'string'},
},
init() {
const {object3D} = this.el
const {name} = this.data
object3D.visible = false
const v = document.querySelector(this.data.video)
const showImage = ({detail}) => {
if (name !== detail.name) {
return
}
v.play()
object3D.position.copy(detail.position)
object3D.quaternion.copy(detail.rotation)
object3D.scale.set(detail.scale, detail.scale, detail.scale)
object3D.visible = true
}
const hideImage = ({detail}) => {
if (name !== detail.name) {
return
}
v.pause()
object3D.visible = false
}
this.el.sceneEl.addEventListener('xrimagefound', showImage)
this.el.sceneEl.addEventListener('xrimageupdated', showImage)
this.el.sceneEl.addEventListener('xrimagelost', hideImage)
},
})
| 8thwall/web/examples/aframe/alpha-video/target-video.js/0 | {
"file_path": "8thwall/web/examples/aframe/alpha-video/target-video.js",
"repo_id": "8thwall",
"token_count": 416
} | 0 |
// Copyright (c) 2021 8th Wall, Inc.
/* globals AFRAME */
// This component hides and shows certain elements as the camera moves
AFRAME.registerComponent('portal', {
schema: {
width: {default: 4},
height: {default: 6},
depth: {default: 1},
},
init() {
this.camera = document.getElementById('camera')
this.contents = document.getElementById('portal-contents')
this.walls = document.getElementById('hider-walls')
this.portalWall = document.getElementById('portal-wall')
this.isInPortalSpace = false
this.wasOutside = true
},
tick() {
const {position} = this.camera.object3D
const isOutside = position.z > this.data.depth / 2
const withinPortalBounds =
position.y < this.data.height && Math.abs(position.x) < this.data.width / 2
if (this.wasOutside !== isOutside && withinPortalBounds) {
this.isInPortalSpace = !isOutside
}
this.contents.object3D.visible = this.isInPortalSpace || isOutside
this.walls.object3D.visible = !this.isInPortalSpace && isOutside
this.portalWall.object3D.visible = this.isInPortalSpace && !isOutside
this.wasOutside = isOutside
},
})
AFRAME.registerComponent('bob', {
schema: {
distance: {default: 0.15},
duration: {default: 1000},
},
init() {
const {el} = this
const {data} = this
data.initialPosition = this.el.object3D.position.clone()
data.downPosition = data.initialPosition.clone().setY(data.initialPosition.y - data.distance)
data.upPosition = data.initialPosition.clone().setY(data.initialPosition.y + data.distance)
const vectorToString = v => `${v.x} ${v.y} ${v.z}`
data.initialPosition = vectorToString(data.initialPosition)
data.downPosition = vectorToString(data.downPosition)
data.upPosition = vectorToString(data.upPosition)
data.timeout = null
const animatePosition = position => el.setAttribute('animation__bob', {
property: 'position',
to: position,
dur: data.duration,
easing: 'easeInOutQuad',
loop: false,
})
const bobDown = () => {
if (data.shouldStop) {
animatePosition(data.initialPosition)
data.stopped = true
return
}
animatePosition(data.downPosition)
data.timeout = setTimeout(bobUp, data.duration)
}
const bobUp = () => {
if (data.shouldStop) {
animatePosition(data.initialPosition)
data.stopped = true
return
}
animatePosition(data.upPosition)
data.timeout = setTimeout(bobDown, data.duration)
}
const bobStop = () => {
data.shouldStop = true
}
const bobStart = () => {
if (data.stopped) {
data.shouldStop = false
data.stopped = false
bobUp()
}
}
this.el.addEventListener('bobStart', bobStart)
this.el.addEventListener('bobStop', bobStop)
bobUp()
},
})
| 8thwall/web/examples/aframe/portal/portal-components.js/0 | {
"file_path": "8thwall/web/examples/aframe/portal/portal-components.js",
"repo_id": "8thwall",
"token_count": 1123
} | 1 |
const reportWebVitals = (onPerfEntry) => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({getCLS, getFID, getFCP, getLCP, getTTFB}) => {
getCLS(onPerfEntry)
getFID(onPerfEntry)
getFCP(onPerfEntry)
getLCP(onPerfEntry)
getTTFB(onPerfEntry)
})
}
}
export default reportWebVitals
| 8thwall/web/examples/aframe/reactapp/src/reportWebVitals.js/0 | {
"file_path": "8thwall/web/examples/aframe/reactapp/src/reportWebVitals.js",
"repo_id": "8thwall",
"token_count": 164
} | 2 |
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>8th Wall Web: babylon.js</title>
<link rel="stylesheet" type="text/css" href="index.css">
<!-- Babylon.js -->
<script src="//cdn.jsdelivr.net/npm/babylonjs@4.1.0/babylon.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/babylonjs-loaders@4.1.0/babylonjs.loaders.min.js"></script>
<!-- Javascript tweening engine -->
<script src="//cdnjs.cloudflare.com/ajax/libs/tween.js/18.6.4/tween.umd.js"></script>
<!-- XR Extras - provides utilities like load screen, almost there, and error handling.
See github.com/8thwall/web/tree/master/xrextras -->
<script src="//cdn.8thwall.com/web/xrextras/xrextras.js"></script>
<!-- 8thWall Web - Replace the app key here with your own app key -->
<script async src="//apps.8thwall.com/xrweb?appKey=XXXXXXXX"></script>
<!-- client code -->
<script src="index.js"></script>
</head>
<body>
<canvas id="renderCanvas"></canvas>
</body>
</html>
| 8thwall/web/examples/babylonjs/placeground/index.html/0 | {
"file_path": "8thwall/web/examples/babylonjs/placeground/index.html",
"repo_id": "8thwall",
"token_count": 466
} | 3 |
/*
Ported to JavaScript by Lazar Laszlo 2011
lazarsoft@gmail.com, www.lazarsoft.info
*/
/*
*
* Copyright 2007 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function DataBlock(numDataCodewords, codewords)
{
this.numDataCodewords = numDataCodewords;
this.codewords = codewords;
this.__defineGetter__("NumDataCodewords", function()
{
return this.numDataCodewords;
});
this.__defineGetter__("Codewords", function()
{
return this.codewords;
});
}
DataBlock.getDataBlocks=function(rawCodewords, version, ecLevel)
{
if (rawCodewords.length != version.TotalCodewords)
{
throw "ArgumentException";
}
// Figure out the number and size of data blocks used by this version and
// error correction level
var ecBlocks = version.getECBlocksForLevel(ecLevel);
// First count the total number of data blocks
var totalBlocks = 0;
var ecBlockArray = ecBlocks.getECBlocks();
for (var i = 0; i < ecBlockArray.length; i++)
{
totalBlocks += ecBlockArray[i].Count;
}
// Now establish DataBlocks of the appropriate size and number of data codewords
var result = new Array(totalBlocks);
var numResultBlocks = 0;
for (var j = 0; j < ecBlockArray.length; j++)
{
var ecBlock = ecBlockArray[j];
for (var i = 0; i < ecBlock.Count; i++)
{
var numDataCodewords = ecBlock.DataCodewords;
var numBlockCodewords = ecBlocks.ECCodewordsPerBlock + numDataCodewords;
result[numResultBlocks++] = new DataBlock(numDataCodewords, new Array(numBlockCodewords));
}
}
// All blocks have the same amount of data, except that the last n
// (where n may be 0) have 1 more byte. Figure out where these start.
var shorterBlocksTotalCodewords = result[0].codewords.length;
var longerBlocksStartAt = result.length - 1;
while (longerBlocksStartAt >= 0)
{
var numCodewords = result[longerBlocksStartAt].codewords.length;
if (numCodewords == shorterBlocksTotalCodewords)
{
break;
}
longerBlocksStartAt--;
}
longerBlocksStartAt++;
var shorterBlocksNumDataCodewords = shorterBlocksTotalCodewords - ecBlocks.ECCodewordsPerBlock;
// The last elements of result may be 1 element longer;
// first fill out as many elements as all of them have
var rawCodewordsOffset = 0;
for (var i = 0; i < shorterBlocksNumDataCodewords; i++)
{
for (var j = 0; j < numResultBlocks; j++)
{
result[j].codewords[i] = rawCodewords[rawCodewordsOffset++];
}
}
// Fill out the last data block in the longer ones
for (var j = longerBlocksStartAt; j < numResultBlocks; j++)
{
result[j].codewords[shorterBlocksNumDataCodewords] = rawCodewords[rawCodewordsOffset++];
}
// Now add in error correction blocks
var max = result[0].codewords.length;
for (var i = shorterBlocksNumDataCodewords; i < max; i++)
{
for (var j = 0; j < numResultBlocks; j++)
{
var iOffset = j < longerBlocksStartAt?i:i + 1;
result[j].codewords[iOffset] = rawCodewords[rawCodewordsOffset++];
}
}
return result;
}
| 8thwall/web/examples/camerapipeline/qrcode/jsqrcode/src/datablock.js/0 | {
"file_path": "8thwall/web/examples/camerapipeline/qrcode/jsqrcode/src/datablock.js",
"repo_id": "8thwall",
"token_count": 1196
} | 4 |
<!doctype html>
<html>
<head>
<title>8thWall Web: Simple Shaders</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link rel="stylesheet" type="text/css" href="index.css">
<!-- XR Extras - provides utilities like load screen, almost there, and error handling.
See github.com/8thwall/web/tree/master/xrextras -->
<script src="//cdn.8thwall.com/web/xrextras/xrextras.js"></script>
<!-- 8thWall Web - Replace the app key here with your own app key -->
<script async src="//apps.8thwall.com/xrweb?appKey=XXXXXXXX"></script>
<!-- Client code -->
<script defer src="index.js"></script>
</head>
<body>
<canvas id="camerafeed"></canvas>
<div class="nextbutton" id="nextbutton">Next ></div>
</body>
</html>
| 8thwall/web/examples/camerapipeline/simpleshaders/index.html/0 | {
"file_path": "8thwall/web/examples/camerapipeline/simpleshaders/index.html",
"repo_id": "8thwall",
"token_count": 310
} | 5 |
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>8th Wall Web: babylon.js</title>
<link rel="stylesheet" type="text/css" href="index.css">
<!-- Babylon.js -->
<script src="//cdn.jsdelivr.net/npm/babylonjs@5.4.0/babylon.min.js" crossorigin="anonymous"></script>
<script src="//cdn.jsdelivr.net/npm/babylonjs-materials@5.4.0/babylonjs.materials.min.js" crossorigin="anonymous"></script>
<!-- XR Extras - provides utilities like load screen, almost there, and error handling.
See github.com/8thwall/web/tree/master/xrextras -->
<script src="//cdn.8thwall.com/web/xrextras/xrextras.js"></script>
<!-- Landing Pages - see https://www.8thwall.com/docs/web/#landing-pages -->
<script src='//cdn.8thwall.com/web/landing-page/landing-page.js'></script>
<!-- 8thWall Web - Replace the app key here with your own app key -->
<script async src="//apps.8thwall.com/xrweb?appKey=XXXXX"></script>
<!-- client code -->
<script src="index.js"></script>
</head>
<body>
<canvas id="renderCanvas"></canvas>
</body>
</html>
| 8thwall/web/gettingstarted/babylonjs/index.html/0 | {
"file_path": "8thwall/web/gettingstarted/babylonjs/index.html",
"repo_id": "8thwall",
"token_count": 485
} | 6 |
/* globals AFRAME, XRExtras, XR8 */
import {xrComponents} from './xr-components'
import {xrPrimitives} from './xr-primitives'
import {ensureXrAndExtras} from './ensure'
let xrextrasAframe = null
const onxrloaded = () => { XR8.addCameraPipelineModule(XRExtras.Loading.pipelineModule()) }
// We want to start showing the loading screen eagerly (before AFRAME has loaded and parsed the
// scene and set up everything). We also need to work around a bug in the AFRAME loading in iOS
// Webviews for almost there.
const eagerload = () => {
// Manually traverse the dom for an aframe scene and check its attributes.
const scene = document.getElementsByTagName('a-scene')[0]
if (!scene) {
return
}
const attrs = scene.attributes
let foundAlmostThere = false
let foundLoading = false
let redirectUrl = null
let runConfig = null
// Eagerly inspect the dom, and trigger loading or almost there modules early if appropriate.
const xrconfigPresent = Array.from(attrs).map(attr => attr.name).includes('xrconfig')
Object.keys(attrs).forEach((a) => {
const attr = attrs.item(a).name
if (attr === 'xrextras-almost-there') {
foundAlmostThere = true
const redirectMatch = new RegExp('url:([^;]*)').exec(attrs.item(a).value)
if (redirectMatch) {
redirectUrl = redirectMatch[1]
}
}
if (attr === 'xrextras-loading') {
foundLoading = true
}
// We use xrconfig if it is present, else xrweb or xrface or xrlayers.
if (attr === 'xrconfig' ||
(!xrconfigPresent && (attr === 'xrweb' || attr === 'xrface' || attr === 'xrlayers'))) {
const allowedDevicesMatch = new RegExp('allowedDevices:([^;]*)').exec(attrs.item(a).value)
if (allowedDevicesMatch) {
runConfig = {allowedDevices: allowedDevicesMatch[1].trim()}
}
}
})
if (foundAlmostThere) {
if (redirectUrl) {
window.XRExtras.AlmostThere.configure({url: redirectUrl})
}
// eslint-disable-next-line no-unused-expressions
window.XR8
? window.XRExtras.AlmostThere.checkCompatibility(runConfig)
: window.addEventListener(
'xrloaded', () => window.XRExtras.AlmostThere.checkCompatibility(runConfig)
)
}
if (foundLoading) {
const waitForRealityTexture =
!!(scene.attributes.xrweb || scene.attributes.xrface || scene.attributes.xrlayers)
window.XRExtras.Loading.showLoading({onxrloaded, waitForRealityTexture})
}
}
function create() {
let registered = false
// NOTE: new versions of 8frame should be added in descending order, so that the latest version
// is always in position 1.
const allowed8FrameVersions = ['latest', '0.9.0', '0.8.2']
const LATEST_8FRAME = allowed8FrameVersions[1] // The 'latest' version of 8frame.
// Check that the requested version of AFrame has a corresponding 8Frame implementation.
const checkAllowed8FrameVersions = version => new Promise((resolve, reject) => (allowed8FrameVersions.includes(version)
? resolve(version === 'latest' ? LATEST_8FRAME : version)
: reject(`'${version}' is an unsupported AFrame version. Alowed versions: (${allowed8FrameVersions})`)))
// Load an external javascript resource in a promise that resolves when the javascript has loaded.
const loadJsPromise = url => new Promise((resolve, reject) => document.head.appendChild(Object.assign(
document.createElement('script'), {async: true, onload: resolve, onError: reject, src: url}
)))
// If XR or XRExtras load before AFrame, we need to manually register their AFrame components.
const ensureAFrameComponents = () => {
if (window.XR8) {
window.AFRAME.registerComponent('xrconfig', XR8.AFrame.xrconfigComponent())
window.AFRAME.registerComponent('xrweb', XR8.AFrame.xrwebComponent())
window.AFRAME.registerComponent('xrface', XR8.AFrame.xrfaceComponent())
window.AFRAME.registerComponent('xrlayers', XR8.AFrame.xrlayersComponent())
window.AFRAME.registerComponent('xrlayerscene', XR8.AFrame.xrlayersceneComponent())
window.AFRAME.registerPrimitive('sky-scene', XR8.AFrame.skyscenePrimitive())
}
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
window.XRExtras && window.XRExtras.AFrame.registerXrExtrasComponents()
}
// Register a map of component-name -> component, e.g.
// {
// 'component-1': component1,
// 'component-2': component2,
// }
const registerComponents =
components => Object.keys(components).map(k => AFRAME.registerComponent(k, components[k]))
const registerPrimitives =
primitives => Object.keys(primitives).map(k => AFRAME.registerPrimitive(k, primitives[k]))
// Load the 8th Wall preferred version of AFrame at runtime ensuring that xr components are added.
const loadAFrameForXr = (args) => {
const {version = 'latest', components = {}} = args || {}
return checkAllowed8FrameVersions(version)
.then(ver => loadJsPromise(`//cdn.8thwall.com/web/aframe/8frame-${ver}.min.js`))
.then(ensureAFrameComponents)
.then(ensureXrAndExtras)
.then(_ => registerComponents(components))
}
// Register XRExtras AFrame components.
const registerXrExtrasComponents = () => {
// If AFrame is not ready, or we already registered components, skip.
if (registered || !window.AFRAME) {
return
}
// Only register the components once.
registered = true
// Show the loading screen as early as we can - add a System because it will get `init` called
// before assets finish loading, versus a Component which gets `init` after load.
AFRAME.registerSystem('eager-load-system', {
init() {
try {
/* eslint-disable-next-line no-unused-expressions */
window.XRExtras
? eagerload()
: window.addEventListener('xrextrasloaded', eagerload, {once: true})
} catch (err) {
// eslint-disable-next-line no-console
console.error(err)
}
},
})
registerComponents(xrComponents())
registerPrimitives(xrPrimitives())
}
// Eagerly try to register the aframe components, if aframe has already loaded.
registerXrExtrasComponents()
return {
// Load the 8th Wall version of AFrame at runtime ensuring that xr components are added.
loadAFrameForXr,
// Register the XRExtras components. This should only be called after AFrame has loaded.
registerXrExtrasComponents,
}
}
const AFrameFactory = () => {
if (!xrextrasAframe) {
xrextrasAframe = create()
}
return xrextrasAframe
}
export {
AFrameFactory,
}
| 8thwall/web/xrextras/src/aframe/aframe.js/0 | {
"file_path": "8thwall/web/xrextras/src/aframe/aframe.js",
"repo_id": "8thwall",
"token_count": 2343
} | 7 |
* {
font-family: inherit;
box-sizing: inherit;
}
.absolute-fill {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
.hidden {
display: none !important;
}
.error-text-outer-container {
display: flex;
align-items: center;
justify-content: center;
}
.error-text-container {
flex: 0 0 auto;
text-align: center;
width: 100%;
}
.error-text-header {
font-family: 'Nunito', sans-serif;
font-size: 16pt;
color: white;
letter-spacing: .37;
line-height: 23pt;
}
.xrextras-old-style .error-text-header {
color: #323232;
}
.error-text-hint {
font-family: 'Nunito', sans-serif;
font-size: 14pt;
color: #A8A8BA;
letter-spacing: .37;
}
.error-text-detail {
font-family: 'Nunito', sans-serif;
font-size: 14pt;
color: white;
}
.xrextras-old-style .error-text-detail {
color: #323232;
}
.error-margin-top-5 {
margin-top: 5vh;
}
.error-margin-top-20 {
margin-top: 20vh;
}
.desktop-home-link {
font-family: 'Nunito-SemiBold', sans-serif;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 10px;
padding-right: 10px;
border-radius: 10px;
color: white;
background-color: #464766;
-webkit-user-select: all;
/* Chrome 49+ */
-moz-user-select: all;
/* Firefox 43+ */
-ms-user-select: all;
/* No support yet */
user-select: all;
pointer-events: auto;
}
.xrextras-old-style .desktop-home-link {
color: #323232;
background-color:rgba(173, 80, 255, 0.2);
}
.desktop-home-link.mobile {
position: fixed;
width: 100vw;
font-size: 1.1em;
font-weight: 800;
border-radius: 0px;
bottom: 30%;
left: 50%;
transform: translateX(-50%);
}
.xrextras-old-style .foreground-image {
filter: invert(1);
}
| 8thwall/web/xrextras/src/common.css/0 | {
"file_path": "8thwall/web/xrextras/src/common.css",
"repo_id": "8thwall",
"token_count": 723
} | 8 |
<div id="recorder" class="recorder-container">
<svg viewBox="0 0 38 38" class="progress-container">
<circle class="progress-track" r="16" cx="19" cy="19"></circle>
<circle id="progressBar" class="progress-bar" r="16" cx="19" cy="19"></circle>
<circle class="loading-circle" r="16" cx="19" cy="19"></circle>
</svg>
<button id="recorder-button" class="style-reset">
Record
</button>
</div>
<div id="flashElement" class="flash-element"></div>
| 8thwall/web/xrextras/src/mediarecorder/record-button.html/0 | {
"file_path": "8thwall/web/xrextras/src/mediarecorder/record-button.html",
"repo_id": "8thwall",
"token_count": 171
} | 9 |
const STATS_URL = 'https://cdn.8thwall.com/web/aframe/stats.16.min.js'
let statsModule = null
const loadJsPromise = url => new Promise((resolve, reject) => (
document.head.appendChild(
Object.assign(
document.createElement('script'),
{async: true, onload: resolve, onError: reject, src: url}
)
)
))
const StatsFactory = () => {
if (statsModule == null) {
statsModule = create()
}
return statsModule
}
function create() {
const pipelineModule = () => {
let stats_ = null
return {
name: 'stats',
onBeforeRun: () => (
window.Stats ? Promise.resolve() : loadJsPromise(STATS_URL)
),
onAttach: () => {
stats_ = new Stats()
stats_.showPanel(0)
stats_.dom.style.zIndex = 5000
stats_.dom.style.position = 'absolute'
stats_.dom.style.top = '0px'
stats_.dom.style.left = '0px'
document.body.appendChild(stats_.dom)
},
onUpdate: () => {
stats_.update()
},
onDetach: () => {
document.body.removeChild(stats_.dom)
stats_ = null
},
}
}
return {
// Creates a camera pipeline module that, when installed, adds a framerate stats element to
// the window dom. If the Stats package is not yet loaded, it will load it.
pipelineModule,
}
}
export {
StatsFactory,
}
| 8thwall/web/xrextras/src/statsmodule/stats.js/0 | {
"file_path": "8thwall/web/xrextras/src/statsmodule/stats.js",
"repo_id": "8thwall",
"token_count": 557
} | 10 |
## ไธใ้ข่ฒๆจกๅผ
้ข่ฒๆจกๅผๆไธค็ง๏ผ
- RGBA
`rgba(0,0,0,0.5); //้ป่ฒ๏ผ้ๆๅบฆ0.5`
- HSLA๏ผ้ข่ฒ(0~360)๏ผ้ฅฑๅๅบฆ(0%~100%)๏ผๆๅบฆ(0%~100%)๏ผ้ๆๅบฆ(0~1)๏ผ
**็บขๆฉ้ป็ปฟ้่็ดซ็บข**๏ผ้ข่ฒไป 0~360 ้กบๅบ๏ผๅๅ 30ๅบฆใๆฏๅฆ็บข่ฒไธบ0๏ผ้ป่ฒไธบ120๏ผ็ปฟ่ฒไธบ240ใ
`HSLA(0, 100%, 50%, 1); // ็บข่ฒไธ้ๆ๏ผ้ฅฑๅๅบฆ100%๏ผไบฎๅบฆ50%`
ๆๅบฆ้ป่ฎคๆฏ50%,ไธ่ฌๅปบ่ฎฎไฟ็50็ๅผ๏ผๅฆๆๅ ๅฐ100ๅ๏ผๅๆ็ฝ่ฒ๏ผ้ๅฐ0ๅไธบ้ป่ฒใ
> ๆณจๆ๏ผ
>
> 1ใRGBAๅHSLAไธญ็้ๆๅบฆ**ไธไผๅฝฑๅๅญๅ
็ด ็้ๆๅบฆ๏ผไธๅ
ท็ปงๆฟๆง๏ผ**
>
> 2ใ**opacity ไผๅฝฑๅๅญๅ
็ด ็้ๆๅบฆ๏ผๅญๅ
็ด ไผ็ปงๆฟ็ถๅ
็ด ็้ๆๅบฆใ**
>
> 3ใ**transparent ไธๅฏ่ฐ่้ๆๅบฆ๏ผๅง็ปๅฎๅ
จ้ๆใ**๏ผ`color: transparent;`๏ผ
## ไบใๆๅญ้ดๅฝฑ
่ฏญๆณ๏ผ
```css
/*้ดๅฝฑๅฏไปฅๅ ๅ ๏ผไฝฟ็จ้ๅท้ๅผ*/
text-shadow: offsetX offsetY blur color,
offsetX1 offsetY1 blur1 color1, ...
```
> `offsetX`๏ผXๆนๅๅ็งปๅบฆ
>
> `offsetY`๏ผYๆนๅๅ็งปๅบฆ
>
> `blur`๏ผ้ดๅฝฑ็ๆจก็ณๅบฆ
>
> `color`๏ผ้ดๅฝฑ้ข่ฒ
็คบไพ๏ผ
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
* {
padding: 0;
margin: 0;
}
.demo {
width: 600px;
padding: 30px;
background-color: #666;
margin: 20px auto;
text-align: center;
font: bold 80px/100% "ๅพฎ่ฝฏ้
้ป";
color: #fff;
}
/*ๆทปๅ ้ดๅฝฑ text-shadow:offsetX offsetY blur color*/
.demo1 {
text-shadow: -5px -5px 5px orange;
}
.demo2 {
color: #000;
text-shadow: 0 1px 0 #fff;
}
/*็ซไฝๆตฎ้ๆๆ*/
.demo3 {
text-shadow: -1px -1px 0 red,
-2px -2px 0 orange,
-3px -3px 0 yellow,
-4px -4px 0 green,
-5px -5px 0 cyan,
-6px -6px 0 blue,
-7px -7px 0 purple;
}
.demo4 {
text-shadow: 0 0 30px pink;
}
</style>
</head>
<body>
<div class="demo demo1">ๆๆฏๆฑๅฐ็ฝ</div>
<div class="demo demo2">ๆๆฏๆฑๅฐ็ฝ</div>
<div class="demo demo3">ๆๆฏๆฑๅฐ็ฝ</div>
<div class="demo demo4">ๆๆฏๆฑๅฐ็ฝ</div>
</body>
</html>
```
![1](./images/1.png)
## ไธใ็ๆจกๅ
1ใๅจ้ป่ฎคๆ
ๅตไธ๏ผCSS ่ฎพ็ฝฎ็็ๅญๅฎฝๅบฆไป
ไป
ๆฏๅ
ๅฎนๅบ็ๅฎฝๅบฆ๏ผ่้็ๅญ็ๅฎฝๅบฆใๅๆ ท๏ผ้ซๅบฆ็ฑปไผผใ็ๆญฃ็ๅญ็ๅฎฝๅบฆ๏ผๅจ้กต้ขๅ็ฐๅบๆฅ็ๅฎฝๅบฆ๏ผๅ้ซๅบฆ๏ผ้่ฆๅ ไธไธไบๅ
ถๅฎ็ๅฑๆงใไพๅฆ๏ผ
- padding + border + width = ็ๅญ็ๅฎฝๅบฆ
- padding + border + height = ็ๅญ็้ซๅบฆ
ๅพๆๆพ๏ผ่ฟไธ็ด่ง๏ผๅพๅฎนๆๅบ้๏ผ้ ๆ็ฝ้กตไธญๅ
ถๅฎๅ
็ด ็้ไฝใ
2ใCSS3ไธญๅฏไปฅ้่ฟ`box-sizing` ๆฅๆๅฎ็ๆจกๅ๏ผๅณๅฏๆๅฎไธบ`content-boxใborder-box`๏ผ่ฟๆ ทๆไปฌ่ฎก็ฎ็ๅญๅคงๅฐ็ๆนๅผๅฐฑๅ็ไบๆนๅใ
- `content-box`๏ผๅฏน่ฑก็ๅฎ้
ๅฎฝๅบฆ็ญไบ่ฎพ็ฝฎ็ width ๅผๅ borderใpadding ไนๅใ**๏ผ็ๅญๅฎ้
็ๅฎฝๅบฆ = ่ฎพ็ฝฎ็ width + padding + border๏ผ**
- `border-box`๏ผ ๅฏน่ฑก็ๅฎ้
ๅฎฝๅบฆๅฐฑ็ญไบ่ฎพ็ฝฎ็widthๅผ๏ผๅณไฝฟๅฎไนๆ border ๅ padding ไนไธไผๆนๅๅฏน่ฑก็ๅฎ้
ๅฎฝๅบฆใ**๏ผ็ๅญๅฎ้
็ๅฎฝๅบฆ = ่ฎพ็ฝฎ็ width๏ผ**๏ผ็ธๅบ็็ๅญ็ๅ
ๅฎน็ๅฎฝๅบฆๆ้ซๅบฆๅบ้ดไผๅๅฐใ
3ใๆต่งๅจ็ๅ
ผๅฎนๆง
IE8 ๅไปฅไธ็ๆฌๆฏๆ่ฏฅๅฑๆง๏ผFirefox ้่ฆๅ ไธๆต่งๅจๅๅๅ็ผ `-moz-`๏ผๅฏนไบไฝ็ๆฌ็ IOS ๅ Android ๆต่งๅจไน้่ฆๅ ไธ `-webkit-`
ๆฌงๆๆต่งๅจ๏ผๅ็ผ -o-
IEๆต่งๅจ๏ผๅ็ผ -ms-
## ๅใ่พนๆกๅ่ง
ไฝฟ็จ `border-radius` ๅฑๆงๆฅ่ฎพ็ฝฎๅ่งใ
```css
/*ๆทปๅ ่พนๆกๅ่ง*/
/*1.่ฎพ็ฝฎไธไธชๅผ๏ผๅไธช่ง็ๅ่งๅผ้ฝไธๆ ท*/
border-radius: 10px;
border-radius: 50%;
/*2.่ฎพ็ฝฎไธคไธชๅผ:็ฌฌไธไธชๅผๆงๅถๅทฆไธ/ๅณไธ๏ผ็ฌฌไบไธชๅผๆงๅถๅณไธ/ๅทฆไธ*/
border-radius: 10px 30px;
/*3.่ฎพ็ฝฎไธไธชๅผ๏ผ็ฌฌไธไธชๅผๆงๅถๅทฆไธ๏ผ็ฌฌไบๅผๆงๅถๅณไธ/ๅทฆไธ๏ผ็ฌฌไธไธชๅผๆงๅถๅณไธ*/
border-radius: 10px 40px 60px;
/*4.่ฎพ็ฝฎๅไธชๅผ๏ผๅทฆไธ ๅณไธ ๅณไธ ๅทฆไธ*/
border-radius: 10px 30px 60px 100px;
/*5.ๆทปๅ /ๆฏ็จๆฅ่ฎพ็ฝฎๅฝๅๆฐดๅนณๅๅ็ดๆนๅ็ๅๅพๅผ๏ผๆฐดๅนณxๆนๅ/ๅ็ดyๆนๅ*/
border-radius: 100px/50px;
/*6.ๆทปๅ ๆไธช่ง็น็ๅ่ง*/
border-radius: 0px 50px 0px 0px;
/*ๆ่
๏ผborder-ไธไธ-ๅทฆๅณ-radius:*/
border-top-right-radius: 100px;
border-top-left-radius: 100px;*/
border-bottom-left-radius: 100px;
border-bottom-right-radius: 100px;
/*7.่ฎพ็ฝฎๆไธช่ง็น็ไธคไธชๆนๅไธ็ไธๅๅ่ง*/
border-top-right-radius: 100px 50px; /*่ฎพ็ฝฎไธๅ็งป100px๏ผๅณๅ็งป50pxๆ ทๅผ็ๅ่ง*/
border-bottom-left-radius: 80px 40px; /*่ฎพ็ฝฎไธๅ็งป80px๏ผๅทฆๅ็งป40pxๆ ทๅผ็ๅ่ง*/
border-bottom-right-radius: 60px 30px;/*่ฎพ็ฝฎไธๅ็งป60px๏ผๅณๅ็งป30pxๆ ทๅผ็ๅ่ง*/
border-top-left-radius: 40px 20px; /*่ฎพ็ฝฎไธๅ็งป40px๏ผๅทฆๅ็งป20pxๆ ทๅผ็ๅ่ง*/
/*8.ๅฆๆๆณ่ฎพ็ฝฎๅไธช่ง็น็ไธๅๆนๅไธ็ไธๅๅ่งๅผ*/
/*ๅๅซๆฏๆฐดๅนณๆนๅ็ๅ็งป๏ผๅทฆไธ๏ผๅณไธ๏ผๅณไธ๏ผๅทฆไธ ๏ผๅ็ดๆนๅ็ๅ็งป๏ผๅทฆไธ๏ผๅณไธ๏ผๅณไธ๏ผๅทฆไธ*/
border-radius: 100px 0px 0px 0px/20px 0px 0px 0px;
```
## ไบใ่พนๆก้ดๅฝฑ
่ฏญๆณ๏ผ
```css
box-shadow:h v blur spread color inset
```
> `h`๏ผๆฐดๅนณๆนๅ็ๅ็งปๅผ๏ผๅฟ
ๅกซ๏ผ
> `v`๏ผๅ็ดๆนๅ็ๅ็งปๅผ๏ผๅฟ
ๅกซ๏ผ
> `blur`๏ผๆจก็ณๅบฆ--ๅฏ้๏ผ้ป่ฎค0 ๏ผๅฟ
ๅกซ๏ผ
> `spread`๏ผ้ดๅฝฑ็ๅฐบๅฏธ๏ผๆฉๅฑๅๆถ็ผฉ้ดๅฝฑ็ๅคงๅฐ--ๅฏ้ ้ป่ฎค0
> `color`๏ผ้ข่ฒ--ๅฏ้๏ผ้ป่ฎค้ป่ฒ
> `inset`๏ผๅ
้ดๅฝฑ--ๅฏ้,้ป่ฎคๆฏๅค้ดๅฝฑ
ๅฝ็ถ๏ผbox-shadow ๅ text-shadow ไธๆ ท๏ผไนๆฏๅฏไปฅๆทปๅ ๅคไธช็๏ผไน้ด็จ้ๅท้ๅผใ
```css
box-shadow: 10px 10px 5px pink (inset),
-10px -10px 5px pink; /*spread็ญไธ้่ฆ๏ผ็็ฅไธๅ*/
```
![](./images/0.png)
| Daotin/Web/02-CSS/02-CSS3/02-้ข่ฒๆจกๅผ๏ผๆๅญ้ดๅฝฑ๏ผ็ๆจกๅ๏ผ่พนๆกๅ่ง๏ผ่พนๆก้ดๅฝฑ.md/0 | {
"file_path": "Daotin/Web/02-CSS/02-CSS3/02-้ข่ฒๆจกๅผ๏ผๆๅญ้ดๅฝฑ๏ผ็ๆจกๅ๏ผ่พนๆกๅ่ง๏ผ่พนๆก้ดๅฝฑ.md",
"repo_id": "Daotin",
"token_count": 3831
} | 11 |
## 1ใๅฝๆฐ็ๅฎไน
```javascript
// ็ฌฌไธ็ง๏ผๅฃฐๆๅผๅฝๆฐ-------------------------------
function fn1(){
console.log("ๆๆฏ็ฌฌไธ็งๅฎไนๆนๆณ๏ผ");
}
// ็ฌฌไบ็ง๏ผ่ตๅผๅผๅฝๆฐ------------------------------------
var fn2 = function (){
console.log("ๆๆฏ็ฌฌไบ็งๅฎไนๆนๆณ๏ผ");
}; // ๆณจๆๅๅท
// ไฝฟ็จๆนๅผ1๏ผ
fn2();
// ไฝฟ็จๆนๅผ2๏ผๅฝๆฐ็่ช่ฐ็จ
(function (a,b){
ใใconsole.log("ๆๆฏ็ฌฌไบ็งๅฎไนๆนๆณ๏ผ" + a+b); // ๆๆฏ็ฌฌไบ็งๅฎไนๆนๆณ๏ผ3
})(1,2); // ๅ้ข็้ขๅฐๆฌๅท็จๆฅไผ ๅ
ฅๅๆฐ
//็ฌฌไธ็ง-----------------------------------------------------
var fn3 = new Function("a", "b", "console.log('ๆๆฏ็ฌฌไธ็งๅฎไนๆนๆณ๏ผ' + a + b)");
```
> **็ฌฌไธ็ง๏ผ**๏ผๅฝๆฐ็ๅฃฐๆ๏ผ็ฌฌไธ็งๅฎไนๆนๆณๆๅผบๅคง๏ผๅฎไนๅฎๆฏๅ๏ผๅจๅช้ไฝฟ็จ้ฝๅฏไปฅ๏ผๆ ไฝ็ฝฎ้ๅถใ
>
> **็ฌฌไบ็ง๏ผ**(ๅฝๆฐ่กจ่พพๅผ๏ผๅฟๅๅฝๆฐ) ๅไธค็งๅฎไนๆนๆณๆฏๆๅฑ้ๆง็ใ๏ผไฝฟ็จๅฝๆฐๅฟ
้กปๅจๅฎไนๅฝๆฐไนๅ๏ผ็ฌฌไบ็งๅฝๆฐ็้ๆฏไฝฟ็จ `fn2 = null;` ็ฌฌไธ็งๆนๅผไธๅฏ้ๆฏใ
>
> **็ฌฌไธ็ง๏ผ**new Function ็ๆนๅผๅฎไน็ๅฝๆฐ้ๅธธๅผบๅคง๏ผๅ ไธบๆง่ก็ๅฝๆฐไปฃ็ ๆฏไปฅๅญ็ฌฆไธฒ็ๅฝขๅผไผ ๅ
ฅ็๏ผ้ฃไนๅฐฑๅฏไปฅไปๅฐๅๆ ไผ ๅ
ฅ๏ผ่ฟๅฏไปฅไปๅๅฐไผ ๅ
ฅ๏ผ่ฟๅฐฑๅพ็้ผไบ๏ผๅฝๆฐ็ไปฃ็ ็ซ็ถไธๅๅจๅฝๆฐไฝ้้ขใใใ
## 2ใๅฝๆฐ็่ฐ็จ
```javascript
// 1.ๅฝๆฐๅ();
foo();
//2.ๅฝๆฐ่ช่ฐ็จใ
// ๅฝๆฐ็่ช่ฐ็จ๏ผไป
ๆง่กไธๆฌกใ
// ๅฝๆฐ็ๅๆฐๅธฆๅ
ฅ้่ฟๅ้ข็ๅฐๆฌๅทๅธฆๅ
ฅๆฐๆฎ.
// ่ฟๆ ทๅ๏ผ้้ข็ๅ
ๅฎนๅฐฑๆฏ็งๆ็ๅ้ๆ่
ๅฝๆฐ๏ผๅฐฑๅฝขๆไบๅฐ้ญ็ฉบ้ด
(function(){})();
// 3.ไฝฟ็จcall๏ผapply
foo.call(null,ๅๆฐ1๏ผๅๆฐ2, ...);
foo.apply(null,[ๅๆฐ1๏ผๅๆฐ2, ...]);
```
## 3ใๅฝๆฐๅ
- ่ฆ้ตๅพช้ฉผๅณฐๅฝๅๆณใ
- ไธ่ฝๅๅ๏ผๅฝๆฐ้่ฝฝ๏ผ๏ผๅฆๅๅ้ข็ๅฝๆฐไผ่ฆ็ๅ้ข็ๅฝๆฐใ
```js
//ๆๅฐๅฝๆฐๅ๏ผๅฐฑ็ญไบๆๅฐๆดไธชๅฝๆฐใ
console.log(fn);
//ๆๅฐๆง่กๅฝๆฐ๏ผๅฐฑ็ญไบๆๅฐๅฝๆฐ็่ฟๅๅผใ
console.log(fn());
```
## 4ใๅฝขๅๅๅฎๅ
- ๅฝขๅไธ้่ฆๅ var.
- ๅฝขๅ็ไธชๆฐๅๅฎๅ็ไธชๆฐๅฏไปฅไธไธ่ด ใ
## 5ใ่ฟๅๅผ
1. ๅฆๆๅฝๆฐๆฒกๆๆพ็คบ็ไฝฟ็จ return ่ฏญๅฅ ๏ผ้ฃไนๅฝๆฐๆ้ป่ฎค็่ฟๅๅผ๏ผundefined
2. ๅฆๆๅฝๆฐไฝฟ็จ return ่ฏญๅฅ๏ผไฝๆฏ return ๅ้ขๆฒกๆไปปไฝๅผ๏ผ้ฃไนๅฝๆฐ็่ฟๅๅผไนๆฏ๏ผundefined.
**return ๅฏไปฅ่ฟๅ็็ฑปๅๅ
ๅซไธๅๅ ็ง๏ผ**
### 1ใๅทฅๅๆจกๅผ
่ฆๆฑ๏ผ
- ๅฝๆฐๅ
้จๅๅปบไธไธชๅฏน่ฑก๏ผ็ฑไธไธชๅฑ้จๅ้ๆฅๆถ๏ผ็ถๅ่ฟๅ่ฟไธชๅฏน่ฑกใ
- ๅฏไปฅ้่ฟๅฝๆฐๅๆฐๆนๅๅฏน่ฑก็ๅ
ๅฎน
```js
function fn2(w,color) {
var div=document.createElement("div");
Object.assign(div.style,{
width:(w || 50)+"px",
height:(w || 50)+"px",
backgroundColor:color || "red",
position:"absolute"
});
return div;
}
fn2(100, "blue");
```
### 2ใๅไพๆจกๅผ
```js
var obj={
divs:null,
createDiv:function (w,color) {
if(!this.divs){
this.divs=document.createElement("div");
Object.assign(this.divs.style,{
width:(w || 50)+"px",
height:(w || 50)+"px",
backgroundColor:color || "red"
});
}
return this.divs;
}
};
obj.createDiv(100, "blue");
obj.createDiv(100, "blue");
```
### 3ใ้่ฟๅๆฐไผ ๅ
ฅๅฏน่ฑก
```js
function fn3(obj) {
obj.a=10;
return obj;
}
var objs={
a:1,
b:2
};
var obj2=fn3(objs);
console.log(obj2===objs);//true ไผ ๅ
ฅ็ๆฏๅฏน่ฑก็ๅผ็จ
```
### 4ใ้่ฟๅๆฐไผ ๅ
ฅๅฝๆฐ
```js
// ๅๆฐๅฐฑๆฏๅฝๆฐ๏ผ่ฟๅ็ๆฏๅๆฐ็ๆง่ก็ปๆ
function fn4(fn) {
return fn();
}
function fn5() {
return 5;
}
function fn6() {
return 6;
}
console.log(fn4(fn5)); // 5
console.log(fn4(fn6)); // 6
```
### 5ใ่ฟๅไธไธช็งๅฏๅฏน่ฑก
```js
// ่ฟๅไธไธช็งๅฏ็ๅฏน่ฑก๏ผๆ็งๆๅ้
function fn7() {
return (function () {
var c=10;
return {
a:1,
b:2,
d:c
}
})();
}
console.log(fn7()); // ็งๆๅ้ c
```
### 6ใ่ฟๅๅคไธชๅ
็ด ็ๆฐ็ป๏ผES5ไธญ็่งฃๆ่ตๅผ๏ผ
```js
function fn8() {
var div=document.createElement("div");
var input=document.createElement("input");
return [div,input];
}
let [div,input]=fn8();
document.body.appendChild(div);
document.body.appendChild(input);
```
### 7ใ่ฟๅๅคไธชๅ
็ด ็ๅฏน่ฑก๏ผES6ไธญ่งฃๆ่ตๅผ๏ผ
```js
function fn9() {
return {a:1,b:2}
}
let {a,b}=fn9();
console.log(a,b); // 1,2
```
### 8ใไผ ๅ
ฅๅๆฐไธบๅฝๆฐ๏ผ่ฟๅๅฏน่ฑก
```js
function fn10(fn,obj) {
return fn.bind(obj || {});
}
function fn11(a,b) {
this.a=a;
this.b=b;
return this;
}
function fn12(c,d) {
this.c=c;
this.d=d;
return this;
}
var obj5={f:50};
console.log(fn10(fn11)(10,20)); // {a:10,b:20}
console.log(fn10(fn12,obj5)(30,50)); //{c:30,d:50,f:50}
```
### 9ใ่ฟๅๅฝๆฐ
```js
function fn13() {
return function (a,b) {
console.log(a,b);
}
}
fn13()(8,9);
```
## 6ใๅ้ๅไฝ็จๅ
**ๅ
จๅฑๅ้**๏ผ
1ใๅจ script ไฝฟ็จ var ๅฎไน็ๅ้๏ผๆๆ็ script ๅ
ฑไบซๅ
ถๅ
จๅฑๆง๏ผjs ้้ขๆฒกๆๅ็บงไฝ็จๅๆฆๅฟต๏ผๅชๆๅ
จๅฑไฝ็จๅๅๅฑ้จไฝ็จๅ๏ผใ
2ใๅจ script ๆฒกๆ var ็ๅ้๏ผๅณไฝฟๅจๅฝๆฐๅ
้จ๏ผใ
3ใไฝฟ็จwindowๅ
จๅฑๅฏน่ฑกๆฅๅฃฐๆ๏ผๅ
จๅฑๅฏน่ฑก็ๅฑๆงๅฏนๅบไนๆฏๅ
จๅฑๅ้ใ`window.test = 50; `
```javascript
function fn(){
ใใvar a = b = c = 1;ใใ // bๅcๅฐฑๆฏ้ๅผๅ
จๅฑๅ้๏ผ็ญๅท๏ผ
ใใvar a = 1; b = 2; c = 3; // bๅcๅฐฑๆฏ้ๅผๅ
จๅฑๅ้๏ผๅๅท๏ผ
ใใvar a = 1 , b = 2 , c = 3; // bๅcๅฐฑไธๆฏ้ๅผๅ
จๅฑๅ้๏ผ้ๅท๏ผ
}
```
๏ผๅ
จๅฑๅ้ๆฏไธ่ฝ่ขซๅ ้ค็๏ผ้ๅผๅ
จๅฑๅ้ๆฏๅฏไปฅ่ขซๅ ้ค็๏ผ
```javascript
var num1 = 10;
num2 = 20;
delete num1;
delete num2;
console.log(typeof num1); // number
console.log(typeof num2); // undefined
```
**ๅฑ้จๅ้**๏ผ
1ใๅฝๆฐๅ
้จ็จ var ๅฎไน็ๅ้ใ
2ใๅฝๆฐ็ๅฝขๅใ
### 6.1ใๅ้ๅฃฐๆๆๅ๏ผ้ข่งฃๆ๏ผ
**ไฝ็จ๏ผ**ๆฅ็่ฏญๆณ้่ฏฏใjs็่งฃๆๅจๅจ้กต้ขๅ ่ฝฝ็ๆถๅ๏ผ้ฆๅ
ๆฃๆฅ้กต้ขไธ็่ฏญๆณ้่ฏฏใๆๅ้ๅฃฐๆๆๅ่ตทๆฅใ๏ผๅ้ๅฃฐๆๆๅๅๅฝๆฐๆดไฝๆๅ๏ผ
### 6.2ใๅ้็ๆๅ
**ๅชๆๅๅ้ๅ๏ผไธๆๅๅ้ๅผใ**
```javascript
consolas.log(aaa);// ๆๅฐ็็ปๆๆฏ undefined ๏ผๅ ไธบๅชๆๅๅ้ๅ๏ผไธๆๅๅ้ๅผใ
var aaa = 111;
```
ๅจๅฝๆฐ่ๅดๅ
๏ผ็
งๆ ท้็จใ
### 6.3ใๅฝๆฐ็ๆๅ
function ็ดๆฅๅฎไน็ๆนๆณ๏ผๆดไฝๆๅ๏ผไธ้ข่ฏด็็ฌฌไธ็งๅฝๆฐๅฎไน็ๆนๆณ๏ผ.
```javascript
fn();
var aaa = 111;
function fn(){
//ๅ้ๅฃฐๆๆๅๅจๅฝๆฐๅ
้จ็
งๆ ทๅฎ็จใ
//ๅฝๆฐ็ๅฐฑ่ฟๅๅ๏ผๅฑ้จๅ้ไฝ็จๅ๏ผ๏ผๆๅฐ็aaaไธๆฏ111๏ผ่ๆฏ undefinedใ
console.log(aaa); // undefined
var aaa = 222;
}
```
**้ข่งฃๆไผๅๅ๏ผ**
ๅคๅฏน็ script ๆ ็ญพไธญๅฝๆฐ้ๅ็่ฏ๏ผ้ข่งฃๆไธไผๅฒ็ชใไนๅฐฑๆฏ้ข่งฃๆ็ไฝ็จๅๆฏๆฏไธไธช็ script ๆ ็ญพใ
> **varๅ
ๆๅ๏ผfunctionๅๆๅ๏ผ**
็คบไพ๏ผ
```javascript
console.log(a); // ่พๅบaๅฝๆฐไฝ
function a() {
console.log("aaaaa");
}
var a = 1;
console.log(a); // ่พๅบ1
```
ๆๅฐ็ฌฌไธไธช็ปๆ็ๆถๅ๏ผvarไผๆๅ๏ผไนๅ function ๅๆๅ๏ผไฝๆฏๅฝๆฐaๅๅ้a้ๅ๏ผfunction็aๅจๅ้ข่ฆ็ๆๅ้a๏ผๆไปฅ็ฌฌไธไธช่พๅบ a ๅฝๆฐไฝ.
็ฌฌไบไธชๅ้ขvar a = 1;ๆๅไนๅ๏ผ่ฟไธชไฝ็ฝฎๅฐฑ็ธๅฝไบๅชๆ a = 1; ่ตๅผ๏ผๆไปฅ็ฌฌไบไธชๆๅฐ1.
### 6.4ใๅ้ๆๅไธๅฝๆฐๆๅ็ๆบๅถ
๏ผๅ่้พๆฅ๏ผhttps://segmentfault.com/a/1190000008568071
๏ผ้ๅธธ่ฏฆ็ป๏ผ [01-jsๅ้ๆๅไธๅฝๆฐๆๅ็่ฏฆ็ป่ฟ็จ.md](E:\Web\github\Web\QF Phase 2\01-jsๅ้ๆๅไธๅฝๆฐๆๅ็่ฏฆ็ป่ฟ็จ.md)
**ๆณจๆ๏ผES6 ไธญ็ let ๅฐไธๅ่ฟ่ก้ข็ผ่ฏๆไฝใ**
ไธไผ่ฟ่กๅ้ๆๅ๏ผไปฃ็ ๅฐไปไธๅฐไธ่ฟ่กๆง่ก๏ผๅจๅ้็ๅฎไนไนๅ๏ผๅ้็ไฝฟ็จไผๆฅ้ใ
### 6.5ใๅฟๅๅฝๆฐ
ไฝ็จๅคง่ดๅฆไธ๏ผ
```javascript
//1.็ดๆฅ่ฐ็จ
(function (){
console.log(1);
})();
//2.็ปๅฎไบไปถ
document.onclick = function () {
alert(1);
}
//3.ๅฎๆถๅจ
setInterval(function () {
console.log(444);
},1000);
```
## 7ใMath ๅฝๆฐ
```js
Math.random() // ่ฟๅ 0 ~ 1 ไน้ด็้ๆบๆฐใ
Math.abs(x) // ่ฟๅๆฐ็็ปๅฏนๅผใ
Math.pow(10,2)// 10็2ๆฌกๆนใ
Math.round(x) //ๆๆฐๅ่ไบๅ
ฅไธบๆๆฅ่ฟ็ๆดๆฐใ
Math.ceil(x) //ๅฏนๆฐ่ฟ่กไธ่ๅ
ฅใ
Math.floor(x) //ๅฏนๆฐ่ฟ่กไธ่ๅ
ฅใ
//----------------------------------------------------------------
//็คบไพ๏ผ
console.log(Math.ceil(1.2)); // 2
console.log(Math.ceil(1.5)); // 2
console.log(Math.ceil(1.6)); // 2
console.log(Math.ceil(-1.2)); // -1
console.log(Math.ceil(-1.5)); // -1
console.log(Math.ceil(-1.6)); // -1
console.log(Math.floor(1.2)); // 1
console.log(Math.floor(1.5)); // 1
console.log(Math.floor(1.6)); // 1
console.log(Math.floor(-1.2));// -2
console.log(Math.floor(-1.5));// -2
console.log(Math.floor(-1.6));// -2
console.log(Math.round(1.2)); // 1
console.log(Math.round(1.5)); // 2
console.log(Math.round(1.6)); // 2
console.log(Math.round(-1.2)); // -1
console.log(Math.round(-1.5)); // -1
console.log(Math.round(-1.6)); // -2
```
### 7.1ใ้ๆบ็ๆๆไธช่ๅด็ๆดๆฐ
```js
var minNum = 1;
var maxNum = 100;
var num = Math.round(Math.random() * (maxNum - minNum)) + minNum;
```
`toFixed()` ๏ผๆนๆณๅฏๆ ๆฐๅญๅ่ไบๅ
ฅไธบๆๅฎๅฐๆฐไฝๆฐ็ๆฐๅญใ
```js
var num = 10;
console.log(num.toFixed(2)); // 10.00
```
## 8ใๅฝๆฐไนๆฏๅฏน่ฑก
```js
//ๅฝๆฐไนๆฏๅฏน่ฑก
function fn() {}
fn.a=10; // ็ปๅฝๆฐๅฏน่ฑกๅๅปบไธไธชๅๆฐa
fn.fn2=function () { // ็ปๅฝๆฐๅฏน่ฑกๅๅปบไธไธชๅๆฐfn2
return 5;
};
for(var i in fn) {
console..log(i); // a fn2
}
//----------------------------------------
function fn1(a,b) {
if(arguments.callee.length!==arguments.length){
console.log("่พๅ
ฅๅๆฐ้่ฏฏ")
}
// console.log(this.a);//้่ฏฏ็
console.log(arguments.callee.a);//ๅฏไปฅ่ทๅๅฝๅๅฝๆฐๅฏน่ฑก็ๅฑๆงๅๆนๆณ
console.log(arguments.callee.fn2());
console.log(arguments.length) // 2
for(var str in arguments.callee){
console.log(str)
}
}
fn1(3,5);
// ๅฝๆฐlengthๆฏๅฝขๅ็ไธชๆฐ๏ผๅarguments.lengthไธไธๅฎ็ธๅ
console.log(fn1.length); // 2
```
> ๆณจๆ๏ผ
>
> ๅฝๆฐ.length === ๅฝๆฐๅฝขๅ็ไธชๆฐ
>
> arguments.length === ๅฝๆฐๅฎๅ็ไธชๆฐ
>
> arguments.callee === ๅจๅชไธชๅฝๆฐ้้ขๅฐฑ่กจ็คบๅชไธชๅฝๆฐ๏ผๅฝๅ่ฐ็จๅ
ถ็ๅฝๆฐ๏ผใ
## 9ใๅ
ถไป
### 9.1ใๅฝๆฐ็ๅฃฐๆๅๅฝๆฐ่กจ่พพๅผ็ๅบๅซ
```js
// ๅฝๆฐ็ๅฃฐๆ
if(true) {
function f1() {
console.log("f1()--1");
}
} else {
function f1() {
console.log("f1()--2");
}
}
f1();
```
> ๅฝๆฐๅฃฐๆๅฆๆๆพๅจ if-else- ้้ข๏ผ
>
> chrome ๅ firefox ่พๅบ f1()--1,
>
> IE8 ไธ่พๅบ f1()--2๏ผๅ ไธบๅฝๆฐๅฃฐๆไผๆๅ๏ผ็ฌฌไบไธชๅฐ็ฌฌไธไธช่ฆ็ไบใ
```js
// ๅฝๆฐ่กจ่พพๅผ
var func;
if(true) {
func = function () {
console.log("f1()--1");
};
} else {
func = function () {
console.log("f1()--2");
};
}
func();
```
> ๅฝๆฐ่กจ่พพๅผ็ๆนๅผ๏ผ่พๅบ้ฝๆฏ f1()--1ใๆไปฅๅฐฝ้ไฝฟ็จๅฝๆฐ่กจ่พพๅผใ
### 9.2ใไธฅๆ ผๆจกๅผ
```js
function func() {
console.log(this) // window
}
func();
```
> ๆญฃๅธธๆ
ๅตไธๆฏๆญฃ็กฎ็ใ
```js
"use strict";
function func() {
console.log(this) // window
}
window.func(); // ไธฅๆ ผๆจกๅผไธๅฟ
้กปๅ window๏ผๅ ไธบไป่ฎคไธบๅฝๆฐๆฏไธไธชๆนๆณ๏ผๆนๆณๅฟ
้กป้่ฟๅฏน่ฑกๆฅ่ฐ็จ็ใ
```
**9.2.1ใๅฝๆฐไนๆฏๅฏน่ฑก๏ผๅฏน่ฑกไธไธๅฎๆฏๅฝๆฐ๏ผๆฏๅฆ๏ผMath๏ผใ**
ๅช่ฆๆ `__proto__` ็ๅฐฑๆฏๅฏน่ฑก๏ผ
ๅชๆ่ฆ `prototype` ็ๅฐฑๆฏๅฝๆฐ๏ผๅ ไธบๅฝๆฐๆไผ่ฐ็จ prototype ๅฑๆงใ
ๅฏน่ฑกไธไธๅฎๆฏๅฝๆฐ๏ผๆฏๅฆ Math๏ผไธญๆ `__proto__` ๏ผไฝๆฏๆฒกๆ `prototype`ใ
**9.2.2ใๆๆ็ๅฝๆฐ้ฝๆฏ็ฑ Function ๆ้ ๅฝๆฐๅๅปบ็ๅฎไพๅฏน่ฑกใ**
ๆข็ถๅฝๆฐๆฏๅฏน่ฑก๏ผ้ฃไนๆฏไปไนๆ้ ๅฝๆฐๅๅปบ็ๅข๏ผ
```js
var f1 = new Function("a", "b", "return a+b");
f1(1,2);
// ไธ้ข็ธๅฝไบ๏ผๅฝๆฐ็ๅฃฐๆ
function f1(a, b) {
return a+b;
}
f1(1,2);
// ็ธๅฝไบ๏ผๅฝๆฐ่กจ่พพๅผ
var f1 = function (a, b) {
return a+b;
}
f1(1,2);
```
้ฃไน Function ๆฏไธชไปไนไธ่ฅฟๅข๏ผ
็ปๆฅ็ๆฏๅฏน่ฑกไนๆฏๅฝๆฐใ็ถๅๆฅ็ๅฎ็ `__proto__` ๆๅ็ๆฏ Object็ๅๅๅฏน่ฑกใๆๆ็ๅฏน่ฑกๆๅ็้ฝๆฏObject็ๅๅๅฏน่ฑกใ | Daotin/Web/03-JavaScript/01-JavaScriptๅบ็ก็ฅ่ฏ/04-ๅฝๆฐ.md/0 | {
"file_path": "Daotin/Web/03-JavaScript/01-JavaScriptๅบ็ก็ฅ่ฏ/04-ๅฝๆฐ.md",
"repo_id": "Daotin",
"token_count": 7365
} | 12 |
ๆ้ฃๆบๅฐๆกไพ
็ฉๆณ๏ผ้ฎ็ไธไธๅทฆๅณๆนๅ้ฎๆงๅถ้ฃๆบ็็งปๅจ๏ผๅญๅผนๆๅฐๆๆบ๏ผๆๆบๆถๅคฑ๏ผ่ฎกๅๆฟๆพ็คบๆถ็ญๆๆบๆฐ้ใ
ไปฃ็ ๅฆไธ๏ผ
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
.dv {
width: 300px;
height: 600px;
margin: 20px auto;
position: relative;
}
.box {
width: 300px;
height: 500px;
/* margin: 20px auto; */
border: 2px solid #666;
position: relative;
overflow: hidden;
}
.me {
width: 49px;
height: 61px;
background: url("../images/me.png");
background-size: 49px 61px;
border: 1px solid green;
box-sizing: border-box;
position: absolute;
left: 125px;
top: 439px;
}
.zd {
width: 7px;
height: 18px;
background: url("../images/bullet.png");
background-size: 7px 18px;
position: absolute;
}
.plane {
width: 30px;
height: 18px;
background: url("../images/plane1.png");
background-size: 30px 18px;
border: 1px solid red;
box-sizing: border-box;
position: absolute;
}
p {
width: 300px;
height: 50px;
background-color: aqua;
position: absolute;
border: 2px solid #666;
top: 500px;
left: 0;
}
p span {
color: red;
font-size: 30px;
}
.over {
width: 300px;
height: 500px;
background-color: rgba(0, 0, 0, 0.6);
position: absolute;
left: 0;
top: 0;
display: none;
}
.over span {
width: 214px;
height: 52px;
position: absolute;
background-image: url("../images/logo.png");
background-size: 214px 52px;
left: 42px;
top: 250px;
}
</style>
</head>
<body>
<div class="dv">
<div class="box">
<div class="over"><span></span></div>
<div class="me"></div>
<!-- <div class="zd"></div> -->
<!-- <div class="plane"></div> -->
</div>
<p>ไฝ ๅทฒๅป่ฝๆๆบ <span>0</span> ๆถ</p>
</div>
</body>
<script src="../js/daotin.js"></script>
<script>
var box = document.querySelector(".box");
// console.log(box);
var me = document.querySelector(".me");
var span = document.querySelector("p span");
var over = document.querySelector(".over");
var step = 5; // me ็งปๅจ้ๅบฆ
var bulletSpeed = 20; // ๅญๅผน็งปๅจ้ๅบฆ
var planeSpeed = 1;
var bulletCreatTimer = 0;
var planeCreatTimer = 0;
var boxWidth = getStyle(box, "width");
var boxHeight = getStyle(box, "height");
var meWidth = parseInt(getStyle(me, "width"));
var meHeight = parseInt(getStyle(me, "height"));
var bulletWidth = 0;
var bulletHeight = 0;
var planeWidth = 0;
var planeHeight = 0;
// ไบง็ๅญๅผน
function creatBullet() {
var bullet = document.createElement("div");
bullet.className = "zd";
box.appendChild(bullet);
bulletWidth = parseInt(getStyle(bullet, "width"));
bulletHeight = parseInt(getStyle(bullet, "height"));
bullet.style.top = parseInt(getStyle(me, "top")) - parseInt(getStyle(bullet, "height")) + "px";
bullet.style.left = parseInt(getStyle(me, "left")) + parseInt(getStyle(me, "width")) / 2 - parseInt(getStyle(
bullet, "width")) / 2 + "px";
// ๆฏไธชๅญๅผน้ฝๆ่ชๅทฑ็ฌ็ซ็ๅฎๆถๅจ๏ผๆไปฅไฝฟ็จbullet.timer
bullet.timer = setInterval(function () {
bullet.style.top = parseInt(getStyle(bullet, "top")) - bulletSpeed + "px";
var planeAll = document.querySelectorAll(".plane");
if (parseInt(bullet.style.top) <= 0) {
clearInterval(bullet.timer);
bullet.remove();
}
// ๆฏ็ๆไธ้ขๅญๅผน๏ผๅคๆญๅญๅผนไธๆๆบ็ไฝ็ฝฎ
for (var i = 0; i < planeAll.length; i++) {
var planeItem = planeAll[i];
var tmpplaneLeft = parseInt(getStyle(planeItem, "left"));
var tmpplaneTop = parseInt(getStyle(planeItem, "top"));
var tmpbulletLeft = parseInt(getStyle(bullet, "left"));
var tmpbulletTop = parseInt(getStyle(bullet, "top"));
var meLeft = parseInt(getStyle(me, "left"));
var meTop = parseInt(getStyle(me, "top"));
// ๆๆบๆๅฐไบๆๆน้ฃๆบ๏ผๆธธๆ็ปๆ
if ((tmpplaneLeft + planeWidth > meLeft) && (meLeft + meWidth > tmpplaneLeft) &&
(tmpplaneTop + planeHeight > meTop) && (meTop + meHeight > tmpplaneTop)) {
for (var i = 0; i < planeAll.length; i++) {
clearInterval(planeAll[i].timer);
}
document.onkeydown = document.onkeyup = null;
clearInterval(bullet.timer);
clearInterval(bulletCreatTimer);
clearInterval(planeCreatTimer);
over.style.display = "block";
}
// ๅญๅผนๆๅฐๆๆบ๏ผๆๆบๆถๅคฑ
if ((tmpbulletLeft + bulletWidth > tmpplaneLeft) && (tmpplaneLeft + planeWidth > tmpbulletLeft) &&
(tmpbulletTop + bulletHeight > tmpplaneTop) && (tmpplaneTop + planeHeight > tmpbulletTop)) {
span.innerHTML = span.innerHTML * 1 + 1;
clearInterval(bullet.timer);
bullet.remove();
clearInterval(planeItem.timer);
planeItem.remove();
}
}
}, 100);
};
bulletCreatTimer = setInterval(creatBullet, 200);
// ไบง็ๆๆบ
function creatPlane() {
var plane = document.createElement("div");
plane.className = "plane";
box.appendChild(plane);
planeWidth = parseInt(getStyle(plane, "width"));
planeHeight = parseInt(getStyle(plane, "height"));
plane.style.left = Math.floor(Math.random() *
(parseInt(getStyle(box, "width")) - parseInt(getStyle(plane, "width")))) + "px";
plane.style.top = 0;
plane.timer = setInterval(function (e) {
plane.style.top = parseInt(plane.style.top) + planeSpeed + "px";
if (parseInt(plane.style.top) >= (parseInt(boxHeight) - parseInt(getStyle(plane,
"height")))) {
clearInterval(plane.timer);
plane.remove();
}
}, 10);
};
planeCreatTimer = setInterval(creatPlane, 1000);
// ้ฎ็ๆงๅถๆๆน้ฃๆบ็งปๅจ
document.onkeydown = document.onkeyup = function (e) {
var evt = window.event || e;
var keyCode = evt.which || evt.keyCode;
switch (keyCode) {
case 37: //ๅทฆ
me.style.left = parseInt(getStyle(me, "left")) - step + "px";
parseInt(me.style.left) <= 0 ? me.style.left = 0 : me.style.left = me.style.left;
break;
case 38: //ไธ
me.style.top = parseInt(getStyle(me, "top")) - step + "px";
parseInt(me.style.top) <= 0 ? me.style.top = 0 : me.style.top = me.style.top;
break;
case 39: //ๅณ
me.style.left = parseInt(getStyle(me, "left")) + step + "px";
parseInt(me.style.left) >= (parseInt(boxWidth) - parseInt(meWidth)) ?
me.style.left = (parseInt(boxWidth) - parseInt(meWidth)) + "px" :
me.style.left = me.style.left;
break;
case 40: //ไธ
me.style.top = parseInt(getStyle(me, "top")) + step + "px";
parseInt(me.style.top) >= (parseInt(boxHeight) - parseInt(meHeight)) ?
me.style.top = (parseInt(boxHeight) - parseInt(meHeight)) + "px" :
me.style.top = me.style.top;
break;
default:
break;
}
}
</script>
</html
```
![](./images/1.gif) | Daotin/Web/03-JavaScript/02-DOM/ๆกไพ04๏ผๆ้ฃๆบ.md/0 | {
"file_path": "Daotin/Web/03-JavaScript/02-DOM/ๆกไพ04๏ผๆ้ฃๆบ.md",
"repo_id": "Daotin",
"token_count": 4668
} | 13 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.map {
width: 800px;
height: 600px;
background-color: #ccc;
position: relative;
}
</style>
</head>
<body>
<div class="map"></div>
<script src="common.js"></script>
<script>
// ่ทๅๅฐๅพๅฏน่ฑก
var map = document.getElementsByClassName("map")[0];
// ไบง็้ๆบๆฐๅฏน่ฑก
(function () {
// ไบง็้ๆบๆฐ็ๆ้ ๅฝๆฐ
function Random() {
}
// ๆRandomๆด้ฒ็ปwindow
window.Random = Random;
// ๅจๅๅๅฏน่ฑกไธญๆทปๅ ๆนๆณ
Random.prototype.getRandom = function (min, max) { // ่ๅด min ~ max-1
return Math.floor(Math.random() * (max - min) + min);
};
}());
// ไบง็ๅฐๆนๅๅฏน่ฑก-----------------------------------------
(function () {
// ไฟๅญ้ฃ็ฉ็ๆฐ็ป
var elements = [];
// ้ฃ็ฉ็ๆ้ ๅฝๆฐ
function Food(width, height, color) {
this.width = width || 20;
this.height = height || 20;
this.color = color || "green";
this.x = 0; // leftๅฑๆง
this.y = 0; // topๅฑๆง
this.element = document.createElement("div"); // ้ฃ็ฉๅฎไพๅฏน่ฑก
}
// ๅฐFoodๆด้ฒ็ปwindow
window.Food = Food;
// ๅๅงๅๅฐๆนๅ็ๆพ็คบๆๆๅไฝ็ฝฎ
Food.prototype.init = function () {
// ๆฏๆฌกๅจๅๅปบๅฐๆนๅไนๅๅ
ๅ ้คไนๅ็ๅฐๆนๅ๏ผไฟ่ฏmapไธญๅชๆไธไธชๅฐๆนๅ
remove();
var div = this.element;
map.appendChild(div);
div.style.width = this.width + "px";
div.style.height = this.height + "px";
div.style.backgroundColor = this.color;
div.style.position = "absolute";
this.x = new Random().getRandom(0, map.offsetWidth / this.width) * this.width;
this.y = new Random().getRandom(0, map.offsetHeight / this.height) * this.height;
div.style.left = this.x + "px";
div.style.top = this.y + "px";
// ๆdivๅ ๅฐๆฐ็ปไธญ
elements.push(div);
};
// ็งๆๅฝๆฐ๏ผๅ ้คๅฐๆนๅ
function remove() {
for (var i = 0; i < elements.length; i++) {
elements[i].parentElement.removeChild(elements[i]);
elements.splice(i, 1); // ๆธ
็ฉบๆฐ็ป๏ผไปi็ไฝ็ฝฎๅ ้ค1ไธชๅ
็ด
}
}
}());
// ไบง็ๅฐ่ๅฏน่ฑก------------------------------------------------------
(function () {
// ๅๅปบๆฐ็ปไฟๅญๅฐ่่บซไฝ็ๆฏไธชdiv
var elements = [];
function Snack(width, height, direction) {
// ๅฐ่ๆฏไธๅ็ๅฎฝ้ซ
this.width = width || 20;
this.height = height || 20;
this.direction = direction || "right";
this.beforeDirection = this.direction;
// ๅฐ่็ปๆ่บซไฝ็ๆฏไธชๅฐๆนๅ
this.body = [
{x: 3, y: 2, color: "red"},
{x: 2, y: 2, color: "orange"},
{x: 1, y: 2, color: "orange"}
];
}
// ๅฐSnackๆด้ฒ็ปwindow
window.Snack = Snack;
// ไธบๅๅๆทปๅ ๅฐ่ๅๅงๅ็ๆนๆณ
Snack.prototype.init = function (map) {
// ๆพ็คบๅฐ่ไนๅๅ ้คๅฐ่
remove();
// ๅพช็ฏๅๅปบๅฐ่่บซไฝdiv
for (var i = 0; i < this.body.length; i++) {
var div = document.createElement("div");
map.appendChild(div);
div.style.width = this.width + "px";
div.style.height = this.height + "px";
div.style.position = "absolute";
// ็งปๅจๆนๅ๏ผ็งปๅจ็ๆถๅ่ฎพ็ฝฎ
// ๅๆ ไฝ็ฝฎ
var tempObj = this.body[i];
div.style.left = tempObj.x * this.width + "px";
div.style.top = tempObj.y * this.width + "px";
div.style.backgroundColor = tempObj.color;
// ๅฐๅฐ่ๆทปๅ ๅฐๆฐ็ป
elements.push(div);
}
};
// ไธบๅๅๆทปๅ ๅฐ่็งปๅจๆนๆณ
Snack.prototype.move = function (food) {
var index = this.body.length - 1; // ๅฐ่่บซไฝ็็ดขๅผ
// ไธ่่ๅฐ่ๅคด้จ
for (var i = index; i > 0; i--) { // i>0 ่ไธๆฏ i>=0
this.body[i].x = this.body[i - 1].x;
this.body[i].y = this.body[i - 1].y;
}
// ๅฐ่ๅคด้จ็งปๅจ
switch (this.direction) {
case "right" :
// if(this.beforeDirection !== "left") {
this.body[0].x += 1;
// }
break;
case "left" :
this.body[0].x -= 1;
break;
case "up" :
this.body[0].y -= 1;
break;
case "down" :
this.body[0].y += 1;
break;
default:
break;
}
// ๅฐ่็งปๅจ็ๆถๅ๏ผๅฝๅฐ่ๅทๅๆ ๅ้ฃ็ฉ็ๅๆ ็ธๅ่กจ็คบๅๅฐ้ฃ็ฉ
var headX = this.body[0].x * this.width;
var headY = this.body[0].y * this.height;
// ๅๅฐ้ฃ็ฉ๏ผๅฐๅฐพๅทดๅคๅถไธไปฝๅ ๅฐๅฐ่bodyๆๅ
if ((headX === food.x) && (headY === food.y)) {
var last = this.body[this.body.length - 1];
this.body.push({
x: last.x,
y: last.y,
color: last.color
});
// ๅ ้ค้ฃ็ฉ
food.init();
}
};
// ็งๆๅฝๆฐ๏ผๅ ้คๅฐ่
function remove() {
var i = elements.length - 1;
for (; i >= 0; i--) {
elements[i].parentNode.removeChild(elements[i]);
elements.splice(i, 1);
}
}
}());
// ไบง็ๆธธๆๅฏน่ฑก----------------------------------------------------------
(function () {
var that = null;
function Game(map) {
this.food = new Food(20, 20, "purple");
this.snack = new Snack(20, 20);
this.map = map;
that = this;
}
// ๅๅงๅๆธธๆ
Game.prototype.init = function () {
this.food.init(this.map);
this.snack.init(this.map);
this.autoRun();
this.changeDirection();
};
// ๅฐ่่ชๅจ่ท่ตทๆฅ
Game.prototype.autoRun = function () {
var timeId = setInterval(function () {
this.snack.move(this.food);
this.snack.init(this.map);
// ๅคๆญๆๅคงX,Y่พน็
var maxX = this.map.offsetWidth / this.snack.width;
var maxY = this.map.offsetHeight / this.snack.height;
// Xๆนๅ่พน็
if ((this.snack.body[0].x < 0) || (this.snack.body[0].x >= maxX)) {
// ๆๅขไบ
clearInterval(timeId);
alert("Oops, Game Over!");
}
// Yๆนๅ่พน็
if ((this.snack.body[0].y < 0) || (this.snack.body[0].y >= maxY)) {
// ๆๅขไบ
clearInterval(timeId);
alert("Oops, Game Over!");
}
}.bind(that), 150); // ไฝฟ็จbind๏ผ้ฃไนinitๆนๆณไธญๆๆ็this้ฝๅฐ่ขซbind็ๅๆฐthatๆฟๆข
};
// ๆไธ้ฎ็ๆนๅๅฐ่็งปๅจๆนๅ
Game.prototype.changeDirection = function () {
addAnyEventListener(document, "keydown", function (e) {
// ๆฏๆฌกๆ้ฎไนๅไฟๅญๆ้ฎๆนๅ
this.snack.beforeDirection = this.snack.direction;
switch (e.keyCode) {
case 37: // ๅทฆ
this.snack.beforeDirection !== "right" ? this.snack.direction = "left" : this.snack.direction = "right";
break;
case 38: // ไธ
this.snack.beforeDirection !== "down" ? this.snack.direction = "up" : this.snack.direction = "down";
break;
case 39: // ๅณ
this.snack.beforeDirection !== "left" ? this.snack.direction = "right" : this.snack.direction = "left";
break;
case 40: // ไธ
this.snack.beforeDirection !== "up" ? this.snack.direction = "down" : this.snack.direction = "up";
break;
default:
break;
}
}.bind(that));
};
window.Game = Game;
}());
var game = new Game(map);
game.init();
</script>
</body>
</html> | Daotin/Web/03-JavaScript/04-JavaScript้ซ็บง็ฅ่ฏ/ๆกไพๆบ็ /่ดชๅ่/index.html/0 | {
"file_path": "Daotin/Web/03-JavaScript/04-JavaScript้ซ็บง็ฅ่ฏ/ๆกไพๆบ็ /่ดชๅ่/index.html",
"repo_id": "Daotin",
"token_count": 5407
} | 14 |
ๅๆ๏ผๆไปฌๅจmysqlๅๅปบไบไธไธชๆฐๆฎๅบ: mydb.
mydb ้้ขๆไธชๆฐๆฎ่กจ mytableใ
mytable ไธญ็ๆฐๆฎไธบ๏ผ
| id | name | age |
| ---- | ------ | ---- |
| 1 | daotin | 18 |
| 2 | lvonve | 19 |
| 3 | li | 20 |
PHPไปฃ็ ่ฟๆฅๆฐๆฎๅบmydb๏ผ
```php
<?php
@header("content-type:text/html;charset=utf8");
mysql_connect("localhost:3306", "root", "root"); // ๅฆๆๆ ๆณ้พๆฅๅฐไผๆฅ้๏ผๆฅ้ไฟกๆฏๅฆไธ๏ผ
// Warning: mysql_connect() [function.mysql-connect]: [2002] ็ฑไบ็ฎๆ ่ฎก็ฎๆบ็งฏๆๆ็ป๏ผๆ ๆณ่ฟๆฅใ (trying to connect via tcp://localhost:33062) in
$connect = mysql_select_db("mydb"); // ้ๆฉ็ๆฐๆฎๅบๅญๅจ่ฟๅ1๏ผๅฆๅไธบ็ฉบ
if($connect) {
echo "ๆฐๆฎๅบๅญๅจ";
} else {
echo "ๆฐๆฎๅบไธๅญๅจ";
}
$sql = 'select * from mytable'; // ๅฎไนๆฅ่ฏขๆฐๆฎ่กจ๏ผmytable๏ผ่ฏญๅฅ
$res = mysql_query($sql); // ๆง่กๆฐๆฎ่กจๆฅ่ฏข่ฏญๅฅ๏ผ่ฟๅๅผๆฏresouceๆ ผๅผ็ๆฐๆฎใ
// mysql_fetch_array ๅฐresouceๆ ผๅผ็ๆฐๆฎ่ฝฌๅๆArrayๆฐๆฎ็ฑปๅ
// ็ฑไบmysql_fetch_arrayๆฏๆฌกๅช่ฝ่ฝฌๆขๆฐๆฎ่กจ็ไธ่กๆฐๆฎ๏ผๆไปฅ่ฆๅพช็ฏ่ฝฌๆขใ
// ไฝฟ็จwhileๆฏๅ ไธบๆฒกๆๆฐๆฎ็ๅฐๆน่ฝฌๆข็็ปๆไธบfalse
// ๆๅๅฐๅคไธชarrayๅ ๅ
ฅๆฐ็ปlistไธญใ
$list = array();
while($item = mysql_fetch_array($res)) {
$list[] = $item;
}
// ไฝฟ็จjson_encodeๅฐ่ฝฌๆข็array้ๅๅๆjsonๅฏน่ฑก้ๅใ
echo json_encode($list);
?>
```
่ทๅๅฐ็ๆฐๆฎๅฆไธ๏ผ
![](./images/2.png)
ๆไปฌๅ็ฐไธไธช้ฎ้ข๏ผๅฐฑๆฏ่ทๅๅฐ็ๆไธคไปฝ็ธๅ็ๆฐๆฎ๏ผ่ฟๅฐฑ้ ๆๆฐๆฎ็ๅไฝ๏ผๆไน่งฃๅณๅข๏ผ
่งฃๅณๅๆณ๏ผ
ๆไปฌ็จๅฆไธไธชๆฐ็ปๆฅๆพๅ
ฅ่ทๅๅฐ็ๆฐ็ปไธญ๏ผๆไปฌ้่ฆ็ๆฐๆฎใ
```php
$list = array();
while($item = mysql_fetch_array($res)) {
$tmp = array();
$tmp["id"] = $item["id"];
$tmp["name"] = $item["name"];
$tmp["age"] = $item["age"];
$tmp["status"] = $item["status"];
$list[] = $tmp;
}
// ไฝฟ็จjson_encodeๅฐ่ฝฌๆข็array้ๅๅๆjsonๅฏน่ฑก้ๅใ
echo json_encode($list);
```
ไบๆฏๅฐฑ่ทๅๅฐไบๆไปฌๆณ่ฆ็ๆฐๆฎ๏ผ
![](./images/3.png)
ๅพๅฐๆฐๆฎๅ๏ผๆไปฌๅฐฑๅฏไปฅ้่ฟhtmlไปฃ็ ๅฐๅ
ถๆธฒๆๅฐ้กต้ข๏ผ
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
div {
width: 400px;
margin: 50px auto;
}
table {
width: 400px;
border: 1px solid #666;
border-collapse: collapse;
text-align: center;
}
</style>
</head>
<body>
<div>
<table border="1">
<tr>
<th>็ผๅท</th>
<th>็จๆทๅ</th>
<th>ๅนด้พ</th>
<th>ๆไฝ</th>
</tr>
<!-- <tr>
<td>1</td>
<td>ๅๅ</td>
<td>18</td>
<td><a href="javascript:;">ๅ ้ค</a></td>
</tr>
<tr>
<td>2</td>
<td>ๆ็</td>
<td>18</td>
<td><a href="javascript:;">ๅ ้ค</a></td>
</tr> -->
</table>
</div>
</body>
<script>
var table = document.querySelector("table");
var xhr = new XMLHttpRequest();
xhr.open("get", "http://localhost/php/1121/connectDB.php", true);
xhr.send();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
let list = JSON.parse(xhr.responseText);
list.map(function (item) {
let id = item["id"];
let uname = item["name"];
let age = item["age"];
var tr = document.createElement("tr");
var td_id = document.createElement("td");
var td_name = document.createElement("td");
var td_age = document.createElement("td");
var td_del = document.createElement("td");
var a = document.createElement("a");
a.innerHTML = "ๅ ้ค";
a.href = "javascript:;";
td_id.innerHTML = id;
td_name.innerHTML = uname;
td_age.innerHTML = age;
td_del.appendChild(a);
tr.appendChild(td_id);
tr.appendChild(td_name);
tr.appendChild(td_age);
tr.appendChild(td_del);
table.appendChild(tr);
a.onclick = function () {
//?
};
});
}
};
</script>
</html>
```
![](./images/4.png)
้่ฆๆณจๆ็ๆฏ๏ผ็ฑไบajaxๅๅฐๅๆบ็ญ็ฅ็ๅฝฑๅ๏ผๆไปฅๆไปฌ็htmlไปฃ็ ไธๅฎๅphpๆไปถๅจ็ธๅ็ๅ่ฎฎ๏ผ็ธๅ็ๅๅ๏ผ็ธๅ็็ซฏๅฃไธใ
ๅฅฝไบ๏ผไธ้ข็ไปฃ็ ่ฟๆไธไธช้ฎ้ข๏ผๅฐฑๆฏๆไปฌๅจ็นๅปๅ ้ค็ๆถๅ๏ผ้่ฆๅฐๆฐๆฎๅบ็ๅฏนๅบ็ๆฐๆฎๅ ้คๅ๏ผ
ไธ้่ฆ๏ผไธ่ฌๆญฃๅธธ็ๆไฝๆฏๆฏไธชๆฐๆฎ้ฝๅฏนๅบไธไธชstatus๏ผ่กจ็คบๆฏๅฆๅฏไปฅ่ฎฟ้ฎ๏ผๆไปฌไปฅstatus=1ๅฏไปฅ่ฎฟ้ฎ๏ผstatus=0ไธๅฏไปฅ่ฎฟ้ฎไธบไพ๏ผๆฅๅฎ็ฐๅ ้คๆไฝใ
ๆไปฅๆไปฌๆฐๆฎๅบ็ๆฐๆฎ็ฐๅจๆฏไธ้ข็ๆ ทๅญ๏ผ
![](./images/5.png)
ๆไปฌphpไปฃ็ ไน่ฆไฟฎๆนไธ๏ผ
| Daotin/Web/05-PHP&ๆฐๆฎๅบ/04-PHP่ฟๆฅmysqlๆฐๆฎๅบ.md/0 | {
"file_path": "Daotin/Web/05-PHP&ๆฐๆฎๅบ/04-PHP่ฟๆฅmysqlๆฐๆฎๅบ.md",
"repo_id": "Daotin",
"token_count": 3243
} | 15 |
// Stacked Icons
// -------------------------
.@{fa-css-prefix}-stack {
position: relative;
display: inline-block;
width: 2em;
height: 2em;
line-height: 2em;
vertical-align: middle;
}
.@{fa-css-prefix}-stack-1x, .@{fa-css-prefix}-stack-2x {
position: absolute;
left: 0;
width: 100%;
text-align: center;
}
.@{fa-css-prefix}-stack-1x { line-height: inherit; }
.@{fa-css-prefix}-stack-2x { font-size: 2em; }
.@{fa-css-prefix}-inverse { color: @fa-inverse; }
| Daotin/Web/07-็งปๅจWebๅผๅ/ๆกไพๆบ็ /03-ๅพฎ้ๆ/lib/font-awesome-4.7.0/less/stacked.less/0 | {
"file_path": "Daotin/Web/07-็งปๅจWebๅผๅ/ๆกไพๆบ็ /03-ๅพฎ้ๆ/lib/font-awesome-4.7.0/less/stacked.less",
"repo_id": "Daotin",
"token_count": 201
} | 16 |
## ไธใlet
**ไฝ็จ๏ผไธvar็ฑปไผผ, ็จไบๅฃฐๆไธไธชๅ้ใ**
**letๅvar็ๅบๅซ๏ผ**
- ๅจๅไฝ็จๅๅ
ๆๆ(ๅช่ฆๆ{}ๅบ็ฐ ๅๅชๅจ่ฏฅ{}่ๅดๅ
็ๆ)
- ไธ่ฝ้ๅคๅฃฐๆ
- ไธไผ้ขๅค็, ไธๅญๅจๆๅ
```html
<script type="text/javascript">
console.log(res); //ไธไผ้ขๅค็, ไธๅญๅจๆๅ๏ผๆฅ้
// ไธ่ฝ้ๅคๅฃฐๆ
let res = 10;
let res = 10; // ๆฅ้
</script>
```
**ๅบ็จ๏ผๅพช็ฏ้ๅๅ ็ๅฌ**
ๆไปฌๅ
ๅผ็ไธไธชไพๅญ๏ผ
```html
<body>
<button>ๆต่ฏ1</button>
<button>ๆต่ฏ2</button>
<button>ๆต่ฏ3</button>
<script type="text/javascript">
let btns = document.getElementsByTagName('button');
for (var i = 0; i < btns.length; i++) {
btns[i].onclick = function () {
alert(i);
}
}
</script>
</body>
```
ๆไปฌๅๅซ็นๅปๆ้ฎ็ๆถๅ๏ผๅๅซๆๅฐๅคๅฐ๏ผ
็ปๆ๏ผๆๅฐ็้ฝๆฏ2ใ**ๅ ไธบๅ่ฐๅฝๆฐ็ๅๆณไผ่ฟ่ก่ฆ็ๆไฝ**ใๅฆไฝ่งฃๅณ๏ผ
**ๆนๆณไธ๏ผไฝฟ็จ้ญๅ
ใ**
```js
for (var i = 0; i < btns.length; i++) {
(function(){
btns[i].onclick = function () {
alert(i);
}
})(i);
}
```
่ฟ็งๆนๅผ็ธๅฝไบ๏ผๆฏไธชๅ่ฐๅฝๆฐๆไธช่ชๅทฑ็ๅบ้ด๏ผๅไธชๅบ้ดไบไธๅนฒๆฐใ่ let ๆญฃๅฅฝๆ่ฟไธช็นๆงใ
**ๆนๆณไบ๏ผๅฐ forๅพช็ฏ็ varๆนไธบletๅณๅฏใ**
## ไบใconst
ไฝ็จ๏ผๅฎไนไธไธชๅธธ้ใ
็น็น๏ผ
- ไธ่ฝไฟฎๆน
- (ๅธธ้ๅไป่ง่ไธๆฅๅฐ ๆๅฅฝๆๆๅญๆฏๅคงๅ)
- ๅ
ถๅฎ็น็นๅletใ
```js
const uName = 'Daotin';
```
## ไธใๅ้็่งฃๆ่ตๅผ
็่งฃ๏ผไปๅฏน่ฑกๆๆฐ็ปไธญๆๅๆฐๆฎ, ๅนถ่ตๅผ็ปๅ้(ๅคไธช)ใ
### 1ใๅฏน่ฑก็่งฃๆ่ตๅผ
ไนๅๆไปฌ่ฆ่ทๅไธไธชๅฏน่ฑก็ๅฑๆง๏ผไผๅฎไนๅ้็ถๅๆฅๆถๅฏน่ฑก็ๅฑๆงๅผใ
```js
let obj = {name : 'kobe', age : 39};
let name = obj.name;
let age = obj.age;
console.log(name, age);
```
ๅฏน่ฑก็่งฃๆ่ตๅผๅฏไปฅ่ฟๆ ทๅ๏ผ
```js
let {name, age} = obj;
console.log(name, age); // name ๅฐฑๆฏobj.name๏ผageๅฐฑๆฏobj.age
```
็ปๅฏน่ฑก็่งฃๆ่ตๅผ**่ตทไธชๅซๅ**๏ผ
```js
let obj = {name:'daotin', age:18};
let {name:myname, age:myage} = obj; // ็ปnameๅageๅๅซ่ตทไธชๅซๅmynameๅmyage
```
**ๆๅฎ้ป่ฎคๅผ**๏ผๅฏนไบๅฏน่ฑกไธๅญๅจ็ๅฑๆง๏ผๅฏไปฅๆทปๅ ้ป่ฎคๅผ๏ผ๏ผ
```js
let obj = {name:'daotin', age:18};
let {name,age,sex='man'} = obj; // ็ปๅฎobjๅฏน่ฑกไธไธชๅฑๆง้ป่ฎคๅผ
```
> ๆณจๆ๏ผ
> 1ใๅฏน่ฑก็่งฃๆ่ตๅผๅฟ
้กปไฝฟ็จๅคงๆฌๅท {}
>
> 2ใๅคงๆฌๅท้้ข็ๅ้ๅๅฟ
้กปๅobj้้ข็ๅฑๆงๅ็ธๅ
>
> 3ใๅฏไปฅๅชๅฎไนไธ้จๅๅ้ๆฅๆถไธ้จๅ็objๅฑๆง๏ผไธ้่ฆๅ
จ้จๆฅๆถใ
### 2ใๆฐ็ป็่งฃๆ่ตๅผ
ๆฐ็ปๆฒกๆๅฏน่ฑก็ๆฐ็ปๅ๏ผไฝๆฏๆไธๆ ๅฏไปฅไฝฟ็จใๆไปฅ่ฟ้็ๅ้ๅๅฏไปฅ้ไพฟ่ตทใ
```js
let arr = ['abc', 23, true];
let [a, b, c] = arr;
console.log(a, b, c);
```
> ๆณจๆ๏ผ
>
> 1ใๆฐ็ป็่งฃๆ่ตๅผๅฟ
้กปไฝฟ็จไธญๆฌๅท []๏ผๅนถไธๅฏน้กบๅบๆ่ฆๆฑใ
>
> 2ใๅฏไปฅ็ปๅฎ้ป่ฎคๅผ
**ๅฆๆๅชๆณๅๅ
ถไธญ็ๆๅ ไธชๅผ๏ผ้ฃไนๅ้ๅฏไปฅไฝฟ็จ้ๅท้ๅผใ**
`let [,,a,,] = arr;`
**ๅฆๆๅฎไน็ๅ้ไธชๆฐๆฏๆฐ็ป็ไธชๆฐๅค๏ผๅคๅบๆฅ็ๅ้็ๅผไธบ** `undefined`ใ
## ๅใๆจกๆฟๅญ็ฌฆไธฒ
ไฝ็จ๏ผ็ฎๅๅญ็ฌฆไธฒ็ๆผๆฅใ
ๆณจๆ๏ผ
1ใๆจกๆฟๅญ็ฌฆไธฒๅฟ
้กป็จ ``` ` ๅ
ๅซ๏ผ
2ใๅๅ็้จๅไฝฟ็จ`${xxx}`ๅฎไน
```js
let obj = {
name: 'anverson',
age: 41
};
// ๆไปฌไนๅๆผๆฅๅญ็ฌฆไธฒ็จ็ๆฏ+
console.log('ๆๅซ:' + obj.name + ', ๆ็ๅนด้พๆฏ๏ผ' + obj.age);
// ไฝฟ็จๆจกๆฟๅญ็ฌฆไธฒ็ๆนๅผ
console.log(`ๆๅซ:${obj.name}, ๆ็ๅนด้พๆฏ๏ผ${obj.age}`);
```
## ไบใๅฏน่ฑก็็ฎๅๅๆณ
ๅฆๆๆๅ้ๅๅฏน่ฑก็ๅฑๆงๅ็งฐ็ธๅ๏ผไนๅ็ๅๆณๆฏ่ตๅผๆไฝ๏ผ
```js
let a = 1;
let b = 2;
let Obj = {
a: a,
b: b,
};
```
็ฐๅจ๏ผๅฆๆๅ้ๅๅฏน่ฑก็ๅฑๆงๅ็งฐ็ธๅ๏ผๅฏไปฅ็ฎๅๅฆไธ๏ผ
```js
let a = 1;
let b = 2;
let Obj = {
a,
b,
};
```
ๅฏนไบๅฏน่ฑก็ๅฑๆง๏ผๅฆๆๆฏไธชๅฝๆฐ็่ฏ๏ผไนๅฏไปฅ็ฎๅ๏ผ
ไนๅ็ๅๆณไธบ๏ผ
```js
let Obj = {
foo: function(){
//...
}
};
```
็ฐๅจ็ๅๆณไธบ๏ผ๏ผๅปๆๅๅทๅfunction๏ผ
```js
let Obj = {
foo(){
//...
}
};
```
## ๅ
ญใ็ฎญๅคดๅฝๆฐ
ไฝ็จ๏ผ**็ฎญๅคดๅฝๆฐ็ไฝ็จไธป่ฆๆฏๅฎไนๅฟๅๅฝๆฐใ**
ๆไธ้ขๅ ็งๆ
ๅต็ๅฟๅๅฝๆฐ้ฝๅฏไปฅไฝฟ็จ็ฎญๅคดๅฝๆฐ๏ผ
```js
let foo = function () {};
// ่ฝฌๆขๆ็ฎญๅคดๅฝๆฐ
let foo = () => {};
//------------------------------
let Obj = {
foo: function () { }
}
// ่ฝฌๆขๆ็ฎญๅคดๅฝๆฐ
let Obj = {
foo: () => { }
}
```
ๅบๆฌ่ฏญๆณ**๏ผๅๆฐ๏ผ**๏ผ
1ใๅฟๅๅฝๆฐๆฒกๆๅๆฐ๏ผ() ไธ่ฝ็็ฅ๏ผๅ ไฝไฝ็จใ`let foo = () => {};`
2ใๅชๆไธไธชๅๆฐ๏ผ() ๅฏไปฅ็็ฅ๏ผไนๅฏไปฅไธ็็ฅใ`let foo = a => {};`
3ใๅคไธชๅๆฐ๏ผ() ไธ่ฝ็็ฅใ`let foo = (a,b) => {};`
ๅบๆฌ่ฏญๆณ**๏ผๅฝๆฐไฝ๏ผ**๏ผ
1ใๅฝๆฐไฝๅชๆไธๆก่ฏญๅฅ๏ผๅฏไปฅ็็ฅ{}๏ผๅนถไธ้ป่ฎค่ฟๅ็ปๆ๏ผไธ้่ฆ return๏ผใ
```js
let foo = (x, y) => x + y;
console.log(foo(1, 2));
```
2ใๅฝๆฐไฝๅฆๆๆๅคไธช่ฏญๅฅ, ้่ฆ็จ{}ๅ
ๅด๏ผ่ฅๆ้่ฆ่ฟๅ็ๅ
ๅฎน๏ผ้่ฆๆทปๅ returnใ
```js
let foo = (x, y) => {
console.log(x, y);
return x + y;
};
console.log(foo(1, 2));
```
**็ฎญๅคดๅฝๆฐ็็น็น๏ผ**
1ใไธ่ฝๅๆ้ ๅฝๆฐ๏ผไธ่ฝๅฎไพๅ๏ผ
2ใๆฒกๆ arguments
**3ใ็ฎญๅคดๅฝๆฐๆฒกๆ่ชๅทฑ็this๏ผ็ฎญๅคดๅฝๆฐ็thisไธๆฏ่ฐ็จ็ๆถๅๅณๅฎ็๏ผthisๆๅไธไธๆ็ฏๅขใ๏ผๆๆ๏ผ็ฎญๅคดๅฝๆฐ็ๅคๅฑ็ๆฏๅฆๆๅฝๆฐ๏ผๅฆๆๆ๏ผ็ฎญๅคดๅฝๆฐ็thisๅฐฑๆฏๅคๅฑๅฝๆฐ็this๏ผๅฆๆๆฒกๆ๏ผๅไธบ window๏ผ**
> ็ฎๅๆนๆณ๏ผ็ฎญๅคดๅฝๆฐ๏ผthisๅฐฑๅพๅคๆชไธๅฑ๏ผๅค้ขๅฆๆ่ฟๆฏ็ฎญๅคดๅฝๆฐ๏ผ็ปง็ปญๅพๅคๆช๏ผ็ดๅฐๆฒกๆ็ฎญๅคดๅฝๆฐ็ๅฐๆนๅฐฑๆฏๅฝๅthis็ๆๅใ
```html
<script type="text/javascript">
let foo = () => {
console.log(this);
};
foo(); // window ๅฏน่ฑก
let Obj1 = {
bar() {
let foo = () => {
console.log(this);
};
foo();
}
};
Obj1.bar(); // Obj1 ๅฏน่ฑก๏ผ็ฎญๅคดๅฝๆฐๅคๅฑๆๅฝๆฐbar๏ผbar้้ข็thisๆฏObj1.
let Obj2 = {
bar: () => {
let foo = () => {
console.log(this);
};
foo();
}
};
Obj2.bar(); // window ๅฏน่ฑก๏ผ็ฎญๅคดๅฝๆฐๅคๅฑๆๅฝๆฐbar๏ผbarๅฝๆฐไนๆฏ็ฎญๅคดๅฝๆฐ๏ผbar็ๅคๅฑๆฒกๆๅฝๆฐ๏ผๆไปฅbar้้ข็thisๆฏwindow๏ผๆไปฅfoo้้ข็thisไนๆฏwindowใ
</script>
```
## ไธใๅฑๅผ็ฌฆ/ไธ็น่ฟ็ฎ็ฌฆ
**ไฝ็จ๏ผ**
**1ใ็จๆฅๅไปฃ arguments ไฝๆฏ arguments ็ตๆดป,**
arguments ๆฏไธชไผชๆฐ็ป๏ผไฝๆฏไธ็น่ฟ็ฎ็ฌฆๆฏ**็ๆฐ็ป**๏ผๅฏไปฅไฝฟ็จ forEach ็ญๆนๆณใ
![](./images/9.png)
2ใไธ็น๏ผๅฏๅๅๆฐ๏ผ่ฟ็ฎ็ฌฆๅช่ฝๆฏ**ๆๅ้จๅๅฝขๅๅๆฐใ** ไฝๆฏๅ้ขๆฏๅฏไปฅๆๅๆฐๆฅๅ ไฝ็ใ
![](./images/11.png)
**3ใๆฉๅฑ่ฟ็ฎ็ฌฆ**
```js
let arr = [1, 6];
let arr1 = [2, 3, 4, 5];
arr = [1, ...arr1, 6];
console.log(arr); // [1,2,3,4,5,6]
console.log(...arr); // 1 2 3 4 5 6
```
่ฏญๆณ๏ผ`...ๆฐ็ปๅ` ๏ผ่กจ็คบ้ๅๆฐ็ป็ๆๆๅ
็ด ใ
## ๅ
ซใๅฝขๅ้ป่ฎคๅผ
ไฝ็จ๏ผๅฝไธไผ ๅ
ฅๅๆฐ็ๆถๅ้ป่ฎคไฝฟ็จๅฝขๅ้็้ป่ฎคๅผใ
```html
<script type="text/javascript">
//ๅฎไนไธไธช็น็ๅๆ
function Point(x = 12, y = 12) { // ๅฝขๅ็้ป่ฎคๅผ
this.x = x;
this.y = y;
}
let p = new Point();
console.log(p);
let point = new Point(25, 36);
console.log(point);
</script>
```
| Daotin/Web/08-ES6่ฏญๆณ/03-let๏ผconst๏ผ่งฃๆ่ตๅผ๏ผๆจกๆฟๅญ็ฌฆไธฒ๏ผๅฏน่ฑก็ฎๅ๏ผ็ฎญๅคดๅฝๆฐ๏ผไธ็น่ฟ็ฎ็ฌฆ๏ผๅฝขๅ้ป่ฎคๅผ.md/0 | {
"file_path": "Daotin/Web/08-ES6่ฏญๆณ/03-let๏ผconst๏ผ่งฃๆ่ตๅผ๏ผๆจกๆฟๅญ็ฌฆไธฒ๏ผๅฏน่ฑก็ฎๅ๏ผ็ฎญๅคดๅฝๆฐ๏ผไธ็น่ฟ็ฎ็ฌฆ๏ผๅฝขๅ้ป่ฎคๅผ.md",
"repo_id": "Daotin",
"token_count": 4733
} | 17 |
## asyncๆจกๅไป็ป
*Async is a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript. Although originally designed for use with Node.js and installable via npm install --save async, it can also be used directly in the browser.*
asyncๆฏไธไธชๅฎ็จ็ๆจกๅ๏ผๅฏนไบๅค็ๅผๆญฅjavascriptๆฅ่ฏด๏ผๅฎๅฏไปฅๆไพ็ฎไปๅผบๅคง็ๅ่ฝใ่ฝ็ถๆๅ่ฎพ่ฎก็ๆถๅ่งไธบNodejs่ฎพ่ฎก็๏ผๅฏไปฅ้่ฟ`npm install --save async` ๆฅๅผๅ
ฅasyncๆจกๅ๏ผไฝๆฏ็ฐๅจๅฎไนๅฏไปฅ่ขซ็ดๆฅ็จๅจๆต่งๅจไธญ๏ผไนๅฐฑๆฏๅ็ซฏjsไปฃ็ ไธญใ
## asyncไธไธชๆจกๅผ
async็ๅผๆญฅๆต็จ็ฎก็ไธป่ฆๅไธบไธไธชๆจกๅผ๏ผ
- ๅนถ่กๆ ๅ
ณ่
- ไธฒ่กๆ ๅ
ณ่
- ไธฒ่กๆๅ
ณ่
### ๅนถ่กๆ ๅ
ณ่ parallel
```js
const async = require("async");
/**
* ๅนถ่กๆ ๅ
ณ่
* ่ฏญๆณ๏ผasync.parallel([],(err,data)=>{})
* ๅๆฐ1๏ผๅฏไปฅๆฏไธชๅฏน่ฑกๆ่
ๆฐ็ป
* ๅฆๆๆฏๆฐ็ป๏ผๅ
ๅฎนไธบไธ็ณปๅๅฟๅๅฝๆฐ้ๅ๏ผๅฟๅๅฝๆฐ็ๅๆฐไธบไธไธชๅ่ฐๅฝๆฐ
* ๅฆๆๆฏๅฏน่ฑก๏ผๅ
ๅฎนไธบไธ็ณปๅๅฑๆงๅผไธบๅฟๅๅฝๆฐ็ปๆ๏ผๅฟๅๅฝๆฐ็ๅๆฐไธบไธไธชๅ่ฐๅฝๆฐ
*
* ๅ่ฐๅฝๆฐ็็ฌฌไธไธชๅๆฐ๏ผๅนถ่กไปปๅกๆง่กๅคฑ่ดฅ็้่ฏฏไฟกๆฏ
* ็ฌฌไบไธชๅๆฐ๏ผๅค็็ๆฐๆฎ
*
* async.parallel ็ฌฌไบไธชๅๆฐไธญ็dataๆฏๆๆๅนถ่กไปปๅกๆง่กๅฎๆๅ๏ผๆฑ่ๆ็้ๅ
*/
console.time("time");
// ๅๆฐไธบๆฐ็ป
async.parallel([
(cb) => {
setTimeout(() => {
cb(null, "daotin");
}, 2000);
},
(cb) => {
setTimeout(() => {
cb(null, "lvonve");
}, 1000);
}
], (err, data) => {
if (!err) {
console.timeEnd("time"); // time: 2001.771ms
console.log(data); // ['daotin', 'lvonve']
}
});
// ๅๆฐไธบๅฏน่ฑก
// ๆๅ่ทๅๅฐ็dataไนๆฏๅฏน่ฑก๏ผๅฑๆงๅๅฐฑๆฏๅ้ข็ๅฑๆงๅใ
console.time("time");
async.parallel({
one(cb) {
setTimeout(() => {
cb(null, "123");
}, 2000);
},
two(cb) {
setTimeout(() => {
cb(null, "123");
}, 2000);
}
}, (err, data) => {
console.timeEnd("time"); // time: 2004.775ms
if (!err) {
console.log(data); //{ one: '123', two: '123' }
}
});
```
### ไธฒ่กๆ ๅ
ณ่ series
```js
console.time("time");
console.time("time1");
async.series({
one(cb) {
setTimeout(() => {
cb(null, "123");
}, 2000);
},
two(cb) {
console.timeEnd("time1"); //time1: 2004.965ms
setTimeout(() => {
cb(null, "456");
}, 1000);
}
}, (err, data) => {
console.timeEnd("time"); // time: 3010.950ms
if (!err) {
console.log(data); //{ one: '123', two: '456' }
}
});
```
ๅฏไปฅ็ๅฐ๏ผ้คไบๅ
ณ้ฎ่ฏ`series`ๅไบไนๅค๏ผๆ ผๅผ้ฝไธๆ ท๏ผๅชไธ่ฟๅทฒๆฏไธฒ่กไบใ
### ไธฒ่กๆๅ
ณ่ waterfall
> ๆณจๆ๏ผไธฒ่กๆๅ
ณ่็็ฌฌไธไธชๅๆฐๅฟ
้กปๆฏๆฐ็ป๏ผไธ่ฝๆฏๅฏน่ฑก
>
> ๆฐ็ปไธญ็ฌฌไธไธชไปปๅก็ๅ่ฐๅฝๆฐcb็็ฌฌไบไธชๅๆฐๅผๅงๆฏไผ ็ปไธไธไธชไปปๅก็ๅฎๅใ
>
> ็ฌฌไบไธชไปปๅกๅฝๆฐๅฝขๅๅๅ ไธชๅฐฑๆฏไธไธไธชไผ ไธๆฅ็ๅฎๅ๏ผ่ฟ้ๆฏnameๅฝขๅๅฏนๅบโdaotinโๅฎๅใ
```js
console.time("time");
console.time("time1");
async.waterfall([
cb => {
setTimeout(() => {
cb(null, 'daotin');
}, 2000);
},
(name, cb) => {
console.timeEnd('time1'); // time1: 2004.008ms
setTimeout(() => {
cb(null, 'lvonve-' + name);
}, 1000);
}
], (err, data) => {
console.timeEnd("time"); // time: 3008.387ms
if (!err) {
console.log(data); //lvonve-daotin
}
});
```
| Daotin/Web/10-Node.js/06-ๆฉๅฑasync.md/0 | {
"file_path": "Daotin/Web/10-Node.js/06-ๆฉๅฑasync.md",
"repo_id": "Daotin",
"token_count": 2056
} | 18 |
## ไธใfluxๆถๆ
ไปไนๆฏflux๏ผ
็ฎๅ่ฏด๏ผFlux ๆฏไธ็งๆถๆๆๆณ๏ผไธ้จ่งฃๅณ่ฝฏไปถ็็ปๆ้ฎ้ขใ
ไธ่ฌ**ไธญๅคงๅreact้กน็ฎ**ไผ็จๅฐ Flux๏ผไพฟไบ็ฎก็ๆฐๆฎๆจกๅใๅฐๅ้กน็ฎๅฐฑๆฒกๅฟ
่ฆไฝฟ็จไบใ
### 1ใๅบๆฌๆฆๅฟต
้ฆๅ
๏ผFluxๅฐไธไธชๅบ็จๅๆๅไธช้จๅใ
- **View**๏ผ ่งๅพๅฑ
- **Action**๏ผๅจไฝ๏ผ๏ผ่งๅพๅฑๅๅบ็ๆถๆฏ๏ผ็จๆฅไฟฎๆนๆฐๆฎๆจกๅ๏ผๆฏๅฆmouseClick๏ผ
- **Dispatcher**๏ผๆดพๅๅจ๏ผ๏ผ็จๆฅๆฅๆถActionsใๆง่กๅ่ฐๅฝๆฐ
- **Store**๏ผๆฐๆฎๅฑ๏ผ๏ผ็จๆฅๅญๆพๅบ็จ็็ถๆ๏ผไธๆฆๅ็ๅๅจ๏ผๅฐฑๆ้Views่ฆๆดๆฐ้กต้ข
![](./img/3.png)
> Flux ็ๆๅคง็น็น๏ผๅฐฑๆฏๆฐๆฎ็"ๅๅๆตๅจ"ใ
>
>
>
> 1. ็จๆท่ฎฟ้ฎ View๏ผ๏ผๅๆถๅฐViewไธญ่งๅพๆดๆฐ็ๅฝๆฐ่ตๅผ็ปStore็็ๅฌๅฝๆฐsubscribe๏ผ
> 2. View ๅๅบ็จๆท็ Action
> 3. Dispatcher ๆถๅฐ Action๏ผ่ฆๆฑ Store ่ฟ่ก็ธๅบ็ๆดๆฐ
> 4. Store ๆดๆฐๅ๏ผ๏ผ่งฆๅStore็subscribeๅฝๆฐๆฅๆดๆฐView่งๅพ๏ผ
### 2ใ็คบไพ
ๆๆ๏ผๅๅปบList็ปไปถๆพ็คบๅ่กจ๏ผ็นๅปๆทปๅ ๆ้ฎๆทปๅ ๆฐๆฎ๏ผ็นๅปๅ ้คๆ้ฎๅ ้คๆๅไธไธชๆฐๆฎใ
#### 2.1ใๅๅปบstore๏ผไฟๅญๆฐๆฎๆจกๅ
```jsx
export let store = {
state: {
list: [
{ name: 'ๅๅ1' },
{ name: 'ๅๅ2' },
{ name: 'ๅๅ3' },
{ name: 'ๅๅ4' },
]
},
}
```
#### 2.2ใๅๅปบaction
็นๅปๆ้ฎ็ๆถๅๆถๅๅๅปบใ
ๅๅปบ็ๆถๅๆทปๅ `type`ๅฑๆงๆฏไธบไบๅ่พจไนๅ่ฏฅๅฆไฝๆไฝstoreใ
```jsx
// List.js
import { store } from './store'
import dispatcher from './dispatcher'
export class List extends React.Component {
constructor() {
super();
// Listๅ ่ฝฝ็ๆถๅ๏ผ้่ฟstore.getList()ๅฝๆฐ่ทๅstore็ๆฐๆฎ
this.state = store.getList();
this.add = this.add.bind(this);
this.del = this.del.bind(this);
}
add() {
// ๅๅปบaction
let action = {
type: 'ADD_ITEM',
name: 'ๆฐ็ๅๅ'
}
}
del() {
// ๅๅปบaction
let action = {
type: 'DEL_ITEM'
}
}
render() {
let domList = this.state.list.map((item, i) => {
return (
<li key={i}>
{item.name}
</li>
);
})
return (
<div>
<button onClick={this.add}>ๆทปๅ </button>
<button onClick={this.del}>ๅ ้ค</button>
<ul>
{domList}
</ul>
</div>
)
}
}
```
> store็ๆฐๆฎ่ทๅไนไธ่ฝ็ดๆฅๆไฝ๏ผ่ๆฏ้่ฆstore่ชๅทฑๆไพ่ชๅฎไนๆนๆณๆๅฏไปฅใ
#### 2.3ใๅๅปบdispatcher
```jsx
// dispatcher.js
import flux from "flux";
import { store } from "./store";
let Dispatcher = flux.Dispatcher;
let dispatcher = new Dispatcher();
dispatcher.register(action => {
// ๅๆฐactionๅณๆฏ่ทๅๅฐaction็ๅผ
console.log(action);
})
export default dispatcher;
```
ไธบไบ่ฝ่ทๅๅฐaction๏ผๆไปฅๅจๅๅปบactionไนๅ๏ผ่ฟ่ฆๅ้็ปdispatcher๏ผ
```js
import dispatcher from './dispatcher'
add() {
let action = {
type: 'ADD_ITEM',
name: 'ๆฐ็ๅๅ'
}
dispatcher.dispatch(action);
}
del() {
let action = {
type: 'DEL_ITEM'
}
dispatcher.dispatch(action);
}
```
#### 2.4ใๆดๆฐstore
dispatcher่ทๅๅฐactionๅ้่ฆๆดๆฐstoreใไน้่ฆ่ฐ็จstoreๆไพ็่ชๅฎไนๆนๆณใ
```jsx
// store.js
export let store = {
state: {
list: [
{ name: 'ๅๅ1' },
{ name: 'ๅๅ2' },
{ name: 'ๅๅ3' },
{ name: 'ๅๅ4' },
]
},
getList() {
return this.state;
},
// ่ชๅฎไนๆไฝstoreๆนๆณ
addList(name) {
this.state.list.push({ name });
},
delList(name) {
this.state.list.pop();
},
}
```
```jsx
// dispatcher.js
import flux from "flux";
import { store } from "./store";
let Dispatcher = flux.Dispatcher;
let dispatcher = new Dispatcher();
dispatcher.register(action => {
// ๆ นๆฎtypeๆฅๆไฝไธๅ็storeๆนๆณ
switch (action.type) {
case 'ADD_ITEM':
store.addList(action.name);
break;
case 'DEL_ITEM':
store.delList();
break;
default:
break;
}
})
export default dispatcher;
```
#### 2.5ใๆดๆฐview
ๆญคๆถstoreๅทฒ็ปๆดๆฐ๏ผไฝๆฏviewๆฒกๆๆดๆฐ๏ผๅฆไฝๆดๆฐview๏ผ
> ๅจstoreๅฎไนไธไธชๅ้bindUpdate๏ผ็จๆฅ่ฐ็จview็ๆดๆฐๆนๆณใๅจListๅ ่ฝฝๆถๅฐฑๆbindUpdate่ตๅผไธบview็ๆดๆฐๆนๆณ๏ผๅช่ฆstore็ๆฐๆฎไธๆดๆฐ๏ผๅฐฑ่ฐ็จ่ฟไธชๆนๆณๆฅๆดๆฐ่งๅพใ
```jsx
export let store = {
state: {
list: [
{ name: 'ๅๅ1' },
{ name: 'ๅๅ2' },
{ name: 'ๅๅ3' },
{ name: 'ๅๅ4' },
]
},
// ๅฎไนๆดๆฐviewๅ้
bindUpdate: null,
getList() {
return this.state;
},
addList(name) {
// ๆดๆฐstore
this.state.list.push({ name });
// ๆง่กๆดๆฐview
this.bindUpdate();
},
delList(name) {
// ๆดๆฐstore
this.state.list.pop();
// ๆง่กๆดๆฐview
this.bindUpdate();
},
}
```
```jsx
import { store } from './store'
import dispatcher from './dispatcher'
export class List extends React.Component {
constructor() {
super();
this.state = store.getList();
this.add = this.add.bind(this);
this.del = this.del.bind(this);
}
componentDidMount = () => {
// Listๅ ่ฝฝๅฎๆๅๅฐbindUpdate่ตๅผไธบๆดๆฐๆนๆณ
store.bindUpdate = this.updateView.bind(this);
}
add() {
let action = {
type: 'ADD_ITEM',
name: 'ๆฐ็ๅๅ'
}
dispatcher.dispatch(action);
}
del() {
let action = {
type: 'DEL_ITEM'
}
dispatcher.dispatch(action);
}
// ๆดๆฐๆนๆณ๏ผ่ทๅstore.state็ๆๆฐๆฐๆฎ่ฟ่กๆดๆฐ
updateView() {
this.setState(store.state)
}
render() {
let domList = this.state.list.map((item, i) => {
return (
<li key={i}>
{item.name}
</li>
);
})
return (
<div>
<button onClick={this.add}>ๆทปๅ </button>
<button onClick={this.del}>ๅ ้ค</button>
<ul>
{domList}
</ul>
</div>
)
}
}
```
ไบๆฏไน๏ผๆดไธชๅๅๆตๅจๅพช็ฏๅฎๆใ
##### ไผๅviewๆดๆฐ
ไนๅview็ๆดๆฐๆฏ้่ฟๅฐList็ไธไธชๆดๆฐๆนๆณ่ตๅผ็ปstore็ไธไธชๅ้๏ผไฝๆฏๆไธช้ฎ้ขๆฏ๏ผๅฆๆๆๅพๅคไธช็ปไปถ็่ฏ๏ผๅฐฑ็ฑๅพๅคไธชstore๏ผๅฐฑ้่ฆๅพๅคไธชๅ้๏ผ้ฃๅฐฑๅคช้บป็ฆไบ๏ผๅ
ถๅ็งฐๅคด้ฝ่ตทๅคงไบใ
ๆไปฅ๏ผๆไปฌๅฏไปฅ้่ฟnode่ชๅธฆ็eventๅฏน่ฑกๆฅๅ่งๅฏ่
ๆจกๅผใ
```jsx
let EventEmitter = require('events').EventEmitter;
let event = new EventEmitter();
export let store = {
state: {
list: [
{ name: 'ๅๅ1' },
{ name: 'ๅๅ2' },
{ name: 'ๅๅ3' },
{ name: 'ๅๅ4' },
]
},
getList() {
return this.state;
},
addList(name) {
this.state.list.push({ name });
// ๆฏๆฌกๆฐๆฎๆจกๅๆๅๆด๏ผ่งฆๅupdateไบไปถ
event.emit('update');
},
delList(name) {
this.state.list.pop();
// ๆฏๆฌกๆฐๆฎๆจกๅๆๅๆด๏ผ่งฆๅupdateไบไปถ
event.emit('update');
},
bindUpdate(cb) {
// ็ๅฌupdateไบไปถ
event.on('update', cb);
},
unBindUpdate(cb) {
this.removeListener('update', cb);
}
}
```
ๅจList้้ขๅ ่ฝฝๅฎๆๅ่ฟ่ก็ปๅฎ`bindUpdate`ๅฝๆฐ๏ผ
ๅธ่ฝฝ็ๆถๅ็ปๅฎ`unBindUpdate`ๅฝๆฐ๏ผ
```js
componentDidMount = () => {
store.bindUpdate(this.updateView.bind(this));
}
componentWillUnmount() {
store.unBindUpdate(this.updateView.bind(this));
}
```
่ฟๆถๅไธ็ฎกๆๅคๅฐไธช็ปไปถ๏ผ้ฝๅฏไปฅไฝฟ็จbindUpdateๅunBindUpdate่ฟ่ก่งๅพๆดๆฐใ
##### ็ปง็ปญไผๅ
ๆไปฌไฝฟ็จevent็ๆถๅ๏ผnewไบไธไธชๅฏน่ฑก๏ผๅฏๆฏๅฐฑๅช็จๅฐไบonๅemitๆนๆณ๏ผๅคชๆตช่ดนๅ
ๅญไบใ
ๆไปฌๅ็ฐeventๅฏน่ฑกไธญๅ
ถๅฎๆฒกๆonๅemitๆนๆณ๏ผ่ฟไบๆนๆณ้ฝๆฏEventEmitterๅๅๅฏน่ฑกไธญ็๏ผ้ฃไนๆไปฌ็ดๆฅๆEventEmitterๅๅๅฏน่ฑกๆฟ่ฟๆฅๅฐฑๅฅฝไบใ
```jsx
let EventEmitter = require('events').EventEmitter;
export let store = {
state: {
list: [
{ name: 'ๅๅ1' },
{ name: 'ๅๅ2' },
{ name: 'ๅๅ3' },
{ name: 'ๅๅ4' },
]
},
// ๆEventEmitter.prototypeๅ
จ้จcopy่ฟๆฅ๏ผๅฐฑไธ้่ฆnewไบใ
...EventEmitter.prototype,
getList() {
return this.state;
},
addList(name) {
this.state.list.push({ name });
// ๆง่กๆดๆฐ
// this.bindUpdate();
this.emit('update');
},
delList(name) {
this.state.list.pop();
// ๆง่กๆดๆฐ
this.emit('update');
},
bindUpdate(cb) {
this.on('update', cb);
}
}
```
่ฐ็จ็ๆถๅ๏ผ็ดๆฅไฝฟ็จthis.onๅthis.emitๅฐฑๅฏไปฅไบใ
##### ไผๅstoreๅviewๆดๆฐ
ไนๅstore็ๆดๆฐๆนๅผๆฏๅจdispatcherไธญ่ฐ็จstore็ๆดๆฐๅไธชๆดๆฐๆนๆณ่ฟ่กๆดๆฐ๏ผๅฆๆๆนๆณๅพๅค็่ฏ๏ผๅฐฑ่ฆๅๅพๅคๆนๆณๆฏ่พ้บป็ฆใๅนถไธๆฏไธชๆนๆณไธญ้ฝ้่ฆemitๆดๆฐ่งๅพใ
![](./img/4.png)
![](./img/5.png)
ๆไปฅๆไปฌๅจstoreไธญๅขๅ ไธไธช็ฑปไผผreact็setStateๆนๆณ๏ผไธๆฌกๆงๆดๆนๆๆstore็stateใ
![](./img/6.png)
![](./img/7.png)
#### 2.6ใ่งๅพๅๅฑ
ๆไปฌไนๅList็ปไปถ่งๅพ็ๆพ็คบๅ้ป่พๅค็ไปฃ็ ๆฏๅๅจไธ่ตท็๏ผ่งๅพๅๅฑๅฐฑๆฏๆไปไปฌๅๅผใ
ๅๅผๅๅไธบ`ๅฎนๅจ็ปไปถ`ๅ`UI็ปไปถ`
UI็ปไปถๅค่ด่ดฃ่งๅพๆพ็คบ๏ผ
ๅฎนๅจ็ปไปถๅ
่ฃนUI๏ผๅนถ่ด่ดฃ้ป่พๅค็ใ
็ฐๅจๅฐListๅๅฑ๏ผ
ๅฎนๅจ็ปไปถไธบ๏ผ`ListController.js`
UI็ปไปถไธบ๏ผ`List.js`
```js
// List.js
export class List extends React.Component {
constructor() {
super();
}
render() {
let domList = this.props.list.map((item, i) => {
return (
<li key={i}>
{item.name}
</li>
);
})
return (
<div>
<button onClick={this.props.add}>ๆทปๅ </button>
<button onClick={this.props.del}>ๅ ้ค</button>
<ul>
{domList}
</ul>
</div>
)
}
}
```
```jsx
//ListController.js
import { store } from '../store'
import dispatcher from '../dispatcher'
import { List } from './List'
export class ListController extends React.Component {
constructor() {
super();
this.state = store.getState();
this.add = this.add.bind(this);
this.del = this.del.bind(this);
}
componentDidMount = () => {
store.bindUpdate(this.updateView.bind(this));
}
componentWillUnmount() {
store.unBindUpdate(this.updateView.bind(this));
}
add() {
let action = {
type: 'ADD_ITEM',
name: 'ๆฐ็ๅๅ'
}
dispatcher.dispatch(action);
}
del() {
let action = {
type: 'DEL_ITEM'
}
dispatcher.dispatch(action);
}
updateView() {
this.setState(store.state)
}
render() {
// ่ฐ็จList UI็ปไปถ
return <List list={this.state.list} add={this.add} del={this.del} />
}
}
```
### 3ใflux้กน็ฎๆ่ทฏ
1ใๅฐ่งๅพ้จๅ็้กต้ข็ปไปถๆๅๆๅฎนๅจ็ปไปถๅUI็ปไปถ
ๅฎนๅจ็ปไปถๅฏ็ปงๆฟ ๅฐ่ฃ
ๅฅฝ็ Controller ไปฅ่ชๅจๅฎ็ฐ็ปๅฎๆดๆฐ่งๅพๆนๆณๅๅธ่ฝฝ็ปไปถๆถ่ชๅจ่งฃ็ป๏ผ้ฟๅ
ๆๆๅฎนๅจ็ปไปถๅ็ธๅ็ไปฃ็ ใ
๏ผๅ
ถไธญๅทฎๅผ้จๅๅไธช็ปไปถ็store้่ฟๆ้ ๅฝๆฐ็็ฌฌไบไธชๅๆฐไผ ๅ
ฅใ๏ผ
```jsx
export class Controller extends React.Component {
constructor(props, store) {
super(props);
this.store = store;
this.state = this.store.getState();
this.store.subscribe(this.updateView.bind(this));
}
updateView() {
this.setState(this.store.getState());
}
componentWillUnmount() {
this.store.unBindUpdate(this.updateView.bind(this));
}
}
```
> Controller ไนๆไปฅ็ปงๆฟ React.Componentๆฏๅ ไธบๅฎนๅจ็ปไปถ้่ฆ๏ผไฝๆฏๅไธ่ฝๅๆถ็ปงๆฟControllerๅReact.Component๏ผๆไปฅ้ๅ่ฟ็งๅตๅฅ็ปงๆฟ็ๆนๅผใ
UI็ปไปถๆๆๆฐๆฎ(็นๅป็ญๅ็งไบไปถๆ่ฐ็จ็ๅฝๆฐ)ๅๆฅ่ชไบprops(็ฑๅฎนๅจ็ปไปถไผ ๅ
ฅ)
็ฑปไผผไปฅไธๆนๅผ๏ผ
```jsx
render() {
return <Home {...this.state} />
}
```
`<Home />` ๅณๆฏUI็ปไปถใ
this.state ๅช้ๆฅๅข๏ผ
ๆฅ่ชๅฏนๅบ็store๏ผthis.state = HomeStore.getState();
store็stateๆฅ่ชๅช้ๅข๏ผ
ๆฅ่ช้กต้ขๅ ่ฝฝๆถajax่ฏทๆฑ๏ผ่ฏทๆฑๅฐๆฐๆฎๅๅ
ฅstoreใ
ๆข็ถ่ฆๆไฝstore๏ผ้ฃไนๅฐฑ่ฆ้่ฟaction->dispatcher->store->view็้กบๅบๆฅใ
2ใๅๅปบactionๅทฅๅๅฝๆฐ
- ๅฎไนไธไธชๅๅงๅ ็actionๅทฅๅๅฝๆฐ
- ่ฏทๆฑ้่ฆ็ๆฐๆฎ
- ๅฐๆฟๅฐ็ๆฐๆฎๅฐ่ฃ
ๅฐ actionไธญ
- ๅฐactionๅ้ๅฐdispatcher (้่ฟ.dispatch()ๆนๆณ)
3ใๅจๆดพๅๅจdispatcherไธญ้
็ฝฎๅฏนๅบ็case
ๅนถไธไปactionไธญๆฟๅฐๆฐๆฎๅ๏ผ่ฎพ็ฝฎๅฐๅฏนๅบstoreไธญๅณๅฏ
้่ฟๅ่ช็ปไปถ็็ฑปไผผ`HomeStore.setState(action);`ๆนๅผ่ฟ่ก่ฎพ็ฝฎใ
store็stateๆดๆฐไบ๏ผๆณจๆ้่ฆๅจๅฎนๅจ็ปไปถๅ ่ฝฝๅฎๆๅ็ปๅฎ่งๅพๆดๆฐๆนๆณ๏ผ่งๅพๆดๆฐๆนๆณๅฐฑๆฏ็ปไปถ่ทๅๆๆฐstore็stateๆฐๆฎใ
4ใๅจๅฎนๅจ็ปไปถ็ๅ ่ฝฝๅฎๆ็็ๅฝๅจๆๅฝๆฐไธญ๏ผ่ฐ็จไธ่ฟฐๆญฅ้ชคๅฐ่ฃ
ๅฅฝ็actionๅทฅๅๅฝๆฐ๏ผไนๅฐฑๆฏๆๅผ้กต้ข็ๆถๅ่ฟ่กajax่ฏทๆฑ๏ผ
5ใ่ทฏ็ฑ้จๅๅผๅ
ฅ็็ปไปถ ๆณจๆ้่ฆๅๆขๆๅฎนๅจ็ปไปถใ
## ็ฎๆflux้กน็ฎ
้พๆฅ๏ผhttps://github.com/Daotin/daotin.github.io/issues/132#issue-602918224
| Daotin/Web/13-React/05-Fluxๆถๆ.md/0 | {
"file_path": "Daotin/Web/13-React/05-Fluxๆถๆ.md",
"repo_id": "Daotin",
"token_count": 8268
} | 19 |
## ไธใๆฅๅฃ
jsไธญ็ฑป็ๆฅๅฃๅฎไน๏ผ
```typescript
interface Human {
run();
eat();
}
```
> ๆฅๅฃ็ๆนๆณๆฒกๆๆนๆณไฝใ
>
> ๅฎ็ฐๆฅๅฃ็็ฑป๏ผๅฟ
้กปๅฎ็ฐๆฅๅฃไธญ็ๆๆๆนๆณใ
## ไบใไพ่ตๆณจๅ
ฅ(ๆๅก)
ไพ่ตๆณจๅ
ฅๅฐฑๆฏ่ชๅทฑๅๅปบไธไธชๆๅก๏ผๆๅก็ๆฌ่ดจๅฐฑๆฏไธไธช็ฑป๏ผ๏ผ็ถๅๅจไฝฟ็จ็ฑป็ๆถๅ๏ผไธ้่ฆ่ชๅทฑnew็ฑป็ๅฎไพ๏ผๅช้่ฆๆ็
ง็นๅฎ็ๆนๅผๆณจๅ
ฅ๏ผ็ฑป็ๅฎไพๅฐฑไผ่ขซ่ชๅจๅๅปบ๏ผ็ถๅ็ดๆฅไฝฟ็จๅณๅฏใ
### 1ใๅๅปบๆๅก
```js
ng g service services/DIYMath // ng g s services/DIYMath
```
ๅๅปบ็ๆถๅไผๆไธช่ญฆๅ`WARNING Service is generated but not provided, it must be provided to be used` ๆชๅผๅ
ฅๆๅก๏ผๅ้ขๆณจๆๅผๅ
ฅใ
### 2ใๅฎ็ฐๆๅก้ป่พไปฃ็
```typescript
import { Injectable } from '@angular/core';
// ๆๅก่ฃ
้ฅฐๅจ
// ไฝ็จ๏ผๆญคๆๅกๅฏไปฅๅ่ฐ็จๅซ็ๆๅก
@Injectable()
export class DIYMathService {
// ๅฆๆ่ฐ็จๅซ็ๆๅก
constructor(private xxx:newDIYMath) { }
// ๅ
add(a: number, b: number): number {
return a * 1 + b * 1;
}
// ๅ
reduce(a: number, b: number): number {
return a * 1 - b * 1;
}
}
```
### 3ใๅจไธปๆจกๅไธญๆณจๅ
ฅๆๅก
```typescript
// app.module.ts
providers: [DIYMathService],
```
> ๅฆๆๆชๅจไธปๆจกๅไธญๆณจๅ
ฅๆๅก็่ฏ๏ผไผๆฅ`DI Error` ้่ฏฏใ
### 4ใๅจ็ปไปถไธญไฝฟ็จๆๅก
```typescript
// a.component.ts
import { DIYMathService } from 'app/services/diymath.service';
export class AComponent implements OnInit {
constructor(
// ไฝฟ็จDIYMathServiceๆๅก
private dm: DIYMathService
) { }
a: number = 0;
b: number = 0;
alg: string = '+';
result: number = 0;
opt() {
this.result = this.dm[this.alg](this.a, this.b);
}
ngOnInit() {
}
}
```
```html
<!-- a.component.html -->
<div>
<input type="text" [(ngModel)]="a">
<select (change)="opt()" [(ngModel)]="alg">
<option value="add">+</option>
<option value="reduce">-</option>
</select>
<input type="text" [(ngModel)]="b">
= <span>{{result}}</span>
</div>
```
### 5ใTips
ๅฆๆๆญคๆถๆไปฌ็้กน็ฎๆๅพๅคๅฐๆนไฝฟ็จไบDIYMathServiceๆๅก๏ผไฝๆฏๆไปฌๅๅๅปบไบไธไธชๆฐ็ๆๅกNewDIYMathService๏ผๅฎๆฏDIYMathService่ฆๅฅฝ๏ผๆไปฅๆไปฌๅๅฐ้กน็ฎไธญๆๆ็DIYMathServiceๆฟๆขๆNewDIYMathService๏ผๆไนๆฟๆข๏ผไธไธชไธชๆๆน๏ผ
ไธ้่ฆ๏ผๅช้่ฆๅจๆณจๅ
ฅไธปๆจกๅ็ๆถๅ๏ผ**ๆ็พๅคดๅ็่**ๅณๅฏ๏ผ
```
ๅฐ
providers: [DIYMathService],
ๆนไธบ๏ผ
providers: [{ provide: DIYMathService, useClass: NewDIYMathService }],
```
> ๅ
ถๅฎ`providers: [DIYMathService]`
>
> ๅฐฑ็ธๅฝไบ`providers: [{ provide: DIYMathService, useClass: DIYMathService}]`
> ๆณจๆ๏ผๅฆๆๆ็พๅคดๅ็่๏ผ้ฃไนๅจ็่็ๆๅก้้ขไธ่ฝๅผๅ
ฅ็พๅคดๆๅก๏ผๅฆๅๆฅ้๏ผ
ไนๅฐฑๆฏไธ้ข็ๅๆณๆฅ้๏ผ
```typescript
import { Injectable } from '@angular/core';
import { DIYMathService } from './diymath.service';
@Injectable()
// ็่
export class NewDIYMathService {
// ๅผๅ
ฅ็พๅคด
constructor(public dm: DIYMathService) { }
// ...
}
```
![](./img/8.png)
## ไธใhttpไปฃ็
็ฑไบangularๆฒกๆไฝฟ็จwebpack๏ผๆไปฅhttpไปฃ็็้
็ฝฎๅไนๅ็ไธๅใ
ๅฆไฝ่ฎพ็ฝฎhttpไปฃ็๏ผ
1ใๆฐๅปบhttpไปฃ็ๆไปถ๏ผโ **ๆไปถๅญๆพๅจ้กน็ฎๆ น็ฎๅฝไธ**๏ผ
```json
// proxy.config.json
{
"/zhuiszhu": {
"target": "http://www.projectlog.top:3000"
}
}
```
2ใๆทปๅ ๅฐ้กน็ฎๅฏๅจไธญ
```json
// package.json
"scripts": {
"start": "ng serve --proxy-config proxy.config.json",
},
```
> ๐ก ่ฎฐๅพ่ฆ้ๅฏๆๅกๅฆ๏ผ
3ใๅ่ตทhttp่ฏทๆฑ
angularๆๅ
็ฝฎ็http่ฏทๆฑๆๅก๏ผๅช้่ฆๆณจๅ
ฅๅณๅฏไฝฟ็จใ
```js
import { Http } from '@angular/http';
export class HomeComponent implements OnInit {
// ๆณจๅ
ฅไฝฟ็จHttpๆๅก
constructor(private http: Http) { }
ngOnInit() {
// ๅ่ตทajax่ฏทๆฑ
this.http.get('/zhuiszhu/goods/getList').subscribe(res => {
// res.json()ๅฏไปฅ่ทๅ็ๆณ่ฆ็ๆฐๆฎ
console.log(res.json());
})
}
}
```
| Daotin/Web/14-Angular/04-ๆฅๅฃ๏ผไพ่ตๆณจๅ
ฅ๏ผhttpไปฃ็.md/0 | {
"file_path": "Daotin/Web/14-Angular/04-ๆฅๅฃ๏ผไพ่ตๆณจๅ
ฅ๏ผhttpไปฃ็.md",
"repo_id": "Daotin",
"token_count": 2171
} | 20 |
Manifest-Version: 1.0
Class-Path:
| Humsen/web/web-core/src/META-INF/MANIFEST.MF/0 | {
"file_path": "Humsen/web/web-core/src/META-INF/MANIFEST.MF",
"repo_id": "Humsen",
"token_count": 15
} | 21 |
package pers.husen.web.common.constants;
/**
* ๆฐๆฎๅบๅญๆฎตๅธธ้
*
* @author ไฝๆ่
*
* 2017ๅนด11ๆ8ๆฅ
*/
public class DbConstans {
/** ๆฐๆฎๅบๅญๆฎตๆๆ็ถๆ */
public static final int FIELD_VALID_FLAG = 0;
/** ๆฐๆฎๅบๅญๆฎตๅ ้ค็ถๆ */
public static final int FIELD_DELETED_FLAG = 1;
} | Humsen/web/web-core/src/pers/husen/web/common/constants/DbConstans.java/0 | {
"file_path": "Humsen/web/web-core/src/pers/husen/web/common/constants/DbConstans.java",
"repo_id": "Humsen",
"token_count": 159
} | 22 |
/**
* ้็จๅฉๆ
*
* @author ไฝๆ่
*
* 2017ๅนด10ๆ21ๆฅ
*/
package pers.husen.web.common.helper; | Humsen/web/web-core/src/pers/husen/web/common/helper/package-info.java/0 | {
"file_path": "Humsen/web/web-core/src/pers/husen/web/common/helper/package-info.java",
"repo_id": "Humsen",
"token_count": 54
} | 23 |
package pers.husen.web.dao;
/**
* @author ไฝๆ่
*
* 2017ๅนด9ๆ30ๆฅ
*/
public interface VisitTotalDao {
/**
* ๆฅ่ฏขๆๆ่ฎฟ้ฎ้
* @return
*/
public int queryVisitTotal();
/**
* ๆฅ่ฏขๅฝๆฅ่ฎฟ้ฎ้
* @return
*/
public int queryVisitToday();
/**
* ๆดๆฐๅฝๆฅ่ฎฟ้ฎ้ๅๆป่ฎฟ้ฎ้
*
* @param visitDate
* @return
*/
public int updateVisitCount();
}
| Humsen/web/web-core/src/pers/husen/web/dao/VisitTotalDao.java/0 | {
"file_path": "Humsen/web/web-core/src/pers/husen/web/dao/VisitTotalDao.java",
"repo_id": "Humsen",
"token_count": 192
} | 24 |
package pers.husen.web.dbutil.mappingdb;
/**
* @author ไฝๆ่
* @desc ๆ็ซ ๅ็ฑปๆฐๆฎๅบๆ ๅฐ
* @created 2017ๅนด12ๆ12ๆฅ ไธๅ10:14:34
*/
public class ArticleCategoryMapping {
/**
* ๆฐๆฎๅบๅ็งฐ
*/
public static final String DB_NAME = "article_category";
public static final String CATEGORY_ID = "category_id";
public static final String CATEGORY_NAME = "category_name";
public static final String CREATE_DATE = "create_date";
public static final String CATEGORY_DELETE = "category_delete";
} | Humsen/web/web-core/src/pers/husen/web/dbutil/mappingdb/ArticleCategoryMapping.java/0 | {
"file_path": "Humsen/web/web-core/src/pers/husen/web/dbutil/mappingdb/ArticleCategoryMapping.java",
"repo_id": "Humsen",
"token_count": 217
} | 25 |
package pers.husen.web.service;
import java.util.ArrayList;
import pers.husen.web.bean.vo.MessageAreaVo;
import pers.husen.web.dao.MessageAreaDao;
import pers.husen.web.dao.impl.MessageAreaDaoImpl;
/**
* @author ไฝๆ่
*
* 2017ๅนด9ๆ25ๆฅ
*/
public class MessageAreaSvc implements MessageAreaDao{
private static final MessageAreaDaoImpl messageAreaDaoImpl = new MessageAreaDaoImpl();
@Override
public ArrayList<MessageAreaVo> queryAllMessageArea(int messageId) {
return messageAreaDaoImpl.queryAllMessageArea(messageId);
}
@Override
public int insertMessageNew(MessageAreaVo mVo) {
return messageAreaDaoImpl.insertMessageNew(mVo);
}
}
| Humsen/web/web-core/src/pers/husen/web/service/MessageAreaSvc.java/0 | {
"file_path": "Humsen/web/web-core/src/pers/husen/web/service/MessageAreaSvc.java",
"repo_id": "Humsen",
"token_count": 231
} | 26 |
package pers.husen.web.servlet.image;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import pers.husen.web.common.handler.ImageDownloadHandler;
/**
* ๅพ็ไธ่ฝฝ
*
* @author ไฝๆ่
*
* 2017ๅนด10ๆ20ๆฅ
*/
@WebServlet(urlPatterns= {"/imageDownload.hms", "/imageDownload"})
public class ImageDownloadSvt extends HttpServlet {
private static final long serialVersionUID = 1L;
public ImageDownloadSvt() {
super();
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ImageDownloadHandler iHandler = new ImageDownloadHandler();
iHandler.imageDownloadHandler(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
} | Humsen/web/web-core/src/pers/husen/web/servlet/image/ImageDownloadSvt.java/0 | {
"file_path": "Humsen/web/web-core/src/pers/husen/web/servlet/image/ImageDownloadSvt.java",
"repo_id": "Humsen",
"token_count": 357
} | 27 |
# web
ไธชไบบ็ฝ็ซ้กน็ฎ๏ผๅ
ๆฌๅๅฎขใไปฃ็ ๅบใๆไปถไธ่ฝฝใ็่จใ็ปๅฝๆณจๅ็ญๅ่ฝ
็ฝๅ๏ผwww.hemingsheng.cn
------------
## ไธป่ฆๆไปถ็ปๆๅฆไธ
- `WebContent` -> ๅ็ซฏๆบๆไปถ ๏ผๅ็ซฏไธๆนๆไปถๅจ`/WebContent/plugins`ไธ๏ผ
- `config` -> ้
็ฝฎๆไปถ
- `docs` -> ่ฏดๆๆๆกฃ
- `libs` -> ๅ็ซฏjarๅ
- `src` -> ๅ็ซฏๆบๆไปถ
------------
### webๅทฅ็จ็ฎๅฝ็ปๆๅฆไธ๏ผ
web:
โ .classpath
โ .gitattributes
โ .gitignore
โ .project
โ README.md
โ
โโconfig
โ db_connect_info.properties
โ log4j2.xml
โ
โโdocs
โ webๅ็ซฏๅฝๅ่ง่.txt
โ web้กน็ฎๅ็ซฏๅฝๅ่ง่.txt
โ ็ฝ็ซlogoๅพ็.png
โ
โโlibs
โ โโfile
โ โ commons-fileupload-1.3.3.jar
โ โ commons-io-2.5.jar
โ โ
โ โโjavamail
โ โ javax.mail.jar
โ โ
โ โโjson
โ โ commons-beanutils-1.7.0.jar
โ โ commons-collections-3.1.jar
โ โ commons-lang-2.5.jar
โ โ commons-logging.jar
โ โ ezmorph-1.0.3.jar
โ โ json-lib-2.4-jdk15.jar
โ โ
โ โโlog4j
โ โ log4j-api-2.8.2.jar
โ โ log4j-core-2.8.2.jar
โ โ
โ โโpsql
โ โ postgresql-42.1.4.jar
โ โ
โ โโservlet
โ servlet-api.jar
โ
โโsrc
โ โ rebel.xml
โ โ
โ โโpers
โ โโhusen
โ โโweb
โ โ package-info.java
โ โ
โ โโbean
โ โ โ package-info.java
โ โ โ
โ โ โโpo
โ โ โ AccessAtatisticsPo.java
โ โ โ ImageUploadPo.java
โ โ โ package-info.java
โ โ โ
โ โ โโvo
โ โ BlogArticleVo.java
โ โ CodeLibraryVo.java
โ โ FileDownloadVo.java
โ โ ImageUploadVo.java
โ โ MessageAreaVo.java
โ โ package-info.java
โ โ ReleaseFeatureVo.java
โ โ UserInfoVo.java
โ โ VisitTotalVo.java
โ โ
โ โโcommon
โ โ โ package-info.java
โ โ โ
โ โ โโconstants
โ โ โ BootstrapConstans.java
โ โ โ CommonConstants.java
โ โ โ package-info.java
โ โ โ
โ โ โโhandler
โ โ โ FileDownloadHandler.java
โ โ โ FileUploadHandler.java
โ โ โ ImageDownloadHandler.java
โ โ โ ImageUploadHandler.java
โ โ โ package-info.java
โ โ โ
โ โ โโhelper
โ โ โ DateFormatHelper.java
โ โ โ package-info.java
โ โ โ RandomCodeHelper.java
โ โ โ SendEmailHelper.java
โ โ โ StackTrace2Str.java
โ โ โ TypeConvertHelper.java
โ โ โ
โ โ โโtemplate
โ โ โโhtml
โ โ BlogTemplate.java
โ โ CodeTemplate.java
โ โ GenericTemplate.java
โ โ
โ โโconfig
โ โ DeployPathConfig.java
โ โ Log4j2Config.java
โ โ package-info.java
โ โ
โ โโdao
โ โ โ BlogArticleDao.java
โ โ โ CodeLibraryDao.java
โ โ โ FileDownloadDao.java
โ โ โ ImageUploadDao.java
โ โ โ MessageAreaDao.java
โ โ โ ReleaseFeatureDao.java
โ โ โ UserInfoDao.java
โ โ โ VisitTotalDao.java
โ โ โ
โ โ โโimpl
โ โ BlogArticleDaoImpl.java
โ โ CodeLibraryDaoImpl.java
โ โ FileDownloadDaoImpl.java
โ โ ImageUploadDaoImpl.java
โ โ MessageAreaDaoImpl.java
โ โ ReleaseFeatureDaoImpl.java
โ โ UserInfoDaoImpl.java
โ โ VisitTotalDaoImpl.java
โ โ
โ โโdbutil
โ โ โ DbDeleteUtils.java
โ โ โ DbInsertUtils.java
โ โ โ DbQueryUtils.java
โ โ โ DbUpdateUtils.java
โ โ โ
โ โ โโassist
โ โ โ AssistUtils.java
โ โ โ DbConnectUtils.java
โ โ โ package-info.java
โ โ โ SetPsParamUtils.java
โ โ โ TypeTransformUtils.java
โ โ โ
โ โ โโmappingdb
โ โ BlogDetailsMapping.java
โ โ CodeLibraryMapping.java
โ โ FileDownloadMapping.java
โ โ ImageUploadMapping.java
โ โ MessageAreaMapping.java
โ โ package-info.java
โ โ ReleaseFeatureMapping.java
โ โ UserInfoMapping.java
โ โ VisitTotalMapping.java
โ โ
โ โโlistener
โ โ OnlineCountListener.java
โ โ package-info.java
โ โ WebInitConfigListener.java
โ โ
โ โโservice
โ โ BlogArticleSvc.java
โ โ CodeLibrarySvc.java
โ โ FileDownloadSvc.java
โ โ ImageUploadSvc.java
โ โ MessageAreaSvc.java
โ โ ReleaseFeatureSvc.java
โ โ UserInfoSvc.java
โ โ VisitTotalSvc.java
โ โ
โ โโservlet
โ โ package-info.java
โ โ
โ โโblog
โ โ BlogArticlePerPageServlet.java
โ โ BlogArticleServlet.java
โ โ BlogPerByIdServlet.java
โ โ BlogTotalCountServlet.java
โ โ NewBlogUploadServlet.java
โ โ
โ โโcodelib
โ โ CodeLibPerPageServlet.java
โ โ CodeLibraryServlet.java
โ โ CodeLibTotalCountServlet.java
โ โ CodePerByIdServlet.java
โ โ NewCodeUploadServlet.java
โ โ
โ โโcommon
โ โ AccessAtatisticsServlet.java
โ โ
โ โโcontact
โ โ SendEmailServlet.java
โ โ
โ โโdownload
โ โ FileDownloadServlet.java
โ โ FileDownPerPageServlet.java
โ โ FileDownTotalCountServlet.java
โ โ FileUploadServlet.java
โ โ
โ โโimage
โ โ ImageDownloadServlet.java
โ โ ImageUploadServlet.java
โ โ package-info.java
โ โ
โ โโmessage
โ โ MessageGetServlet.java
โ โ MessageUploadServlet.java
โ โ
โ โโreleasefea
โ โ LatestReleaseFeatureServlet.java
โ โ NewReleaseFeatureServlet.java
โ โ
โ โโuserinfo
โ UserInfoModifyServlet.java
โ UserInfoQueryServlet.java
โ UserInfoRegisterServlet.java
โ UserLoginValidateServlet.java
โ
โโWebContent
โ index.jsp
โ
โโcss
โ โโarticle
โ โ article.css
โ โ
โ โโcontact
โ โ contact.css
โ โ
โ โโdownload
โ โ download.css
โ โ
โ โโerror
โ โ error.css
โ โ
โ โโindex
โ โ article-profile.css
โ โ index.css
โ โ version-feature.css
โ โ
โ โโlogin
โ โ email-check.css
โ โ login.css
โ โ retrive-pwd.css
โ โ
โ โโmessage
โ โ message.css
โ โ pager.css
โ โ
โ โโnavigation
โ โ left-menu-bar.css
โ โ rightbar.css
โ โ topbar.css
โ โ
โ โโpersonal_center
โ โ modify-email.css
โ โ modify-pwd.css
โ โ modify-userinfo.css
โ โ mycenter.css
โ โ
โ โโupload
โ editor-article.css
โ
โโerror
โ error.jsp
โ
โโimages
โ โ favicon.ico
โ โ mainbg.png
โ โ
โ โโbackground
โ โ bg-1.jpg
โ โ bg-2.jpg
โ โ bg-3.jpg
โ โ bg-4.jpg
โ โ
โ โโmessage
โ head-0.jpg
โ head-1.jpg
โ head-2.jpg
โ head-3.jpg
โ head-4.jpg
โ head-5.jpg
โ head-6.jpg
โ head-7.jpg
โ head-8.jpg
โ
โโjs
โ โ customize-sdk.js
โ โ is-pc-or-mobile.js
โ โ pagination.js
โ โ
โ โโarticle
โ โ article-markdown.js
โ โ blog.js
โ โ code-library.js
โ โ
โ โโcontact
โ โ contact.js
โ โ
โ โโdownload
โ โ download.js
โ โ
โ โโeditor
โ โ editor.js
โ โ
โ โโindex
โ โ latestblog.js
โ โ latestcode.js
โ โ version-feature.js
โ โ
โ โโlogin
โ โ formvalidator.js
โ โ
โ โโmessage
โ โ message.js
โ โ pager.js
โ โ
โ โโnavigation
โ โ left-menu-bar.js
โ โ topbar.js
โ โ
โ โโpersonal_center
โ modify-email.js
โ modify-pwd.js
โ modify-userinfo.js
โ personal-center.js
โ
โโlogin
โ email_check.html
โ login.jsp
โ retrive_pwd.html
โ
โโMETA-INF
โ MANIFEST.MF
โ
โโmodule
โ blog.jsp
โ code_library.jsp
โ contact.jsp
โ download.jsp
โ message.jsp
โ
โโnavigation
โ rightbar.jsp
โ topbar.jsp
โ
โโpersonal_center
โ modify_email.html
โ modify_email1.html
โ modify_pwd.html
โ modify_userinfo.html
โ mycenter.jsp
โ
โโplugins
โ โ plugins.jsp
โ โ
โ โโbootstrap
โ โ โโcss
โ โ โ bootstrap.css
โ โ โ bootstrap.css.map
โ โ โ bootstrap.min.css
โ โ โ bootstrap.min.css.map
โ โ โ
โ โ โโfonts
โ โ โ glyphicons-halflings-regular.eot
โ โ โ glyphicons-halflings-regular.svg
โ โ โ glyphicons-halflings-regular.ttf
โ โ โ glyphicons-halflings-regular.woff
โ โ โ glyphicons-halflings-regular.woff2
โ โ โ
โ โ โโjs
โ โ bootstrap.js
โ โ bootstrap.min.js
โ โ
โ โโeditormd
โ โโjquery
โ โ โโjs
โ โ jquery-3.2.1.min.js
โ โ jquery.cookie.js
โ โ jquery.easing.1.3.js
โ โ jquery.flexslider-min.js
โ โ jquery.form.min.js
โ โ jquery.waypoints.min.js
โ โ
โ โโjqueryconfirm
โ โ โโcss
โ โ โ jquery-confirm.min.css
โ โ โ
โ โ โโjs
โ โ jquery-confirm.min.js
โ โ
โ โโjson
โ โ โโjs
โ โ json2.js
โ โ
โ โโtemplate
โ โ โโcss
โ โ โ animate.css
โ โ โ flexslider.css
โ โ โ icomoon.css
โ โ โ style.css
โ โ โ style.css.map
โ โ โ
โ โ โโjs
โ โ main.js
โ โ modernizr-2.6.2.min.js
โ โ
โ โโvalidator
โ โโcss
โ โ bootstrapValidator.css
โ โ bootstrapValidator.min.css
โ โ
โ โโjs
โ โ bootstrapValidator.js
โ โ bootstrapValidator.min.js
โ โ
โ โโlanguage
โ ar_MA.js
โ be_FR.js
โ be_NL.js
โ bg_BG.js
โ cs_CZ.js
โ da_DK.js
โ de_DE.js
โ en_US.js
โ es_CL.js
โ es_ES.js
โ fa_IR.js
โ fr_FR.js
โ gr_EL.js
โ he_IL.js
โ hu_HU.js
โ id_ID.js
โ it_IT.js
โ ja_JP.js
โ nl_NL.js
โ no_NO.js
โ pl_PL.js
โ pt_BR.js
โ pt_PT.js
โ ro_RO.js
โ ru_RU.js
โ sq_AL.js
โ sr_RS.js
โ sv_SE.js
โ th_TH.js
โ tr_TR.js
โ ua_UA.js
โ vi_VN.js
โ zh_CN.js
โ zh_TW.js
โ
โโupload
โ editor_article.jsp
โ upload_file.jsp
โ
โโWEB-INF
โ web.xml
โ
โโlib
| Humsen/web/web-mobile/README.md/0 | {
"file_path": "Humsen/web/web-mobile/README.md",
"repo_id": "Humsen",
"token_count": 10856
} | 28 |
@charset "UTF-8";
.topbar-nav {
min-height: 30px;
width: 100%;
margin-bottom: 0;
}
.topbar-nav label {
color: #6e83ab;
}
.navbar-brand-a {
padding: 5px 15px 1px;
height: 30px;
}
.access-today {
margin-left: 5% !important;
}
.online-current {
margin-top: 4px;
margin-left: 20px;
}
.topbar-btn-login {
padding: 2px 2px !important;
font-size: 13px;
border: 1px solid #f0ad4e;
margin-left: 2%;
display: none;
}
.topbar-btn-pers {
padding: 2px 2px !important;
font-size: 13px;
border: 1px solid #5bc0de;
margin-left: 2%;
display: none;
}
.topbar-btn-right {
padding: 2px 2px !important;
font-size: 13px;
border: 1px solid #5bc0de;
display: none;
margin-left: 6px;
}
.choose-theme {
margin: 10px;
}
.web-pc-blank {
float: left;
margin-left: 20px;
}
.header-nav {
float: left;
margin-left: 6%;
}
.choose-theme button {
float: left;
}
.top-bar-div{
margin: 18px 0px 5px 10px;
} | Humsen/web/web-mobile/WebContent/css/navigation/topbar.css/0 | {
"file_path": "Humsen/web/web-mobile/WebContent/css/navigation/topbar.css",
"repo_id": "Humsen",
"token_count": 426
} | 29 |
/**
* jQuery MD5 hash algorithm function
*
* <code>
* Calculate the md5 hash of a String
* String $.md5 ( String str )
* </code>
*
* Calculates the MD5 hash of str using the ยป RSA Data Security, Inc. MD5
* Message-Digest Algorithm, and returns that hash. MD5 (Message-Digest
* algorithm 5) is a widely-used cryptographic hash function with a 128-bit hash
* value. MD5 has been employed in a wide variety of security applications, and
* is also commonly used to check the integrity of data. The generated hash is
* also non-reversable. Data cannot be retrieved from the message digest, the
* digest uniquely identifies the data. MD5 was developed by Professor Ronald L.
* Rivest in 1994. Its 128 bit (16 byte) message digest makes it a faster
* implementation than SHA-1. This script is used to process a variable length
* message into a fixed-length output of 128 bits using the MD5 algorithm. It is
* fully compatible with UTF-8 encoding. It is very useful when u want to
* transfer encrypted passwords over the internet. If you plan using UTF-8
* encoding in your project don't forget to set the page encoding to UTF-8
* (Content-Type meta tag). This function orginally get from the WebToolkit and
* rewrite for using as the jQuery plugin.
*
* Example Code <code>
* $.md5("I'm Persian.");
* </code> Result <code>
* "b8c901d0f02223f9761016cfff9d68df"
* </code>
*
* @alias Muhammad Hussein Fattahizadeh < muhammad [AT] semnanweb [DOT] com >
* @link http://www.semnanweb.com/jquery-plugin/md5.html
* @see http://www.webtoolkit.info/
* @license http://www.gnu.org/licenses/gpl.html [GNU General Public License]
* @param {jQuery}
* {md5:function(string))
* @return string
*/
(function($) {
var rotateLeft = function(lValue, iShiftBits) {
return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits));
}
var addUnsigned = function(lX, lY) {
var lX4, lY4, lX8, lY8, lResult;
lX8 = (lX & 0x80000000);
lY8 = (lY & 0x80000000);
lX4 = (lX & 0x40000000);
lY4 = (lY & 0x40000000);
lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
if (lX4 & lY4)
return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
if (lX4 | lY4) {
if (lResult & 0x40000000)
return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
else
return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
} else {
return (lResult ^ lX8 ^ lY8);
}
}
var F = function(x, y, z) {
return (x & y) | ((~x) & z);
}
var G = function(x, y, z) {
return (x & z) | (y & (~z));
}
var H = function(x, y, z) {
return (x ^ y ^ z);
}
var I = function(x, y, z) {
return (y ^ (x | (~z)));
}
var FF = function(a, b, c, d, x, s, ac) {
a = addUnsigned(a, addUnsigned(addUnsigned(F(b, c, d), x), ac));
return addUnsigned(rotateLeft(a, s), b);
};
var GG = function(a, b, c, d, x, s, ac) {
a = addUnsigned(a, addUnsigned(addUnsigned(G(b, c, d), x), ac));
return addUnsigned(rotateLeft(a, s), b);
};
var HH = function(a, b, c, d, x, s, ac) {
a = addUnsigned(a, addUnsigned(addUnsigned(H(b, c, d), x), ac));
return addUnsigned(rotateLeft(a, s), b);
};
var II = function(a, b, c, d, x, s, ac) {
a = addUnsigned(a, addUnsigned(addUnsigned(I(b, c, d), x), ac));
return addUnsigned(rotateLeft(a, s), b);
};
var convertToWordArray = function(string) {
var lWordCount;
var lMessageLength = string.length;
var lNumberOfWordsTempOne = lMessageLength + 8;
var lNumberOfWordsTempTwo = (lNumberOfWordsTempOne - (lNumberOfWordsTempOne % 64)) / 64;
var lNumberOfWords = (lNumberOfWordsTempTwo + 1) * 16;
var lWordArray = Array(lNumberOfWords - 1);
var lBytePosition = 0;
var lByteCount = 0;
while (lByteCount < lMessageLength) {
lWordCount = (lByteCount - (lByteCount % 4)) / 4;
lBytePosition = (lByteCount % 4) * 8;
lWordArray[lWordCount] = (lWordArray[lWordCount] | (string
.charCodeAt(lByteCount) << lBytePosition));
lByteCount++;
}
lWordCount = (lByteCount - (lByteCount % 4)) / 4;
lBytePosition = (lByteCount % 4) * 8;
lWordArray[lWordCount] = lWordArray[lWordCount]
| (0x80 << lBytePosition);
lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
return lWordArray;
};
var wordToHex = function(lValue) {
var WordToHexValue = "", WordToHexValueTemp = "", lByte, lCount;
for (lCount = 0; lCount <= 3; lCount++) {
lByte = (lValue >>> (lCount * 8)) & 255;
WordToHexValueTemp = "0" + lByte.toString(16);
WordToHexValue = WordToHexValue
+ WordToHexValueTemp.substr(WordToHexValueTemp.length - 2,
2);
}
return WordToHexValue;
};
var uTF8Encode = function(string) {
string = string.replace(/\x0d\x0a/g, "\x0a");
var output = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
output += String.fromCharCode(c);
} else if ((c > 127) && (c < 2048)) {
output += String.fromCharCode((c >> 6) | 192);
output += String.fromCharCode((c & 63) | 128);
} else {
output += String.fromCharCode((c >> 12) | 224);
output += String.fromCharCode(((c >> 6) & 63) | 128);
output += String.fromCharCode((c & 63) | 128);
}
}
return output;
};
$.extend({
md5 : function(string) {
var x = Array();
var k, AA, BB, CC, DD, a, b, c, d;
var S11 = 7, S12 = 12, S13 = 17, S14 = 22;
var S21 = 5, S22 = 9, S23 = 14, S24 = 20;
var S31 = 4, S32 = 11, S33 = 16, S34 = 23;
var S41 = 6, S42 = 10, S43 = 15, S44 = 21;
string = uTF8Encode(string);
x = convertToWordArray(string);
a = 0x67452301;
b = 0xEFCDAB89;
c = 0x98BADCFE;
d = 0x10325476;
for (k = 0; k < x.length; k += 16) {
AA = a;
BB = b;
CC = c;
DD = d;
a = FF(a, b, c, d, x[k + 0], S11, 0xD76AA478);
d = FF(d, a, b, c, x[k + 1], S12, 0xE8C7B756);
c = FF(c, d, a, b, x[k + 2], S13, 0x242070DB);
b = FF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE);
a = FF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF);
d = FF(d, a, b, c, x[k + 5], S12, 0x4787C62A);
c = FF(c, d, a, b, x[k + 6], S13, 0xA8304613);
b = FF(b, c, d, a, x[k + 7], S14, 0xFD469501);
a = FF(a, b, c, d, x[k + 8], S11, 0x698098D8);
d = FF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF);
c = FF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1);
b = FF(b, c, d, a, x[k + 11], S14, 0x895CD7BE);
a = FF(a, b, c, d, x[k + 12], S11, 0x6B901122);
d = FF(d, a, b, c, x[k + 13], S12, 0xFD987193);
c = FF(c, d, a, b, x[k + 14], S13, 0xA679438E);
b = FF(b, c, d, a, x[k + 15], S14, 0x49B40821);
a = GG(a, b, c, d, x[k + 1], S21, 0xF61E2562);
d = GG(d, a, b, c, x[k + 6], S22, 0xC040B340);
c = GG(c, d, a, b, x[k + 11], S23, 0x265E5A51);
b = GG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA);
a = GG(a, b, c, d, x[k + 5], S21, 0xD62F105D);
d = GG(d, a, b, c, x[k + 10], S22, 0x2441453);
c = GG(c, d, a, b, x[k + 15], S23, 0xD8A1E681);
b = GG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8);
a = GG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6);
d = GG(d, a, b, c, x[k + 14], S22, 0xC33707D6);
c = GG(c, d, a, b, x[k + 3], S23, 0xF4D50D87);
b = GG(b, c, d, a, x[k + 8], S24, 0x455A14ED);
a = GG(a, b, c, d, x[k + 13], S21, 0xA9E3E905);
d = GG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8);
c = GG(c, d, a, b, x[k + 7], S23, 0x676F02D9);
b = GG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A);
a = HH(a, b, c, d, x[k + 5], S31, 0xFFFA3942);
d = HH(d, a, b, c, x[k + 8], S32, 0x8771F681);
c = HH(c, d, a, b, x[k + 11], S33, 0x6D9D6122);
b = HH(b, c, d, a, x[k + 14], S34, 0xFDE5380C);
a = HH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44);
d = HH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9);
c = HH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60);
b = HH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70);
a = HH(a, b, c, d, x[k + 13], S31, 0x289B7EC6);
d = HH(d, a, b, c, x[k + 0], S32, 0xEAA127FA);
c = HH(c, d, a, b, x[k + 3], S33, 0xD4EF3085);
b = HH(b, c, d, a, x[k + 6], S34, 0x4881D05);
a = HH(a, b, c, d, x[k + 9], S31, 0xD9D4D039);
d = HH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5);
c = HH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8);
b = HH(b, c, d, a, x[k + 2], S34, 0xC4AC5665);
a = II(a, b, c, d, x[k + 0], S41, 0xF4292244);
d = II(d, a, b, c, x[k + 7], S42, 0x432AFF97);
c = II(c, d, a, b, x[k + 14], S43, 0xAB9423A7);
b = II(b, c, d, a, x[k + 5], S44, 0xFC93A039);
a = II(a, b, c, d, x[k + 12], S41, 0x655B59C3);
d = II(d, a, b, c, x[k + 3], S42, 0x8F0CCC92);
c = II(c, d, a, b, x[k + 10], S43, 0xFFEFF47D);
b = II(b, c, d, a, x[k + 1], S44, 0x85845DD1);
a = II(a, b, c, d, x[k + 8], S41, 0x6FA87E4F);
d = II(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0);
c = II(c, d, a, b, x[k + 6], S43, 0xA3014314);
b = II(b, c, d, a, x[k + 13], S44, 0x4E0811A1);
a = II(a, b, c, d, x[k + 4], S41, 0xF7537E82);
d = II(d, a, b, c, x[k + 11], S42, 0xBD3AF235);
c = II(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB);
b = II(b, c, d, a, x[k + 9], S44, 0xEB86D391);
a = addUnsigned(a, AA);
b = addUnsigned(b, BB);
c = addUnsigned(c, CC);
d = addUnsigned(d, DD);
}
var tempValue = wordToHex(a) + wordToHex(b) + wordToHex(c)
+ wordToHex(d);
return tempValue.toLowerCase();
}
});
})(jQuery); | Humsen/web/web-mobile/WebContent/js/customize-jquery.md5.js/0 | {
"file_path": "Humsen/web/web-mobile/WebContent/js/customize-jquery.md5.js",
"repo_id": "Humsen",
"token_count": 4688
} | 30 |
/**
* ็ผ่พ็ๆฌ็นๆง
*
* @author ไฝๆ่
*
* 2017ๅนด11ๆ10ๆฅ
*/
// ๅฝๅๆๆฐ็ๆฌid
var latest_version_id;
// ๅฝๅ็ผ่พ็ๆฌid
var curr_version_id;
//ๅฝๅ็ๆฌๅท
var curr_version_num;
$(function() {
// ่ทๅๅฝๅๆๆฐ็ๆฌ
getLatestVersion();
// ็ปๅฎๅ ่ฝฝไธไธไธช็ๆฌไบไปถ
$('#btn_prevV').click(prevVersionClick);
// ็ปๅฎๅ ่ฝฝไธไธไธช็ๆฌไบไปถ
$('#btn_nextV').click(nextVersionClick);
// ็ปๅฎๆธ
็ฉบๅฝๅ็ผ่พๅบ
$('#btn_clearCurr').click(clearCurrClick);
// ็ปๅฎๆไบคไบไปถ
$('#btn_subEditVsion').bind('click', submitNewVerFea);
});
/**
* ่ทๅๅฝๅๆๆฐ็ๆฌ
*
* @returns
*/
function getLatestVersion() {
$.ajax({
type : 'POST',
url : '/latestRlseFetr.hms',
dataType : 'json',
success : function(response) {
latest_version_id = response.releaseId;
$('#txt_latestV').val(response.releaseNumber);
fillVersionEditor(response);
},
error : function(XMLHttpRequest, textStatus) {
$.confirm({
title : 'ๅ ่ฝฝๆฐ็็นๆงๅบ้',
content : textStatus + ' : ' + XMLHttpRequest.status,
autoClose : 'ok|2000',
type : 'red',
buttons : {
ok : {
text : '็กฎ่ฎค',
btnClass : 'btn-primary',
},
}
});
}
});
}
/**
* ๅกซๅ
็ๆฌไฟกๆฏ
* @param versionArticle
* @returns
*/
function fillVersionEditor(versionArticle){
//ๅ
ๆธ
็ฉบ
clearCurrClick();
curr_version_id = versionArticle.releaseId;
curr_version_num = versionArticle.releaseNumber;
$('#txt_newV').val(versionArticle.releaseNumber);
var relContent = versionArticle.releaseContent;
relContent = relContent.match(/<p>(\S*)<\/p>/)[1];
relContent = relContent.split('</p><p>');
$('.version-input').each(function(i) {
$(this).val(relContent[i].split('ใ')[1]);
});
}
/**
* ็ปๅฎๅ ่ฝฝไธไธไธช็ๆฌไบไปถ
*
* @returns
*/
function prevVersionClick() {
//ๅฆๆ็ๆฌ่ถ
่ฟๆๆฐ๏ผ็ดๆฅ่ฟๅ
if(curr_version_id+1 > latest_version_id){
return;
}
$.ajax({
type : 'POST',
url : '/latestRlseFetr.hms',
dataType : 'json',
data : {
releaseId : curr_version_id+1,
},
success : function(response) {
fillVersionEditor(response);
},
error : function(XMLHttpRequest, textStatus) {
$.confirm({
title : 'ๅ ่ฝฝๆฐ็็นๆงๅบ้',
content : textStatus + ' : ' + XMLHttpRequest.status,
autoClose : 'ok|2000',
type : 'red',
buttons : {
ok : {
text : '็กฎ่ฎค',
btnClass : 'btn-primary',
},
}
});
}
});
}
/**
* ็ปๅฎๅ ่ฝฝไธไธไธช็ๆฌไบไปถ
*
* @returns
*/
function nextVersionClick() {
//ๅฆๆ็ๆฌๅฐไบ็ญไบ0๏ผ็ดๆฅ่ฟๅ
if(curr_version_id-1 <= 0){
return;
}
$.ajax({
type : 'POST',
url : '/latestRlseFetr.hms',
dataType : 'json',
data : {
releaseId : curr_version_id-1,
},
success : function(response) {
fillVersionEditor(response);
},
error : function(XMLHttpRequest, textStatus) {
$.confirm({
title : 'ๅ ่ฝฝๆฐ็็นๆงๅบ้',
content : textStatus + ' : ' + XMLHttpRequest.status,
autoClose : 'ok|2000',
type : 'red',
buttons : {
ok : {
text : '็กฎ่ฎค',
btnClass : 'btn-primary',
},
}
});
}
});
}
/**
* ็ปๅฎๆธ
็ฉบๅฝๅ็ผ่พๅบ
*
* @returns
*/
function clearCurrClick() {
$('.version-input').each(function(i) {
$(this).val('');
});
$('#txt_newV').val('');
}
/**
* ๆฐ็ๆฌ็นๆงๆไบค
*
* @returns
*/
function submitNewVerFea() {
// ่ทๅๆ็ซ ็ป่
var article_data = JSON.stringify(articleDetail());
if (typeof (article_data) == 'undefined') {
$.confirm({
title : 'ๆถ้ๆฐ็็นๆงๅบ้',
content : 'ๆฐ็็นๆงๅ
ๅฎนไธ่ฝไธบ็ฉบ',
autoClose : 'ok|2000',
type : 'red',
buttons : {
ok : {
text : '็กฎ่ฎค',
btnClass : 'btn-primary',
},
}
});
return;
}
$.ajax({
type : 'POST',
async : false,
url : '/editRlseFetr.hms',
dataType : 'json',
data : {
type : $.trim($('#txt_newV').val()) != curr_version_num ? 'create' : 'modify',
releaseId : curr_version_id,
newArticle : article_data,
},
success : function(response, status) {
if (response == 1) {
//ๅฆๆๆฏๆฐๅปบ๏ผๆๆฐ็ๆฌๅทๅ 1
if($.trim($('#txt_newV').val()) != curr_version_num){
getLatestVersion();
}
$.confirm({
title : 'ไธไผ ๆๅ',
content : 'ๆฐ็็นๆงไธไผ ๆๅ',
autoClose : 'ok|2000',
type : 'green',
buttons : {
ok : {
text : '็กฎ่ฎค',
btnClass : 'btn-primary',
},
}
});
} else {
$.confirm({
title : 'ไธไผ ๅคฑ่ดฅ',
content : 'ไธไผ ๅคฑ่ดฅ',
autoClose : 'ok|2000',
type : 'red',
buttons : {
ok : {
text : '็กฎ่ฎค',
btnClass : 'btn-primary',
},
}
});
}
},
error : function(XMLHttpRequest, textStatus) {
$.confirm({
title : 'ไธไผ ๅบ้',
content : textStatus + ' : ' + XMLHttpRequest.status,
autoClose : 'ok|2000',
type : 'red',
buttons : {
ok : {
text : '็กฎ่ฎค',
btnClass : 'btn-primary',
},
}
});
}
});
}
/**
* ๆไบคๆถ่ทๅๆฐ็็นๆง็ป่
*
* @returns
*/
function articleDetail() {
var new_version_feature = {};
var version_feature = '';
$('.version-input').each(function(i) {
if ($(this).val() != '') {
version_feature += '<p>' + (i + 1) + 'ใ' + $(this).val() + '</p>';
}
});
// ๅฆๆๆฐ็็นๆงไธบ็ฉบ๏ผ็ดๆฅ่ฟๅ
if (version_feature == '') {
return;
}
new_version_feature.releaseAuthor = 'ไฝๆ่';
new_version_feature.releaseDate = $.nowDateHMS();
new_version_feature.releaseNumber = $('#txt_newV').val();
new_version_feature.releaseContent = version_feature;
return new_version_feature;
} | Humsen/web/web-mobile/WebContent/js/personal_center/editor_version.js/0 | {
"file_path": "Humsen/web/web-mobile/WebContent/js/personal_center/editor_version.js",
"repo_id": "Humsen",
"token_count": 2845
} | 31 |
<link rel="stylesheet" href="/css/personal_center/modify-pwd.css">
<!-- ไฟฎๆน็จๆทๅฏ็ ่ๆฌ -->
<script src="/js/personal_center/modify-pwd.js"></script>
<form id="modifyPwdForm" class="form-horizontal modify-pwd-form">
<div class="form-group">
<label for="oldPassword" class="col-sm-2 control-label">ๆงๅฏ็ </label>
<div class="col-sm-8">
<input type="password" class="form-control" id="oldPassword"
name="oldPassword" placeholder="่ฏท่พๅ
ฅๆงๅฏ็ " aria-describedby="helpBlock">
</div>
<span id="helpBlock" class="help-block old-pwd-wrong-info">ๆงๅฏ็ ่พๅ
ฅ้่ฏฏ</span>
</div>
<div class="form-group">
<label for="newPassword" class="col-sm-2 control-label">ๆฐๅฏ็ </label>
<div class="col-sm-8">
<input type="password" class="form-control" id="newPassword"
name="newPassword" placeholder="่ฏท่พๅ
ฅๆฐๅฏ็ ">
</div>
</div>
<div class="form-group">
<label for="confirmPwd" class="col-sm-2 control-label">็กฎ่ฎคๆฐๅฏ็ </label>
<div class="col-sm-8">
<input type="password" class="form-control" id="confirmPwd"
name="confirmPwd" placeholder="่ฏท็กฎ่ฎคๆฐๅฏ็ ">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-8">
<a id="submitModifyPwd" class="btn btn-default" href="#"
role="button">ๆไบค</a>
</div>
</div>
</form> | Humsen/web/web-mobile/WebContent/personal_center/modify_pwd.html/0 | {
"file_path": "Humsen/web/web-mobile/WebContent/personal_center/modify_pwd.html",
"repo_id": "Humsen",
"token_count": 586
} | 32 |
/*
* Editor.md
*
* @file editormd.logo.css
* @version v1.5.0
* @description Open source online markdown editor.
* @license MIT License
* @author Pandao
* {@link https://github.com/pandao/editor.md}
* @updateTime 2015-06-09
*/
/*! prefixes.scss v0.1.0 | Author: Pandao | https://github.com/pandao/prefixes.scss | MIT license | Copyright (c) 2015 */
@font-face {
font-family: 'editormd-logo';
src: url("../fonts/editormd-logo.eot?-5y8q6h");
src: url(".../fonts/editormd-logo.eot?#iefix-5y8q6h") format("embedded-opentype"), url("../fonts/editormd-logo.woff?-5y8q6h") format("woff"), url("../fonts/editormd-logo.ttf?-5y8q6h") format("truetype"), url("../fonts/editormd-logo.svg?-5y8q6h#icomoon") format("svg");
font-weight: normal;
font-style: normal;
}
.editormd-logo,
.editormd-logo-1x,
.editormd-logo-2x,
.editormd-logo-3x,
.editormd-logo-4x,
.editormd-logo-5x,
.editormd-logo-6x,
.editormd-logo-7x,
.editormd-logo-8x {
font-family: 'editormd-logo';
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
font-size: inherit;
line-height: 1;
display: inline-block;
text-rendering: auto;
vertical-align: inherit;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.editormd-logo:before,
.editormd-logo-1x:before,
.editormd-logo-2x:before,
.editormd-logo-3x:before,
.editormd-logo-4x:before,
.editormd-logo-5x:before,
.editormd-logo-6x:before,
.editormd-logo-7x:before,
.editormd-logo-8x:before {
content: "\e1987";
/*
HTML Entity 󡦇
example: <span class="editormd-logo">󡦇</span>
*/
}
.editormd-logo-1x {
font-size: 1em;
}
.editormd-logo-lg {
font-size: 1.2em;
}
.editormd-logo-2x {
font-size: 2em;
}
.editormd-logo-3x {
font-size: 3em;
}
.editormd-logo-4x {
font-size: 4em;
}
.editormd-logo-5x {
font-size: 5em;
}
.editormd-logo-6x {
font-size: 6em;
}
.editormd-logo-7x {
font-size: 7em;
}
.editormd-logo-8x {
font-size: 8em;
}
.editormd-logo-color {
color: #2196F3;
}
| Humsen/web/web-mobile/WebContent/plugins/editormd/css/editormd.logo.css/0 | {
"file_path": "Humsen/web/web-mobile/WebContent/plugins/editormd/css/editormd.logo.css",
"repo_id": "Humsen",
"token_count": 1011
} | 33 |
End of preview. Expand
in Dataset Viewer.
README.md exists but content is empty.
Use the Edit dataset card button to edit it.
- Downloads last month
- 39