Skip to content

Commit

Permalink
Start adding unsplash code
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherJennings committed Jan 24, 2019
1 parent 0e5303c commit 5ee8151
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 23 deletions.
51 changes: 41 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"deploy-dev": "npm run build-dev && .\\deploy.bat"
},
"dependencies": {
"unsplash-js": "^4.8.0",
"vue": "^2.5.21"
},
"devDependencies": {
Expand All @@ -36,8 +37,8 @@
"parser": "babel-eslint"
},
"globals": {
"CustomElement": false
}
"CustomElement": false
}
},
"postcss": {
"plugins": {
Expand Down
63 changes: 52 additions & 11 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,26 +1,63 @@
/* global CustomElement */
<template>
<div id="app" v-if="loaded">
<input :disabled="element.disabled" v-model="element.value" placeholder="edit me">
<p>Saved: {{ value }}</p>
<p>AK: {{ element.config.accessKey }}</p>
<p>SK: {{ element.config.secretKey }}</p>
<input :disabled="element.disabled" v-model="searchTerm" placeholder="edit me">
<button @click="searchPhotos">Search</button>
<p>Saved: {{ value }} {{ height }}</p>
<pre v-html="searchResults"></pre>
</div>
</template>

<script>
import Unsplash, { toJson } from 'unsplash-js'
export default {
name: 'app',
data: function () {
return {
loaded: false,
searchTerm: "",
searchResults: "",
height: "",
element: {},
configuration: {}
}
},
computed: {
value() {
return this.element.value
},
unsplashInstance() {
return this.loaded
? new Unsplash({
applicationId: this.element.config.accessKey,
secret: this.element.config.secretKey
})
: null
}
},
methods: {
searchPhotos() {
if(this.unsplashInstance && this.searchTerm) {
this.unsplashInstance.search.photos(this.searchTerm)
.then(toJson)
.then(json => {
this.searchResults = json
})
}
},
updateSize() {
// Update the custom element height in the Kentico UI.
const height = Math.max(
document.body.scrollHeight,
document.body.offsetHeight,
document.documentElement.clientHeight,
document.documentElement.scrollHeight,
document.documentElement.offsetHeight
)
this.height = height
CustomElement.setHeight(height);
}
},
watch: {
Expand All @@ -32,15 +69,19 @@ export default {
},
created: function() {
CustomElement.init((element, context) => {
// Set up the element with initial value
this.element = element
this.context = context
this.loaded = true
// console.log(element)
// console.log(context)
})
// Set up the element with initial value
this.element = element
this.context = context
this.loaded = true
this.updateSize()
})
},
updated: function() {
this.updateSize()
}
}
</script>

<style>
Expand Down

0 comments on commit 5ee8151

Please sign in to comment.