Skip to content

Instantly share code, notes, and snippets.

@publickeating
publickeating / binding.js
Created January 3, 2011 17:05
Proposed addition to expose isForward
/**
Returns the direction of the binding. If isForward is YES, then the value
being passed came from the "from" side of the binding (i.e. the "Binding.path"
you named). If isForward is NO, then the value came from the "to" side (i.e.
the property you named with "propertyBinding"). You can vary your transform
behavior if you are based on the direction of the change.
@returns {Boolean}
*/
isForward: function() {
@publickeating
publickeating / gist:778432
Created January 13, 2011 19:25
File upload server response
res.send(JSON.stringify({
state: 'success',
fileName: file.filename,
mimeType: file.mime,
imagePath: relativePath
}), {
'Content-Type': 'text/plain'
}, 200);
@publickeating
publickeating / main.js
Created June 28, 2011 04:10
Pre-running button touch handling to prevent first touch delay
// at the end of main.js...
var buttonView = SC.ButtonView.create({
layout: { left: -1000, width: 100, height: 24, top: 0 },
didAppendToDocument: function() {
var self = this,
layer = this.get('layer'),
params;
params = {
@publickeating
publickeating / gist:1050492
Created June 28, 2011 04:27
touchstart Results
Simulated Touch
iPad 1 (normal) iPhone 4 (normal) iPad 1 (pre-run) iPhone 4 (pre-run)
@publickeating
publickeating / full_screen_sheet_pane.js
Created August 17, 2011 19:05
Full screen sheet view
/*
Apply this mixin to a pane to make it slide in from the top and fill the screen. The pane should not override layout.
*/
MyApp.FullScreenSheetPane = {
// May not be necessary in your app
defaultResponder: MyApp,
// Make sure it is offscreen (these values will be auto-adjusted)
layout: { top: −200, left: 0, height: 200, right: 0 },
@publickeating
publickeating / main.js
Created March 6, 2012 16:04 — forked from cronco/main.js
sproutcore issue - availableList contentBinding crashes app
/* ... */
var items = Items.store.find('Items.Item');
// Don't need this
//Items.selectedItemsController.set('content',[]);
Items.mainItemsController.set('content', items);
/* ... */
@publickeating
publickeating / controllable.js
Created April 12, 2012 03:27
SliderView rewrite on top of TemplateView
// ==========================================================================
// Project: SproutCore - JavaScript Application Framework
// Copyright: ©2006-2011 Strobe Inc. and contributors.
// Portions ©2008-2011 Apple Inc. All rights reserved.
// License: Licensed under MIT license (see license.js)
// ==========================================================================
/**
This mixin should be applied to all control views.
@publickeating
publickeating / stackable_child_views.js
Created July 12, 2012 16:42
SC.StackableChildViews Draft
/**
This mixin automatically positions the view's child views in a stack either
vertically or horizontally and adjusts the View's height or width respectively
to fit. It does this by checking the height or width of each child view
(depending on the direction of layout) and positioning the following child view
accordingly.
If the child view's frame changes, then the parent view will re-layout all of
the others to fit and re-adjust its width or height to fit as well.
@publickeating
publickeating / my_view.js
Created January 28, 2013 18:39
Allow a collection view to reload if the status of its content changes even if the content's length doesn't change (like with RecordArray's).
myStack: SC.StackedView.extend({
// Observes changes to our content.
contentDidChange: function () {
var previousContent = this.previousContent,
this.get('content');
// Clean up observer on previous content
if (previousContent) {
@publickeating
publickeating / custom_view_with_internal_statechart.js
Last active December 13, 2015 17:19
A custom view that manages its state using SC.StatechartManager instead of internal flags. This is a simple view that only needs to toggle an active property when the mouse is over it. However, as simple as this requirement is, we can see that it benefits from using a statechart because the isEnabled value affects the behaviour. Imagine if there…
/**
* A view that adds an 'active' class when the mouse is over it.
*/
MyApp.MyView = SC.View.extend(SC.StatechartManager, {
/** @private */
displayProperties: ['isActive', 'isEnabled'],
/**
Whether the view is active or not.