Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html lang="en" id="ngapp" ng-app="testing">

<head>
  <base href="/">
</head>

<body ng-controller="testing">
  
  <div id="template_creator">
    <div id="template_builder_box_container" ng-style="height(50)" resize>
		<div id="template_builder_container">
			<br />
			<div id="textbox_item" class="noselect" draggable-types>New Text Box</div>
      <br />
      <div id="sm_textbox_item" class="noselect" draggable-types>Small</div>
		</div>
    </div>
  </div>
  
  <div id="pageContent" class="slide" ng-style="height(40)" resize du-scroll-container>
  
  <div id="formBox" ng-style="formbox(templateData.pdf_width)" zoom>
	<div class="trimSpace" ng-style="trimSpace(templateData.pdf_width)" zoom>
		<div id="formScale" ng-style="formScale(templateData.pdf_width)" zoom>
			<form action="#" id="{{ templateData.id }}_form">
				<div ng-repeat="key in [] | range:templateData.max_pages">				
					<div class="formContainer" id="{{ templateData.id + '_' + (key+1) }}" ng-style="{width: templateData.pdf_width+'px', height: templateData.pdf_height+'px'}">
						<div class="formContent">
							<div class="formBackground" id="documentPage_{{ (key+1) }}" droppable>
								<div ng-hide="preview" ng-repeat="item in templateItems">
									<div ng-if="item.info.page == (key+1) && item.info.type == 'text'" id="{{ $index }}" data-type="{{ item.info.type }}" ng-click="clickElement($index)" class="text" ng-style="item.style" textbox-draggable>{{ item.info.name }}</div>
								</div>
							</div>
						</div>
					</div>
				</div>			
			</form>
		</div>
	</div>
</div>
  </div>
</body>

</html>
              
            
!

CSS

              
                body {
  background-color:#F3F5F6;
}

#pageContent
{ 
	position:relative;
	padding-bottom:20px;
	z-index:2;
	overflow:auto;
    background-color:#EFF1F5;
	-webkit-overflow-scrolling: touch;
}


#formBoxContainer
{
	display:block;
	padding:20px 15px 15px 15px;
	width:100%;
	clear: both;
}

#formBox { display:block;position:relative;height:100%;padding:15px;}


#formScale::after {
  display: block;
  content: '';
  padding-bottom:5px;
}

#formScale
{
	/*display:none;*/
	position:relative;
	width:816px;
	margin:0;
	-webkit-transform-origin: 0 0;
    -moz-transform-origin: 0 0;
    transform-origin: 0 0;
    -ms-transform-origin: 0 0;
	-webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.trimSpace {
    display: block;
    position: relative;
    margin: 0 auto;
    padding: 0;
    overflow: hidden;
}

.formContainer
{
	position:relative;
	margin : 0 auto 15px auto;
	padding:0;
}
.formContent
{
	position:absolute;
	width:100%;
	height:100%;
}
.formBackground
{
  width:100%;
  height:100%;
  background-color:#fff;
  background-size:contain;
  background-position:top center;
  background-repeat:no-repeat;
}

div.text {
	font-family: Arial, sans-serif;
	font-size:14px;
	background-color:#E2F4FE;
	outline: 0;
	border:0;
	width:100%;
	height:20px;
	padding: 0;
	position:absolute;
}

#template_creator { float:right;background-color:#F9FAFB;border-right:1px solid #ECF0F1;width:250px;}

#template_builder_box_container { position:relative;height:100%;width:100%;padding-bottom:50px;overflow:auto; }
#template_builder_container {padding-bottom: 13px;border-bottom:1px dashed #ECF0F1;}

#textbox_item { cursor:pointer;font-size:12px;background-color:#E2F4FE;width:220px;padding:10px;color:#000;;font-weight:normal; }

#sm_textbox_item { cursor:pointer;font-size:12px;background-color:#E2F4FE;width:25px;padding:10px;color:#000;font-weight:normal; }
              
            
!

JS

              
                //
$.ui.ddmanager.prepareOffsets = function( t, event ) { var i, j, m = $.ui.ddmanager.droppables[ t.options.scope ] || [], type = event ? event.type : null, list = ( t.currentItem || t.element ).find( ":data(ui-droppable)" ).addBack(); droppablesLoop: for ( i = 0; i < m.length; i++ ) { if ( m[ i ].options.disabled || ( t && !m[ i ].accept.call( m[ i ].element[ 0 ], ( t.currentItem || t.element ) ) ) ) { continue; } for ( j = 0; j < list.length; j++ ) { if ( list[ j ] === m[ i ].element[ 0 ] ) { m[ i ].proportions().height = 0; continue droppablesLoop; }  } m[ i ].visible = m[ i ].element.css( "display" ) !== "none"; if ( !m[ i ].visible ) { continue; } if ( type === "mousedown" ) { m[ i ]._activate.call( m[ i ], event ); } m[ i ].offset = m[ i ].element.offset(); m[ i ].proportions({ width: m[ i ].element[ 0 ].offsetWidth * percent, height: m[ i ].element[ 0 ].offsetHeight * percent }); } };
//
function resizeFix(event, ui) { var changeWidth = ui.size.width - ui.originalSize.width, newWidth = ui.originalSize.width + changeWidth / percent, changeHeight = ui.size.height - ui.originalSize.height, newHeight = ui.originalSize.height + changeHeight / percent;  ui.size.width = newWidth; ui.size.height = newHeight; }
//
function dragFix(event, ui) { 
    var containmentArea = $("#documentPage_"+ui.helper.parent().parent().attr('id').replace(/^(\w+)_/, "")),
        contWidth = containmentArea.width(), contHeight = containmentArea.height();

    ui.position.left = Math.max(0, Math.min(ui.position.left / percent , contWidth - ui.helper.width()));
    ui.position.top = Math.max(0, Math.min(ui.position.top  / percent,  contHeight- ui.helper.height()));
}

var routerApp = angular.module('testing', ['ui.router', 'angular.filter', 'ui.sortable'])

//range on an empty array
.filter('range', function() {return function(input, total) {total = parseInt(total);for (var i=0; i<total; i++)input.push(i);return input; };})

.directive('resize', function($window) {
    return function(scope, element) {
      var w = angular.element($window);
      scope.getWindowDimensions = function() {
        return {
          'h': w.height(),
          'w': w.width()
        };
      };
      scope.$watch(scope.getWindowDimensions, function(newValue, oldValue) {
        scope.windowHeight = newValue.h;
        scope.windowWidth = newValue.w;
        scope.style = function(amount) {
          return {
            'height': (newValue.h - amount) + 'px',
            'width': (newValue.w - amount) + 'px'
          };
        };
        scope.height = function(amount) {
          return {
            'height': (newValue.h - amount) + 'px'
          };
        };
      }, true);
      w.bind('resize', function() {
        scope.$apply();
      });
    }
})

.directive('zoom', function ($window) {
    return function (scope, element) {
        var w = angular.element($window);
        scope.getWindowDimensions = function () { return { 'h': w.height(), 'w': w.width() }; };
        scope.$watch(scope.getWindowDimensions, function (newValue, oldValue) {
            scope.windowHeight = newValue.h;
            scope.windowWidth = newValue.w;
            var formBox = angular.element($("#formBox")), formScale = angular.element($("#formScale"));
            scope.formScale = function(pdfwidth) { percent = formBox.width() / pdfwidth; return { 'width': pdfwidth+'px', 'transform': 'scale(' + percent + ')', '-moz-transform': 'scale(' + percent + ')', '-webkit-transform': 'scale(' + percent + ')', '-ms-transform': 'scale(' + percent + ')' } };
            scope.trimSpace = function(pdfwidth) { percent = formBox.width() / pdfwidth; return { 'width': (pdfwidth * percent)+'px', 'height': (formScale.height() * percent)+'px'  } };
            scope.formBox = function(pdfwidth) { percent = formBox.width() / pdfwidth; return { 'height': (formScale.height() * percent)+'px'  } }
        }, true);
        w.bind('resize', function () { scope.$apply(); });
    }
})

.directive('draggableTypes', function() {
  return {
    restrict:'A',
    link: function(scope, element, attrs) {

      element.draggable({
        zIndex:3000, 
        appendTo: 'body', 
        helper: function(e, ui){ 
          var formBox = angular.element($("#formBox"));
          percent = formBox.width() / scope.templateData.pdf_width;

          if(element.attr('id') == 'textbox_item')
              return $('<div class="text" style="text-align:left;font-size:14px;width:200px;height:20px;line-height:20px;">New Text Box.</div>').css({ 'transform': 'scale(' + percent + ')', '-moz-transform': 'scale(' + percent + ')', '-webkit-transform': 'scale(' + percent + ')', '-ms-transform': 'scale(' + percent + ')'});
          if(element.attr('id') == 'sm_textbox_item')
              return $('<div class="text" style="text-align:left;font-size:14px;width:5px;height:5px;line-height:20px;"></div>').css({ 'transform': 'scale(' + percent + ')', '-moz-transform': 'scale(' + percent + ')', '-webkit-transform': 'scale(' + percent + ')', '-ms-transform': 'scale(' + percent + ')'});
        }
      });
    }
  };
})

.directive('textboxDraggable', function() {
  return {
    restrict:'A',
    link: function(scope, element, attrs) {
        element.draggable({ 
            cursor: "move",
            drag: dragFix,
            start: function(event, ui) {
                var activeId = element.attr('id');

                scope.activeElement.id = activeId;
                scope.activeElement.name = scope.templateItems[activeId].info.name;

                scope.$apply();
            }
        });
    }
  };
})

.directive('droppable', function($compile) {
  return {
    restrict: 'A',
    link: function(scope,element,attrs){
        element.droppable({
            drop:function(event,ui) {
                
                var draggable = angular.element(ui.draggable),
                    draggable_parent = draggable.parent().parent(),
                    drag_type = draggable.attr('id'),
                    documentBg = element,
                    x = ui.offset.left,
                    y = ui.offset.top,
                    element_top = (y - documentBg.offset().top - draggable.height() * (percent - 1) / 2) / percent,
                    element_left = (x - documentBg.offset().left - draggable.width() * (percent - 1) / 2) / percent,
                    timestamp = new Date().getTime();

                    //just get the document page of where the mouse is if its a new element
                    if(draggable_parent.attr('id') == 'template_builder_box_container' || draggable_parent.attr('id') == 'template_builder_container')
                        var documentPage = documentBg.parent().parent().attr('id').replace(/^(\w+)_/, "");
                    //if you are dragging an element that was already on the page, get parent of draggable and not parent of where mouse is
                    else var documentPage = draggable_parent.parent().parent().attr('id').replace(/^(\w+)_/, "");

                    if(drag_type == "textbox_item")
                    {
                        scope.activeElement.id = scope.templateItems.push({
                            info: {'page': documentPage,'name': 'textbox_'+timestamp, 'type': 'text'},
                            style: {'text-align':'left','font-size':'14px','top':element_top+'px','left':element_left+'px', 'width':'200px', 'height':'20px'}
                        }) - 1;

                        scope.activeElement.name = 'textbox_'+timestamp;
                    }
                    else if(drag_type == "sm_textbox_item")
                    {
                        scope.activeElement.id = scope.templateItems.push({
                            info: {'page': documentPage,'name': '', 'type': 'text'},
                            style: {'text-align':'left','font-size':'14px','top':element_top+'px','left':element_left+'px', 'width':'5px', 'height':'5px'}
                        }) - 1;

                        scope.activeElement.name = 'textbox_'+timestamp;
                    }

                scope.$apply();
            }
        });
    }
  };
})

.controller('testing', function($scope, $rootScope, $state, $stateParams) {
  
  $scope.templateItems = [];
  $scope.activeElement = { id: undefined, name: undefined };
    
  $scope.templateData = {"id":"12345", "max_pages":1,"pdf_width":385,"pdf_height":800};

  $scope.clickElement = function(index)   { $scope.activeElement = { id: index, name: $scope.templateItems[index].info.name } }

});
              
            
!
999px

Console