Задать вопрос
@DanaLapka

Что не так с Object.orderby?

Uncaught Error: RokSprocket Strips: Strips class not available
at Object.orderBy (strips.js:208)
var Strips = new Class({

		Implements: [Options, Events],

		options: {
			settings: {}
		},

		initialize: function(options){
			this.setOptions(options);

			this.stripss = document.getElements('[data-strips]');
			this.settings = {};
			this.timers = {};
			this.strips = {};
			this.statuses = {};
			this.curve = Browser.opera ? {equation: 'ease-in-out'} : {curve: 'cubic-bezier(0.37,0.61,0.59,0.87)'};
			
			try {
				RokMediaQueries.on('every', this.mediaQuery.bind(this));
			}
			catch(error) { if (typeof console != 'undefined') console.error('Error while trying to add a RokMediaQuery "match" event', error); }

		},

		attach: function(strips, settings){
			strips = typeOf(strips) == 'number' ?
					document.getElements('[data-strips=' + this.getID(strips) + ']')
					:
					strips;
			settings = typeOf(settings) == 'string' ? JSON.decode(settings) : settings;

			var containers = (strips ? new Elements([strips]).flatten() : this.stripss);

			containers.each(function(container){
				container.store('roksprocket:strips:attached', true);

				this.setSettings(container, settings, 'restore');

				var relay = {

					mouseenter: container.retrieve('roksprocket:strips:mouseenter', function(event){
						this.stopTimer.call(this, container);
						this.pause.call(this, container);
					}.bind(this)),

					ordering: container.retrieve('roksprocket:strips:ordering', function(event, element){
						this.orderBy.call(this, event, container, element);
					}.bind(this)),

					mouseleave: container.retrieve('roksprocket:strips:mouseleave', function(event){
						this.resume.call(this, container);
						this.startTimer.call(this, container);
					}.bind(this)),

					page: container.retrieve('roksprocket:strips:relay', function(event, page){
						if (event) event.preventDefault();
						this.toPage.call(this, container, page);
					}.bind(this)),

					next: container.retrieve('roksprocket:strips:next', function(event, element){
						this.direction.call(this, event, container, element, 'next');
					}.bind(this)),

					previous: container.retrieve('roksprocket:strips:previous', function(event, element){
						this.direction.call(this, event, container, element, 'previous');
					}.bind(this)),
					

					swipe: container.retrieve('roksprocket:strips:swipe', function(event, element){
						event.preventDefault();
						this.direction.call(this, event, container, element, (event.direction == 'right' ? 'previous' : 'next'));
					}.bind(this))
				};
				
				

['ordering'].each(function(type){
					container.addEvent('click:relay([data-strips-orderby])', relay['ordering']);
				});


				['mouseenter', 'mouseleave'].each(function(type){
					container.addEvent(type, relay[type]);
				});

				['page', 'next', 'previous'].each(function(dir, i){
					var query = '[data-strips-' + dir + ']';
					if (i > 0) query += ', [data-' + dir + ']';

					container.addEvent('click:relay(' + query + ')', relay[dir]);
				}, this);

				container.retrieve('roksprocket:strips:ajax', new RokSprocket.Request({
					model: 'strips',
					model_action: 'getPage',
					onRequest: this.onRequest.bind(this, container),
					onSuccess: function(response){
						this.onSuccess(response, container, container.retrieve('roksprocket:strips:ajax'));
					}.bind(this)
				}));


				if (Browser.Features.Touch) container.addEvent('swipe', relay['swipe']);

				var active = container.getElement('[data-strips-page].active');
				if (!active) this.toPage(container, 0);
				else {
					if (this.getSettings(container).autoplay && this.getSettings(container).autoplay.toInt())
						this.startTimer(container);
				}

			}, this);
		},

		detach: function(strips){
			strips = typeOf(strips) == 'number' ?
					document.getElements('[data-strips=' + this.getID(strips) + ']')
					:
					strips;

			var containers = (strips ? new Elements([strips]).flatten() : this.stripss);

			containers.each(function(container){
				container.store('roksprocket:strips:attached', false);
				var relay = {
					ordering: container.retrieve('roksprocket:strips:ordering'),
					mouseenter: container.retrieve('roksprocket:strips:mouseenter'),
					mouseleave: container.retrieve('roksprocket:strips:mouseleave'),
					page: container.retrieve('roksprocket:strips:relay'),
					next: container.retrieve('roksprocket:strips:next'),
					previous: container.retrieve('roksprocket:strips:previous')
				};
				
				
				['ordering'].each(function(type){
					container.addEvent('click:relay([data-strips-orderby])', relay['ordering']);
				});
				
				['mouseenter', 'mouseleave'].each(function(type){
					container.removeEvent(type, relay[type]);
				});

				['page', 'next', 'previous'].each(function(dir, i){
					var query = '[data-strips-' + dir + ']';
					if (i > 0) query += ', [data-' + dir + ']';

					container.removeEvent('click:relay(' + query + ')', relay[dir]);
				}, this);

				if (Browser.Features.Touch) container.removeEvent('swipe', relay['swipe']);

			}, this);
		},
		
		mediaQuery: function(query){
			var strips;

			for (var id in this.strips){
				strips = this.strips[id];
				strips.resize('fast');
			}
		},

		setSettings: function(container, settings, restore){
			var id = this.getID(container),
				options = Object.clone(this.options.settings);

			if (!restore || !this.settings['id-' + id]){
				this.settings['id-' + id] = Object.merge(options, settings || options);
			}
		},

		getSettings: function(container){
			var id = this.getID(container);

			return this.settings['id-' + id];
		},

		getContainer: function(container){
			if (!container) container = document.getElements('[data-strips]');
			if (typeOf(container) == 'number') container = document.getElement('[data-strips='+container+']');
			if (typeOf(container) == 'string') container = document.getElement(container);

			return container;
		},

		getID: function(id){
			if (typeOf(id) == 'number') id = document.getElement('[data-strips='+id+']');
			if (typeOf(id) == 'string') id = document.getElement(id);
			return !id ? id : id.get('data-strips');
		},

		resume: function(container){
			container = this.getContainer(container);

			var id = this.getID(container);
			this.statuses['id-' + id] = 'play';
		},

		onRequest: function(container){
			container.addClass('loading');
		},
		
		orderBy: function(event, container, element){
			var id = this.getID(container);

			if (!this.strips || !this.strips[id]) throw new Error('RokSprocket Strips: Strips class not available');

			var orderBy = element.get('data-strips-orderby');
			this.strips[id].order(orderBy/*, null, function(callback){}*/);

			container.getElements('[data-strips-orderby]').removeClass('active');
			if (orderBy != 'random') element.addClass('active');
		},


		onSuccess: function(response, container){
			var items = container.getElement('[data-strips-items]'),
				itemList = container.getElements('[data-strips-item]'),
				html = response.getPath('payload.html'),
				page = response.getPath('payload.page'),
				settings = this.getSettings(container),
				animation = settings.animation || 'fadeDelay';

			container.removeClass('loading');

			var dummy = new Element('div', {html: html}),
				elements = dummy.getChildren(), rand, anims;

			if (animation == 'random'){
				animation = Object.keys(Object.merge({}, this.Animations)).getRandom();
			}

			if (!this.Animations[animation]) animation = 'fadeDelay';

			settings.callback = function(){
				if (settings.autoplay && settings.autoplay.toInt()) this.startTimer(container);
			}.bind(this);

			this.Animations[animation].call(this, items, itemList, elements, settings);

			this._switchPage(container, page);
		},

		_switchPage: function(container, page){
			var strips = container.getElements('[data-strips-page]');

			strips.removeClass('active');
			strips[page - 1].addClass('active');
		}

	});
  • Вопрос задан
  • 102 просмотра
Подписаться 1 Оценить 1 комментарий
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы