No description, website, or topics provided.
JavaScript
Latest commit 967b541 Feb 2, 2017 @nhassan nhassan Merge pull request #5 in TMD/core from naz/async-common to master
* commit 'f68c3359c1185fb453da72e2a2d90b912b60d23e':
  Change order of check to see if isAuthenticated and then window.Y and then window.Y.Global
  Move Y.Squarespace.Template.getTweakValue into core
Permalink
Failed to load latest commit information.
src Change order of check to see if isAuthenticated and then window.Y and… Feb 1, 2017
.babelrc
.eslintrc initial commit Aug 18, 2016
.gitignore Checking in umd build result, updating npm scripts Sep 9, 2016
.npmignore adding license stuff Sep 22, 2016
LICENSE corrected license Dec 1, 2016
README.md adding license stuff Sep 22, 2016
package.json 1.0.1 Dec 1, 2016
squarespace-core-1.0.1.min.js updating build artifacts Dec 1, 2016
squarespace-core-1.0.1.min.js.map updating build artifacts Dec 1, 2016
webpack.config.js Minifying UMD dist, adding version number back into filename Sep 15, 2016

README.md

Squarespace Core

This is the public JavaScript API for Squarespace's Developer Platform. It exposes a few crucial methods for building Squarespace templates.

Usage

npm install @squarespace/core;
const core = require('@squarespace/core');

// Or require one of the submodules
const Tweak = require('@squarespace/core/Tweak');

Reference

ImageLoader

Squarespace comes with a number of built-in facilities for managing images that are uploaded via the Squarespace CMS. After uploading an image into a collection, Squarespace automatically creates multiple copies of the image with different sizes. ImageLoader will then help render images properly when they are presented on a page, even on retina displays.

ImageLoader can also be used to fit or fill an image inside ​a parent container, where it automatically determines which image size to use depending on the current dimensions of the container.

ImageLoader.load(img, [config])

Loads an image.

Params

  • img HTMLElement - Image node to be loaded
  • [config] Object - Config object

Return

  • Boolean- True if the image was loaded, false otherwise]

Lifecycle

Certain Squarespace content, like map and chart blocks, have built-in javascript functionality. Typically this JS is initialized when the page is loaded.

If you are building a Developer Platform site that loads Squarespace content through an XHR, you can use the Lifecycle methods provided here to initialize and/or destroy this functionality.

Lifecycle.init()

Loads scripts and calls their initialize methods. This should be called after new HTML content containing Squarespace blocks is added to a page (for example, after AJAX loading a new page).

Lifecycle.destroy()

Triggers each block's destructor. This should be called to clean up blocks that are about to be removed from the page, such as prior to loading in new HTML content.

Tweak

Tweaks allow a developer to isolate specific elements of the design and present options to the user in an easy-to-use interface. Tweaks are surfaced in the Squarespace interface through Style Editor (e.g. yoursite.squarespace.com/config/design/style). Using tweaks, a user can make presentation changes to their website without having to know or edit CSS code. Tweaks are typically used by developers through LESS variables, mixins, and class names added to the <body> element.

Sometimes, a developer may find it necessary to access the value of a tweak through Javascript, or to watch for changes in that tweak and update the DOM accordingly. The Tweak module of squarespace-core is provides an interface for doing so.

Tweak.getValue(name)

Gets the value of one of the tweaks given its name.

Params

  • name String - Name of the tweak

Return

  • String- The value of the tweak

Tweak.watch([name], callback)

Listen for changes on a tweak item. If one parameter is provided, the callback will be executed every time any tweak changes. If two parameters are provided and the first parameter is a String, the callback will be executed only when that particular tweak changes. If two parameters are provided and the first parameter is an Array of strings, the callback will be executed any time one of those tweaks changes.

Params

  • name String - Name of the tweak – name Array – Array with multiple tweak names – callback Function - Callback to call when watcher is triggered

Return

  • String- The value of the tweak

Contributing

We are currently not accepting contributions to Squarespace Core.

Copyright and License

Copyright 2016 Squarespace, INC.

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.