SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
</copyright> */
var Montage = require("montage").Montage;
var Converter = require("montage/core/converter/converter").Converter;

exports.TridionBodyColorConverter = Montage.create(Converter, {

    delta: {
        value: 80
    },

    convert: {
        enumerable: false,
        value: function(value) {
            return value - this.delta;
        }
    },

    revert: {
        enumerable: false,
        value: function(value) {
            return value + this.delta;
        }
    }
});

示例#2
0
var Store = exports.Store = Montage.create(Montage, /** @lends module:montage/data/store.Store# */ {

    /*
     * @private
     */
    _connectionInfo:{
        serializable:true,
        enumerable:false,
        value:null
    },

    /*
     * Connection information for the store
     */
    connectionInfo:{
        get:function () {
            return this._connectionInfo;
        },
        set:function (info) {
            // TODO [PJYF May 15 2012] We need to check that the connection info is valid for this store.
            this._connectionInfo = info;
        }
    },

    /**
     Description TODO
     @type {Property}
     @default {Array} new Array(10)
     */
    restrictions:{
        serializable:true,
        writable:false,
        distinct:true,
        value:new Array(10)
    },

    /**
     @private
     */
    _parent:{
        serializable:true,
        enumerable:false,
        value:null
    },

    /**
     Returns the parent store.
     @function
     @returns this._parent
     */
    parent:{
        get:function () {
            return this._parent;
        }
    },

    /**
     Returns the default store manager.<br>
     If none is defined it will create one that will then be reused for subsequent calls.
     @function
     @returns _defaultStoreManager
     */
    defaultManager:{
        get:function () {
            if (_defaultStoreManager === null) {
                _defaultStoreManager = StoreManager.create().init();
            }
            return _defaultStoreManager;
        },
        // This is used only for testing.
        set:function (storeManager) {
            _defaultStoreManager = storeManager;
        }
    },

    /**
     @function
     @returns this.initWithParentAndRestrictions(null, null)
     */
    init:{
        serializable:false,
        enumerable:false,
        value:function () {
            return this.initWithParentAndRestrictions(null, null);
        }
    },

    /**
     @function
     @param {Property} parent TODO
     @returns this.initWithParentAndRestrictions(parent, null)
     */
    initWithParent:{
        serializable:false,
        enumerable:false,
        value:function (parent) {
            return this.initWithParentAndRestrictions(parent, null);
        }
    },
    /**
     Description TODO
     @function
     @param {Property} parent TODO
     @param {Property} restrictions TODO
     @returns itself
     */
    initWithParentAndRestrictions:{
        serializable:false,
        value:function (parent, restrictions) {
            if (this.parent !== null) {
                this.parent.remove(this);
            }
            this._parent = (parent != null ? parent : Store.defaultManager);
            this.parent.addStore(this);

            if (restrictions != null) {
                var restriction, index;
                for (index = 0; typeof (restriction = restrictions[index]) !== "undefined"; index++) {
                    this.restrictions.push(Object.freeze(restriction));
                }
            }
            return this;
        }
    },

    /**
     Description TODO
     @function
     @param {Prototyoe} prototypeName TODO
     @param {Id} moduleId TODO
     @returns null
     */
    blueprintForPrototype:{
        value:function (prototypeName, moduleId) {
            if (this.parent !== null) {
                return this.parent.blueprintForPrototype(prototypeName, moduleId);
            }
            return null;
        }
    },

    /**
     Create a new binder mapping.<br/>This is intended to be subclassed by concrete store to create the right mapping for their store.
     @function
     @returns binder mapping
     */
    createBinderMapping:{
        get:function () {
            return BinderMapping.create();
        }
    },

    /**
     Create a new blueprint mapping.<br/>This is intended to be subclassed by concrete store to create the right mapping for their store.
     @function
     @returns blueprint mapping
     */
    createBlueprintMapping:{
        get:function () {
            return BlueprintMapping.create();
        }
    },

    /**
     Create a new attribute mapping.<br/>This is intended to be subclassed by concrete store to create the right mapping for their store.
     @function
     @returns attribute mapping
     */
    createAttributeMapping:{
        get:function () {
            return AttributeMapping.create();
        }
    },

    /**
     Create a new association mapping.<br/>This is intended to be subclassed by concrete store to create the right mapping for their store.
     @function
     @returns association mapping
     */
    createAssociationMapping:{
        get:function () {
            return AssociationMapping.create();
        }
    },

    /**
     Add a store to the cooperating objects stores.
     @function
     @param {Property} store TODO
     @returns store
     */
    addStore:{
        value:function (store) {
            if (this.parent !== null) {
                return this.parent.addStore(store);
            }
            return store;
        }
    },

    /**
     Remove a store to the cooperating objects stores.
     @function
     @param {Property} store TODO
     @returns store
     */
    removeStore:{
        value:function (store) {
            if (this.parent !== null) {
                return this.parent.removeStore(store);
            }
            return store;
        }
    },

    /**
     Load a blueprint in the store manager.<br>
     This will force the loading of the corresponding store if not already in memory.
     @function
     @param {Property} blueprint Either a binder object or a serialized representation of a binder object.
     @param {Property} transactionId current transaction identifier
     @returns this.parent.requireStoreForBlueprint(binder)
     */
    requireStoreForBlueprint:{
        value:function (blueprint, transactionId) {
            if (this.parent !== null) {
                return this.parent.requireStoreForBlueprint(blueprint, transactionId);
            }
        }
    },

    /**
     Check if the referenced blueprint can be serviced by the target store.
     @function
     @param {Property} blueprint TODO
     @param {Property} transactionId current transaction identifier
     @returns true if the current store can service that binder.
     */
    canServiceBlueprint:{
        value:function (blueprint, transactionId) {
            var blueprintMapping = blueprint.mappingForName(transactionId.mappingFolderName);
            if (!blueprintMapping) {
                return false;
            }
            var binderMapping = blueprintMapping.parent;
            if (!binderMapping) {
                return false;
            }
            var metadata = Montage.getInfoForObject(this);
            if ((binderMapping.storePrototypeName === metadata.objectName) && (binderMapping.storeModuleId === metadata.moduleId)) {
                if (this.connectionInfo) {
                    var connectionInfo = binderMapping.connectionInformationForName(this.connectionInfo.name);
                    return this.connectionInfo.equals(connectionInfo);
                }
                // TODO [PJYF May 15 2012] I am not sure this is correct it may be a bit bizarre.
                return true;
            }
            return false;
        }
    },

    /**
     Check if the query blueprint can be serviced by this store.
     @function
     @param {Property} query TODO
     @param {Property} transactionId TODO
     @returns {Boolean} true if the current store can service the query
     */
    canServiceQuery:{
        value:function (query, transactionId) {
            if (query != null) {
                return this.canServiceBlueprint(query.blueprint, transactionId);
            }
            return false;
        }
    },
    /**
     Description TODO
     @function
     @param {Object} object  TODO
     @param {Property} context TODO
     @param {Id} transactionId TODO
     @param {name} Mapping folder name used for this transaction
     @returns this.permanentIdForObjectId$Implementation(objectId, context, aTransactionId)
     */
    permanentIdForObjectId:{
        value:function (object, context, transactionId, name) {
            var aTransactionId = transactionId;
            var hadOpenTransaction = false;
            try {
                if (aTransactionId == null) {
                    hadOpenTransaction = TransactionId.manager.hasCurrentTransaction();
                    if (hadOpenTransaction) {
                        aTransactionId = TransactionId.manager.currentTransaction();
                    } else {
                        aTransactionId = TransactionId.manager.startTransaction(name);
                    }
                }
                return this.permanentIdForObjectId$Implementation(object, context, aTransactionId);
            } finally {
                if (!hadOpenTransaction) {
                    TransactionId.manager.closeTransaction(aTransactionId);
                }
            }
        }
    },
    /**
     Description TODO
     @function
     @param {Object} object  TODO
     @param {Property} context TODO
     @param {Id} transactionId TODO
     @returns Promise.ref(null)
     */
    permanentIdForObjectId$Implementation:{
        value:function (object, context, transactionId) {
            if (typeof object.objectId !== "undefined") {
                return Promise.ref(object.objectId);
            }
            return Promise.ref(null);
        }
    },
    /**
     Description TODO
     @function
     @param {Object} objectId  TODO
     @param {Property} context TODO
     @param {Id} transactionId TODO
     @param {name} Mapping folder name used for this transaction
     @returns this.pledgeForObjectId$Implementation(objectId, context, aTransactionId)
     */
    pledgeForObjectId:{
        value:function (objectId, context, transactionId, name) {
            var aTransactionId = transactionId;
            var hadOpenTransaction = false;
            try {
                if (aTransactionId == null) {
                    hadOpenTransaction = TransactionId.manager.hasCurrentTransaction();
                    if (hadOpenTransaction) {
                        aTransactionId = TransactionId.manager.currentTransaction();
                    } else {
                        aTransactionId = TransactionId.manager.startTransaction(name);
                    }
                }
                return this.pledgeForObjectId$Implementation(objectId, context, aTransactionId);
            } finally {
                if (!hadOpenTransaction) {
                    TransactionId.manager.closeTransaction(aTransactionId);
                }
            }
        }
    },
    /**
     Description TODO
     @function
     @param {Object} objectId  TODO
     @param {Property} context TODO
     @param {Id} transactionId TODO
     @returns Promise.ref(null)
     */
    pledgeForObjectId$Implementation:{
        value:function (objectId, context, transactionId) {
            // TODO [PJYF May 17 2011] This needs to be reimplemented
            return Promise.ref(null);
        }
    },
    /**
     Description TODO
     @function
     @param {Object} sourceObject TODO
     @param {Property} relationshipName TODO
     @param {Property} context TODO
     @param {Id} transactionId TODO
     @param {name} Mapping folder name used for this transaction
     @returns this.pledgeForSourceObjectAssociationNamed$Implementation(sourceObject, relationshipName, context, aTransactionId)
     */
    pledgeForSourceObjectAssociationNamed:{
        value:function (sourceObject, relationshipName, context, transactionId, name) {
            var aTransactionId = transactionId;
            var hadOpenTransaction = false;
            try {
                if (aTransactionId == null) {
                    hadOpenTransaction = TransactionId.manager.hasCurrentTransaction();
                    if (hadOpenTransaction) {
                        aTransactionId = TransactionId.manager.currentTransaction();
                    } else {
                        aTransactionId = TransactionId.manager.startTransaction(name);
                    }
                }
                return this.pledgeForSourceObjectAssociationNamed$Implementation(sourceObject, relationshipName, context, aTransactionId);
            } finally {
                if (!hadOpenTransaction) {
                    TransactionId.manager.closeTransaction(aTransactionId);
                }
            }
        }
    },
    /**
     Description TODO
     @function
     @param {Object} sourceObject TODO
     @param {Property} relationshipName TODO
     @param {Property} context TODO
     @param {Id} transactionId TODO
     @returns Promise.ref(null)
     */
    pledgeForSourceObjectAssociationNamed$Implementation:{
        value:function (sourceObject, relationshipName, context, transactionId) {
            if (this.parent !== null) {
                return this.parent.pledgeForSourceObjectAssociationNamed$Implementation(sourceObject, relationshipName, context, transactionId);
            }
            return Promise.ref(null);
        }
    },

    /**
     Returns a pledge for the source object and the relationship referenced.<br>
     The resulting pledge can be a simple one or an array pledge depending on the type of relationship.<br>
     <b>Note:</b> The source object may not be in the current data source. The destination object is.
     @function
     @param {Object} sourceObject TODO
     @param {Property} relationship TODO
     @param {Property} context TODO
     @param {Id} transactionId TODO
     @param {name} Mapping folder name used for this transaction
     @returns this.pledgeForSourceObjectAssociation$Implementation(sourceObject, relationship, context, aTransactionId)
     */
    pledgeForSourceObjectAssociation:{
        value:function (sourceObject, relationship, context, transactionId, name) {
            var aTransactionId = transactionId;
            var hadOpenTransaction = false;
            try {
                if (aTransactionId == null) {
                    hadOpenTransaction = TransactionId.manager.hasCurrentTransaction();
                    if (hadOpenTransaction) {
                        aTransactionId = TransactionId.manager.currentTransaction();
                    } else {
                        aTransactionId = TransactionId.manager.startTransaction(name);
                    }
                }
                return this.pledgeForSourceObjectAssociation$Implementation(sourceObject, relationship, context, aTransactionId);
            } finally {
                if (!hadOpenTransaction) {
                    TransactionId.manager.closeTransaction(aTransactionId);
                }
            }
        }
    },

    /**
     Description TODO
     @function
     @param {Object} sourceObject TODO
     @param {Property} relationship TODO
     @param {Property} context TODO
     @param {Id} transactionId TODO
     @returns this.parent.pledgeForSourceObjectAssociation$Implementation(sourceObject, relationship, context, transactionId)
     */
    pledgeForSourceObjectAssociation$Implementation:{
        value:function (sourceObject, relationship, context, transactionId) {
            if (this.parent !== null) {
                return this.parent.pledgeForSourceObjectAssociation$Implementation(sourceObject, relationship, context, transactionId);
            }
        }
    },

    /**
     Called by the framework whenever a new object is inserted, or a pledge is fired.
     @function
     @param {Object} object TODO
     @param {Property} context TODO
     @param {Id} transactionId TODO
     @param {name} Mapping folder name used for this transaction
     @returns this.initializeObject$Implementation(object, context, aTransactionId)
     */
    initializeObject:{
        value:function (object, context, transactionId, name) {
            var aTransactionId = transactionId;
            var hadOpenTransaction = false;
            try {
                if (aTransactionId == null) {
                    hadOpenTransaction = TransactionId.manager.hasCurrentTransaction();
                    if (hadOpenTransaction) {
                        aTransactionId = TransactionId.manager.currentTransaction();
                    } else {
                        aTransactionId = TransactionId.manager.startTransaction(name);
                    }
                }
                return this.initializeObject$Implementation(object, context, aTransactionId);
            } finally {
                if (!hadOpenTransaction) {
                    TransactionId.manager.closeTransaction(aTransactionId);
                }
            }
        }
    },

    /**
     Description TODO
     @function
     @param {Object} object TODO
     @param {Property} context TODO
     @param {Id} transactionId TODO
     @returns Promise.ref(object)
     */
    initializeObject$Implementation:{
        value:function (object, context, transactionId) {
            if (typeof object.objectId === "undefined") {
                // TODO [PJYF June 17 2011] This will need to be revisited.p
                object.objectId = TemporaryObjectId.create().init();
            }
            return Promise.ref(object);
        }
    },

    /**
     Description TODO
     @function
     @param {Object} target TODO
     @param {Property} context TODO
     @param {Id} transactionId TODO
     @param {name} Mapping folder name used for this transaction
     @returns this.repledgeObject$Implementation(target, context, aTransactionId)
     */
    repledgeObject:{
        value:function (target, context, transactionId, name) {
            var aTransactionId = transactionId;
            var hadOpenTransaction = false;
            try {
                if (aTransactionId == null) {
                    hadOpenTransaction = TransactionId.manager.hasCurrentTransaction();
                    if (hadOpenTransaction) {
                        aTransactionId = TransactionId.manager.currentTransaction();
                    } else {
                        aTransactionId = TransactionId.manager.startTransaction(name);
                    }
                }
                if (Array.isArray(target)) {
                    // Invalidate objects in the list
                    var returnArray = new Array(target.length);
                    var mo, index;
                    for (index = 0; typeof (mo = target[index]) !== "undefined"; index++) {
                        returnArray[index] = this.repledgeObject$Implementation(mo, context, aTransactionId);
                    }
                    return returnArray;
                } else {
                    return this.repledgeObject$Implementation(target, context, aTransactionId);
                }
            } finally {
                if (!hadOpenTransaction) {
                    TransactionId.manager.closeTransaction(aTransactionId);
                }
            }
        }
    },

    /**
     Description TODO
     @function
     @param {Object} object TODO
     @param {Property} context TODO
     @param {Id} transactionId TODO
     @returns Promise.ref(object)
     */
    repledgeObject$Implementation:{
        value:function (object, context, transactionId) {
            if (typeof object.objectId !== "undefined") {
                return this.pledgeForObjectId(object.objectId, context, transactionId);
            }
            return Promise.ref(object);
        }

    },

    /**
     Description TODO
     @function
     @param {Property} context TODO
     @param {Id} transactionId TODO
     @param {name} Mapping folder name used for this transaction
     */
    saveChangesInContext:{
        value:function (context, transactionId, name) {
            var aTransactionId = transactionId;
            var hadOpenTransaction = false;
            try {
                if (aTransactionId == null) {
                    hadOpenTransaction = TransactionId.manager.hasCurrentTransaction();
                    if (hadOpenTransaction) {
                        aTransactionId = TransactionId.manager.currentTransaction();
                    } else {
                        aTransactionId = TransactionId.manager.startTransaction(name);
                    }
                }
                this.saveChangesInContext$Implementation(context, aTransactionId);
            } finally {
                if (!hadOpenTransaction) {
                    TransactionId.manager.closeTransaction(aTransactionId);
                }
            }
        }
    },

    /**
     Description TODO
     @function
     @param {Property} context TODO
     @param {Id} transactionId TODO
     @returns this.parent.saveChangesInContext$Implementation(context, transactionId)
     */
    saveChangesInContext$Implementation:{
        value:function (context, transactionId) {
            if (this.parent !== null) {
                return this.parent.saveChangesInContext$Implementation(context, transactionId);
            }
        }
    },

    /**
     Called on each store before a save.<br>
     Upon receiving this message the store should take steps to prepare the commit and insure it will succeed.<br>
     If the commit cannot succeed it should return a rejected promise.
     @function
     @param {Property} context TODO
     @param {Id} transactionId TODO
     @returns {Boolean} Promise.ref(true)
     */
    prepareToSaveChangesInContext$Implementation:{
        value:function (context, transactionId) {
            // TODO [PJYF Sep 27 2011] This needs to be reimplemented
            return Promise.ref(true);
        }
    },

    /**
     Called on each store before a revert a prepare to save.<br>
     Any step taken to prepare the save should be rolled back.
     @function
     @param {Property} context TODO
     @param {Id} transactionId TODO
     @returns {Boolean} Promise.ref(true)
     */
    cancelSaveChangesInContext$Implementation:{
        value:function (context, transactionId) {
            // TODO [PJYF Sep 27 2011] This needs to be reimplemented
            return Promise.ref(true);
        }
    },

    /**
     Commits the transaction.<br>
     Any failure during this step will cause the store to be left an inconsistent state.
     @function
     @param {Property} context TODO
     @param {Id} transactionId TODO
     @returns {Boolean} Promise.ref(true)
     */
    commitChangesInContext$Implementation:{
        value:function (context, transactionId) {
            // TODO [PJYF Sep 27 2011] This needs to be reimplemented
            return Promise.ref(true);
        }
    },

    /**
     Description TODO
     @function
     @param {Property} query TODO
     @param {Property} context TODO
     @param {Id} transactionId TODO
     @param {name} Mapping folder name used for this transaction
     @returns this.queryInContext$Implementation(query, context, aTransactionId)
     */
    queryInContext:{
        value:function (query, context, transactionId, name) {
            var aTransactionId = transactionId;
            var hadOpenTransaction = false;
            try {
                if (aTransactionId == null) {
                    hadOpenTransaction = TransactionId.manager.hasCurrentTransaction();
                    if (hadOpenTransaction) {
                        aTransactionId = TransactionId.manager.currentTransaction();
                    } else {
                        aTransactionId = TransactionId.manager.startTransaction(name);
                    }
                }
                return this.queryInContext$Implementation(query, context, aTransactionId);
            } finally {
                if (!hadOpenTransaction) {
                    TransactionId.manager.closeTransaction(aTransactionId);
                }
            }
        }
    },

    /**
     Description TODO
     @function
     @param {Property} query TODO
     @param {Property} context TODO
     @param {Id} transactionId TODO
     @returns {Array} Promise.ref([])
     */
    queryInContext$Implementation:{
        value:function (query, context, transactionID) {
            // TODO [PJYF Sept 4 2011] This needs to be implemented
            return Promise.ref([]);
        }
    }


});
var Montage=require("montage").Montage,logger=require("core/logger").logger("store-connection-information"),StoreConnectionInformation=exports.StoreConnectionInformation=Montage.create(Montage,{initWithNameAndInformation:{value:function(e,t,n,r){return this._name=e,this._url=t,this._username=n,this._password=r,this}},equals:{value:function(e){if(!e)return!1;var t=Montage.getInfoForObject(e);if(!t)return!1;var n=Montage.getInfoForObject(this);return t.objectName===n.objectName&&t.moduleId===n.moduleId?this._name===e._name&&this._url===e._url&&this._username===e._username&&this._password===e._password:!1}},_name:{serializable:!0,enumerable:!1,value:null},name:{get:function(){return this._name}},_url:{serializable:!0,enumerable:!1,value:null},url:{get:function(){return this._url}},_username:{serializable:!0,enumerable:!1,value:null},username:{get:function(){return this._username}},_password:{serializable:!0,enumerable:!1,value:null},password:{get:function(){return this._password}}})
示例#4
0
var Montage = require("montage").Montage;

exports.GetStatsResult = Montage.specialize({
    _data: {
        value: null
    },
    data: {
        set: function (value) {
            if (this._data !== value) {
                this._data = value;
            }
        },
        get: function () {
            return this._data;
        }
    }
}, {
    propertyBlueprints: {
        value: [{
            mandatory: false,
            name: "data",
            valueType: "array"
        }]
    }
});
示例#5
0
  contributors may be used to endorse or promote products derived from this
  software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
</copyright> */
exports = typeof exports !== "undefined" ? exports : {};

var Montage = require("montage").Montage;
var Component = require("montage/ui/component").Component;
var ComponentFather = require("reel/template/componentfather.reel").ComponentFather;

var ComponentSon = exports.ComponentSon = Montage.create(ComponentFather, {
    _templateModuleId: {value: "../componentfather.reel/componentfather.html"},

    draw: {
        value: function() {
            this._element.textContent = "Component Son";
        }
    }
});
示例#6
0
exports.ServiceSshd = Montage.specialize({
    _allow_gssapi_auth: {
        value: null
    },
    allow_gssapi_auth: {
        set: function (value) {
            if (this._allow_gssapi_auth !== value) {
                this._allow_gssapi_auth = value;
            }
        },
        get: function () {
            return this._allow_gssapi_auth;
        }
    },
    _allow_password_auth: {
        value: null
    },
    allow_password_auth: {
        set: function (value) {
            if (this._allow_password_auth !== value) {
                this._allow_password_auth = value;
            }
        },
        get: function () {
            return this._allow_password_auth;
        }
    },
    _allow_port_forwarding: {
        value: null
    },
    allow_port_forwarding: {
        set: function (value) {
            if (this._allow_port_forwarding !== value) {
                this._allow_port_forwarding = value;
            }
        },
        get: function () {
            return this._allow_port_forwarding;
        }
    },
    _allow_pubkey_auth: {
        value: null
    },
    allow_pubkey_auth: {
        set: function (value) {
            if (this._allow_pubkey_auth !== value) {
                this._allow_pubkey_auth = value;
            }
        },
        get: function () {
            return this._allow_pubkey_auth;
        }
    },
    _auxiliary: {
        value: null
    },
    auxiliary: {
        set: function (value) {
            if (this._auxiliary !== value) {
                this._auxiliary = value;
            }
        },
        get: function () {
            return this._auxiliary;
        }
    },
    _compression: {
        value: null
    },
    compression: {
        set: function (value) {
            if (this._compression !== value) {
                this._compression = value;
            }
        },
        get: function () {
            return this._compression;
        }
    },
    _enable: {
        value: null
    },
    enable: {
        set: function (value) {
            if (this._enable !== value) {
                this._enable = value;
            }
        },
        get: function () {
            return this._enable;
        }
    },
    _permit_root_login: {
        value: null
    },
    permit_root_login: {
        set: function (value) {
            if (this._permit_root_login !== value) {
                this._permit_root_login = value;
            }
        },
        get: function () {
            return this._permit_root_login;
        }
    },
    _port: {
        value: null
    },
    port: {
        set: function (value) {
            if (this._port !== value) {
                this._port = value;
            }
        },
        get: function () {
            return this._port;
        }
    },
    _sftp_log_facility: {
        value: null
    },
    sftp_log_facility: {
        set: function (value) {
            if (this._sftp_log_facility !== value) {
                this._sftp_log_facility = value;
            }
        },
        get: function () {
            return this._sftp_log_facility;
        }
    },
    _sftp_log_level: {
        value: null
    },
    sftp_log_level: {
        set: function (value) {
            if (this._sftp_log_level !== value) {
                this._sftp_log_level = value;
            }
        },
        get: function () {
            return this._sftp_log_level;
        }
    },
    _type: {
        value: null
    },
    type: {
        set: function (value) {
            if (this._type !== value) {
                this._type = value;
            }
        },
        get: function () {
            return this._type;
        }
    }
}, {
    propertyBlueprints: {
        value: [{
            mandatory: false,
            name: "allow_gssapi_auth",
            valueType: "boolean"
        }, {
            mandatory: false,
            name: "allow_password_auth",
            valueType: "boolean"
        }, {
            mandatory: false,
            name: "allow_port_forwarding",
            valueType: "boolean"
        }, {
            mandatory: false,
            name: "allow_pubkey_auth",
            valueType: "boolean"
        }, {
            mandatory: false,
            name: "auxiliary",
            valueType: "String"
        }, {
            mandatory: false,
            name: "compression",
            valueType: "boolean"
        }, {
            mandatory: false,
            name: "enable",
            valueType: "boolean"
        }, {
            mandatory: false,
            name: "permit_root_login",
            valueType: "boolean"
        }, {
            mandatory: false,
            name: "port",
            valueType: "number"
        }, {
            mandatory: false,
            name: "sftp_log_facility",
            valueObjectPrototypeName: "ServiceSshdSftplogfacility",
            valueType: "object"
        }, {
            mandatory: false,
            name: "sftp_log_level",
            valueObjectPrototypeName: "ServiceSshdSftploglevel",
            valueType: "object"
        }, {
            mandatory: false,
            name: "type"
        }]
    }
});
示例#7
0
var Layer = exports.Layer = Montage.specialize(/** @lends Layer.prototype */ {

    /***************************************************************************
     * Map service
     */

    mapService: {
        value: undefined
    },

    mapServiceLayerId: {
        value: undefined
    },

    /***************************************************************************
     * Basic information
     */

    id: {
        value: undefined
    },

    name: {
        value: ""
    },

    opacity: {
        value: 1
    },

    description: {
        value: ""
    },

    depth: {
        value: 0
    },

    initialBounds: {
        value: undefined
    },

    availableTimes: {
        value: undefined
    },

    clusterBehavior: {
        value: undefined
    },

    group: {
        value: undefined
    },

    url: {
        value: undefined
    },

    legendUrl: {
        value: undefined
    },

    timeServiceUrl: {
        value: undefined
    },

    /***************************************************************************
     * Type information
     */

    geometryType: {
        get: function () {
            return this._geometryType;
        },
        set: function (type) {
            if (type !== this._geometryType) {
                this.dispatchBeforeOwnPropertyChange("canCluster", this.canCluster);
                this.dispatchBeforeOwnPropertyChange("canSetTransparency", this.canSetTransparency);
                this.dispatchBeforeOwnPropertyChange("type", this.type);
                this._geometryType = type;
                this.dispatchOwnPropertyChange("canCluster", this.canCluster);
                this.dispatchOwnPropertyChange("canSetTransparency", this.canSetTransparency);
                this.dispatchOwnPropertyChange("type", this.type);
            }
        }
    },

    isBackground: {
        value: false
    },

    /***************************************************************************
     * State information
     */

    /**
     * When not explicitly set, the type will be derived from the layer's
     * geometry type, its current zoom level, and its map service prototol.
     *
     * @type {Layer.Type}
     */
    type: {
        get: function () {
            return  this._type ?                                                     this._type :
                    this.geometryType === GeometryType.RASTER ?                     Layer.Type.RASTER :
                    this.mapService && this.mapService.protocol === Protocol.WMS ?  Layer.Type.RASTER :
                    this.mapService && this.mapService.protocol === Protocol.WMTS ? Layer.Type.RASTER :
                    this._zoom < this.featureMinZoom ?                              Layer.Type.RASTER :
                                                                                    Layer.Type.FEATURE;
        },
        set: function (type) {
            if (type instanceof Layer.Type || !type) {
                this._type = type || undefined;
            }
        }
    },

    canAnimate: {
        get: function () {
            return this.timeServiceUrl !== undefined;
        }
    },

    canCluster: {
        get: function () {
            // TODO: removing logic for cluster behavior until we figure out why it's getting reset to undefined.
            //return this.geometryType === GeometryType.POINT || this.geometryType === GeometryType.MULTI_POINT && this.clusterBehavior === Layer.ClusteringBehavior.CHANGEABLE;
            return this.geometryType === GeometryType.POINT || this.geometryType === GeometryType.MULTI_POINT;
        }
    },

    canSetTransparency: {
        get: function () {
            // TODO: removing logic for cluster behavior until we figure out why it's getting reset to undefined.
            //return this.geometryType === GeometryType.POINT || this.geometryType === GeometryType.MULTI_POINT && this.clusterBehavior === Layer.ClusteringBehavior.CHANGEABLE;
            return this.geometryType === GeometryType.RASTER || this.geometryType === GeometryType.MULTI_LINE_STRING || this.geometryType === GeometryType.POLYGON;
        }
    },

    isClustering: {
        value: false
    },

    isEnabled: {
        get: function () {
            return this._isEnabled || false;
        },
        set: function (enabled) {
            var self = this;
            if (!enabled && this.isEnabled) {
                this._isEnabled = false;
                this.map = null;
            } else if (enabled && !this.isEnabled) {
                DataService.mainService.getObjectData(this, "geometryType").then(function () {
                    if (!self.isEnabled) {
                        self.dispatchBeforeOwnPropertyChange("isEnabled", false);
                        self._isEnabled = true;
                        self.dispatchOwnPropertyChange("isEnabled", true);
                        self.map = application.delegate && application.delegate.map;
                    }
                });
            }
        }
    },

    /***************************************************************************
     * Zoom information
     */

    minZoom: {
        value: undefined
    },

    maxZoom: {
        value: undefined
    },

    isVisibleAtZoom: {
        value: function (zoom) {
            return !this.minZoom || zoom >= this.minZoom && !this.maxZoom || zoom <= this.maxZoom;
        }
    },

    /***************************************************************************
     * Feature information
     */

    areFeaturesGlobal: {
        get: function () {
            return this._areFeaturesGlobal || false;
        },
        set: function (areGlobal) {
            if (areGlobal != this.areFeaturesGlobal) {
                this._areFeaturesGlobal = areGlobal ? true : false;
                // TODO: Update bounds and visible features accordingly.
            }
        }
    },

    featureMinZoom: {
        value: 0
    },

    featureFields: {
        get: function () {
            var layer = this;
            if (!this._featureFields) {
                this._featureFields = Object.create({}, {
                    all: {
                        get: function () { return layer._featureFields_all; }
                    },
                    detail: {
                        get: function () { return layer._featureFields_detail; }
                    },
                    filter: {
                        get: function () { return layer._featureFields_filter; }
                    },
                    summary: {
                        get: function () { return layer._featureFields_summary; }
                    }
                });
            }
            return this._featureFields;
        }
    },

    _featureFields_all: {
        get: function () {
            if (!this.__featureFields_all) {
                this.__featureFields_all = [];
            }
            return this.__featureFields_all;
        }
    },

    _featureFields_detail: {
        get: function () {
            if (!this.__featureFields_detail) {
                this.__featureFields_detail = [];
            }
            return this.__featureFields_detail;
        }
    },

    _featureFields_filter: {
        get: function () {
            if (!this.__featureFields_filter) {
                this.__featureFields_filter = [];
            }
            return this.__featureFields_filter;
        }
    },

    _featureFields_summary: {
        get: function () {
            if (!this.__featureFields_summary) {
                this.__featureFields_summary = [];
            }
            return this.__featureFields_summary;
        }
    },

    featureFieldConfiguration: {
        get: function () {
            if (!this._featureFieldConfiguration) {
                this._featureFieldConfiguration = {};
            }
            return this._featureFieldConfiguration;
        }
    },

    featureCriteria: {
        get: function () {
            if (!this._featureCriteria) {
                this._featureCriteria = FeatureCriteria.withLayerBoundsAndFilters(this, this.bounds);
            }
            return this._featureCriteria;
        },
        set: function (criteria) {
            if (criteria !== this._featureCriteria) {
                this._featureCriteria = criteria;
                 //if (this.__features_all) {
                 //    DataService.mainService.getChildService(Layer.TYPE).getPropertyData(this, "_features_all");
                 //}
                 //if (this.__features_visible) {
                 //    DataService.mainService.getChildService(Layer.TYPE).getPropertyData(this, "_features_visible");
                 //}
                if (this.areFeaturesGlobal) {
                    DataService.mainService.getChildService(Layer.TYPE).getPropertyData(this, "_features_all");
                } else {
                    DataService.mainService.getChildService(Layer.TYPE).getPropertyData(this, "_features_visible");
                }
            }
        }
    },

    features: {
        get: function () {
            var layer = this;
            if (!this._features) {
                this._features = Object.create({}, {
                    all: {
                        get: function () { return layer._features_all; }
                    },
                    visible: {
                        get: function () { return layer._features_visible; }
                    }
                });
            }
            return this._features;
        }
    },

    _features_all: {
        get: function () {
            if (!this.__features_all) {
                this.__features_all = [];
            }
            return this.__features_all;
        }
    },

    _features_visible: {
        get: function () {
            if (!this.__features_visible) {
                this.__features_visible = [];
            }
            return this.__features_visible;
        }
    },

    /***************************************************************************
     * Map state
     */

    map: {
        get: function () {
            return this._map;
        },
        set: function (map) {
            if (map !== this._map) {
                this._map = map;
                if (this.getBinding("bounds")) {
                    this.cancelBinding("bounds");
                }
                if (this.getBinding("_zoom")) {
                    this.cancelBinding("_zoom");
                }
                if (map) {
                    this._bounds = undefined;
                    if (this.areFeaturesGlobal) {
                        DataService.mainService.getChildService(Layer.TYPE).getPropertyData(this, "_features_all");
                    } else {
                        this.defineBinding("bounds", {"<-": "bounds", "source": map});
                    }
                    this.defineBinding("_zoom", {"<-": "currentZoom", "source": map});
                }
            }
        }
    },

    bounds: {
        get: function () {
            return this._bounds || Bounds.EARTH;
        },
        set: function (bounds) {
            if (bounds && !(bounds instanceof Bounds)) {
                // TODO [Charles]: Remove when map's currentBounds are Bounds.
                bounds = Bounds.withCoordinates(bounds.west, bounds.south, bounds.east, bounds.north);
            }
            if (bounds instanceof Bounds && !bounds.equals(this.bounds) || !bounds && this._bounds) {
                // TODO [Charles]: Fix & use
                // DataService.mainService.updateObjectData() instead of
                // DataService.mainService.getChildService(Layer.TYPE)... Layers
                // shouldn't need to know about any service other than
                // DataService.mainService.
                this._bounds = bounds && !bounds.equals(Bounds.EARTH) ? bounds : undefined;
                //DataService.mainService.getChildService(Layer.TYPE).getPropertyData(this, "_features_visible");
                this.featureCriteria = FeatureCriteria.withLayerBoundsAndFilters(this, this._bounds, this.featureCriteria.filters);
            }
        }
    },

    _zoom: {
        get: function () {
            return this.isEnabled ? this.__zoom : 0;
        },
        set: function (zoom) {
            if (zoom !== this.__zoom) {
                this.dispatchBeforeOwnPropertyChange("type", this.type);
                this.__zoom = zoom;
                this.dispatchOwnPropertyChange("type", this.type);
            }
        }
    },

    /***************************************************************************
     * Rendering
     */

    /**
     * A dictionary for the symbols the engine creates to represent a feature.
     */
    symbols: {
        get: function () {
            if (!this._symbols) {
                this._symbols = {};
            }
            return this._symbols;
        }
    },

    toGeojson: {
        value: function () {
            var features = this.features.all,
                geoJsonFeatures = [],
                i, len;

            if (this.geometryType === GeometryType.RASTER) {
                return null;
            }

            for (i = 0, len = features.length; i < len; i++) {
                geoJsonFeatures.push(features[i].toGeojson());
            }

            return {
                type: "FeatureCollection",
                properties: {
                    name: this.name,
                    description: this.description
                },
                features: geoJsonFeatures
            };
        }
    }

}, /** @lends Layer */ {

    /***************************************************************************
     * Montage data
     */

    /**
     * The Montage Data type of layers.
     *
     * @type {external:ObjectDescriptor}
     */
    TYPE: {
        get: ObjectDescriptor.getterFor(exports, "Layer", {
            "_features_all": {destinationType: Feature.TYPE},
            "_features_visible": {destinationType: Feature.TYPE},
            "_featureFields_all": {destinationType: null},
            "_featureFields_detail": {destinationType: null},
            "_featureFields_summary": {destinationType: null},
            "availableTimes": {destinationType: null},
            "canCluster": {destinationType: null},
            "canSetTransparency": {destinationType: null},
            "geometryType": {destinationType: null},
            "initialBounds": {destinationType: null},
            "renderer": {destinationType: null},
            "type": {destinationType: null},
            "url": {destinationType: null}
        })
    },

    /***************************************************************************
     * Types
     */

    /**
     * @class
     */
    Type: {
        get: Enumeration.getterFor("_Type", "", "name", {
            FEATURE: ["Feature"],
            HAZARD: ["Hazard"],
            HEAT_MAP: ["Heat Map"],
            IMPORT: ["Import"],
            PRODUCT: ["Product"],
            RASTER: ["Raster"]
        })
    },

    /**
     * @class
     */
    ClusteringBehavior: {
        get: Enumeration.getterFor("_ClusteringBehavior", "", "name", {
            ALWAYS_ON: ["always"],
            ALWAYS_OFF: ["never"],
            CHANGEABLE: ["changeable"]
        })
    }

});
示例#8
0
  contributors may be used to endorse or promote products derived from this
  software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
</copyright> */
/**
    @module montage/data/ldap-access/ldap-object-id
    @requires montage/core/core
    @requires montage/core/logger
*/
var Montage = require("montage").Montage;
var logger = require("core/logger").logger("ldap-object-id");
/**
    @class module:montage/data/ldap-access/ldap-object-id.LdapObjectId
    @extends module:montage/core/core.Montage
*/
var LdapObjectId = exports.LdapObjectId = Montage.create(Montage,/** @lends module:montage/data/ldap-access/ldap-object-id.LdapObjectId # */ {


});
var ActionEventListener = exports.ActionEventListener = Montage.create(Montage, /** @lends module:montage/core/event/action-event-listener.ActionEventListener# */ {

/**
    The object to handle the event.
    @type {Property}
    @default {Event handler} null
*/
    handler: {
        value: null,
        serializable: true
    },

/**
    The action (function) to invoke on the handler object.
    @type {Property}
    @default {Event handler} null
*/
    action: {
        value: null,
        serializable: true
    },

/**
    Returns a new ActionEventListener instance with the specified handler and action.
    @function
    @param {Event} handler The event handler.
    @param {Event} action The event handler action.
    @returns itself
*/
    initWithHandler_action_: {
        value: function(handler, action) {
            this.handler = handler;
            this.action = action;

            return this;
        }
    },

/**
    @private
*/
    handleEvent: {
        value: function(event) {
            if (typeof this.action === "function") {
                // TODO call this in what context?
                this.action(event);
            } else {
                this.handler[this.action](event);
            }
        }
    },

/**
    @private
*/
    serializeProperties: {
        value: function(serializer) {
            serializer.set("handler", this.handler, "reference");
            serializer.set("action", this.action);
        }
    }

});
示例#10
0
exports.Stage = Montage.create(Component, /** @lends module:"montage/ui/stage.reel".Stage# */ {

    _vehicle: {
        value: null
    },

    vehicle: {
        get: function() {
            return this._vehicle;
        },
        set: function(value) {
            if (value === this._vehicle) {
                return;
            }

            if (this._vehicle) {
                this._vehicle.modelRepresentation = null;
            }

            this._vehicle = value;

            if (this.templateObjects && this._vehicle) {
                this._vehicle.modelRepresentation = this.collada;
            }
        }
    },

    collada: {
        get: function() {
            return this.templateObjects.collada;
        }
    },

    /**

     @param
         @returns
     */
    templateDidLoad:{
        value:function () {

            if (this.vehicle) {
                this.vehicle.modelRepresentation = this.collada;
            }

            if (this.model) {
                this.run(this.model, this.baseURL);
            }
        }
    },

    model: {value: null},

    model: {
        get: function() {
            return this._model;
        },
        set: function(value) {
            if (value === this._model) {
                return;
            }

            this._model = value;

            if (this._isComponentExpanded) {
                this.run(this.model, this.baseURL);
            }
        }
    },

    location: {value: null},

    _fillViewport: {
        value: true
    },

    fillViewport: {
        get: function() {
            return this._fillViewport;
        },
        set: function(value) {
            if (value === this._fillViewport) {
                return;
            }

            this._fillViewport = value;

            if (this._isComponentExpanded) {
                if (this._fillViewport) {
                    window.addEventListener("resize", this, true);
                } else {
                    window.removeEventListener("resize", this, true);
                }
            }
        }
    },

    height: {value: null},
    width: {value: null},

    prepareForDraw: {
        value: function() {
            if (this.fillViewport) {
                window.addEventListener("resize", this, true);
            }
        }
    },

    captureResize: {
        value: function(evt) {
            this.needsDraw = true;
        }
    },

    willDraw: {
        value: function() {
            this.collada.width = this.width = window.innerWidth - 270;
            this.collada.height = this.height = window.innerHeight;
        }
    },

    run: {
        value: function(scenePath, baseURL) {
            var readerDelegate = {};
            readerDelegate.loadCompleted = function (scene) {
                this.collada.scene = scene;
                this.collada.needsDraw = true;
            }.bind(this);
            var self = this;
            var angle = 0;
            var viewDelegate = {};
            viewDelegate.willDraw = function(view) {
            };

            viewDelegate.didDraw = function(view) {
            };

            this.collada.delegate = viewDelegate;

            var loader = Object.create(RuntimeTFLoader);
            loader.initWithPath(scenePath, require, baseURL);
            loader.delegate = readerDelegate;
            loader.load(null /* userInfo */, null /* options */);
            this.collada.needsDraw = true;
        }
    }

});
示例#11
0
exports.IpfsInfo = Montage.specialize({
    _Addresses: {
        value: null
    },
    Addresses: {
        set: function (value) {
            if (this._Addresses !== value) {
                this._Addresses = value;
            }
        },
        get: function () {
            return this._Addresses;
        }
    },
    _AgentVersion: {
        value: null
    },
    AgentVersion: {
        set: function (value) {
            if (this._AgentVersion !== value) {
                this._AgentVersion = value;
            }
        },
        get: function () {
            return this._AgentVersion;
        }
    },
    _ID: {
        value: null
    },
    ID: {
        set: function (value) {
            if (this._ID !== value) {
                this._ID = value;
            }
        },
        get: function () {
            return this._ID;
        }
    },
    _ProtocolVersion: {
        value: null
    },
    ProtocolVersion: {
        set: function (value) {
            if (this._ProtocolVersion !== value) {
                this._ProtocolVersion = value;
            }
        },
        get: function () {
            return this._ProtocolVersion;
        }
    },
    _PublicKey: {
        value: null
    },
    PublicKey: {
        set: function (value) {
            if (this._PublicKey !== value) {
                this._PublicKey = value;
            }
        },
        get: function () {
            return this._PublicKey;
        }
    }
}, {
    propertyBlueprints: {
        value: [{
            mandatory: false,
            name: "Addresses",
            valueType: "array"
        }, {
            mandatory: false,
            name: "AgentVersion",
            valueType: "String"
        }, {
            mandatory: false,
            name: "ID",
            valueType: "String"
        }, {
            mandatory: false,
            name: "ProtocolVersion",
            valueType: "String"
        }, {
            mandatory: false,
            name: "PublicKey",
            valueType: "String"
        }]
    }
});
示例#12
0
var TextInput = exports.TextInput =  Montage.create(NativeControl, {

/**
  Description TODO
  @private
*/
    _hasFocus: {
        enumerable: false,
        value: false
    },
/**
  Description TODO
  @private
*/
    _value: {
        enumerable: false,
        value: null
    },
/**
  Description TODO
  @private
*/
    _valueSyncedWithInputField: {
        enumerable: false,
        value: false
    },
/**
        Description TODO
        @type {Function}
        @default null
    */
    value: {
        enumerable: true,
        serializable: true,
        get: function() {
            return this._value;
        },
        set: function(value, fromInput) {

            if(value !== this._value) {
                if(this.converter) {
                    var convertedValue;
                    try {
                        convertedValue = this.converter.revert(value);
                        if (this.error) {
                            this.error = null;
                        }
                        this._value = convertedValue;

                    } catch(e) {
                        // unable to convert - maybe error
                        this.error = e;
                        this._valueSyncedWithInputField = false;
                    }

                } else {
                    this._value = value;
                }

                if(fromInput) {
                    this._valueSyncedWithInputField = true;
                    //this.needsDraw = true;
                } else {
                    this._valueSyncedWithInputField = false;
                    this.needsDraw = true;
                }
            }
        }
    },

    // set value from user input
    /**
      @private
    */
    _setValue: {
        value: function() {
            var newValue = this.element.value;
            Object.getPropertyDescriptor(this, "value").set.call(this, newValue, true);
        }
    },
/**
        Description TODO
        @type {Property}
        @default null
    */
    converter:{
        value: null
    },
/**
  Description TODO
  @private
*/
    _error: {
        value: false
    },
 /**
        Description TODO
        @type {Function}
        @default {Boolean} false
    */
    error: {
        get: function() {
            return this._error;
        },
        set: function(v) {
            this._error = v;
            this.errorMessage = this._error ? this._error.message : null;
            this.needsDraw = true;
        }
    },

    _errorMessage: {value: null},
    errorMessage: {
        get: function() {
            return this._errorMessage;
        },
        set: function(v) {
            this._errorMessage = v;
        }
    },

/**
  Description TODO
  @private
*/
    _updateOnInput: {
        value: true
    },

    // switch to turn off auto update upon keypress overriding the Converter flag
/**
        Description TODO
        @type {Function}
        @default {Boolean} true
    */
    updateOnInput: {
        get: function() {
            return !!this._updateOnInput;
        },
        set: function(v) {
            this._updateOnInput = v;
        }
    },

    // Callbacks
    /**
    Description TODO
    @function
    */
    prepareForDraw: {
        enumerable: false,
        value: function() {
            var el = this.element;
            el.addEventListener("focus", this);
            el.addEventListener('input', this);
            el.addEventListener('change', this);
            el.addEventListener('blur', this);
        }
    },
/**
  Description TODO
  @private
*/
    _setElementValue: {
        value: function(value) {
            this.element.value = (value == null ? '' : value);
        }
    },
/**
    Description TODO
    @function
    */
    draw: {
        enumerable: false,
        value: function() {

            var t = this.element;

            if (!this._valueSyncedWithInputField) {
                this._setElementValue(this.converter ? this.converter.convert(this._value) : this._value);
            }


            if (this.error) {
                t.classList.add('montage-text-invalid');
                t.title = this.error.message || '';
            } else {
                t.classList.remove("montage-text-invalid");
                t.title = '';
            }

            var fn = Object.getPrototypeOf(TextInput).draw;
            fn.call(this);

        }
    },
/**
    Description TODO
    @function
    */
    didDraw: {
        enumerable: false,
        value: function() {
            if (this._hasFocus && this._value != null) {
                var length = this._value.toString().length;
                this.element.setSelectionRange(length, length);
            }
            this._valueSyncedWithInputField = true;
        }
    },
    // Event handlers
/**
    Description TODO
    @function
    */
    handleInput: {
        enumerable: false,
        value: function() {
            if (this.converter) {
                if (this.converter.allowPartialConversion === true && this.updateOnInput === true) {
                    this._setValue();
                }
            } else {
                this._setValue();
            }
        }
    },
/**
    Description TODO
    @function
    @param {Event Handler} event TODO
    */
    handleChange: {
        enumerable: false,
        value: function(event) {
            this._setValue();
            this._hasFocus = false;
        }
    },
/**
    Description TODO
    @function
    @param {Event Handler} event TODO
    */
    handleBlur: {
        enumerable: false,
        value: function(event) {
            this._hasFocus = false;
        }
    },
/**
    Description TODO
    @function
    @param {Event Handler} event TODO
    */
    handleFocus: {
        enumerable: false,
        value: function(event) {
            this._hasFocus = true;
        }
    }

});
示例#13
0
var Montage=require("montage").Montage,Component=require("ui/component").Component,NativeControl=require("ui/native-control").NativeControl,Progress=exports.Progress=Montage.create(NativeControl,{});Progress.addAttributes({form:null,max:{dataType:"number"},value:{dataType:"number"}})
示例#14
0
exports.VmDeviceNic = Montage.specialize({
    "_%type": {
        value: null
    },
    "%type": {
        set: function (value) {
            if (this["_%type"] !== value) {
                this["_%type"] = value;
            }
        },
        get: function () {
            return this["_%type"];
        }
    },
    _bridge: {
        value: null
    },
    bridge: {
        set: function (value) {
            if (this._bridge !== value) {
                this._bridge = value;
            }
        },
        get: function () {
            return this._bridge;
        }
    },
    _device: {
        value: null
    },
    device: {
        set: function (value) {
            if (this._device !== value) {
                this._device = value;
            }
        },
        get: function () {
            return this._device;
        }
    },
    _link_address: {
        value: null
    },
    link_address: {
        set: function (value) {
            if (this._link_address !== value) {
                this._link_address = value;
            }
        },
        get: function () {
            return this._link_address;
        }
    },
    _mode: {
        value: null
    },
    mode: {
        set: function (value) {
            if (this._mode !== value) {
                this._mode = value;
            }
        },
        get: function () {
            return this._mode;
        }
    }
}, {
    propertyBlueprints: {
        value: [{
            mandatory: false,
            name: "%type"
        }, {
            mandatory: false,
            name: "bridge",
            valueType: "String"
        }, {
            mandatory: false,
            name: "device",
            valueObjectPrototypeName: "VmDeviceNicDevice",
            valueType: "object"
        }, {
            mandatory: false,
            name: "link_address",
            valueType: "String"
        }, {
            mandatory: false,
            name: "mode",
            valueObjectPrototypeName: "VmDeviceNicMode",
            valueType: "object"
        }]
    }
});
示例#15
0
exports.RadioButtonController = Montage.specialize(/** @lends RadioButtonController# */ {

    _radioButtons: {
        value: null
    },

    _content: {
        value: null
    },

    /**
     * The list of possible options.
     * @type Array.<Object>
     */
    content: {
        get: function () {
            return this.getPath("contentController.content");
        },
        set: function (content) {
            this.contentController = new RangeController()
                .initWithContent(content);
        }
    },

    contentController: {
        value: null
    },

    /**
     * The radio button component corresponding to the currently-selected option.
     * @type {?Component}
     */
    selectedRadioButton: {
        value: null
    },

    _value: {
        value: null
    },

    /**
     * The currently-selected option.
    */
    value: {
        set: function(value) {
            if (this._value !== value) {
                this._value = value;
                this._updateRadioButtons();
            }
        },
        get: function() {
            return this._value;
        }
    },

    /**
     * @private
     */
    constructor: {
        value: function RadioButtonController() {
            this._radioButtons = [];

            this.addRangeAtPathChangeListener("_radioButtons.map{checked}", this, "handleRadioButtonChange");
            this.defineBinding("value ", {
                "<->": "contentController.selection.0"
            });
        }
    },

    _updateRadioButtons: {
        value: function() {
            var value = this._value;

            for (var i = 0, ii = this._radioButtons.length; i < ii; i++) {
                if (value === this._radioButtons[i].value) {
                    this._radioButtons[i].checked = true;
                    break;
                }
            }
        }
    },

    /**
     * Add a radio button to be managed by this controller.
     * @method
     * @param {RadioButton} radioButton
     * @returns {undefined}
     */
    registerRadioButton: {
        value: function(radioButton) {
            if (this._radioButtons.indexOf(radioButton) === -1) {
                this._radioButtons.push(radioButton);
                this._updateRadioButtons();
            }
        }
    },

    /**
     * Remove a radio button from being managed by this controller.
     * @method
     * @param {RadioButton} radioButton
     * @returns {undefined}
     */
    unregisterRadioButton: {
        value: function(radioButton) {
            var ix = this._radioButtons.indexOf(radioButton);
            if (ix >= 0) {
                this._radioButtons.splice(ix, 1);
                if (radioButton === this.selectedRadioButton) {
                    this.selectedRadioButton = null;
                }
            }
        }
    },

    handleRadioButtonChange: {
        value: function(plus, minus, index) {
            if (plus[0] === true) {
                for (var i = 0, ii = this._radioButtons.length; i < ii; i++) {
                    if (i === index) {
                        this.selectedRadioButton = this._radioButtons[i];
                        this.value = this.selectedRadioButton.value;
                    } else {
                        this._radioButtons[i].checked = false;
                    }
                }
            }
        }
    }
});
示例#16
0
var HttpError = exports.HttpError = Montage.specialize({

    constructor: {
        value: function HttpError() {
            this.stack = (new Error()).stack;
        }
    },

    isAuthorizationError: {
        get: function () {
            return this._isAuthorizationError || (this.statusCode === 401 || this.statusCode === 403);
        },
        set: function (value) {
            this._isAuthorizationError = value;
        }
    },

    message: {
        get: function () {
            if (!this._message) {
                this._message = "Status " + this.statusCode + " received for url: " + this.url;
            }
            return this._message;
        }
    },

    name: {
        value: "HttpError"
    },

    url: {
        value: undefined
    },

    statusCode: {
        value: undefined
    }

}, {

    withMessage: {
        value: function (message) {
            var error = new this();
            error._message = message;
            return error;
        }
    },


    withRequestAndURL: {
        value: function (request, url) {
            var error = new this();
            error.statusCode = request.status;
            error.url = url;
            return error;
        }
    }

});
var Montage = require("montage").Montage;

exports.VolumeAttributesAnonymous = Montage.specialize();
示例#18
0
var PressEvent = (function(){
    var value, eventProps, typeProps, eventPropDescriptor, typePropDescriptor, i;

    value = MutableEvent.specialize({
        type: {
            value: "press"
        },
        _event: {
            enumerable: false,
            value: null
        },
        event: {
            get: function() {
                return this._event;
            },
            set: function(value) {
                this._event = value;
            }
        },
        _touch: {
            enumerable: false,
            value: null
        },
        touch: {
            get: function() {
                return this._touch;
            },
            set: function(value) {
                this._touch = value;
            }
        }
    });

    // These properties are available directly on the event
    eventProps = ["altKey", "ctrlKey", "metaKey", "shiftKey",
    "cancelBubble", "currentTarget", "defaultPrevented",
    "eventPhase", "timeStamp", "preventDefault",
    "stopImmediatePropagation", "stopPropagation"];
    // These properties are available on the event in the case of mouse, and
    // on the _touch in the case of touch
    typeProps = ["clientX", "clientY", "pageX", "pageY", "screenX", "screenY", "target"];

    eventPropDescriptor = function(prop) {
        return {
            get: function() {
                return this._event[prop];
            }
        };
    };
    typePropDescriptor = function(prop) {
        return {
            get: function() {
                return (this._touch) ? this._touch[prop] : this._event[prop];
            }
        };
    };

    for (i = eventProps.length - 1; i >= 0; i--) {
        Montage.defineProperty(value, eventProps[i], eventPropDescriptor(eventProps[i]));
    }
    for (i = typeProps.length - 1; i >= 0; i--) {
        Montage.defineProperty(value, typeProps[i], typePropDescriptor(typeProps[i]));
    }

    return value;
}());
示例#19
0
exports.Stage = Montage.create(Component, /** @lends module:"montage/ui/stage.reel".Stage# */ {

    constructor: {
        value: function Stage () {
            this.super();
            this.modelsController = new RangeController().initWithContent([]);
            this.modelsController.selectAddedContent = true;
            this.camerasController = new RangeController().initWithContent([]);
            this.camerasController.selectAddedContent = true;

            this.defineBinding("model" ,{"<-": "modelsController.selection.0"});
            this.defineBinding("camera" ,{"<-": "camerasController.selection.0"});

            this.addOwnPropertyChangeListener("model", this);
            this.addOwnPropertyChangeListener("camera", this);
        }
    },

    view: {
        get: function() {
            return this.templateObjects ? this.templateObjects.view : null;
        }
    },

    /**
     */
    templateDidLoad:{
        value:function () {
            this.view.delegate = this;
        }
    },

    enterDocument: {
        value: function(firstTime) {
            if(firstTime) {
                this.modelsController.content = [

                    { "name": "duck", "path": "model/duck/duck.json"},
                    { "name": "Buggy", "path": "model/rambler/Rambler.json"},
                    { "name": "SuperMurdoch", "path": "model/SuperMurdoch/SuperMurdoch.json"},
                    { "name": "Wine", "path": "model/wine/wine.json"},
                   /*
                    { "name": "Nexus", "path": "model/NexusFlattened/NexusFlattened.json"},
                    { "name": "room1", "path": "model/room/testRoom5.json"},


                    { "name": "megacity", "path": "model/megacity/megacityVideo.json"},
                    { "name": "minebot", "path": "model/minebot/mine_bot_anim.json"},
                    { "name": "Buggy", "path": "model/rambler/Rambler.json"},
                    { "name": "BuggyFlatttened", "path": "model/rambler/RamblerFlattened.json"},
                    { "name": "Wine", "path": "model/wine/wine.json"},
                    { "name": "balloon", "path": "model/baloon3/baloon.json"},
                    { "name": "frigate", "path": "model/frigate/frigate.json"},
                    { "name": "brainsteam", "path": "model/brainsteam/brainsteam.json"},
                    { "name": "vc", "path": "model/vc/vc.json"},
                    { "name": "FemurTri", "path": "model/femur/FemurTri.json"},
                    { "name": "challenge", "path": "model/challenge/challengeFlattened.json"},
                    { "name": "monster", "path": "model/monster/monster.json"},
                    { "name": "FemurPoly", "path": "model/femur/FemurPoly.json"}*/
                ];
                this.modelPath = this.modelsController.content[0].path;
            }
            if (this.fillViewport) {
                window.addEventListener("resize", this, true);
            }
        }
    },

    exitDocument: {
        value: function() {
            if (this.fillViewport) {
                window.removeEventListener("resize", this, true);
            }
        }
    },


    willDraw: {
        value: function() {
            this.view.width = this.width = window.innerWidth - 270;
            this.view.height = this.height = window.innerHeight;
        }
    },

    bytesLimit: { value: 250},

    concurrentRequests: { value: 6},

    modelPath: {
        value: null
    },

    loadingProgress: {
        value: 0
    },

    location: {
        value: null
    },

    _fillViewport: {
        value: true
    },

    fillViewport: {
        get: function() {
            return this._fillViewport;
        },
        set: function(value) {
            if (value && ! this._fillViewport) {
                window.addEventListener("resize", this, true);
            } else if (! value && this._fillViewport) {
                window.removeEventListener("resize", this, true);
            }
            this._fillViewport = value;
        }
    },

    height: {value: null},
    width: {value: null},

    captureResize: {
        value: function(evt) {
            this.needsDraw = true;
        }
    },

    handleOptionsReload: {
        value: function() {
            this.loadScene();
        }
    },

    handleModelChange: {
        value: function() {
            this.run(this.model.path);
            this.loading = true;
        }
    },

    handleCameraChange: {
        value: function(camera) {
            if (camera) {
                var m3dNode = Montage.create(Node);
                m3dNode.scene = this.view.scene;
                m3dNode.id = camera.node.baseId;
                this.view.viewPoint = m3dNode;
            } else {
                //FIXME: handle this case
                //this.view.viewPoint = null;
            }
        }
    },

    run: {
        value: function(scenePath) {
            this.loadScene();
            if (this.view) {
                this.view.scenePath = scenePath;
            }
        }
    },

    loadScene: {
        value: function() {
            var self = this;
            var view = this.view;
            if (view) {
                if (view.sceneRenderer) {
                    if (view.sceneRenderer.scene) {
                        view.sceneRenderer.technique.rootPass.scene.rootNode.apply( function(node, parent) {
                            if (node.meshes) {
                                if (node.meshes.length) {
                                    node.meshes.forEach( function(mesh) {
                                        mesh.loadedPrimitivesCount = 0;
                                        mesh.step = 0;
                                    }, self);
                                }
                            }
                            return null;
                        } , true, null);
                    }
                }
            }
        }
    },

    /* View delegate methods*/

    sceneWillChange: {
        value: function() {
            var resourceManager = this.view.getResourceManager();
            if (resourceManager) {
                this.view.viewPoint = null;
                resourceManager.maxConcurrentRequests = this.concurrentRequests;
                resourceManager.bytesLimit = this.bytesLimit * 1024;
                resourceManager.reset();
            }
        }
    },

    sceneDidChange: {
        value: function() {
            if(this.view.scene) {
                this.loadScene();
                 var resourceManager = this.view.getResourceManager();
                 if (resourceManager) {
                     if (resourceManager.observers.length === 1) { //FIXME:...
                         resourceManager.observers.push(this);
                     }
                 }
                 this.camerasController.content = [];

                 var cameraNodes = [];
                 this.view.scene.glTFElement.rootNode.apply( function(node, parent, context) {
                     if (node.cameras) {
                         if (node.cameras.length)
                             cameraNodes = cameraNodes.concat(node);
                     }
                     return context;
                 } , true, null);

                 cameraNodes.forEach( function(cameraNode) {
                     this.camerasController.content.push( { "name": cameraNode.name, "node": cameraNode} );
                 }, this);
            }
        }
    },

    resourceAvailable: {
        value: function(resource) {
            if (resource.range && this.loading) {
                this.loadingProgress += ((resource.range[1] - resource.range[0])/this.view.totalBufferSize)*100;
                if (this.loadingProgress >= 99) {
                    this.loadingProgress = 0;
                    this.loading = false;
                }
            }
        }
    }


});
示例#20
0
exports.NetworkDevice = Montage.specialize({
    _description: {
        value: null
    },
    description: {
        set: function (value) {
            if (this._description !== value) {
                this._description = value;
            }
        },
        get: function () {
            return this._description;
        }
    },
    _name: {
        value: null
    },
    name: {
        set: function (value) {
            if (this._name !== value) {
                this._name = value;
            }
        },
        get: function () {
            return this._name;
        }
    }
}, {
    propertyBlueprints: {
        value: [{
            mandatory: false,
            name: "description",
            valueType: "String"
        }, {
            mandatory: false,
            name: "name",
            valueType: "String"
        }]
    }
});
示例#21
0
/* <copyright>
 This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
 No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
 (c) Copyright 2011 Motorola Mobility, Inc.  All Rights Reserved.
 </copyright> */
var Montage = require("montage").Montage;
var Effect = require("effect/effect").Effect;

exports.KaliedoscopeEffect = Montage.create(Effect, {

    applyEffect: {
        value: function() {
            console.log("kaliedoscope")
        }
    }

});
示例#22
0
var Selector = exports.Selector = Montage.specialize( {

    syntax: {
        value: null
    },

    initWithSyntax: {
        value: function (syntax) {
            this.syntax = syntax;
            return this;
        }
    },

    initWithPath: {
        value: function (path) {
            this.syntax = parse(path);
            return this;
        }
    },

    stringify: {
        value: function () {
            return stringify(this.syntax);
        }
    },

    serializeSelf: {
        value: function (serializer) {
            serializer.setProperty("path", stringify(this.syntax));
        }
    },

    deserializeSelf: {
        value: function (deserializer) {
            this.syntax = parse(deserializer.getProperty("path"));
        }
    },

    evaluate: {
        value: function (value, parameters) {
            return evaluate(this.syntax, value, parameters);
        }
    }

});
示例#23
0
/**
 * @module logic/earthquake.js
 */
var Montage = require("montage").Montage;

/**
 * @class Earthquake
 * @extends Montage
 *
 * Object representing an earthquake. This placehoder version just holds the
 * coordinates and magnitude of each earthquake, with the X, Y coordinates in
 * EPSG:3857 values. Eventually this earthquake class will be generated
 * dynamically from a blueprint.
 */
exports.Earthquake = Montage.specialize(/** @lends Earthquake.prototype */ {
    constructor: {
        value: function Earthquake(x, y, magnitude) {
            this.x = x;
            this.y = y;
            this.magnitude = magnitude;
        }
    }
});
示例#24
0
var Montage=require("montage").Montage,Component=require("ui/component").Component;exports.Scroller=Montage.create(Component,{_scrollX:{value:0},scrollX:{get:function(){return this._scrollX},set:function(e){this._scrollX!==e&&(this._scrollX=e,this.needsDraw=!0)}},_scrollY:{value:0},scrollY:{get:function(){return this._scrollY},set:function(e){this._scrollY!==e&&(this._scrollY=e,this.needsDraw=!0)}},_maxTranslateX:{value:0},_maxTranslateY:{value:0},_axis:{value:"auto"},axis:{get:function(){return this._axis},set:function(e){this._axis=e,this.needsDraw=!0}},_displayScrollbars:{value:"auto"},displayScrollbars:{get:function(){return this._displayScrollbars},set:function(e){switch(e){case"vertical":case"horizontal":case"both":case"auto":this._displayScrollbars=e;break;default:this._displayScrollbars="none"}this.needsDraw=!0}},_hasMomentum:{value:!0},hasMomentum:{get:function(){return this._hasMomentum},set:function(e){this._hasMomentum=e}},_content:{value:null},_scrollBars:{value:null},handleTranslateStart:{value:function(e){this._scrollBars.opacity=.5}},handleTranslateEnd:{value:function(e){this._scrollBars.opacity=0}},canDraw:{value:function(){return this.needsDraw=!0,Component.canDraw.apply(this,arguments)}},willDraw:{value:function(){this._left=this._element.offsetLeft,this._top=this._element.offsetTop,this._width=this._element.offsetWidth,this._height=this._element.offsetHeight,this._maxTranslateX=this._content.scrollWidth-this._width,this._maxTranslateX<0&&(this._maxTranslateX=0),this._maxTranslateY=this._content.offsetHeight-this._height,this._maxTranslateY<0&&(this._maxTranslateY=0);var e=this.callDelegateMethod("didSetMaxScroll",{x:this._maxTranslateX,y:this._maxTranslateY});e&&(this._maxTranslateX=e.x,this._maxTranslateY=e.y),this.scrollX=Math.min(this._scrollX,this._maxTranslateX),this.scrollY=Math.min(this._scrollY,this._maxTranslateY);switch(this._displayScrollbars){case"horizontal":this._scrollBars.displayHorizontal=!0,this._scrollBars.displayVertical=!1;break;case"vertical":this._scrollBars.displayHorizontal=!1,this._scrollBars.displayVertical=!0;break;case"both":this._scrollBars.displayHorizontal=!0,this._scrollBars.displayVertical=!0;break;case"auto":this._scrollBars.displayHorizontal=!!this._maxTranslateX,this._scrollBars.displayVertical=!!this._maxTranslateY;break;case"none":this._scrollBars.displayHorizontal=!1,this._scrollBars.displayVertical=!1}this._scrollBars.displayHorizontal&&(this._content.scrollWidth?(this._scrollBars.horizontalLength=this._width/this._content.scrollWidth,this._scrollBars.horizontalScroll=this._scrollX/this._content.scrollWidth):(this._scrollBars.horizontalLength=1,this._scrollBars.horizontalScroll=0)),this._scrollBars.displayVertical&&(this._content.offsetHeight?(this._scrollBars.verticalLength=this._height/this._content.offsetHeight,this._scrollBars.verticalScroll=this._scrollY/this._content.offsetHeight):(this._scrollBars.verticalLength=1,this._scrollBars.verticalScroll=0))}},draw:{value:function(){var e=-this._scrollX+"px, "+ -this._scrollY+"px";this._content.style.webkitTransform="translate3d("+e+", 0px)",this._content.style.MozTransform="translate("+e+")",this._content.style.transform="translate("+e+")"}}})
示例#25
0
  this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

* Neither the name of Motorola Mobility LLC nor the names of its
  contributors may be used to endorse or promote products derived from this
  software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
</copyright> */
var Montage = require("montage").Montage;

var NativeInputRangeTest = exports.NativeInputRangeTest = Montage.create(Montage, {
    scroll: {value: null},
    nativeInputRange1: {value: null},
    nativeInputRange: {value: null},
    scroll_range: {value: null}
});
示例#26
0
var Montage=require("montage").Montage,Point=require("core/geometry/point").Point,CubicBezier=exports.CubicBezier=Montage.create(Montage,{init:{enumerable:!1,value:function(e){return e!==null&&(e.length===2?(this.p1=e[0],this.p2=e[1]):e.length===4&&(this.p0=e[0],this.p1=e[1],this.p2=e[2],this.p3=e[3])),this}},position:{enumerable:!1,value:function(e){if(e<0||e>1)return;e=1-e;var t=e*e*e,n=3*e*e*(1-e),r=3*e*(1-e)*(1-e),i=(1-e)*(1-e)*(1-e);return Montage.create(Point).init(this.p0.x*t+this.p1.x*n+this.p2.x*r+this.p3.x*i,this.p0.y*t+this.p1.y*n+this.p2.y*r+this.p3.y*i)}},split:{enumerable:!1,value:function(e){return this.makeScaffolding(e),CubicBezier.create(CubicBezier).init([this.p0,this.p01,this.p012,this.p0123])}},splitToTimingFunction:{enumerable:!1,value:function(e){this.makeScaffolding(e);var t=this.p0123.x,n=this.p0123.y;return CubicBezier.create(CubicBezier).init([Montage.create(Point).init(this.p01.x/t,this.p01.y/n),Montage.create(Point).init(this.p012.x/t,this.p012.y/n)])}},makeScaffolding:{enumerable:!1,value:function(e){e=1-e;var t=1e6;Montage.defineProperty(this,"p01",{value:Point.interpolate(e,this.p0,this.p1,t)}),Montage.defineProperty(this,"p12",{value:Point.interpolate(e,this.p1,this.p2,t)}),Montage.defineProperty(this,"p23",{value:Point.interpolate(e,this.p2,this.p3,t)}),Montage.defineProperty(this,"p012",{value:Point.interpolate(e,this.p01,this.p12,t)}),Montage.defineProperty(this,"p123",{value:Point.interpolate(e,this.p12,this.p23,t)}),Montage.defineProperty(this,"p0123",{value:Point.interpolate(e,this.p012,this.p123,t)})}},p0:{enumerable:!0,value:Montage.create(Point).init(0,0)},p1:{enumerable:!0,value:Montage.create(Point).init(0,0)},p2:{enumerable:!0,value:Montage.create(Point).init(1,1)},p3:{enumerable:!0,value:Montage.create(Point).init(1,1)}})
示例#27
0
文件: custom.js 项目: AlainRo/montage
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

* Neither the name of Motorola Mobility LLC nor the names of its
  contributors may be used to endorse or promote products derived from this
  software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
</copyright> */
var Montage = require("montage").Montage,
    Component = require("montage/ui/component").Component;

exports.Custom = Montage.create(Component, {
});
示例#28
0
"use strict";var Montage=require("montage").Montage,Selector=require("core/selector").Selector,PropertyValidationSemantics=require("core/meta/validation-semantics").PropertyValidationSemantics,logger=require("core/logger").logger("blueprint"),PropertyValidationRule=exports.PropertyValidationRule=Montage.create(Montage,{initWithNameAndBlueprint:{value:function(e,t){return this._name=e,this._blueprint=t,this}},serializeSelf:{value:function(e){e.setProperty("name",this.name),e.setProperty("blueprint",this.blueprint,"reference"),e.setProperty("messageKey",this.messageKey),e.setProperties()}},deserializeSelf:{value:function(e){this._name=e.getProperty("name"),this._blueprint=e.getProperty("blueprint"),this._messageKey=e.getProperty("messageKey");var t=Montage.getSerializablePropertyNames(this);for(var n=0,r=t.length;n<r;n++){var i=t[n];this[i]=e.getProperty(i)}}},_blueprint:{value:null},blueprint:{get:function(){return this._blueprint}},identifier:{get:function(){return[this.blueprint.identifier,"rule",this.name].join("_")}},_name:{value:""},name:{get:function(){return this._name}},_validationSelector:{value:null},validationSelector:{serializable:!1,get:function(){return this._validationSelector||(this._validationSelector=Selector["false"]),this._validationSelector},set:function(e){this._validationSelector=e}},_messageKey:{value:""},messageKey:{serializable:!1,get:function(){return!this._messageKey||this._messageKey.length===0?this._name:this._messageKey},set:function(e){this._messageKey=e}},_propertyValidationEvaluator:{value:null},evaluateRule:{value:function(e){if(this._propertyValidationEvaluator===null){var t=PropertyValidationSemantics.create().initWithBlueprint(this.blueprint);this._propertyValidationEvaluator=t.compile(this.selector.syntax)}return this._propertyValidationEvaluator(e)}}})
示例#29
0
var Flow = exports.Flow = Montage.create(Component, {

    _repetition: {
        serializable: true,
        value: null
    },

    _translateComposer: {
        serializable: true,
        value: null
    },

    _splinePaths: {
        enumerable: false,
        value: null
    },

    splinePaths: {
        enumerable: false,
        get: function () {
            if (!this._splinePaths) {
                this._splinePaths = [];
            }
            return this._splinePaths;
        },
        set: function (value) {
            this._splinePaths = value;
        }
    },

    appendPath: {
        value: function (path) {
            var splinePath = Object.create(FlowBezierSpline).init(),
                pathKnots = path.knots,
                length = path.knots.length,
                knots = [],
                nextHandlers = [],
                previousHandlers = [],
                densities = [],
                i, j;

            splinePath.parameters = {};
            for (i in path.units) {
                splinePath.parameters[i] = {
                    data: [],
                    units: path.units[i]
                };
            }
            for (i = 0; i < length; i++) {
                knots[i] = pathKnots[i].knotPosition;
                previousHandlers[i] = pathKnots[i].previousHandlerPosition;
                nextHandlers[i] = pathKnots[i].nextHandlerPosition;
                densities[i] = pathKnots[i].previousDensity; // TODO: implement previous/next density
                for (j in path.units) {
                    splinePath.parameters[j].data.push(pathKnots[i][j]);
                }
            }
            splinePath.knots = knots;
            splinePath.previousHandlers = previousHandlers;
            splinePath.nextHandlers = nextHandlers;
            splinePath.densities = densities;
            splinePath._computeDensitySummation();
            this.splinePaths.push(splinePath);
            if (!path.hasOwnProperty("headOffset")) {
                path.headOffset = 0;
            }
            if (!path.hasOwnProperty("tailOffset")) {
                path.tailOffset = 0;
            }
            this._paths.push(path);
            this._updateLength();
        }
    },

    _paths: {
        enumerable: false,
        value: null
    },

    paths: { // TODO: listen for changes?
        serializable: true,
        get: function () {
            return this._paths;
        },
        set: function (value) {
            var length = value.length,
                i;

            if (length) {

                if (!this._paths) {
                    this._paths = [];
                } else {
                    this._paths.wipe();
                    this._splinePaths.wipe();
                }

                for (i = 0; i < length; i++) {
                    this.appendPath(value[i]);
                }
            }
        }
    },

    _cameraPosition: {
        enumerable: false,
        value: [0, 0, 800]
    },

    _cameraTargetPoint: {
        enumerable: false,
        value: [0, 0, 0]
    },

    _cameraFov: {
        enumerable: false,
        value: 50
    },

    // TODO: Implement camera roll

    _cameraRoll: {
        enumerable: false,
        value: 0
    },

    cameraPosition: {
        serializable: true,
        get: function () {
            return this._cameraPosition;
        },
        set: function (value) {
            this._cameraPosition = value;
            this._isCameraUpdated = true;
            this.needsDraw = true;
        }
    },

    cameraTargetPoint: {
        serializable: true,
        get: function () {
            return this._cameraTargetPoint;
        },
        set: function (value) {
            this._cameraTargetPoint = value;
            this._isCameraUpdated = true;
            this.needsDraw = true;
        }
    },

    cameraFov: {
        serializable: true,
        get: function () {
            return this._cameraFov;
        },
        set: function (value) {
            this._cameraFov = value;
            this._isCameraUpdated = true;
            this.needsDraw = true;
        }
    },

    cameraRoll: {
        serializable: true,
        get: function () {
            return this._cameraRoll;
        },
        set: function (value) {
            this._cameraRoll = value;
            this._isCameraUpdated = true;
            this.needsDraw = true;
        }
    },

    _stride: {
        enumerable: false,
        value: 0
    },

    stride: {
        serializable: true,
        get: function () {
            return this._stride;
        },
        set: function (value) {
            this._stride = value;
            if (this._translateComposer) {
                this._translateComposer.translateStrideX = value * 300;
            }
        }
    },

    _scrollingTransitionDurationMiliseconds: {
        enumerable: false,
        value: 500
    },

    _scrollingTransitionDuration: {
        enumerable: false,
        value: "500ms"
    },

    scrollingTransitionDuration: { // TODO: think about using the Date Converter
        serializable: true,
        get: function () {
            return this._scrollingTransitionDuration;
        },
        set: function (duration) {
            var durationString = duration + "",
                length = durationString.length,
                value;

            if ((length >= 2) && (durationString[length - 1] === "s")) {
                if ((length >= 3) && (durationString[length - 2] === "m")) {
                    value = durationString.substr(0, length - 2) - 0;
                } else {
                    value = durationString.substr(0, length - 1) * 1000;
                }
            } else {
                value = durationString - 0;
                durationString += "ms";
            }
            if (!isNaN(value) && (this._scrollingTransitionDurationMiliseconds !== value)) {
                this._scrollingTransitionDurationMiliseconds = value;
                this._scrollingTransitionDuration = durationString;
            }
        }
    },

    _scrollingTransitionTimingFunctionBezier: {
        enumerable: false,
        value: [.25, .1, .25, 1]
    },

    _scrollingTransitionTimingFunction: {
        enumerable: false,
        value: "ease"
    },

    hasSelectedIndexScrolling: {
        serializable: true,
        value: false
    },

    selectedIndexScrollingOffset: {
        serializable: true,
        value: 0
    },

    _handleSelectedIndexesChange: {
        enumerable: false,
        value: function (event) {
            if (this.hasSelectedIndexScrolling && event.plus) {
                this.startScrollingIndexToOffset(event.plus[0], this.selectedIndexScrollingOffset);
            }
        }
    },

    _timingFunctions: {
        enumerable: false,
        value: {
            "ease": [.25, .1, .25, 1],
            "linear": [0, 0, 1, 1],
            "ease-in": [.42, 0, 1, 1],
            "ease-out": [0, 0, .58, 1],
            "ease-in-out": [.42, 0, .58, 1]
        }
    },

    scrollingTransitionTimingFunction: {
        serializable: true,
        get: function () {
            return this._scrollingTransitionTimingFunction;
        },
        set: function (timingFunction) {
            var string = timingFunction + "",
                bezier,
                i;

            if (this._timingFunctions.hasOwnProperty(string)) {
                this._scrollingTransitionTimingFunction = string;
                this._scrollingTransitionTimingFunctionBezier = this._timingFunctions[string];
            } else {
                if ((string.substr(0, 13) === "cubic-bezier(") && (string.substr(string.length - 1, 1) === ")")) {
                    bezier = string.substr(13, string.length - 14).split(",");

                    if (bezier.length === 4) {
                        for (i = 0; i < 4; i++) {
                            bezier[i] -= 0;
                            if (isNaN(bezier[i])) {
                                return;
                            }
                        }
                        if (bezier[0] < 0) {
                            bezier[0] = 0;
                        } else {
                            if (bezier[0] > 1) {
                                bezier[0] = 1;
                            }
                        }
                        if (bezier[2] < 0) {
                            bezier[2] = 0;
                        } else {
                            if (bezier[2] > 1) {
                                bezier[2] = 1;
                            }
                        }
                        // TODO: check it is not the same bezier
                        this._scrollingTransitionTimingFunction = "cubic-bezier(" + bezier + ")";
                        this._scrollingTransitionTimingFunctionBezier = bezier;
                    }
                }
            }
        }
    },

    _computeCssCubicBezierValue: {
        enumerable: false,
        value: function (x, bezier) {
            var t = .5,
                step = .25,
                t2,
                k,
                i;

            for (i = 0; i < 20; i++) { // TODO: optimize with Newton's method or similar
                t2 = t * t;
                k = 1 - t;
                if ((3 * (k * k * t * bezier[0] + k * t2 * bezier[2]) + t2 * t) > x) {
                    t -= step;
                } else {
                    t += step;
                }
                step *= .5;
            }
            t2 = t * t;
            k = 1 - t;
            return 3 * (k * k * t * bezier[1] + k * t2 * bezier[3]) + t2 * t;
        }
    },

    _isTransitioningScroll: {
        enumerable: false,
        value: false
    },

    stopScrolling: {
        value: function () {
            this._isTransitioningScroll = false;
            // TODO: Fire scrollingTransitionCancel event
        }
    },

    startScrollingIndexToOffset: { // TODO: Fire scrollingTransitionStart event
        value: function (index, offset) {
            this._scrollingOrigin = this.scroll;
            this._scrollingDestination = index - offset;
            if (this._scrollingDestination > this._length) {
                this._scrollingDestination = this._length;
            } else {
                if (this._scrollingDestination < 0) {
                    this._scrollingDestination = 0;
                }
            }
            this._isScrolling = true;
            this._scrollingStartTime = Date.now();
            this._isTransitioningScroll = true;
            this.needsDraw = true;
        }
    },

    _isCameraUpdated: {
        enumerable: false,
        value: true
    },

    _width: {
        enumerable: false,
        value: null
    },

    _height: {
        enumerable: false,
        value: null
    },

    _repetitionComponents: {
        enumerable: false,
        value: null
    },

    _elementsBoundingSphereRadius: {
        enumerable: false,
        value: 150
    },

    elementsBoundingSphereRadius: {
        serializable: true,
        get: function () {
            return this._elementsBoundingSphereRadius;
        },
        set: function (value) {
            if (this._elementsBoundingSphereRadius !== value) {
                this._elementsBoundingSphereRadius = value;
                this.needsDraw = true;
            }
        }
    },

    _halfPI: {
        enumerable: false,
        value: Math.PI*0.5
    },

    _doublePI: {
        enumerable: false,
        value: Math.PI*2
    },

    _computeFrustumNormals: {
        value: function(out) {
            var math = Math,
                angle = ((this.cameraFov * .5) * this._doublePI) / 360,
                y = math.sin(angle),
                z = math.cos(angle),
                x = (y * this._width) / this._height,
                vX = this.cameraTargetPoint[0] - this.cameraPosition[0],
                vY = this.cameraTargetPoint[1] - this.cameraPosition[1],
                vZ = this.cameraTargetPoint[2] - this.cameraPosition[2],
                yAngle = this._halfPI - math.atan2(vZ, vX),
                tmpZ = vX * math.sin(yAngle) + vZ * math.cos(yAngle),
                rX, rY, rZ,
                rX2, rY2, rZ2,
                xAngle = this._halfPI - math.atan2(tmpZ, vY),
                invLength,
                vectors = [[z, 0, x], [-z, 0, x], [0, z, y], [0, -z, y]],
                iVector,
                i;

            for (i = 0; i < 4; i++) {
                iVector = vectors[i];
                rX = iVector[0];
                rY = iVector[1] * math.cos(-xAngle) - iVector[2] * math.sin(-xAngle);
                rZ = iVector[1] * math.sin(-xAngle) + iVector[2] * math.cos(-xAngle);
                rX2 = rX * math.cos(-yAngle) - rZ * math.sin(-yAngle);
                rY2 = rY;
                rZ2 = rX * math.sin(-yAngle) + rZ * math.cos(-yAngle);
                invLength = 1 / math.sqrt(rX2 * rX2 + rY2 * rY2 + rZ2 * rZ2);
                out.push([rX2 * invLength, rY2 * invLength, rZ2 * invLength]);
            }
        }
    },

    _segmentsIntersection: {
        enumerable: false,
        value: function (segment1, segment2) {
            var n = 0,
                m = 0,
                start,
                end,
                result = [];

            while ((n < segment1.length) && (m < segment2.length)) {
                if (segment1[n][0] >= segment2[m][1]) {
                    m++;
                } else {
                    if (segment1[n][1] <= segment2[m][0]) {
                        n++;
                    } else {
                        if (segment1[n][0] >= segment2[m][0]) {
                            start = segment1[n][0];
                        } else {
                            start = segment2[m][0];
                        }
                        if (segment1[n][1] <= segment2[m][1]) {
                            end = segment1[n][1];
                        } else {
                            end = segment2[m][1];
                        }
                        result.push([start, end]);
                        if (segment1[n][1] < segment2[m][1]) {
                            n++;
                        } else {
                            if (segment1[n][1] > segment2[m][1]) {
                                m++;
                            } else {
                                n++;
                                m++;
                            }
                        }
                    }
                }
            }
            return result;
        }
    },

    _frustrumNormals: {
        enumerable: false,
        distinct: true,
        value: []
    },

    _computeVisibleRange: { // TODO: make it a loop, optimize
        enumerable: false,
        value: function (spline, out) {

            this._frustrumNormals.wipe();

            var splineLength = spline.knotsLength - 1,
            planeOrigin0 = this._cameraPosition[0],
            planeOrigin1 = this._cameraPosition[1],
            planeOrigin2 = this._cameraPosition[2],
                normals = this._frustrumNormals,
                mod,
                r=[], r2=[], r3 = [], tmp,
                i, j,
                elementsBoundingSphereRadius = this._elementsBoundingSphereRadius,
                splineKnots = spline._knots,
                splineNextHandlers = spline._nextHandlers,
                splinePreviousHandlers = spline._previousHandlers,
                reflectionMatrixBuffer = [];

            this._computeFrustumNormals(normals);

            for (i = 0; i < splineLength; i++) {
                mod = normals[0];
                r = spline.directedPlaneBezierIntersection(
                        planeOrigin0 - mod[0] * elementsBoundingSphereRadius,
                        planeOrigin1 - mod[1] * elementsBoundingSphereRadius,
                        planeOrigin2 - mod[2] * elementsBoundingSphereRadius,
                    normals[0],
                    splineKnots[i],
                    splineNextHandlers[i],
                    splinePreviousHandlers[i + 1],
                    splineKnots[i + 1],
                    reflectionMatrixBuffer,
                    r
                );
                if (r.length) {
                    mod = normals[1];
                    r2 = spline.directedPlaneBezierIntersection(
                            planeOrigin0 - mod[0] * elementsBoundingSphereRadius,
                            planeOrigin1 - mod[1] * elementsBoundingSphereRadius,
                            planeOrigin2 - mod[2] * elementsBoundingSphereRadius,
                        normals[1],
                        splineKnots[i],
                        splineNextHandlers[i],
                        splinePreviousHandlers[i + 1],
                        splineKnots[i + 1],
                        reflectionMatrixBuffer,
                        r2
                    );
                    if (r2.length) {
                        tmp = this._segmentsIntersection(r, r2);
                        if (tmp.length) {
                            mod = normals[2];
                            r = spline.directedPlaneBezierIntersection(
                                    planeOrigin0 - mod[0] * elementsBoundingSphereRadius,
                                    planeOrigin1 - mod[1] * elementsBoundingSphereRadius,
                                    planeOrigin2 - mod[2] * elementsBoundingSphereRadius,
                                normals[2],
                                splineKnots[i],
                                splineNextHandlers[i],
                                splinePreviousHandlers[i + 1],
                                splineKnots[i + 1],
                                reflectionMatrixBuffer,
                                r
                            );
                            tmp = this._segmentsIntersection(r, tmp);
                            if (tmp.length) {
                                mod = normals[3];
                                r = spline.directedPlaneBezierIntersection(
                                        planeOrigin0 - mod[0] * elementsBoundingSphereRadius,
                                        planeOrigin1 - mod[1] * elementsBoundingSphereRadius,
                                        planeOrigin2 - mod[2] * elementsBoundingSphereRadius,
                                    normals[3],
                                    splineKnots[i],
                                    splineNextHandlers[i],
                                    splinePreviousHandlers[i + 1],
                                    splineKnots[i + 1],
                                    reflectionMatrixBuffer,
                                    r
                                );
                                tmp = this._segmentsIntersection(r, tmp);
                                for (j = 0; j < tmp.length; j++) {
                                    r3.push([i, tmp[j][0], tmp[j][1]]);
                                }
                            }
                        }
                    }
                }
            }
            var densities = spline._densities, d1, d2, dS, p1, p2, t1, t2;
            for (i = 0; i < r3.length; i++) {
                d1 = densities[r3[i][0]];
                d2 = densities[r3[i][0] + 1];
                dS = r3[i][0] ? spline._densitySummation[r3[i][0]-1] : 0;
                p1 = r3[i][1];
                p2 = r3[i][2];
                t1 = (d2 - d1) * p1 * p1 * .5 + p1 * d1 + dS;
                t2 = (d2 - d1) * p2 * p2 * .5 + p2 * d1 + dS;
                out.push([t1, t2]);
            }
        }
    },

    prepareForDraw: {
        enumerable: false,
        value: function () {
            var self = this;

            this._repetitionComponents = this._repetition._childComponents;
            window.addEventListener("resize", function () {
                self._isCameraUpdated = true;
                self.needsDraw = true;
            }, false);
            this._translateComposer.translateStrideX = this._stride * 300;
        }
    },

/*    _updateIndexMap: {
        enumerable: false,
        value: function (currentIndexMap, newIndexes) {
            var indexMap = currentIndexMap.slice(0, newIndexes.length),
                newIndexesHash = {},
                emptySpaces = [],
                j,
                i;

            for (i = 0; i < newIndexes.length; i++) {
                newIndexesHash[newIndexes[i]] = i;
            }
            for (i = 0; i < indexMap.length; i++) {
                if (newIndexesHash.hasOwnProperty(indexMap[i])) {
                    newIndexes[newIndexesHash[indexMap[i]]] = null;
                } else {
                    emptySpaces.push(i);
                }
            }
            for (i = j = 0; j < emptySpaces.length; i++) {
                if (newIndexes[i] !== null) {
                    indexMap[emptySpaces[j]] = newIndexes[i];
                    j++;
                }
            }
            for (j = indexMap.length; i < newIndexes.length; i++) {
                if (newIndexes[i] !== null) {
                    indexMap[j] = newIndexes[i];
                    j++;
                }
            }
            return indexMap;
        }
    },*/

    _updateIndexMap2: {
        enumerable: false,
        value: function (newIndexes, newIndexesHash) {
            var currentIndexMap = this._repetition.indexMap,
                emptySpaces = [],
                j,
                i,
                currentIndexCount = currentIndexMap && !isNaN(currentIndexMap.length) ? currentIndexMap.length : 0;

            for (i = 0; i < currentIndexCount; i++) {
                //The likelyhood that newIndexesHash had a number-turned-to-string property that wasn't his own is pretty slim as it's provided internally.
                //if (newIndexesHash.hasOwnProperty(currentIndexMap[i])) {
                if (typeof newIndexesHash[currentIndexMap[i]] === "number") {
                    newIndexes[newIndexesHash[currentIndexMap[i]]] = null;
                } else {
                    emptySpaces.push(i);
                }
            }
            for (i = j = 0; (j < emptySpaces.length) && (i < newIndexes.length); i++) {
                if (newIndexes[i] !== null) {
                    this._repetition.mapIndexToIndex(emptySpaces[j], newIndexes[i], false);
                    j++;
                }
            }
            for (j = currentIndexCount; i < newIndexes.length; i++) {
                if (newIndexes[i] !== null) {
                    this._repetition.mapIndexToIndex(j,newIndexes[i], false);
                    j++;
                }
            }
            this._repetition.refreshIndexMap();
        }
    },

    _tmpIndexMap: {
        enumerable: false,
        distinct: true,
        value: []
    },

    _intersections: {
        enumerable: false,
        distinct: true,
        value: []
    },

    willDraw: {
        enumerable: false,
        value: function () {
            var intersections = this._intersections,
                index,
                i,
                j,
                k,
                offset,
                startIndex,
                endIndex,
                mod,
                div,
                iterations,
                newIndexMap,
                time,
                interpolant,
                newIndexesHash = {},
                math = Math,
                paths = this._paths,
                pathsLength = paths.length,
                splinePaths = this.splinePaths;

            newIndexMap = this._tmpIndexMap.wipe();
            if (this._isTransitioningScroll) {
                time = (Date.now() - this._scrollingStartTime) / this._scrollingTransitionDurationMiliseconds; // TODO: division by zero
                interpolant = this._computeCssCubicBezierValue(time, this._scrollingTransitionTimingFunctionBezier);
                if (time < 1) {
                    this.scroll = this._scrollingOrigin + (this._scrollingDestination - this._scrollingOrigin) * interpolant;
                } else {
                    this.scroll = this._scrollingDestination;
                    this._isTransitioningScroll = false;
                }
            }
            this._width = this._element.offsetWidth;
            this._height = this._element.offsetHeight;
            if (splinePaths.length) {
                mod = this._numberOfIterations % pathsLength;
                div = (this._numberOfIterations - mod) / pathsLength;
                for (k = 0; k < pathsLength; k++) {
                    iterations = div + ((k < mod) ? 1 : 0);
                    intersections.wipe();
                    this._computeVisibleRange(splinePaths[k], intersections);
                    splinePaths[k]._computeDensitySummation();
                    offset =  this._scroll - paths[k].headOffset;
                    for (i = 0; i < intersections.length; i++) {
                        startIndex = math.ceil(intersections[i][0] + offset);
                        endIndex = math.ceil(intersections[i][1] + offset);
                        if (startIndex < 0) {
                            startIndex = 0;
                        }
                        if (endIndex > iterations) {
                            endIndex = iterations;
                        }
                        for (j = startIndex; j < endIndex; j++) {
                            index = j * pathsLength + k;
                            if (typeof newIndexesHash[index] === "undefined") {
                                newIndexesHash[index] = newIndexMap.length;
                                newIndexMap.push(index);
                            }
                        }
                    }
                }
                this._updateIndexMap2(newIndexMap, newIndexesHash);
            }
        }
    },

    _cachedPos: {
        enumerable: false,
        distinct: true,
        value: []
    },

    _cachedPosParameter: {
        enumerable: false,
        distinct: true,
        value: {}
    },

    _cachedDrawOffset: {
        enumerable: false,
        distinct: true,
        value: {}
    },


    _cachedSlide: {
        enumerable: false,
        distinct: true,
        value: {}
    },

    draw: {
        enumerable: false,
        value: function () {
            var i,
                length = this._repetitionComponents.length,
                slide,
                style,
                j,
                iOffset = this._cachedDrawOffset,
                iElement,
                pathsLength = this._paths.length,
                pathIndex,
                pos,
                pos3,
                positionKeys,
                positionKeyCount,
                jPositionKey,
                indexMap = this._repetition.indexMap,
                iRepetitionComponentElement,
                math = Math,
                posParameter = this._cachedPosParameter;

            slide = this._cachedSlide.wipe();
            pos = this._cachedPos.wipe();
            if (this._isTransitioningScroll) {
                this.needsDraw = true;
            }
            if (this.isAnimating) { // move it to willDraw
                this._animationInterval();
            }
            if (this._isCameraUpdated) {
                var perspective = math.tan(((90 - this.cameraFov * .5) * this._doublePI) / 360) * this._height * .5,
                    vX = this.cameraTargetPoint[0] - this.cameraPosition[0],
                    vY = this.cameraTargetPoint[1] - this.cameraPosition[1],
                    vZ = this.cameraTargetPoint[2] - this.cameraPosition[2],
                    yAngle = math.atan2(-vX, -vZ),  // TODO: Review this
                    tmpZ,
                    xAngle;

                tmpZ = vX * -math.sin(-yAngle) + vZ * math.cos(-yAngle);
                xAngle = math.atan2(-vY, -tmpZ);
                this._element.style.webkitPerspective = perspective + "px";
                this._repetition._element.style.webkitTransform =
                    "translate3d(" + 0 + "px," + 0 + "px," + perspective + "px)rotateX(" + xAngle + "rad)rotateY(" + (-yAngle) + "rad)" +
                    "translate3d(" + (-this.cameraPosition[0]) + "px," + (-this.cameraPosition[1]) + "px," + (-this.cameraPosition[2]) + "px)";
                this._isCameraUpdated = false;
            }
            if (this.splinePaths.length) {
                for (i = 0; i < length; i++) {
                    pathIndex = indexMap[i] % pathsLength;
                    iOffset = this.offset(math.floor(indexMap[i] / pathsLength),iOffset);
                    slide.index = indexMap[i];
                    slide.time = iOffset.time + this._paths[pathIndex].headOffset;
                    slide.speed = iOffset.speed;
                    pos = this._splinePaths[pathIndex].getPositionAtTime(slide.time, pos, posParameter);
                    iElement = this._repetitionComponents[i].element.parentNode;
                    if ((pos.length > 0) && (slide.index < this._numberOfIterations)) {
                        pos3 = pos[3];
                        style =
                            "-webkit-transform:translate3d(" + pos[0].toFixed(5) + "px," + pos[1].toFixed(5) + "px," + pos[2].toFixed(5) + "px)" +
                            ((typeof pos3.rotateZ !== "undefined") ? "rotateZ(" + pos3.rotateZ + ")" : "") +
                            ((typeof pos3.rotateY !== "undefined") ? "rotateY(" + pos3.rotateY + ")" : "") +
                            ((typeof pos3.rotateX !== "undefined") ? "rotateX(" + pos3.rotateX + ")" : "") + ";";
                        positionKeys = Object.keys(pos3);
                        positionKeyCount = positionKeys.length;
                        for (j = 0; j < positionKeyCount; j++) {
                            jPositionKey = positionKeys[j];
                            if (!(jPositionKey === "rotateX" || jPositionKey === "rotateY" || jPositionKey === "rotateZ")) {
                                style += jPositionKey + ":" + pos3[jPositionKey] + ";";
                            }
                        }
                        iElement.setAttribute("style", style);
                    } else {
                        iElement.setAttribute("style", "-webkit-transform:scale3d(0,0,0);opacity:0");
                    }
                }
            }
        }
    },

    _orphanedChildren: {
        enumerable: false,
        value: null
    },

    _selectedIndexesForRepetition: {
        enumerable: false,
        value: null
    },

    selectedIndexes: {
        serializable: true,
        get: function () {
            if (this._repetition) {
                return this._repetition.selectedIndexes;
            } else {
                return this._selectedIndexesForRepetition;
            }
        },
        set: function (value) {
            if (this._repetition) {
                this._repetition.selectedIndexes = value;
            } else {
                this._selectedIndexesForRepetition = value;
            }
        }
    },

    _activeIndexesForRepetition: {
        enumerable: false,
        value: null
    },

    activeIndexes: {
        serializable: true,
        get: function () {
            if (this._repetition) {
                return this._repetition.activeIndexes;
            } else {
                return this._activeIndexesForRepetition;
            }
        },
        set: function (value) {
            if (this._repetition) {
                this._repetition.activeIndexes = value;
            } else {
                this._activeIndexesForRepetition = value;
            }
        }
    },

    _updateLength: {
        enumerable: false,
        value: function () {
            if (this._paths) {
                var iPath,
                    pathsLength = this._paths.length,
                    iterations,
                    iLength,
                    maxLength = 0,
                    div, mod,
                    i;

                if (pathsLength > 0) {
                    mod = this._numberOfIterations % pathsLength; // TODO: review after implementing multiple paths
                    div = (this._numberOfIterations - mod) / pathsLength;
                    for (i = 0; i < pathsLength; i++) {
                        iPath = this._paths[i];
                        iterations = div + ((i < mod) ? 1 : 0);
                        iLength = iterations - iPath.tailOffset + iPath.headOffset - 1;
                        if (iLength > maxLength) {
                            maxLength = iLength;
                        }
                    }
                    this.length = maxLength;
                }
                this.needsDraw = true;
            }
        }
    },

    _numberOfIterations: {
        enumerable: false,
        value: 0
    },

    numberOfIterations: {
        enumerable: false,
        get: function () {
            return this._numberOfIterations;
        },
        set: function (value) {
            if (this._numberOfIterations !== value) {
                this._numberOfIterations = value;
                this._updateLength();
            }
        }
    },

    _objectsForRepetition: {
        enumerable: false,
        value: null
    },

    objects: {
        serializable: true,
        get: function() {
            if (this._repetition) {
                return this._repetition.objects;
            } else {
                return this._objectsForRepetition;
            }
        },
        set: function(value) {
            if (this._repetition) {
                this._repetition.objects = value;
                this.needsDraw = true;
            } else {
                this._objectsForRepetition = value;
            }
        }
    },

    _contentControllerForRepetition: {
        enumerable: false,
        value: null
    },

    contentController: {
        serializable: true,
        get: function() {
            if (this._repetition) {
                return this._repetition.contentController;
            } else {
                return this._contentControllerForRepetition;
            }
        },
        set: function(value) {
            if (this._repetition) {
                this._repetition.contentController = value;
            } else {
                this._contentControllerForRepetition = value;
            }
        }
    },

    _isSelectionEnabledForRepetition: {
        enumerable: false,
        value: null
    },

    isSelectionEnabled: {
        serializable: true,
        get: function() {
            if (this._repetition) {
                return this._repetition.isSelectionEnabled;
            } else {
                return this._isSelectionEnabledForRepetition;
            }
        },
        set: function(value) {
            if (this._repetition) {
                this._repetition.isSelectionEnabled = value;
            } else {
                this._isSelectionEnabledForRepetition = value;
            }
        }
    },

    propertyChangeBindingListener: {
        value: function(type, listener, useCapture, atSignIndex, bindingOrigin, bindingPropertyPath, bindingDescriptor) {
            if (bindingDescriptor.boundObjectPropertyPath.match(/objectAtCurrentIteration/)) {
                if (this._repetition) {
                    bindingDescriptor.boundObject = this._repetition;
                    return this._repetition.propertyChangeBindingListener.apply(this._repetition, arguments);
                } else {
                    return null;
                }
            } else {
                return Object.prototype.propertyChangeBindingListener.apply(this, arguments);
            }
        }
    },

    deserializedFromTemplate: {
        value: function() {
            this._orphanedChildren = this.childComponents;
            this.childComponents = null;
        }
    },

    templateDidLoad: {
        value: function() {
            var orphanedFragment,
                currentContentRange = this.element.ownerDocument.createRange(),
                wrapper,
                self = this,
                oldWillDraw = this._repetition.willDraw;

            currentContentRange.selectNodeContents(this.element);
            orphanedFragment = currentContentRange.extractContents();
            wrapper = this._repetition.element.appendChild(document.createElement("div"));
            wrapper.appendChild(orphanedFragment);
            this._repetition.indexMapEnabled = true;
            this._repetition.childComponents = this._orphanedChildren;
            if (this._objectsForRepetition !== null) {
                this._repetition.objects = this._objectsForRepetition;
                this._objectsForRepetition = null;
            }
            if (this._contentControllerForRepetition !== null) {
                this._repetition.contentController = this._contentControllerForRepetition;
                this._contentControllerForRepetition = null;
            }
            if (this._isSelectionEnabledForRepetition !== null) {
                this._repetition.isSelectionEnabled = this._isSelectionEnabledForRepetition;
                this._isSelectionEnabledForRepetition = null;
            }
            if (this._selectedIndexesForRepetition !== null) {
                this._repetition.selectedIndexes = this._selectedIndexesForRepetition;
                this._selectedIndexesForRepetition = null;
            }
            if (this._activeIndexesForRepetition !== null) {
                this._repetition.activeIndexes = this._activeIndexesForRepetition;
                this._activeIndexesForRepetition = null;
            }
            this._repetition.willDraw = function () {
                if (oldWillDraw) {
                    oldWillDraw.apply(self._repetition, arguments);
                }
                self.needsDraw = true;
            };
            this._repetition.addPropertyChangeListener("selectedIndexes", function (event) {
                self._handleSelectedIndexesChange.call(self, event);
            },false);
            Object.defineBinding(this, "numberOfIterations", {
                boundObject: this._repetition,
                boundObjectPropertyPath: "_objects.count()",
                oneway: "true"
            });
        }
    },

    // TODO: rename isAnimating and animationInterval to elasticAnimation

    isAnimating: {
        enumerable: false,
        value: false
    },

    _hasElasticScrolling: {
        enumerable: false,
        value: true
    },

    hasElasticScrolling: {
        serializable: true,
        get: function () {
            return this._hasElasticScrolling;
        },
        set: function (value) {
            this._hasElasticScrolling = (value === true) ? true : false;
        }
    },

    _elasticScrollingSpeed: {
        enumerable: false,
        value: 1
    },

    elasticScrollingSpeed: {
        serializable: true,
        get: function () {
            return this._elasticScrollingSpeed;
        },
        set: function (value) {
            this._elasticScrollingSpeed = value;
            if (!value) {
                this.hasElasticScrolling = false;
            }
        }
    },

    _selectedSlideIndex: { // TODO: rename it to elasticScrollingTargetIndex
        enumerable: false,
        value: null
    },

    selectedSlideIndex: {
        get: function () {
            return this._selectedSlideIndex;
        },
        set: function (value) {
            this._selectedSlideIndex=value;
            if (typeof this.animatingHash[this._selectedSlideIndex] !== "undefined") {
                var tmp = this.slide[this._selectedSlideIndex].x;

                this.scroll += this._selectedSlideIndex - tmp;
            }
        }
    },

    _animating: {
        enumerable: false,
        value: null
    },

    animating: {
        enumerable: false,
        get: function () {
            if (!this._animating) {
                this._animating = [];
            }
            return this._animating;
        }
    },

    _animatingHash: {
        enumerable: false,
        value: null
    },

    animatingHash: {
        enumerable: false,
        get: function () {
            if (!this._animatingHash) {
                this._animatingHash = {};
            }
            return this._animatingHash;
        }
    },

    _slide: {
        enumerable: false,
        value: null
    },

    slide: {
        enumerable: false,
        get: function () {
            if (!this._slide) {
                this._slide = {};
            }
            return this._slide;
        }
    },

    startAnimating: {
        enumerable: false,
        value: function (index, pos) {
            if (typeof this.animatingHash[index] === "undefined") {
                var length = this.animating.length;

                this.animating[length] = index;
                this.animatingHash[index] = length;
                this.slide[index] = {
                    speed: 0,
                    x: pos
                };
            } else {
                this.slide[index].x = pos;
            }
        }
    },

    stopAnimating: {
        enumerable: false,
        value: function (index) {
            if (typeof this.animatingHash[index] !== "undefined") {
                this.animating[this.animatingHash[index]] = this.animating[this.animating.length - 1];
                this.animatingHash[this.animating[this.animating.length - 1]] = this.animatingHash[index];
                this.animating.pop();
                delete this.animatingHash[index];
                delete this.slide[index];
            }
        }
    },

    _range: {
        value: 15
    },

    lastDrawTime: {
        value: null
    },

    _maxTranslateX: {
        enumerable: false,
        value: 0
    },

    maxTranslateX: {
        get: function () {
            return this._maxTranslateX;
        },
        set: function (value) {
            this._maxTranslateX = value;
        }
    },

    _length: {
        enumerable: false,
        value: 0
    },

    length: {
        get: function () {
            return this._length;
        },
        set: function (value) {
            if (value < 0) {
                this._length = 0;
            } else {
                this.maxTranslateX = value * 300;
                this._length = value;
            }
        }
    },

    _scroll: {
        enumerable: false,
        value: 0
    },

    _animationInterval: {
        enumerable: false,
        value: function () {
            var animatingLength = this.animating.length,
                n, j, i, _iterations = 8,
                time = Date.now(),
                interval1 = this.lastDrawTime ? (time - this.lastDrawTime) * 0.015 * this._elasticScrollingSpeed : 0,
                interval = interval1 / _iterations,
                x,
                epsilon = .5;

            for (n = 0; n < _iterations; n++) {
                for (j = 0; j < animatingLength; j++) {
                    i = this.animating[j];
                    if (i < this._selectedSlideIndex) {
                        if (typeof this.animatingHash[i + 1] === "undefined") {
                            x = i + 1;
                        } else {
                            x = this.slide[i + 1].x;
                        }
                        this.slide[i].speed = x - this.slide[i].x - 1;
                    } else {
                        if (typeof this.animatingHash[i - 1] === "undefined") {
                            x = i - 1;
                        } else {
                            x = this.slide[i - 1].x;
                        }
                        this.slide[i].speed = x - this.slide[i].x + 1;
                    }
                    this.slide[i].x += (this.slide[i].speed) * interval;
                }
            }
            j = 0;
            while (j < animatingLength) {
                i = this.animating[j];
                if (i < this._selectedSlideIndex) {
                    if (this.slide[i].x > i - epsilon) {
                        this.stopAnimating(i);
                        animatingLength--;
                    } else {
                        j++;
                    }
                } else {
                    if (this.slide[i].x < i + epsilon) {
                        this.stopAnimating(i);
                        animatingLength--;
                    } else {
                        j++;
                    }
                }
            }
            this.lastDrawTime = time;
            if (!animatingLength) {
                this.isAnimating = false;
            } else {
                this.needsDraw = true;
                if (!this.isAnimating) {
                    this.isAnimating = true;
                }
            }
        }
    },

    scroll: {
        serializable: true,
        get: function () {
            return this._scroll;
        },
        set: function (value) {
            /*if ((this._hasElasticScrolling)&&(this._selectedSlideIndex !== null)) {
                var i,
                    n,
                    min = this._selectedSlideIndex - this._range,
                    max = this._selectedSlideIndex + this._range + 1,
                    tmp,
                    j,
                    x;

                tmp = value - this._scroll;
                if (min < 0) {
                    min = 0;
                }

                if (!this.isAnimating) {
                    this.lastDrawTime = Date.now();
                }
                for (i = min; i < max; i++) {
                    if (i != this._selectedSlideIndex) {
                        if (typeof this.animatingHash[i] === "undefined") {
                            x = i;
                        } else {
                            x = this.slide[i].x;
                        }
                        x += tmp;
                        if (i < this._selectedSlideIndex) {
                            if (x < i) {
                                this.startAnimating(i, x);
                            }
                        } else {
                            if (x > i) {
                                this.startAnimating(i, x);
                            }
                        }
                    }
                }
                this.stopAnimating(this._selectedSlideIndex);
                if (!this.isAnimating) {
                    this._animationInterval();
                }
            }*/
            this._scroll = value;
            if (this._translateComposer) {
                this._translateComposer.translateX = value * 300; // TODO Remove magic/spartan numbers
            }
            this.needsDraw = true;
        }
    },

    offset: {
        enumerable: false,
        value: function (interationIndex,offset) {
            if (typeof this.animatingHash[interationIndex] === "undefined") {
                offset.time = interationIndex - this._scroll;
                offset.speed = 0;
            } else {
                offset.time = this.slide[interationIndex].x - this._scroll,
                offset.speed = this.slide[interationIndex].speed
            }
            return offset;
        }
    },

    _isInputEnabled: {
        enumerable: false,
        value: true
    },

    isInputEnabled: {
        serializable: true,
        get: function () {
            return this._isInputEnabled;
        },
        set: function (value) {
            if (value) {
                this._isInputEnabled = true;
                this.needsDraw = true;
            } else {
                this._isInputEnabled = false;
            }
        }
    },

    _translateX: {
        enumerable: false,
        value: 0
    },

    translateX: {
        get: function () {
            return this._translateX;
        },
        set: function (value) {
            if (this._isInputEnabled) {
                this._translateX = value;
                this.scroll = this._translateX / 300;
            }
        }
    }
});
示例#30
0
var RadioButton = exports.RadioButton = Montage.create(CheckInput, {
    _fakeCheck: {
        enumerable: false,
        value: function() {
            var changeEvent;
            // NOTE: this may be BAD, modifying the element outside of
            // the draw loop, but it's what a click/touch would
            // actually have done

            if (!this._element.checked) {
                this._element.checked = true;
                changeEvent = document.createEvent("HTMLEvents");
                changeEvent.initEvent("change", true, true);
                this._element.dispatchEvent(changeEvent);
            }
        }
    },

    _checkedSyncedWithInputField: {
        enumerable: false,
        value: false
    },

    _checked: {
        enumerable: false,
        value: null
    },
    checked: {
        get: function() {
            // If we haven't synced with the input field then our value is
            // more up to date than the element and so we don't get it from the
            // element. If we have synced then the user could have changed
            // the focus to another radio button, so we *do* retrieve it from
            // the element.
            if (this._checkedSyncedWithInputField === true) {
                this._checked = this._element.checked;
            }

            return this._checked;
        },
        set: function(value, fromInput) {
            this._checked = value;
            if (fromInput) {
                this._valueSyncedWithInputField = true;
            } else {
                this._valueSyncedWithInputField = false;
                this.needsDraw = true;
            }

            if(this._checked === true) {
                if(this.name && this.name !== null) {
                    // dispatch an event to all other radiobuttons with the same name
                    var anEvent = document.createEvent("CustomEvent");
                    anEvent.initCustomEvent("checked", true, true, {
                        name: this.name
                    });
                    RadioButton.dispatchEvent(anEvent);
                    RadioButton.addEventListener('checked', this);
                }
            }
        }
    },


    handleChecked:{
        value: function(evt) {
            // if we receive this event, it means that some other radiobutton with the same name
            // has been checked. So, mark this as unchecked.
            if(this.name === evt.detail.name) {
                this.checked = false;
                RadioButton.removeEventListener('checked', this);
            }
        }
    },

    draw: {
        value: function() {
            if (!this._valueSyncedWithInputField) {
                this._element.checked = this._checked;
            }

            // Call super
            Object.getPrototypeOf(RadioButton).draw.call(this);
        }
    }
});