Skip to content

Instantly share code, notes, and snippets.

@smlombardi
Created December 11, 2014 00:41
Show Gist options
  • Save smlombardi/208ce617b54c2e287fd9 to your computer and use it in GitHub Desktop.
Save smlombardi/208ce617b54c2e287fd9 to your computer and use it in GitHub Desktop.
Final Working Toggle Panel
<div ng-app="myApp" ng-init="foobar=true">
<div pb-toggle-panel panel-title="My Directive Panel Test" variable-name="foobar">Lorem ipsum dolor sit amet</div>
</div>
/* jshint strict:false */
/* global app */
'use strict';
var app = angular.module('myApp', []);
app.controller('OrderSearchCtrl', ['$scope', '$route', '$location', 'CountryFactory',
function($scope, $route, $location, CountryFactory) {
}]);
app.directive('pbTogglePanel', function() {
return {
restrict: 'A',
scope:false,
transclude: true,
template: function(tElement, tAttrs) {
var variableName = tAttrs.variableName;
var panelTitle = tAttrs.panelTitle;
var panelText = tElement.text;
return '<div ng-click="' + variableName + '=!' + variableName + '" class="row toggleHeader" ng-class="{open : ' + variableName + '}">\n<div class="col-md-12">\n<h4>' + panelTitle + '</h4>\n</div>\n</div>\n\n<div id="the-' + variableName + '" class="row" ng-show="' + variableName + '">\n<div class="col-md-2">\n<div ng-transclude></div>\n</div>\n</div>';},
};
});
.toggleHeader {
cursor: pointer;
background-color: #ccc;
padding: 5px;
border-radius: 3px;
margin-bottom: 10px;
margin-top: 20px;
h4 {
&:before {
content: '\25b8\0020';
}
}
&.open {
h4 {
&:before {
content: '\25be\0020';
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment