| @@ -1,134 +1,134 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * Template new item section. | |
| 5 | - * | |
| 6 | - * @since 3.0.0 | |
| 7 | - */ | |
| 8 | - | |
| 9 | -?> | |
| 10 | - | |
| 11 | -<script type="text/x-template" id="tmpl-lp-new-section-item"> | |
| 12 | - <div class="new-section-item section-item" @keyup.up="up" @keyup.down="down" :class="{choosing: choosingType}"> | |
| 13 | - <div class="drag lp-sortable-handle"></div> | |
| 14 | - <div class="types" @mouseleave="mouseLeave" @mouseover="mouseOver"> | |
| 15 | - <template v-for="(_type, key) in types"> | |
| 16 | - <label class="type" :title="_type" :class="[key, {current: (type==key)}]"> | |
| 17 | - <input v-model="type" type="radio" name="lp-section-item-type" :value="key"> | |
| 18 | - </label> | |
| 19 | - </template> | |
| 20 | - </div> | |
| 21 | - <div class="title"> | |
| 22 | - <input type="text" :placeholder="placeholderInput" @keyup.enter="createItem($event)" @blur="createItem($event)" v-model="title"> | |
| 23 | - </div> | |
| 24 | - </div> | |
| 25 | -</script> | |
| 26 | - | |
| 27 | -<script type="text/javascript"> | |
| 28 | - window.$Vue = window.$Vue || Vue; | |
| 29 | - | |
| 30 | - jQuery( function( $ ) { | |
| 31 | - ( function( $store ) { | |
| 32 | - $Vue.component( 'lp-new-section-item', { | |
| 33 | - template: '#tmpl-lp-new-section-item', | |
| 34 | - props: [], | |
| 35 | - data: function() { | |
| 36 | - return { | |
| 37 | - type: '', | |
| 38 | - title: '', | |
| 39 | - choosingType: false | |
| 40 | - }; | |
| 41 | - }, | |
| 42 | - created: function() { | |
| 43 | - this.type = this.firstType; | |
| 44 | - }, | |
| 45 | - methods: { | |
| 46 | - up: function( e ) { | |
| 47 | - this.changeType(true); | |
| 48 | - }, | |
| 49 | - down: function( e ) { | |
| 50 | - this.changeType(false); | |
| 51 | - }, | |
| 52 | - mouseOver: function() { | |
| 53 | - this.choosingType = true; | |
| 54 | - }, | |
| 55 | - mouseLeave: function() { | |
| 56 | - this.choosingType = false; | |
| 57 | - }, | |
| 58 | - create: function() { | |
| 59 | - if (!this.title) { | |
| 60 | - return; | |
| 61 | - } | |
| 62 | - this.$emit( 'create', { | |
| 63 | - id: LP.uniqueId(), | |
| 64 | - type: this.type, | |
| 65 | - title: this.title | |
| 66 | - }); | |
| 67 | - this.title = ''; | |
| 68 | - }, | |
| 69 | - createItem: function( e ) { | |
| 70 | - if ( ! this.title ) { | |
| 71 | - return; | |
| 72 | - } | |
| 73 | - | |
| 74 | - if ( e.key === 'Enter' ) { | |
| 75 | - return this.create(); | |
| 76 | - } | |
| 77 | - | |
| 78 | - setTimeout(this.create, 300); | |
| 79 | - }, | |
| 80 | - changeType: function (next) { | |
| 81 | - if ( this.title ) { | |
| 82 | - return; | |
| 83 | - } | |
| 84 | - | |
| 85 | - var types = this.types; | |
| 86 | - var current = this.type; | |
| 87 | - var currentIndex = false; | |
| 88 | - | |
| 89 | - var keys = []; | |
| 90 | - var i = 0; | |
| 91 | - for ( var type in types ) { | |
| 92 | - if ( type === current ) { | |
| 93 | - currentIndex = i; | |
| 94 | - } | |
| 95 | - | |
| 96 | - keys.push( type ); | |
| 97 | - i++; | |
| 98 | - } | |
| 99 | - | |
| 100 | - var nextType = keys[currentIndex + 1] || keys[0]; | |
| 101 | - var previousType = keys[currentIndex - 1] || keys[keys.length - 1]; | |
| 102 | - | |
| 103 | - if ( next ) { | |
| 104 | - this.type = nextType; | |
| 105 | - } else { | |
| 106 | - this.type = previousType; | |
| 107 | - } | |
| 108 | - | |
| 109 | - } | |
| 110 | - }, | |
| 111 | - computed: { | |
| 112 | - placeholderInput: function( e ) { | |
| 113 | - var i18n = $store.getters['i18n/all']; | |
| 114 | - var type = this.types[this.type] || ''; | |
| 115 | - | |
| 116 | - $( this.$el ).find( '.title input' ).focus(); | |
| 117 | - return i18n.new_section_item + ' ' + type.toLowerCase(); | |
| 118 | - }, | |
| 119 | - | |
| 120 | - types: function() { | |
| 121 | - return $store.getters['ci/types']; | |
| 122 | - }, | |
| 123 | - firstType: function() { | |
| 124 | - for ( var type in $store.getters['ci/types'] ) { | |
| 125 | - return type; | |
| 126 | - } | |
| 127 | - | |
| 128 | - return false; | |
| 129 | - } | |
| 130 | - } | |
| 131 | - }); | |
| 132 | - })( LP_Curriculum_Store ); | |
| 133 | - }); | |
| 134 | -</script> | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Template new item section. | |
| 5 | + * | |
| 6 | + * @since 3.0.0 | |
| 7 | + */ | |
| 8 | + | |
| 9 | +?> | |
| 10 | + | |
| 11 | +<script type="text/x-template" id="tmpl-lp-new-section-item"> | |
| 12 | + <div class="new-section-item section-item" @keyup.up="up" @keyup.down="down" :class="{choosing: choosingType}"> | |
| 13 | + <div class="drag lp-sortable-handle"></div> | |
| 14 | + <div class="types" @mouseleave="mouseLeave" @mouseover="mouseOver"> | |
| 15 | + <template v-for="(_type, key) in types"> | |
| 16 | + <label class="type" :title="_type" :class="[key, {current: (type==key)}]"> | |
| 17 | + <input v-model="type" type="radio" name="lp-section-item-type" :value="key"> | |
| 18 | + </label> | |
| 19 | + </template> | |
| 20 | + </div> | |
| 21 | + <div class="title"> | |
| 22 | + <input type="text" :placeholder="placeholderInput" @keyup.enter="createItem($event)" @blur="createItem($event)" v-model="title"> | |
| 23 | + </div> | |
| 24 | + </div> | |
| 25 | +</script> | |
| 26 | + | |
| 27 | +<script type="text/javascript"> | |
| 28 | + window.$Vue = window.$Vue || Vue; | |
| 29 | + | |
| 30 | + jQuery( function( $ ) { | |
| 31 | + ( function( $store ) { | |
| 32 | + $Vue.component( 'lp-new-section-item', { | |
| 33 | + template: '#tmpl-lp-new-section-item', | |
| 34 | + props: [], | |
| 35 | + data: function() { | |
| 36 | + return { | |
| 37 | + type: '', | |
| 38 | + title: '', | |
| 39 | + choosingType: false | |
| 40 | + }; | |
| 41 | + }, | |
| 42 | + created: function() { | |
| 43 | + this.type = this.firstType; | |
| 44 | + }, | |
| 45 | + methods: { | |
| 46 | + up: function( e ) { | |
| 47 | + this.changeType(true); | |
| 48 | + }, | |
| 49 | + down: function( e ) { | |
| 50 | + this.changeType(false); | |
| 51 | + }, | |
| 52 | + mouseOver: function() { | |
| 53 | + this.choosingType = true; | |
| 54 | + }, | |
| 55 | + mouseLeave: function() { | |
| 56 | + this.choosingType = false; | |
| 57 | + }, | |
| 58 | + create: function() { | |
| 59 | + if (!this.title) { | |
| 60 | + return; | |
| 61 | + } | |
| 62 | + this.$emit( 'create', { | |
| 63 | + id: LP.uniqueId(), | |
| 64 | + type: this.type, | |
| 65 | + title: this.title | |
| 66 | + }); | |
| 67 | + this.title = ''; | |
| 68 | + }, | |
| 69 | + createItem: function( e ) { | |
| 70 | + if ( ! this.title ) { | |
| 71 | + return; | |
| 72 | + } | |
| 73 | + | |
| 74 | + if ( e.key === 'Enter' ) { | |
| 75 | + return this.create(); | |
| 76 | + } | |
| 77 | + | |
| 78 | + setTimeout(this.create, 300); | |
| 79 | + }, | |
| 80 | + changeType: function (next) { | |
| 81 | + if ( this.title ) { | |
| 82 | + return; | |
| 83 | + } | |
| 84 | + | |
| 85 | + var types = this.types; | |
| 86 | + var current = this.type; | |
| 87 | + var currentIndex = false; | |
| 88 | + | |
| 89 | + var keys = []; | |
| 90 | + var i = 0; | |
| 91 | + for ( var type in types ) { | |
| 92 | + if ( type === current ) { | |
| 93 | + currentIndex = i; | |
| 94 | + } | |
| 95 | + | |
| 96 | + keys.push( type ); | |
| 97 | + i++; | |
| 98 | + } | |
| 99 | + | |
| 100 | + var nextType = keys[currentIndex + 1] || keys[0]; | |
| 101 | + var previousType = keys[currentIndex - 1] || keys[keys.length - 1]; | |
| 102 | + | |
| 103 | + if ( next ) { | |
| 104 | + this.type = nextType; | |
| 105 | + } else { | |
| 106 | + this.type = previousType; | |
| 107 | + } | |
| 108 | + | |
| 109 | + } | |
| 110 | + }, | |
| 111 | + computed: { | |
| 112 | + placeholderInput: function( e ) { | |
| 113 | + var i18n = $store.getters['i18n/all']; | |
| 114 | + var type = this.types[this.type] || ''; | |
| 115 | + | |
| 116 | + $( this.$el ).find( '.title input' ).focus(); | |
| 117 | + return i18n.new_section_item + ' ' + type.toLowerCase(); | |
| 118 | + }, | |
| 119 | + | |
| 120 | + types: function() { | |
| 121 | + return $store.getters['ci/types']; | |
| 122 | + }, | |
| 123 | + firstType: function() { | |
| 124 | + for ( var type in $store.getters['ci/types'] ) { | |
| 125 | + return type; | |
| 126 | + } | |
| 127 | + | |
| 128 | + return false; | |
| 129 | + } | |
| 130 | + } | |
| 131 | + }); | |
| 132 | + })( LP_Curriculum_Store ); | |
| 133 | + }); | |
| 134 | +</script> | |