Adwords Ad Preview #3

by joplomacedo

HTML

<div class="adEditor">
    <label for="" class="fieldSection">
        <span class="fieldLabel">Headline</span>
        <span class="fieldWrapper">
            <input type="text" class="headlineField field" data-target="headline" maxlength=25 />
        </span>
    </label>
    
    <label for="" class="fieldSection">
        <span class="fieldLabel">Display URL</span>
        <span class="fieldWrapper">
            <input type="text" class="displayURLField field" data-target="displayURL" maxlength=35 />
        </span>
    </label>
    
    <label for="" class="fieldSection">
        <span class="fieldLabel">Line 1</span>
        <span class="fieldWrapper">
            <input type="text" class="descLine1Field field" data-target="descLine1" maxlength=35 />
        </span>
    </label>
    
    <label for="" class="fieldSection">
        <span class="fieldLabel">Line 2</span>
        <span class="fieldWrapper">
            <input type="text" class="descLine2Field field" data-target="descLine2" maxlength=35 />
        </span>
    </label>
</div>


<div class="adPreviewSection">
    <p class="adPreviewSectionHeadline">Preview</p>
    
    <div class="ad">
        <p class="headline line" data-id="headline"></p>
        <p class="displayURL line" data-id="displayURL"></p> 
        <p class="descLine1 descLine line" data-id="descLine1"></p>
        <p class="descLine2 descLine line" data-id="descLine2"></p>   
    </div>
</div>

CSS

* {
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    outline: none;
}

body {
    font-family: helvetica, arial, sans-serif;
    font-size: 14px;
    width: 350px;
    margin: 53px auto;
}

.adEditor {
    margin-bottom: 4em;
}

.fieldSection,
.fieldLabel,
.fieldWrapper,
.field {
    display: block;
}

.fieldSection {
    margin-bottom: 1.3em;
}

.fieldLabel {
    margin-bottom: .1em;
    font-weight: 600;
    font-size: .9em;
}

.field {
    width: 100%;
    border: 1px solid #555;
    padding: .4em;
    color: #616161;
}

.field:focus {
    border-color: #3998CE;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
}

.adPreviewSection {
    border: 1px solid;
}

.adPreviewSectionHeadline {
    font-weight: 600;
    padding: 1em;
    background: #EEE;
    border-bottom: 1px solid;
}

.ad {
    padding: 3em 2em 3.5em;
    line-height: 18px;
    background-color: #fff;
}

.headline {
    font-size: 18px;
    color: #1A0DAB;
    cursor: pointer;
}

.headline:hover {
    text-decoration: underline;
}

.displayURL {
    color: #006621;
    font-size: 13px;
}

.descLine {
    color: #545454;
    font-size: 13px;
}

.line:before {
    display: inline-block;
    content: 'p';
    color: transparent;
    width: 0;
    overflow: hidden;
    vertical-align: top;
}

JavaScript

$('.adEditor .field').on('keydown', function (e) {
    var $field = $(e.target),
        val,
        target = $field.data('target'),
        $target = $('[data-id=' + target + ']');
    
    setTimeout(function () {
        val = $field.val();
        $target.text(val);
    }, 25);
});