drrobotnik
5/8/2015 - 3:35 AM

themes-wp-rollback.js

/**
 *  Theme Specific WP Rollback
 *
 *  @description: Adds a rollback option to themes
 *  @copyright: http://opensource.org/licenses/gpl-2.0.php GNU Public License
 */



jQuery.noConflict();
(function ( $ ) {

	//On DOM Ready
	$( function () {
		var themes;
		themes = wp.themes = wp.themes || {};
		themes.data = _wpThemeSettings;


		themes.router = new themes.InstallerRouter();

		// Handles `theme` route event
		// Queries the API for the passed theme slug
		themes.router.on( 'route:preview', function( slug ) {

			console.log('route triggered');
			//request.theme = slug;
			//self.view.collection.query( request );
		});

		wp.themes.Model = Backbone.Model.extend({
			// Adds attributes to the default data coming through the .org themes api
			// Map `id` to `slug` for shared code
			initialize: function() {
				var description;

				console.log(this.get( 'slug' ));

				// If theme is already installed, set an attribute.
				if ( _.indexOf( themes.data.installedThemes, this.get( 'slug' ) ) !== -1 ) {
					this.set({ installed: true });
				}

				// Set the attributes
				this.set({
					// slug is for installation, id is for existing.
					id: this.get( 'slug' ) || this.get( 'id' )
				});

				// Map `section.description` to `description`
				// as the API sometimes returns it differently
				if ( this.has( 'sections' ) ) {
					description = this.get( 'sections' ).description;
					this.set({ description: description });
				}
			},
			winning: function() {
				console.log('winning!');
			}
		});



		//console.log(_wpThemeSettings.themes[0].update);

		_wpThemeSettings.themes[0].update = _wpThemeSettings.themes[0].update + '.. J/K lol.';

		//Use backbone
		//var themes;
		//themes.view.Theme = themes.view.Theme.extend( {
		//
		//	render: function () {
		//		console.log( "2 " );
		//		this.on( "theme:expand", function ( data ) {
		//			console.log( "member submit event " );
		//
		//		} );
		//	}
		//
		//} );

		var rollback = wp.Backbone.View.extend( {

			events     : {
				'click': 'addRollback'
			},
			addRollback: function ( e ) {
				alert( 'here' );
			}
			//var view = new themes.view.Themes();
			//view.on( 'theme:expand', function ( theView ) {
			//	console.log( 'here' );
			//	console.log( theView );
			//} );

		} );

		var themes = new themes.Model;
		themes.data = _wpThemeSettings;
		themes.set('slug','moose');


		//themes.foo = window.wp.themes.get('slug');

		themes.initialize();
		themes.winning();

	
		//var rollback = _.extend({}, Backbone.Events);

		//var HeaderView = themes.view.Details.extend({
		//  initialize: function() {
		//	  themes.view.Details.prototype.initialize.call(this);
		//
		//	  alert('heyo');
		//
		//  }
		//});


		//console.log( rollback );
		//$( themes ).on( 'click', function ( e ) {
		//	console.log( themes.template );
		//	console.log( themes.focusedTheme );
		//	console.log(e);
		//	$( '.inactive-theme' ).append( 'Hello' );
		//
		//} );


	} );


})( jQuery );