Skip to content

Commit

Permalink
Added in support for interpreters to import different types of palett…
Browse files Browse the repository at this point in the history
…e definitions. Removed previous colourlovers references.
  • Loading branch information
mbitson committed May 1, 2020
1 parent c3f1285 commit 6027c4f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 118 deletions.
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@

<!-- Material Color Generator Application & Factories-->
<script src="scripts/app.js"></script>
<script src="scripts/factories/colourLovers.js"></script>

<!-- Load interpreter services -->
<script src="scripts/services/interpreters/angularJsInterpreter.js"></script>
Expand Down
3 changes: 1 addition & 2 deletions scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ mcgApp.config(function ($routeProvider, $mdThemingProvider, $sceDelegateProvider
});

$sceDelegateProvider.resourceUrlWhitelist([
'self',
'http://www.colourlovers.com/api/**'
'self'
]);

// Watch for theme updates to dynamically change the theme.
Expand Down
85 changes: 33 additions & 52 deletions scripts/controllers/ColorGeneratorCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// Define our default color generator controller!
mcgApp.controller('ColorGeneratorCtrl',
function ($scope, $mdDialog, ColourLovers, $rootScope, $mdColorPalette, $mdSidenav, $cookies, $location )
function ($scope, $mdDialog, $rootScope, $mdColorPalette, $mdSidenav, $cookies, $location, TopInterpreter )
{
// Init function.
// This is placed into a function
Expand Down Expand Up @@ -43,7 +43,6 @@ function ($scope, $mdDialog, ColourLovers, $rootScope, $mdColorPalette, $mdSiden

// Define palettes
$scope.palettes = [];
$scope.colourlovers = [];

// Toolbar is hidden by default.
$scope.initSpeedDial();
Expand Down Expand Up @@ -417,16 +416,45 @@ function ($scope, $mdDialog, ColourLovers, $rootScope, $mdColorPalette, $mdSiden
{
// ...add the palette!
if(typeof code === "string"){
$scope.palettes = JSON.parse(code);
}else if(typeof code === "object"){
$scope.addPaletteFromObject(code);
var palettesObject = $scope.parseImportString(code);
if(palettesObject === false){
alert('Error importing your provided code. Code should be originally exported from this tool and unmodified.');
return;
}
$scope.palettes = palettesObject;
}
}, function () { } );

// Google Analytics Event Track
ga( 'send', 'event', 'mcg', 'import_code' );
};

/**
* Takes input code and attempts to determine the appropriate interpreter and generate the palettes object.
* @param code string
* @returns {boolean|*}
*/
$scope.parseImportString = function(code)
{
var interpreters = TopInterpreter.getInterpreters();
for (var name in interpreters) {
if (interpreters.hasOwnProperty(name)) {
var interpreter = interpreters[name];
if(
typeof interpreter.isApplicable === "function" &&
typeof interpreter.import === "function" &&
interpreter.isApplicable(code) === true
) {
var returnObj = interpreter.import(code);
if(returnObj){
return returnObj;
}
}
}
}
return false;
};

// Function to show export json for loading carts later
$scope.showDemo = function ()
{
Expand Down Expand Up @@ -494,53 +522,6 @@ function ($scope, $mdDialog, ColourLovers, $rootScope, $mdColorPalette, $mdSiden
ga('send', 'event', 'mcg', 'copy_code');
};

// Function to show generic clipboard alert dialog
$scope.showColourLovers = function ()
{
$mdDialog.show( {
templateUrl: 'templates/dialogs/colourlovers.html',
controller: ColourLoversDialogController
} );

// Google Analytics Event Track
ga( 'send', 'event', 'mcg', 'view_colourlovers' );

function ColourLoversDialogController( $scope, $mdDialog, ColourLovers )
{
$scope.init = function(){
$scope.colourlovers = [];
$scope.setColors = $rootScope.setPalettesByColors;
$scope.getTop();
};

// Get top colourlover palettes.
$scope.getTop = function(){
ColourLovers.getTop();
};

// Get new colourlover palettes.
$scope.getNew = function () {
ColourLovers.getNew();
};

// Get random colourlover palettes.
$scope.getRandom = function () {
ColourLovers.getRandom();
};

// Function to close dialog
$scope.closeDialog = function () {
$mdDialog.hide();
};

var CLGetSuccess = function (data) {
$scope.colourlovers = data;
};

$scope.init();
}
};

$scope.makeSafe = function(s){
return s.replace(/[^a-z0-9]/gi, '').toLowerCase();
};
Expand Down
23 changes: 0 additions & 23 deletions scripts/factories/colourLovers.js

This file was deleted.

10 changes: 0 additions & 10 deletions templates/color_generator.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@
<ng-md-icon icon="file_upload" size="34" style="fill:#ffffff;"></ng-md-icon>
</md-button>
</div>
<!--<div class="md-accent bright-text">-->
<!--<md-button class="md-accent" ng-click="showColourLovers()" style="margin-right: 15px;" aria-label="Select A ColourLovers Theme">-->
<!--<md-tooltip>Select A ColourLovers Theme</md-tooltip>-->
<!--<ng-md-icon icon="palette" size="34" style="fill:#fff;"></ng-md-icon>-->
<!--</md-button>-->
<!--</div>-->
<div class="md-accent bright-text">
<md-button class="md-accent" ng-click="addBasePalette()" style="margin-right: 15px;" aria-label="Add Palette">
<md-tooltip>Add Palette</md-tooltip>
Expand Down Expand Up @@ -114,10 +108,6 @@
<md-tooltip>Add Palette</md-tooltip>
<ng-md-icon icon="add_box" size="34" style="fill:#fff;"></ng-md-icon>
</md-button>
<!--<md-button class="md-accent" md-visible="dialTooltipOpen" ng-click="showColourLovers()" style="margin-right: 15px;" aria-label="Select A ColourLovers Theme">-->
<!--<md-tooltip>Select A ColourLovers Theme</md-tooltip>-->
<!--<ng-md-icon icon="palette" size="34" style="fill:#fff;"></ng-md-icon>-->
<!--</md-button>-->
<md-button class="md-accent" md-visible="dialTooltipOpen" ng-click="showImport()" style="margin-right: 15px;" aria-label="Import Theme">
<md-tooltip>Import</md-tooltip>
<ng-md-icon icon="file_upload" size="34" style="fill:#fff;"></ng-md-icon>
Expand Down
30 changes: 0 additions & 30 deletions templates/dialogs/colourlovers.html

This file was deleted.

0 comments on commit 6027c4f

Please sign in to comment.