author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 18:35:50 +0200 | |
changeset 11 | bf1778c34b9a |
parent 7 | cf61fcea0001 |
permissions | -rwxr-xr-x |
5 | 1 |
/*! |
2 |
* postformats.js v1.0.1 |
|
3 |
*/ |
|
4 |
!function ($) { |
|
5 |
||
6 |
"use strict"; // jshint ;_; |
|
7 |
||
8 |
/* POSTFORMATS CLASS DEFINITION |
|
9 |
* ====================== */ |
|
10 |
var formats = "input.post-format" |
|
11 |
, metaboxes = [ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
12 |
'#ot-post-format-aside' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
, '#ot-post-format-audio' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
, '#ot-post-format-chat' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
, '#ot-post-format-gallery' |
5 | 16 |
, '#ot-post-format-image' |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
, '#ot-post-format-link' |
5 | 18 |
, '#ot-post-format-quote' |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
, '#ot-post-format-status' |
5 | 20 |
, '#ot-post-format-video' |
21 |
] |
|
22 |
, ids = metaboxes.join(',') |
|
23 |
, insertAfter = '#titlediv' |
|
24 |
, imageBox = '#postimagediv' |
|
25 |
, placeholder = 'postimagediv-placeholder' |
|
26 |
, Postformats = function (element, options) { |
|
27 |
this.$element = $(element) |
|
28 |
.on('click.postformats.data-api', $.proxy(this.toggle, this)) |
|
29 |
this.$id = this.$element.attr('id') |
|
30 |
this.init() |
|
31 |
} |
|
32 |
||
33 |
Postformats.prototype = { |
|
34 |
||
35 |
constructor: Postformats |
|
36 |
|
|
37 |
, init: function () { |
|
38 |
||
39 |
// Moves the metaboxes into place |
|
40 |
$( '#ot-' + this.$id ).insertAfter( $( insertAfter ) ).hide() |
|
41 |
|
|
42 |
// Show the checked metabox |
|
43 |
if ( this.$element.is(':checked') ) { |
|
44 |
|
|
45 |
this.show() |
|
46 |
|
|
47 |
} |
|
48 |
|
|
49 |
} |
|
50 |
|
|
51 |
, toggle: function () { |
|
52 |
||
53 |
// Hides all the post format metaboxes |
|
54 |
$(ids).each(function() { |
|
55 |
|
|
56 |
$(this).hide() |
|
57 |
|
|
58 |
}) |
|
59 |
|
|
60 |
// Shows the clicked post format metabox |
|
61 |
this.show() |
|
62 |
|
|
63 |
} |
|
64 |
|
|
65 |
, show: function () { |
|
66 |
|
|
67 |
// Featured image is never really hidden so it requires different code |
|
68 |
if ( this.$id == 'post-format-image' ) { |
|
69 |
|
|
70 |
if ( $( '#' + placeholder ).length == 0 ) |
|
71 |
$( imageBox ).after( '<div id="' + placeholder + '"></div>' ).insertAfter( insertAfter ).css({'marginTop':'20px','marginBottom':'0px'}).find('h3 span').text(option_tree.with) |
|
72 |
|
|
73 |
// Revert image |
|
74 |
} else { |
|
75 |
||
76 |
$( '#' + placeholder ).replaceWith( $( imageBox ).css({'marginTop':'0px','marginBottom':'20px'}) ) |
|
77 |
$( imageBox ).find('h3 span').text(option_tree.replace) |
|
78 |
|
|
79 |
} |
|
80 |
|
|
81 |
// Show the metabox |
|
82 |
$( '#ot-' + this.$id ).css({'marginTop':'20px','marginBottom':'0px'}).show() |
|
83 |
|
|
84 |
} |
|
85 |
|
|
86 |
} |
|
87 |
|
|
88 |
/* POSTFORMATS PLUGIN DEFINITION |
|
89 |
* ======================= */ |
|
90 |
var old = $.fn.postformats |
|
91 |
||
92 |
$.fn.postformats = function (option) { |
|
93 |
return this.each(function () { |
|
94 |
var $this = $(this) |
|
95 |
, data = $this.data('postformats') |
|
96 |
, options = typeof option == 'object' && option |
|
97 |
if (!data) $this.data('postformats', (data = new Postformats(this, options))) |
|
98 |
if (typeof option == 'string') data[option]() |
|
99 |
}) |
|
100 |
} |
|
101 |
||
102 |
$.fn.postformats.Constructor = Postformats |
|
103 |
|
|
104 |
/* POSTFORMATS NO CONFLICT |
|
105 |
* ================= */ |
|
106 |
$.fn.postformats.noConflict = function () { |
|
107 |
$.fn.postformats = old |
|
108 |
return this |
|
109 |
} |
|
110 |
||
111 |
/* POSTFORMATS DATA-API |
|
112 |
* ============== */ |
|
113 |
$(document).on('ready.postformats.data-api', function () { |
|
114 |
$(formats).each(function () { |
|
115 |
$(this).postformats() |
|
116 |
}) |
|
117 |
}) |
|
118 |
||
119 |
}(window.jQuery); |