PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / trunk
Secure Custom Fields vtrunk
6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / assets / src / js / _acf-notice.js
secure-custom-fields / assets / src / js Last commit date
bindings 6 months ago commands 1 week ago pro 1 week ago _acf-compatibility.js 1 year ago _acf-condition-types.js 7 months ago _acf-condition.js 1 year ago _acf-conditions.js 1 year ago _acf-field-accordion.js 6 months ago _acf-field-button-group.js 7 months ago _acf-field-checkbox.js 1 month ago _acf-field-color-picker.js 7 months ago _acf-field-date-picker.js 1 month ago _acf-field-date-time-picker.js 1 month ago _acf-field-file.js 1 month ago _acf-field-google-map.js 6 months ago _acf-field-icon-picker.js 1 month ago _acf-field-image.js 1 month ago _acf-field-link.js 1 year ago _acf-field-oembed.js 1 month ago _acf-field-page-link.js 1 year ago _acf-field-post-object.js 1 year ago _acf-field-radio.js 1 month ago _acf-field-range.js 1 year ago _acf-field-relationship.js 1 month ago _acf-field-select.js 1 month ago _acf-field-tab.js 3 weeks ago _acf-field-taxonomy.js 7 months ago _acf-field-time-picker.js 1 month ago _acf-field-true-false.js 1 month ago _acf-field-url.js 1 year ago _acf-field-user.js 1 year ago _acf-field-wysiwyg.js 1 month ago _acf-field.js 1 year ago _acf-fields.js 1 year ago _acf-helpers.js 1 year ago _acf-hooks.js 1 year ago _acf-internal-post-type.js 7 months ago _acf-media.js 1 week ago _acf-modal.js 1 year ago _acf-model.js 1 year ago _acf-notice.js 7 months ago _acf-panel.js 1 year ago _acf-popup.js 7 months ago _acf-postbox.js 1 year ago _acf-screen.js 10 months ago _acf-select2.js 1 year ago _acf-tinymce.js 6 months ago _acf-tooltip.js 10 months ago _acf-unload.js 1 year ago _acf-validation.js 1 month ago _acf.js 7 months ago _browse-fields-modal.js 7 months ago _field-group-compatibility.js 1 year ago _field-group-conditions.js 1 year ago _field-group-field.js 3 months ago _field-group-fields.js 10 months ago _field-group-locations.js 1 year ago _field-group-settings.js 1 year ago _field-group.js 10 months ago acf-escaped-html-notice.js 1 year ago acf-field-group.js 1 year ago acf-input.js 1 year ago acf-internal-post-type.js 1 year ago acf.js 1 year ago
_acf-notice.js
180 lines
1 ( function ( $, undefined ) {
2 var Notice = acf.Model.extend( {
3 data: {
4 text: '',
5 type: '',
6 timeout: 0,
7 dismiss: true,
8 target: false,
9 location: 'before',
10 close: function () {},
11 },
12
13 events: {
14 'click .acf-notice-dismiss': 'onClickClose',
15 },
16
17 tmpl: function () {
18 return '<div class="acf-notice"></div>';
19 },
20
21 setup: function ( props ) {
22 $.extend( this.data, props );
23 this.$el = $( this.tmpl() );
24 },
25
26 initialize: function () {
27 // render
28 this.render();
29
30 // show
31 this.show();
32 },
33
34 render: function () {
35 // class
36 this.type( this.get( 'type' ) );
37
38 // text
39 this.html( '<p>' + acf.escHtml( this.get( 'text' ) ) + '</p>' );
40
41 // close
42 if ( this.get( 'dismiss' ) ) {
43 this.$el.append(
44 '<a href="#" class="acf-notice-dismiss acf-icon -cancel small"></a>'
45 );
46 this.$el.addClass( '-dismiss' );
47 }
48
49 // timeout
50 var timeout = this.get( 'timeout' );
51 if ( timeout ) {
52 this.away( timeout );
53 }
54 },
55
56 update: function ( props ) {
57 // update
58 $.extend( this.data, props );
59
60 // re-initialize
61 this.initialize();
62
63 // refresh events
64 this.removeEvents();
65 this.addEvents();
66 },
67
68 show: function () {
69 var $target = this.get( 'target' );
70 var location = this.get( 'location' );
71 if ( $target ) {
72 if ( location === 'after' ) {
73 $target.append( this.$el );
74 } else {
75 $target.prepend( this.$el );
76 }
77 }
78 },
79
80 hide: function () {
81 this.$el.remove();
82 },
83
84 away: function ( timeout ) {
85 this.setTimeout( function () {
86 acf.remove( this.$el );
87 }, timeout );
88 },
89
90 type: function ( type ) {
91 // remove prev type
92 var prevType = this.get( 'type' );
93 if ( prevType ) {
94 this.$el.removeClass( '-' + prevType );
95 }
96
97 // add new type
98 this.$el.addClass( '-' + type );
99
100 // backwards compatibility
101 if ( type == 'error' ) {
102 this.$el.addClass( 'acf-error-message' );
103 }
104 },
105
106 html: function ( html ) {
107 this.$el.html( acf.escHtml( html ) );
108 },
109
110 text: function ( text ) {
111 this.$( 'p' ).html( acf.escHtml( text ) );
112 },
113
114 onClickClose: function ( e, $el ) {
115 e.preventDefault();
116 this.get( 'close' ).apply( this, arguments );
117 this.remove();
118 },
119 } );
120
121 acf.newNotice = function ( props ) {
122 // ensure object
123 if ( typeof props !== 'object' ) {
124 props = { text: props };
125 }
126
127 // instantiate
128 return new Notice( props );
129 };
130
131 var noticeManager = new acf.Model( {
132 wait: 'prepare',
133 priority: 1,
134 initialize: function () {
135 const $notices = $( '.acf-admin-notice' );
136 if ( ! $notices.length ) {
137 return;
138 }
139 $notices.each( function () {
140 if ( $( this ).data( 'persisted' ) ) {
141 let dismissed = acf.getPreference( 'dismissed-notices' );
142
143 if (
144 dismissed &&
145 typeof dismissed == 'object' &&
146 dismissed.includes( $( this ).data( 'persist-id' ) )
147 ) {
148 $( this ).remove();
149 } else {
150 $( this ).show();
151 $( this ).on(
152 'click',
153 '.notice-dismiss',
154 function ( e ) {
155 dismissed =
156 acf.getPreference( 'dismissed-notices' );
157 if (
158 ! dismissed ||
159 typeof dismissed != 'object'
160 ) {
161 dismissed = [];
162 }
163 dismissed.push(
164 $( this )
165 .closest( '.acf-admin-notice' )
166 .data( 'persist-id' )
167 );
168 acf.setPreference(
169 'dismissed-notices',
170 dismissed
171 );
172 }
173 );
174 }
175 }
176 } );
177 },
178 } );
179 } )( jQuery );
180